From ead3a7406d18f4f2ee5afe581bcb04f8d64fcb5e Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期日, 23 三月 2025 14:36:20 +0800 Subject: [PATCH] curData + T+L --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java | 141 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 113 insertions(+), 28 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 2329579..8230371 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,6 +13,7 @@ import com.iailab.module.model.api.mcs.McsApi; import com.iailab.module.model.api.mcs.dto.*; import com.iailab.module.model.api.mdk.dto.StScheduleRecordVO; +import com.iailab.module.model.common.enums.CommonDict; import com.iailab.module.model.common.enums.DataTypeEnum; import com.iailab.module.model.common.enums.PreLineTypeEnum; import com.iailab.module.model.enums.CommonConstant; @@ -24,12 +25,13 @@ import com.iailab.module.model.mcs.pre.entity.MmPredictAlarmMessageEntity; import com.iailab.module.model.mcs.pre.service.*; import com.iailab.module.model.mcs.pre.vo.MmItemOutputRespVO; +import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmConfigSaveReqVO; import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmMessageSaveReqVO; import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; +import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; +import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity; import com.iailab.module.model.mcs.sche.entity.StScheduleSuggestEntity; -import com.iailab.module.model.mcs.sche.service.StScheduleRecordService; -import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService; -import com.iailab.module.model.mcs.sche.service.StScheduleSuggestService; +import com.iailab.module.model.mcs.sche.service.*; import com.iailab.module.model.mcs.sche.vo.StScheduleSuggestSaveReqVO; import com.iailab.module.model.mdk.vo.ItemVO; import com.iailab.module.model.mpk.service.ChartParamService; @@ -78,6 +80,9 @@ private MmItemResultJsonService mmItemResultJsonService; @Autowired + private StAdjustResultService stAdjustResultService; + + @Autowired private ChartService chartService; @Autowired @@ -107,6 +112,14 @@ @Autowired private ElectricityPriceSegmentedService electricityPriceSegmentedService; + @Autowired + private StScheduleModelService stScheduleModelService; + + @Autowired + private StScheduleModelSettingService stScheduleModelSettingService; + + @Autowired + private StAdjustConfigService stAdjustConfigService; private int HOUR_MINS = 60; @Override @@ -121,6 +134,7 @@ PredictItemTreeDTO moduleOpt = new PredictItemTreeDTO(); moduleOpt.setId(item.getId()); moduleOpt.setLabel(item.getModulename()); + moduleOpt.setDisabled(true); List<PredictItemTreeDTO> children = new ArrayList<>(); List<ItemVO> itemList = mmPredictItemService.getByModuleId(item.getId()); itemList.forEach(item1 -> { @@ -164,7 +178,7 @@ break; } } - ItemVO predictItem = mmPredictItemService.getItemByIdFromCache(output.getItemid()); + ItemVO predictItem = mmPredictItemService.getItemById(output.getItemid()); if (predictItem.getLastTime() != null) { predictTime = predictItem.getLastTime(); } else { @@ -186,6 +200,7 @@ Calendar calendar = Calendar.getInstance(); calendar.setTime(predictTime); calendar.add(Calendar.HOUR_OF_DAY, 1); + calendar.add(Calendar.MINUTE, 1); endTime = calendar.getTime(); } @@ -204,6 +219,9 @@ viewDto.setRealData(getHisData(output.getPointid(), 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)); + viewDto.setCurData(mmItemResultJsonService.getData(output.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + // 模拟调整曲线 + viewDto.setAdjData(stAdjustResultService.getData(output.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); List<Double> values = new ArrayList<>(); if (!CollectionUtils.isEmpty(viewDto.getRealData())) { @@ -251,6 +269,14 @@ viewDto.setMaxValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); viewDto.setMinValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); } + //处理预测累计 + if (output.getIscumulant() == 1) { + if (StringUtils.isNotBlank(output.getCumulpoint())) { + viewDto.setCumulantRealData(getHisData(output.getCumulpoint(), startTime, endTime)); + } + viewDto.setCumulantPreData(mmItemResultService.getData(output.getId() + CommonDict.CUMULANT_SUFFIX, startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + } + dataViewList.add(viewDto); } result.setStartTime(startTime); @@ -308,6 +334,16 @@ viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); } viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + //处理预测累计 + if (out.getIscumulant() == 1) { + if (StringUtils.isNotBlank(out.getCumulpoint())) { + viewDto.setCumulantRealData(getHisData(out.getCumulpoint(), startTime, endTime)); + } + viewDto.setCumulantPreData(mmItemResultService.getData(out.getId() + CommonDict.CUMULANT_SUFFIX, startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + } + // 调整预测值 + viewDto.setAdjData(stAdjustResultService.getData(out.getId(),predictItem.getLastTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + viewMap.put(out.getResultName(), viewDto); } result.setStartTime(startTime); @@ -317,6 +353,7 @@ result.setViewMap(viewMap); return result; } + @Override public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { @@ -370,13 +407,19 @@ } else { dataView.setRealData(new ArrayList<>()); } - dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat)); + dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat, 3)); + // 调整预测值 + dataView.setAdjData(stAdjustResultService.getData(outPut.getId(),predictTime,timeFormat)); dataView.setLineType(lineType.getCode()); switch (lineType) { case TN: dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime, timeFormat)); break; case TL: + dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat)); + dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat)); + break; + case CL: dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat)); dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat)); break; @@ -394,13 +437,14 @@ }).collect(Collectors.toList()); dataView.setPreMax(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); dataView.setPreMin(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); - dataView.setPreLast(new BigDecimal(curList.get(curList.size() - 1))); - dataView.setPreCumulant(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).sum())); + dataView.setPreLast(new BigDecimal(curList.get(curList.size() - 1)).setScale(2, BigDecimal.ROUND_HALF_UP)); + dataView.setPreCumulant(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).sum()).setScale(2, BigDecimal.ROUND_HALF_UP)); } String alarmObj = chartParams.get(CommonConstant.ALARM_OBJ); if (StringUtils.isNotBlank(alarmObj)) { - List<AlarmMessageRespDTO> alarmList = ConvertUtils.sourceToTarget(mmPredictAlarmMessageService.getList(alarmObj, predictTime), AlarmMessageRespDTO.class); + String alarmTitle = chartParams.get(CommonConstant.ALARM_TITLE); + List<AlarmMessageRespDTO> alarmList = ConvertUtils.sourceToTarget(mmPredictAlarmMessageService.getList(alarmObj, predictTime, alarmTitle), AlarmMessageRespDTO.class); dataView.setAlarmList(alarmList); if (CollectionUtils.isEmpty(alarmList)) { dataView.setAlarmMessage("暂无预警信息"); @@ -513,6 +557,9 @@ */ private List<Object[]> getHisData(String pointId, Date startTime, Date endTime) { List<Object[]> result = new ArrayList<>(); + if (StringUtils.isBlank(pointId)) { + return result; + } ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); queryPointDto.setPointNo(pointDTO.getPointNo()); @@ -525,7 +572,7 @@ valueDTOS.forEach(item -> { Object[] values = new Object[2]; values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); - values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); + values[1] = new BigDecimal(item.getV()).setScale(3, BigDecimal.ROUND_HALF_UP); result.add(values); }); return result; @@ -554,7 +601,7 @@ 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); + values[1] = new BigDecimal(item.getV()).setScale(3, BigDecimal.ROUND_HALF_UP); result.add(values); }); return result; @@ -599,8 +646,8 @@ } @Override - public List<ScheduleSuggestRespDTO> listScheduleSuggest(Map<String, Object> params) { - return Collections.emptyList(); + public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO vo) { + return stScheduleSuggestService.list(vo); } @Override @@ -681,9 +728,15 @@ result.put(key, BigDecimal.ZERO); } MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), itemNo[1], itemNo[2]); - + String outputId = outPut.getId(); + // 判断是否有第五个参数,如果有第5个参数为1,则取累计值 + if (itemNo.length >= 5){ + if (StringUtils.isNotBlank(itemNo[4]) && "1".equals(itemNo[4])){ + outputId = outPut.getId() + CommonDict.CUMULANT_SUFFIX; + } + } Date predictTime = predictItem.getLastTime(); - List<Object[]> curData = mmItemResultJsonService.getData(outPut.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + List<Object[]> curData = mmItemResultJsonService.getData(outputId, predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); if(CollectionUtils.isEmpty(curData)) { result.put(key, BigDecimal.ZERO); } else { @@ -767,20 +820,52 @@ return true; } - /** - * 计算功率因数 p²/(根号:p²+Q²) - **/ - public Double calculateCos(Double PValue,Double QValue) { - // 绝对值 - PValue = Math.abs(PValue); - QValue = Math.abs(QValue); - //PValue [0,0.001] 直接判断为关闭返回0 - if (PValue >= 0 && PValue <= 0.001) { - return 0.0; - }else { - BigDecimal result = new BigDecimal(PValue).divide(BigDecimal.valueOf(Math.sqrt(Math.pow(PValue, 2) + Math.pow(QValue, 2))), 2, BigDecimal.ROUND_HALF_UP); - return result.doubleValue(); - } + @Override + public Boolean updateScheduleModelSetting(String modelCode, String key, String value) { + StScheduleModelEntity model = stScheduleModelService.getByModelCode(modelCode); + stScheduleModelSettingService.updateByModelIdAndKey(model.getId(), key, value); + return true; + } + + @Override + public Boolean updateAlarmConfig(String alarmObj,String upperLimit,String lowerLimit) { + MmPredictAlarmConfigSaveReqVO reqVO = new MmPredictAlarmConfigSaveReqVO(); + reqVO.setAlarmObj(alarmObj); + reqVO.setUpperLimit(BigDecimal.valueOf(Double.parseDouble(upperLimit))); + reqVO.setLowerLimit(BigDecimal.valueOf(Double.parseDouble(lowerLimit))); + mmPredictAlarmConfigService.updateByAlarmObj(reqVO); + return true; + } + + @Override + public Boolean updateChartParam(ChartDTO chartDTO) { + ChartDTO oldChartDTO = chartService.getChartByChartCode(chartDTO.getChartCode()); + List<ChartParamDTO> chartParams = chartDTO.getChartParams(); + chartParams.forEach(item -> { + item.setChartId(oldChartDTO.getId()); + }); + chartParamService.updateByChartIdAndParamCode(chartParams); + return true; + } + + @Override + public MmItemOutputDTO getItemOutputByItemid(String itemid, String resultstr, String resultIndex) { + return ConvertUtils.sourceToTarget(mmItemOutputService.getByItemid(itemid,resultstr,resultIndex),MmItemOutputDTO.class); + } + + @Override + public List<Object[]> getItemResult(String outputid, Date startTime, Date endTime, String timeFormat) { + return mmItemResultService.getData(outputid,startTime,endTime,timeFormat); + } + + @Override + public PredictItemVO getPredictItemByItemNo(String itemNo) { + return ConvertUtils.sourceToTarget(mmPredictItemService.getItemByItemNo(itemNo),PredictItemVO.class); + } + + @Override + public List<Object[]> getItemResultLastPoint(String outputid, Date startTime, Date endTime, String timeFormat) { + return mmItemResultLastPointService.getData(outputid,startTime,endTime,timeFormat); } private Date[] calResultTime(ItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) { -- Gitblit v1.9.3