From 50084de4a140dece61019b64fd91df041d242e47 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期一, 23 十二月 2024 15:28:53 +0800 Subject: [PATCH] getInfoByIds(Set<String> pointIds) 模型输入计划数据获取、补全 模型输入mergeitem存默认生成的outputid sampleInfo.setPointMap 避免重复查询point --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java | 9 ++- iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java | 4 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java | 49 +++++++++++++--- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java | 15 ++-- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java | 4 + iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java | 2 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java | 17 +++-- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java | 12 +--- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java | 5 + iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java | 18 +++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java | 2 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java | 10 +-- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java | 12 ++-- 13 files changed, 103 insertions(+), 56 deletions(-) diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java index 6a8c3f5..98ab9d3 100644 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java @@ -7,9 +7,9 @@ import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; -import javax.annotation.security.PermitAll; import java.util.List; import java.util.Map; +import java.util.Set; /** * @author PanZhibao @@ -32,7 +32,7 @@ @PostMapping(PREFIX + "/info/ids") @Operation(summary = "根据多个测点ID查询测点信息") - List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") List<String> pointIds); + List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") Set<String> pointIds); @PostMapping(PREFIX + "/query-points/real-value") @Operation(summary = "查询多个测点当前值") diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java index d57f185..74744b1 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java @@ -42,7 +42,7 @@ } @Override - public List<ApiPointDTO> getInfoByIds(List<String> pointIds) { + public List<ApiPointDTO> getInfoByIds(Set<String> pointIds) { List<ApiPointDTO> result = new ArrayList<>(pointIds.size()); for (String pointId : pointIds) { result.add(daPointService.getSimpleInfoById(pointId)); diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java index d9bfcc7..ee15741 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java @@ -29,12 +29,12 @@ */ public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { Map<String, List<DataValueVO>> resultMap = new HashMap<>(); - List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); - - if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { - resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); - return resultMap; - } +// List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); +// +// if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { +// resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); +// return resultMap; +// } Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); HashMap<String,List<DataValueVO>> predictLists = new HashMap<>(); for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java index 025ce4e..3aae6ce 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java @@ -1,5 +1,6 @@ package com.iailab.module.model.mdk.predict.impl; +import com.iailab.module.model.common.exception.ModelResultErrorException; import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; import com.iailab.module.model.mcs.pre.service.MmPredictModelService; @@ -39,7 +40,7 @@ * @throws ItemInvokeException */ @Override - public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException { + public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException,ModelResultErrorException { PredictResultVO predictResult = new PredictResultVO(); String itemId = predictItemDto.getId(); try { @@ -50,6 +51,8 @@ } predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName()); predictResult.setPredictId(itemId); + } catch (ModelResultErrorException ex) { + throw ex; } catch (Exception ex) { throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", ItemInvokeException.errorItemFailed, itemId)); diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java index 19c8582..c66d887 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java @@ -64,7 +64,7 @@ } String modelId = predictModel.getId(); try { - List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime); + List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName); String modelPath = predictModel.getModelpath(); if (modelPath == null) { log.info("模型路径不存在,modelId=" + modelId); @@ -143,9 +143,12 @@ result.setPredictDoubleValues(predictDoubleValues); result.setModelResult(modelResult); result.setPredictTime(predictTime); - } catch (Exception ex) { - log.error("调用发生异常,异常信息为:{}", ex); + } catch (ModelResultErrorException ex) { ex.printStackTrace(); + throw ex; + } catch (Exception ex) { + log.error("调用发生异常,异常信息为:{1}", ex); +// ex.printStackTrace(); throw new ModelInvokeException(ex.getMessage()); } return result; diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java index dc0ff35..9cb12d7 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java @@ -1,9 +1,12 @@ package com.iailab.module.model.mdk.sample; +import com.iailab.module.data.api.plan.PlanItemApi; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.data.api.point.dto.ApiPointDTO; import com.iailab.module.data.api.point.dto.ApiPointValueDTO; import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; +import com.iailab.module.data.common.ApiDataQueryDTO; +import com.iailab.module.data.common.ApiDataValueDTO; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.service.MmItemOutputService; import com.iailab.module.model.mcs.pre.service.MmItemResultService; @@ -14,18 +17,20 @@ import com.iailab.module.model.mdk.sample.dto.SampleData; import com.iailab.module.model.mdk.sample.dto.SampleInfo; import com.iailab.module.model.mdk.vo.DataValueVO; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; -import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * 预测样本数据构造 */ +@Slf4j @Component public class PredictSampleDataConstructor extends SampleDataConstructor { @@ -33,6 +38,9 @@ @Autowired private DataPointApi dataPointApi; + + @Autowired + private PlanItemApi planItemApi; @Autowired private MmItemResultService mmItemResultService; @@ -51,8 +59,9 @@ * @return */ @Override - public List<SampleData> prepareSampleData(SampleInfo sampleInfo) { + public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { List<SampleData> sampleDataList = new ArrayList<>(); + Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); //对每个爪分别进行计算 for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 @@ -74,7 +83,7 @@ //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 for (int i = 0; i < entry.getColumnItemList().size(); i++) { try { - List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i)); + List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap); //补全数据 ColumnItem columnItem = entry.getColumnItemList().get(i); dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, @@ -89,6 +98,7 @@ } } catch (Exception e) { e.printStackTrace(); + throw e; } } SampleData sampleData = new SampleData(); @@ -102,20 +112,23 @@ * getData * * @param columnItem + * @param pointMap * @return * @throws Exception */ - private List<DataValueVO> getData(ColumnItem columnItem) throws Exception { + private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap) throws Exception { List<DataValueVO> dataList = new ArrayList<>(); String paramType = columnItem.getParamType(); switch (ModelParamType.getEumByCode(paramType)) { case DATAPOINT: - ApiPointDTO point = dataPointApi.getInfoById(columnItem.getParamId()); ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); - queryDto.setPointNo(point.getPointNo()); + queryDto.setPointNo(pointMap.get(columnItem.getParamId()).getPointNo()); queryDto.setStart(columnItem.getStartTime()); queryDto.setEnd(columnItem.getEndTime()); List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto); + if (CollectionUtils.isEmpty(pointValueList)) { + break; + } dataList = pointValueList.stream().map(t -> { DataValueVO vo = new DataValueVO(); vo.setDataTime(t.getT()); @@ -126,15 +139,31 @@ case NORMALITEM: case MERGEITEM: MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getParamId()); - dataList = mmItemResultService.getPredictValue(outPut.getId(), - columnItem.getStartTime(), columnItem.getEndTime()); - if (dataList == null) { - throw new Exception("没有预测值"); + List<DataValueVO> predictValue = mmItemResultService.getPredictValue(outPut.getId(), columnItem.getStartTime(), columnItem.getEndTime()); + if (CollectionUtils.isEmpty(predictValue)) { + break; } + dataList = predictValue; break; + case PLAN: + ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO(); + queryPlanItemDto.setItemNo(columnItem.getParamId()); + queryPlanItemDto.setStart(columnItem.getStartTime()); + queryPlanItemDto.setEnd(columnItem.getEndTime()); + List<ApiDataValueDTO> planValueList = planItemApi.queryPlanItemHistoryValue(queryPlanItemDto); + if (CollectionUtils.isEmpty(planValueList)) { + break; + } + dataList = planValueList.stream().map(t -> { + DataValueVO vo = new DataValueVO(); + vo.setDataTime(t.getDataTime()); + vo.setDataValue(t.getDataValue()); + return vo; + }).collect(Collectors.toList()); default: break; } + log.info("数据获取,columnItem:" + columnItem + ",dataList" + dataList); return dataList; } } diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java index 0be1977..c79b974 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java @@ -9,14 +9,12 @@ 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 com.iailab.module.model.mdk.sample.dto.SampleInfo; 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.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -59,7 +57,8 @@ * @return */ @Override - protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) { + protected SampleInfo getColumnInfo(String modelId, Date predictTime) { + SampleInfo sampleInfo = new SampleInfo(); List<ColumnItemPort> resultList = new ArrayList<>(); List<ColumnItem> columnItemList = new ArrayList<>(); ColumnItem columnInfo = new ColumnItem(); @@ -73,9 +72,9 @@ //设置当前查询数据长度,初始值为最小端口数据长度 int curDataLength = modelInputParamEntityList.get(0).getDatalength(); // 统一获取测点的信息 - List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toList()); + Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); - Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); + Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1,e2) -> e1)); for (MmModelParamEntity entry : modelInputParamEntityList) { columnInfo.setParamType(entry.getModelparamtype()); @@ -108,7 +107,9 @@ curPort.setDataLength(curDataLength); curPort.setPortOrder(curPortOrder); resultList.add(curPort); - return resultList; + sampleInfo.setColumnInfo(resultList); + sampleInfo.setPointMap(pointMap); + return sampleInfo; } /** diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java index ce7dd8b..19d75fd 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java @@ -1,6 +1,7 @@ package com.iailab.module.model.mdk.sample; import com.iailab.module.model.mdk.common.exceptions.DataAccessException; +import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; import com.iailab.module.model.mdk.sample.dto.SampleData; import com.iailab.module.model.mdk.sample.dto.SampleInfo; import org.springframework.beans.factory.annotation.Autowired; @@ -24,18 +25,15 @@ @Autowired private SampleFactory sampleFactory; - public List<SampleData> constructSample(String typeA, String modelId, Date runTime) { + public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName) throws ModelInvokeException { try { SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime); SampleDataConstructor sampleDataConstructor = sampleFactory.createSampelData(typeA); return sampleDataConstructor.prepareSampleData(sampleInfo); } catch (Exception e) { - DataAccessException exception = new DataAccessException(MessageFormat.format("{0},类名为{1}", - DataAccessException.errorDataAccess, Thread.currentThread().getStackTrace()[1].getClassName())); - System.out.println(exception); - e.printStackTrace(); - return null; + throw new ModelInvokeException(MessageFormat.format("{0},Name:{1}", + ModelInvokeException.errorGetModelArithParam, itemName)); } diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java index a51c53f..dba4323 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java @@ -1,8 +1,11 @@ package com.iailab.module.model.mdk.sample; +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.data.enums.DataPointFreqEnum; +import com.iailab.module.data.enums.TimeGranularitySecEnum; import com.iailab.module.model.mdk.common.enums.ModelParamType; import com.iailab.module.model.mdk.sample.dto.SampleData; import com.iailab.module.model.mdk.sample.dto.SampleInfo; @@ -21,6 +24,8 @@ @Autowired private DataPointApi dataPointApi; + @Autowired + private PlanItemApi planItemApi; /** * prepareSampleData @@ -28,7 +33,7 @@ * @param sampleInfo * @return */ - public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo); + public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception; /** * 补全数据 @@ -74,7 +79,7 @@ endTime = calendar.getTime(); end = endTime.getTime(); - oneMin = 24 * 60 * 60 * 1000; + oneMin = 60 * 1000L; mins = ((end - start) / oneMin); break; case DATAPOINT: @@ -103,6 +108,15 @@ end = calendar2.getTime().getTime(); mins = ((end - start) / oneMin); break; + case PLAN: + // 计划数据 + ApiPlanItemDTO planItem = planItemApi.getInfoById(paramId); + oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue(); + // 设置时间偏移量 + start = start - (start % oneMin) + oneMin; + end = end - (end % oneMin) + oneMin; + mins = ((end - start) / oneMin); + break; default: break; } diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java index 515637b..1ed6feb 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java @@ -48,14 +48,8 @@ * @return */ protected SampleInfo prepareSampleInfo(String modelId, Date predictTime) { - SampleInfo sampleInfo = new SampleInfo(); - //调用样本列数的方法 -// sampleInfo.setSampleColumn(getSampleColumn(modelId)); //样本的列信息 - sampleInfo.setColumnInfo(getColumnInfo(modelId, predictTime)); - //样本的采样周期 -// sampleInfo.setSampleCycle(getSampleCycle(modelId)); - return sampleInfo; + return getColumnInfo(modelId, predictTime); } /** @@ -74,7 +68,7 @@ * @param predictTime * @return */ - protected abstract List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime); + protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime); /** * 样本的采样周期 @@ -180,7 +174,7 @@ granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); break; case MERGEITEM: - granularity = mmPredictItemService.getItemByIdFromCache(columnItem.getParamId()).getGranularity(); + granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); break; case IND: ApiIndItemDTO indItemDTO = indItemApi.getInfoById(columnItem.getParamId()); diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java index f8547d6..3dc2e7e 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java @@ -8,14 +8,12 @@ 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 com.iailab.module.model.mdk.sample.dto.SampleInfo; 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.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -34,7 +32,8 @@ } @Override - protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) { + protected SampleInfo getColumnInfo(String modelId, Date predictTime) { + SampleInfo sampleInfo = new SampleInfo(); List<ColumnItemPort> resultList = new ArrayList<>(); List<ColumnItem> columnItemList = new ArrayList<>(); ColumnItem columnInfo = new ColumnItem(); @@ -48,7 +47,7 @@ //设置当前查询数据长度,初始值为最小端口数据长度 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()); + 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); Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); @@ -83,7 +82,9 @@ curPort.setDataLength(curDataLength); curPort.setPortOrder(curPortOrder); resultList.add(curPort); - return resultList; + sampleInfo.setColumnInfo(resultList); + sampleInfo.setPointMap(pointMap); + return sampleInfo; } @Override diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java index 14fab98..0c7548f 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java @@ -1,5 +1,6 @@ package com.iailab.module.model.mdk.sample.dto; +import com.iailab.module.data.api.point.dto.ApiPointDTO; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,6 +9,7 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.util.List; +import java.util.Map; @Data @AllArgsConstructor @@ -30,4 +32,6 @@ private Integer sampleCycle; private BigDecimal[][] deviation; + // 所有测点信息,避免重复查询 + private Map<String, ApiPointDTO> pointMap; } \ No newline at end of file diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java index 0282148..70a3172 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java @@ -63,7 +63,7 @@ try { //1.根据模型id构造模型输入样本 long now = System.currentTimeMillis(); - List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime); + List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName()); log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒"); if (CollectionUtils.isEmpty(sampleDataList)) { log.info("调度模型构造样本失败,schemeCode=" + schemeCode); -- Gitblit v1.9.3