dengzedong
3 天以前 07890ec0dcb75572740f25a29c80f6d7bddb39e0
提交 | 用户 | 时间
45520a 1 package com.iailab.module.model.mdk.sample;
D 2
07890e 3 import com.iailab.module.data.api.point.DataPointApi;
D 4 import com.iailab.module.data.api.point.dto.ApiPointDTO;
5 import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity;
45520a 6 import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity;
D 7 import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService;
07890e 8 import com.iailab.module.model.mdk.common.enums.ModelParamType;
45520a 9 import com.iailab.module.model.mdk.sample.dto.ColumnItem;
D 10 import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Component;
13 import org.springframework.util.CollectionUtils;
14
15 import java.util.ArrayList;
16 import java.util.Date;
17 import java.util.List;
07890e 18 import java.util.Map;
D 19 import java.util.function.Function;
20 import java.util.stream.Collectors;
45520a 21
D 22 @Component
23 public class ScheduleSampleInfoConstructor extends SampleInfoConstructor {
24
25     @Autowired
26     private StScheduleModelParamService stScheduleModelParamService;
07890e 27
D 28     @Autowired
29     private DataPointApi dataPointApi;
45520a 30
D 31     @Override
32     protected Integer getSampleColumn(String modelId) {
33         return null;
34     }
35
36     @Override
37     protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) {
38         List<ColumnItemPort> resultList = new ArrayList<>();
39         List<ColumnItem> columnItemList = new ArrayList<>();
40         ColumnItem columnInfo = new ColumnItem();
41         ColumnItemPort curPort = new ColumnItemPort();  //当前端口
42         List<StScheduleModelParamEntity> modelInputParamEntityList = stScheduleModelParamService.getByModelidFromCache(modelId);
43         if (CollectionUtils.isEmpty(modelInputParamEntityList)) {
44             return null;
45         }
46         //设置当前端口号,初始值为最小端口(查询结果按端口号从小到达排列)
47         int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder();
48         //设置当前查询数据长度,初始值为最小端口数据长度
49         int curDataLength = modelInputParamEntityList.get(0).getDatalength();
07890e 50         // 统一获取测点的信息
D 51         List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toList());
52         List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
53         Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity()));
54
45520a 55         for (StScheduleModelParamEntity entry : modelInputParamEntityList) {
D 56             columnInfo.setParamType(entry.getModelparamtype());
57             columnInfo.setParamId(entry.getModelparamid());
58             columnInfo.setDataLength(entry.getDatalength());
59             columnInfo.setModelParamOrder(entry.getModelparamorder());
60             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
07890e 61             columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap));
D 62             columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap));
45520a 63             columnInfo.setGranularity(super.getGranularity(columnInfo));
D 64
65             //对每一个爪进行数据项归并
66             if (curPortOrder != entry.getModelparamportorder()){
67                 //当数据项端口号不为当前端口号时,封装上一个端口类,操作下一个端口类
68                 curPort.setColumnItemList(columnItemList);
69                 curPort.setDataLength(curDataLength);
70                 curPort.setPortOrder(curPortOrder);
71                 resultList.add(curPort);
72                 curPort = new ColumnItemPort(); //对象重新初始化,防止引用拷贝导致数据覆盖
73                 //封装上一个端口类后更新当前的各个参数
74                 columnItemList = new ArrayList<>();
75                 curDataLength = entry.getDatalength();
76                 curPortOrder = entry.getModelparamportorder();
77             }
78             columnItemList.add(columnInfo);
79             columnInfo = new ColumnItem();    //对象重新初始化,防止引用拷贝导致数据覆盖
80         }
81         //当迭代到最后一个项的时候,封装最后一个端口的信息
82         curPort.setColumnItemList(columnItemList);
83         curPort.setDataLength(curDataLength);
84         curPort.setPortOrder(curPortOrder);
85         resultList.add(curPort);
86         return resultList;
87     }
88
89     @Override
90     protected Integer getSampleCycle(String modelId) {
91         return null;
92     }
93
94 }