From b270a07828a9627f1a42e254a430c9921fec4e95 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期三, 26 三月 2025 16:14:37 +0800 Subject: [PATCH] Merge branch 'master' of http://dlindusit.com:53929/r/iailab-plat --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java | 65 ++++++++++++-------------------- 1 files changed, 25 insertions(+), 40 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 e3c6e3e..9478194 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 @@ -42,11 +42,9 @@ * @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, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { + public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, String paramType, Integer granularity) { if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) { return dataEntityList; } else if (length < dataEntityList.size()) { @@ -54,8 +52,7 @@ } List<DataValueVO> completionDataEntityList = new ArrayList<>(); - long oneMin = 0L; - + long oneMin = granularity * 1000L;; long start = startTime.getTime(); long end = endTime.getTime(); long mins = 0L; @@ -63,53 +60,27 @@ switch (ModelParamType.getEumByCode(paramType)) { case NORMALITEM: case MERGEITEM: - // 预测值 - oneMin = PredGranularityEnum.MIN1.getCode() * 1000L; - start = start - (start % oneMin) + oneMin; - end = end - (end % oneMin) + oneMin; - mins = ((end - start) / oneMin); + // 设置时间偏移量 + mins = calMins(start, end, granularity); break; case DATAPOINT: - // 测点值 - ApiPointDTO dataPoint = pointMap.get(paramId); - oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); + case PLAN: // 设置时间偏移量 - start = start - (start % oneMin) + oneMin; - end = end - (end % oneMin) + oneMin; - mins = ((end - start) / oneMin); + mins = calMins(start, end, granularity) + 1; break; case IND: - // 指标数据 - 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); - start = calendar2.getTime().getTime(); - - calendar2.setTime(endTime); - 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(); + case IND_ASCII: // 设置时间偏移量 - start = start - (start % oneMin) + oneMin; - end = end - (end % oneMin) + oneMin; - mins = ((end - start) / oneMin); + mins = calMins(start, end, granularity) + 1; break; default: break; } Map<Long, Double> sourceDataMap = new HashMap<>(dataEntityList.size()); for (DataValueVO dataEntity : dataEntityList) { - sourceDataMap.put(dataEntity.getDataTime().getTime(), dataEntity.getDataValue()); + if (null != dataEntity.getDataTime()) { + sourceDataMap.put(dataEntity.getDataTime().getTime(), dataEntity.getDataValue()); + } } //找出缺少项 @@ -140,6 +111,20 @@ return completionDataEntityList; } + private long calMins(long start, long end, Integer granularity) { + long oneMin = granularity * 1000L; + // 设置时间偏移量 + if (granularity >= 24 * 60 * 60) { + // 如果时间粒度大于等于一天,因为时区问题,特殊处理,否则时间为8:00,而非0:00 + start = start - ((start + 8 * 60 * 60 * 1000) % oneMin); + end = end - ((end + 8 * 60 * 60 * 1000) % oneMin); + } else { + start = start - (start % oneMin); + end = end - (end % oneMin); + } + return ((end - start) / oneMin); + } + /** * getFirstValue * -- Gitblit v1.9.3