dengzedong
2025-02-20 1ab11991a6bc2b0496c83cb969b0f5bc6f22a309
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java
@@ -1,9 +1,12 @@
package com.iailab.module.model.mdk.sample;
import com.iailab.module.data.api.ind.IndItemApi;
import com.iailab.module.data.api.ind.dto.ApiIndItemDTO;
import com.iailab.module.data.api.plan.PlanItemApi;
import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
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;
@@ -30,13 +33,16 @@
    @Autowired
    private PlanItemApi planItemApi;
    @Autowired
    private IndItemApi indItemApi;
    @Override
    protected Integer getSampleColumn(String modelId) {
        return null;
    }
    @Override
    protected SampleInfo getColumnInfo(String modelId, Date predictTime) {
    protected SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength) {
        SampleInfo sampleInfo = new SampleInfo();
        List<ColumnItemPort> resultList = new ArrayList<>();
        List<ColumnItem> columnItemList = new ArrayList<>();
@@ -49,7 +55,7 @@
        //设置当前端口号,初始值为最小端口(查询结果按端口号从小到达排列)
        int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder();
        //设置当前查询数据长度,初始值为最小端口数据长度
        int curDataLength = modelInputParamEntityList.get(0).getDatalength();
        int curDataLength = super.getDataLength(dynamicDataLength, curPortOrder, modelInputParamEntityList.get(0).getDatalength());
        // 统一获取测点的信息
        Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet());
        List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
@@ -57,20 +63,24 @@
        // 统一获取计划数据的信息
        Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet());
        List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds);
        Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1));
        Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1, e2) -> e1));
        // 统一获取指标数据的信息
        Set<String> indIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND) || ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND_ASCII)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet());
        List<ApiIndItemDTO> inds = indItemApi.getInfoByIds(indIds);
        Map<String, ApiIndItemDTO> indMap = inds.stream().collect(Collectors.toMap(ApiIndItemDTO::getId, Function.identity(), (e1, e2) -> e1));
        for (StScheduleModelParamEntity entry : modelInputParamEntityList) {
            columnInfo.setParamType(entry.getModelparamtype());
            columnInfo.setParamId(entry.getModelparamid());
            columnInfo.setDataLength(entry.getDatalength());
            columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength()));
            columnInfo.setModelParamOrder(entry.getModelparamorder());
            columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap));
            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap));
            columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap));
            columnInfo.setGranularity(super.getGranularity(columnInfo, pointMap, planMap,indMap));
            columnInfo.setStartTime(getStartTime(columnInfo, predictTime));
            columnInfo.setEndTime(getEndTime(columnInfo, predictTime));
            //对每一个爪进行数据项归并
            if (curPortOrder != entry.getModelparamportorder()){
            if (curPortOrder != entry.getModelparamportorder()) {
                //当数据项端口号不为当前端口号时,封装上一个端口类,操作下一个端口类
                curPort.setColumnItemList(columnItemList);
                curPort.setDataLength(curDataLength);
@@ -79,7 +89,7 @@
                curPort = new ColumnItemPort(); //对象重新初始化,防止引用拷贝导致数据覆盖
                //封装上一个端口类后更新当前的各个参数
                columnItemList = new ArrayList<>();
                curDataLength = entry.getDatalength();
                curDataLength = super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength());
                curPortOrder = entry.getModelparamportorder();
            }
            columnItemList.add(columnInfo);
@@ -93,6 +103,7 @@
        sampleInfo.setColumnInfo(resultList);
        sampleInfo.setPointMap(pointMap);
        sampleInfo.setPlanMap(planMap);
        sampleInfo.setIndMap(indMap);
        return sampleInfo;
    }
@@ -101,4 +112,5 @@
        return null;
    }
}