From 977edcb50e46f57d5b8fdd4551736b1605fef6fc Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期二, 19 十一月 2024 13:15:02 +0800 Subject: [PATCH] 预测数据查询 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 41 insertions(+), 11 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java index ea0e09e..0c2d4f5 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java @@ -13,9 +13,9 @@ import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.service.*; import com.iailab.module.model.mdk.vo.ItemVO; -import com.iailab.module.model.mpk.service.ChartParamService; import com.iailab.module.model.mpk.service.ChartService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; @@ -146,8 +146,8 @@ viewDto.setOutId(outId); viewDto.setResultstr(output.getResultstr()); viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); - viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime)); - viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime)); + viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); List<Double> values = new ArrayList<>(); if (!CollectionUtils.isEmpty(viewDto.getRealData())) { @@ -249,7 +249,7 @@ legend.add(out.getResultstr()); PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); - viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime)); + viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); viewMap.put(out.getResultstr(), viewDto); } result.setStartTime(startTime); @@ -280,7 +280,8 @@ if (predictItem == null || predictItem.getLastTime() == null) { return result; } - PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.valueOf(chartParams.get(CommonConstant.LINE_TYPE)); + String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); + PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(chartParams.get(CommonConstant.LINE_TYPE)); BigDecimal rangeH = chartParams.get(CommonConstant.RANGE_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_H)); BigDecimal rangeL = chartParams.get(CommonConstant.RANGE_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_L)); BigDecimal limitH = chartParams.get(CommonConstant.LIMIT_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_H)); @@ -309,7 +310,7 @@ calendar.add(Calendar.MINUTE, lengthRight); endTime = calendar.getTime(); } - List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity()); + List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat); List<String> legend = new ArrayList<>(); MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), resultStr); PreDataViewRespDTO dataView = new PreDataViewRespDTO(); @@ -320,15 +321,15 @@ dataView.setRangeL(rangeL); dataView.setLimitH(limitH); dataView.setLimitL(limitL); - dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime)); - dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime)); + dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime, timeFormat)); + dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat)); switch (lineType) { case TN: - dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime)); + dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime, timeFormat)); break; case TL: - dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime)); - dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime)); + dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat)); + dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat)); break; default: break; @@ -369,6 +370,35 @@ return result; } + /** + * 获取真实值 + * + * @param pointId + * @param startTime + * @param endTime + * @param timeFormat + * @return + */ + private List<Object[]> getHisData(String pointId, Date startTime, Date endTime, String timeFormat) { + List<Object[]> result = new ArrayList<>(); + ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); + ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); + queryPointDto.setPointNo(pointDTO.getPointNo()); + queryPointDto.setStart(startTime); + queryPointDto.setEnd(endTime); + List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); + if (CollectionUtils.isEmpty(valueDTOS)) { + return result; + } + valueDTOS.forEach(item -> { + Object[] values = new Object[2]; + values[0] = DateUtils.format(item.getT(), timeFormat); + values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); + result.add(values); + }); + return result; + } + @Override public Boolean createAlarmMessage(AlarmMessageRespDTO dto) { return true; -- Gitblit v1.9.3