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