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