From b651cbfd94d8d636c01b61e483ed1cff98e1bcb9 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 23 十二月 2024 16:13:56 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- 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-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java | 6 + iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java | 54 ++++++++-- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java | 32 ++++-- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java | 7 + 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 | 33 ++++-- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java | 37 +++---- 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 | 24 +++- iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java | 15 +- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java | 9 + iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java | 10 - iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java | 4 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java | 12 +- 17 files changed, 180 insertions(+), 85 deletions(-) diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java index b54bd3b..1d42428 100644 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java @@ -2,19 +2,18 @@ import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; +import com.iailab.module.data.api.point.dto.ApiPointDTO; import com.iailab.module.data.common.ApiDataQueryDTO; import com.iailab.module.data.common.ApiDataValueDTO; import com.iailab.module.data.enums.ApiConstants; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.*; import java.util.LinkedHashMap; import java.util.List; +import java.util.Set; /** * @author PanZhibao @@ -36,10 +35,14 @@ LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(@RequestBody ApiDataQueryDTO dto); @GetMapping(PREFIX + "/info/no/{itemNo}") - @Operation(summary = "根据测点编号查询测点信息") + @Operation(summary = "根据编号查询计划数据信息") ApiPlanItemDTO getInfoByNo(@PathVariable("itemNo") String itemNo); @GetMapping(PREFIX + "/info/id/{id}") - @Operation(summary = "根据测点编号查询测点信息") + @Operation(summary = "根据id查询计划数据信息") ApiPlanItemDTO getInfoById(@PathVariable("id") String id); + + @PostMapping(PREFIX + "/info/ids") + @Operation(summary = "根据多个id查询计划数据信息") + List<ApiPlanItemDTO> getInfoByIds(@RequestParam("planIds") Set<String> planIds); } \ No newline at end of file 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/plan/PlanItemApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java index b37fc51..ac3c99d 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java @@ -3,6 +3,7 @@ import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; +import com.iailab.module.data.api.point.dto.ApiPointDTO; import com.iailab.module.data.common.ApiDataQueryDTO; import com.iailab.module.data.common.ApiDataValueDTO; import com.iailab.module.data.plan.item.collection.PlanItemCollector; @@ -16,8 +17,10 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Set; /** * @author PanZhibao @@ -65,4 +68,10 @@ return ConvertUtils.sourceToTarget(entity, ApiPlanItemDTO.class); } + @Override + public List<ApiPlanItemDTO> getInfoByIds(Set<String> planIds) { + List<PlanItemEntity> plans = planItemService.getInfoByIds(planIds); + return ConvertUtils.sourceToTarget(plans,ApiPlanItemDTO.class); + } + } \ No newline at end of file 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-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java index 5556f7d..6204f18 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java @@ -2,6 +2,7 @@ import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.BaseService; +import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; import com.iailab.module.data.plan.item.entity.PlanItemEntity; import com.iailab.module.data.plan.item.vo.PlanItemDataVO; import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO; @@ -9,6 +10,7 @@ import java.util.List; import java.util.Map; +import java.util.Set; /** * @author PanZhibao @@ -32,4 +34,6 @@ void delete(String id); List<PlanItemDataVO> getSourceValue(Map<String, Object> params); + + List<PlanItemEntity> getInfoByIds(Set<String> planIds); } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java index 6b89b39..155475e 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java @@ -4,6 +4,7 @@ import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; +import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; import com.iailab.module.data.plan.item.dao.PlanItemDao; import com.iailab.module.data.plan.item.entity.PlanItemEntity; import com.iailab.module.data.plan.item.service.PlanItemService; @@ -78,4 +79,9 @@ public List<PlanItemDataVO> getSourceValue(Map<String, Object> params) { return baseDao.getSourceValue(params); } + + @Override + public List<PlanItemEntity> getInfoByIds(Set<String> planIds) { + return baseDao.selectBatchIds(planIds); + } } \ No newline at end of file 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..093156e 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,13 @@ 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.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 +18,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 +39,9 @@ @Autowired private DataPointApi dataPointApi; + + @Autowired + private PlanItemApi planItemApi; @Autowired private MmItemResultService mmItemResultService; @@ -51,8 +60,10 @@ * @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(); + Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); //对每个爪分别进行计算 for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 @@ -74,11 +85,11 @@ //对每一项依次进行数据查询,然后将查询出的值赋给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,planMap); //补全数据 ColumnItem columnItem = entry.getColumnItemList().get(i); dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, - columnItem.paramId, columnItem.getParamType()); + columnItem.paramId, columnItem.getParamType(),pointMap,planMap); /** 如果数据取不满,把缺失的数据点放在后面 */ if (dataEntityList != null && dataEntityList.size() != 0) { @@ -89,6 +100,7 @@ } } catch (Exception e) { e.printStackTrace(); + throw e; } } SampleData sampleData = new SampleData(); @@ -102,20 +114,24 @@ * getData * * @param columnItem + * @param pointMap + * @param planMap * @return * @throws Exception */ - private List<DataValueVO> getData(ColumnItem columnItem) throws Exception { + private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) 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 +142,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(planMap.get(columnItem.getParamId()).getItemNo()); + 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..4104e2d 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 @@ -1,5 +1,7 @@ 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.model.mcs.pre.entity.MmModelParamEntity; @@ -9,14 +11,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; @@ -40,6 +40,9 @@ @Autowired private DataPointApi dataPointApi; + @Autowired + private PlanItemApi planItemApi; + /** * 返回样本矩阵的列数 * @@ -59,7 +62,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 +77,13 @@ //设置当前查询数据长度,初始值为最小端口数据长度 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)); + // 统一获取计划数据的信息 + Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(MmModelParamEntity::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)); for (MmModelParamEntity entry : modelInputParamEntityList) { columnInfo.setParamType(entry.getModelparamtype()); @@ -83,9 +91,9 @@ 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)); + columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); + columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); + columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); //对每一个爪进行数据项归并 if (curPortOrder != entry.getModelparamportorder()){ @@ -108,7 +116,10 @@ curPort.setDataLength(curDataLength); curPort.setPortOrder(curPortOrder); resultList.add(curPort); - return resultList; + sampleInfo.setColumnInfo(resultList); + sampleInfo.setPointMap(pointMap); + sampleInfo.setPlanMap(planMap); + 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..c25dae4 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; @@ -12,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; -import java.sql.Timestamp; import java.util.*; abstract class SampleDataConstructor { @@ -21,6 +23,8 @@ @Autowired private DataPointApi dataPointApi; + @Autowired + private PlanItemApi planItemApi; /** * prepareSampleData @@ -28,7 +32,7 @@ * @param sampleInfo * @return */ - public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo); + public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception; /** * 补全数据 @@ -37,10 +41,11 @@ * @param dataEntityList * @param startTime * @param endTime + * @param planMap * @return */ public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, - String paramId, String paramType) { + String paramId, String paramType, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) { return dataEntityList; } else if (length < dataEntityList.size()) { @@ -74,12 +79,12 @@ endTime = calendar.getTime(); end = endTime.getTime(); - oneMin = 24 * 60 * 60 * 1000; + oneMin = 60 * 1000L; mins = ((end - start) / oneMin); break; case DATAPOINT: // 测点值 - ApiPointDTO dataPoint = dataPointApi.getInfoById(paramId); + ApiPointDTO dataPoint = pointMap.get(paramId); oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); // 设置时间偏移量 start = start - (start % oneMin) + oneMin; @@ -103,6 +108,15 @@ end = calendar2.getTime().getTime(); mins = ((end - start) / oneMin); break; + case PLAN: + // 计划数据 + ApiPlanItemDTO planItem = planMap.get(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..3f8f72b 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); /** * 样本的采样周期 @@ -92,7 +86,7 @@ * @return * @throws Exception */ - protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap) { + protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { Date dateTime = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(originalTime); @@ -112,7 +106,11 @@ dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); break; case PLAN: - dateTime = calendar.getTime(); + ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); + if (apiPlanItemDTO == null) { + return null; + } + dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); break; default: break; @@ -128,7 +126,7 @@ * @return * @throws Exception */ - protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap) { + protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { Date dateTime = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(originalTime); @@ -148,12 +146,11 @@ dateTime = calendar.getTime(); break; case PLAN: - ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId()); - if (planItem == null) { + ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); + if (apiPlanItemDTO == null) { return null; } - dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), - TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue()); + dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); break; default: break; @@ -168,26 +165,24 @@ * @return * @throws Exception */ - protected Integer getGranularity(ColumnItem columnItem) { + protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { // 默认60s Integer granularity = 60; switch (ModelParamType.getEumByCode(columnItem.getParamType())) { case DATAPOINT: - ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); + ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); break; case NORMALITEM: - 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()); granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; break; case PLAN: - ApiPlanItemDTO apiPlanItemDTO = planItemApi.getInfoById(columnItem.getParamId()); + ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue(); break; default: 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..bc58d7b 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 @@ -1,21 +1,20 @@ 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.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 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; @@ -28,13 +27,17 @@ @Autowired private DataPointApi dataPointApi; + @Autowired + private PlanItemApi planItemApi; + @Override protected Integer getSampleColumn(String modelId) { return null; } @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,9 +51,13 @@ //设置当前查询数据长度,初始值为最小端口数据长度 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())); + // 统一获取计划数据的信息 + 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)); for (StScheduleModelParamEntity entry : modelInputParamEntityList) { columnInfo.setParamType(entry.getModelparamtype()); @@ -58,9 +65,9 @@ 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)); + columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); + columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); + columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); //对每一个爪进行数据项归并 if (curPortOrder != entry.getModelparamportorder()){ @@ -83,7 +90,10 @@ curPort.setDataLength(curDataLength); curPort.setPortOrder(curPortOrder); resultList.add(curPort); - return resultList; + sampleInfo.setColumnInfo(resultList); + sampleInfo.setPointMap(pointMap); + sampleInfo.setPlanMap(planMap); + 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..39bea32 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,7 @@ package com.iailab.module.model.mdk.sample.dto; +import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; +import com.iailab.module.data.api.point.dto.ApiPointDTO; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,6 +10,7 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.util.List; +import java.util.Map; @Data @AllArgsConstructor @@ -30,4 +33,8 @@ private Integer sampleCycle; private BigDecimal[][] deviation; + // 所有测点信息,避免重复查询 + private Map<String, ApiPointDTO> pointMap; + // 所有计划数据信息,避免重复查询 + private Map<String, ApiPlanItemDTO> planMap; } \ 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