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/sample/SampleDataConstructor.java | 70 ++++++++++++++++++++--------------- 1 files changed, 40 insertions(+), 30 deletions(-) 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 34a5900..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,13 +41,15 @@ * @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) { + public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, + 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()){ - return dataEntityList.subList(dataEntityList.size()-length,dataEntityList.size()); + } else if (length < dataEntityList.size()) { + return dataEntityList.subList(dataEntityList.size() - length, dataEntityList.size()); } List<DataValueVO> completionDataEntityList = new ArrayList<>(); @@ -54,38 +60,35 @@ long mins = 0L; switch (ModelParamType.getEumByCode(paramType)) { - case PREDICTITEM: + case NORMALITEM: + case MERGEITEM: // 预测值 Calendar calendar = Calendar.getInstance(); calendar.setTime(startTime); - calendar.set(Calendar.HOUR_OF_DAY,0); - calendar.set(Calendar.MINUTE,0); - calendar.set(Calendar.SECOND,0); - calendar.add(Calendar.DAY_OF_YEAR,1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.add(Calendar.DAY_OF_YEAR, 1); startTime = calendar.getTime(); start = startTime.getTime(); calendar.setTime(endTime); - calendar.set(Calendar.HOUR_OF_DAY,0); - calendar.set(Calendar.MINUTE,0); - calendar.set(Calendar.SECOND,0); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); 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; end = end - (end % oneMin) + oneMin; - - mins = ((end - start) / oneMin); break; case IND: @@ -93,18 +96,25 @@ oneMin = 24 * 60 * 60 * 1000; Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(startTime); - calendar2.set(Calendar.HOUR_OF_DAY,0); - calendar2.set(Calendar.MINUTE,0); - calendar2.set(Calendar.SECOND,0); + calendar2.set(Calendar.HOUR_OF_DAY, 0); + calendar2.set(Calendar.MINUTE, 0); + calendar2.set(Calendar.SECOND, 0); start = calendar2.getTime().getTime(); calendar2.setTime(endTime); - calendar2.set(Calendar.HOUR_OF_DAY,0); - calendar2.set(Calendar.MINUTE,0); - calendar2.set(Calendar.SECOND,0); + calendar2.set(Calendar.HOUR_OF_DAY, 0); + calendar2.set(Calendar.MINUTE, 0); + calendar2.set(Calendar.SECOND, 0); 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: @@ -117,7 +127,7 @@ //找出缺少项 Map<Long, Double> dataMap = new LinkedHashMap<>(); - for (int i = 0; i < mins; i ++) { + for (int i = 0; i < mins; i++) { Long key = start + oneMin * i; Double value = sourceDataMap.get(key); dataMap.put(key, value); @@ -132,11 +142,11 @@ } else if (item.getValue() == null) { item.setValue(lastItem.getValue()); } - k ++; + k++; lastItem = item; DataValueVO dataEntity = new DataValueVO(); - dataEntity.setDataTime(new Timestamp(item.getKey())); + dataEntity.setDataTime(new Date(item.getKey())); dataEntity.setDataValue(item.getValue()); completionDataEntityList.add(dataEntity); } -- Gitblit v1.9.3