From 60e664bd398e908206d00eb8e17c3b4796c70df1 Mon Sep 17 00:00:00 2001 From: dongyukun <1208714201@qq.com> Date: 星期一, 24 三月 2025 18:42:33 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java | 283 ++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 202 insertions(+), 81 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 e8a8aa5..b4b3cfa 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 @@ -12,9 +12,11 @@ import com.iailab.module.data.common.ApiDataQueryDTO; 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.enums.CommonConstant; import com.iailab.module.model.common.enums.PreLineTypeEnum; +import com.iailab.module.model.enums.CommonConstant; import com.iailab.module.model.influxdb.pojo.InfluxModelResultByOutPutIdsPOJO; import com.iailab.module.model.influxdb.service.InfluxDBService; import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; @@ -23,16 +25,17 @@ 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.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; import com.iailab.module.model.mpk.service.ChartService; +import com.iailab.module.model.mpk.service.ElectricityPriceSegmentedService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -41,11 +44,8 @@ import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * @author PanZhibao @@ -79,6 +79,9 @@ private MmItemResultJsonService mmItemResultJsonService; @Autowired + private StAdjustResultService stAdjustResultService; + + @Autowired private ChartService chartService; @Autowired @@ -105,6 +108,17 @@ @Autowired private InfluxDBService influxDBService; + @Autowired + private ElectricityPriceSegmentedService electricityPriceSegmentedService; + + @Autowired + private StScheduleModelService stScheduleModelService; + + @Autowired + private StScheduleModelSettingService stScheduleModelSettingService; + + @Autowired + private StAdjustConfigService stAdjustConfigService; private int HOUR_MINS = 60; @Override @@ -119,6 +133,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 -> { @@ -155,8 +170,14 @@ } Date predictTime = reqVO.getPredictTime(); if (predictTime == null) { - MmItemOutputEntity output = mmItemOutputService.getOutPutById(reqVO.getOutIds().get(0)); - ItemVO predictItem = mmPredictItemService.getItemByIdFromCache(output.getItemid()); + MmItemOutputEntity output = null; + for (String outId : outIds) { + output = mmItemOutputService.getOutPutById(outId); + if (output != null) { + break; + } + } + ItemVO predictItem = mmPredictItemService.getItemById(output.getItemid()); if (predictItem.getLastTime() != null) { predictTime = predictItem.getLastTime(); } else { @@ -178,6 +199,7 @@ Calendar calendar = Calendar.getInstance(); calendar.setTime(predictTime); calendar.add(Calendar.HOUR_OF_DAY, 1); + calendar.add(Calendar.MINUTE, 1); endTime = calendar.getTime(); } @@ -196,6 +218,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())) { @@ -243,6 +268,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); @@ -300,6 +333,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); @@ -309,6 +352,7 @@ result.setViewMap(viewMap); return result; } + @Override public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { @@ -362,7 +406,9 @@ } 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: @@ -375,6 +421,19 @@ default: break; } + + //处理预测累计 + if (outPut.getIscumulant() != null && outPut.getIscumulant() == 1) { + /*if (StringUtils.isNotBlank(outPut.getCumulpoint())) { + dataView.setCumulantRealData(getHisData(outPut.getCumulpoint(), startTime, endTime)); + }*/ + List<Object[]> cumulantPreList = mmItemResultService.getData(outPut.getId() + CommonDict.CUMULANT_SUFFIX, startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + dataView.setCumulantPreData(cumulantPreList); + if (!CollectionUtils.isEmpty(cumulantPreList)) { + dataView.setCumulantPreLast(new BigDecimal(cumulantPreList.get(cumulantPreList.size() - 1)[1].toString()).setScale(2, BigDecimal.ROUND_HALF_UP)); + } + } + if (!CollectionUtils.isEmpty(dataView.getRealData())) { Object[] rdo = dataView.getRealData().get(dataView.getRealData().size() - 1); dataView.setCurrValue(new BigDecimal(rdo[1].toString())); @@ -386,20 +445,43 @@ }).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()) - .divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); + 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("暂无预警信息"); } else { dataView.setAlarmMessage(alarmList.get(0).getContent()); } + } + + try { + String adjValuePoint = chartParams.get(CommonConstant.ADJ_VALUE_POINT); + if (StringUtils.isNotBlank(adjValuePoint)) { + List<String> pointNos = new ArrayList<>(); + pointNos.add(adjValuePoint); + Map<String, Object> adjValue = dataPointApi.queryPointsRealValue(pointNos); + dataView.setAdjValue(new BigDecimal(adjValue.get(adjValuePoint).toString())); + } + + String adjValueArrPoint = chartParams.get(CommonConstant.ADJ_VALUE_ARR_POINT); + if (StringUtils.isNotBlank(adjValueArrPoint)) { + String[] adjPointArr = adjValueArrPoint.split(","); + Map<String, Object> adjValue = dataPointApi.queryPointsRealValue(Arrays.asList(adjPointArr)); + BigDecimal[] adjValueArr = new BigDecimal[adjPointArr.length]; + for(int i = 0; i < adjPointArr.length; i++) { + adjValueArr[i] = new BigDecimal(adjValue.get(adjPointArr[i]).toString()); + } + dataView.setAdjValueArr(adjValueArr); + } + } catch (Exception ex) { + ex.printStackTrace(); } result.setPredictTime(predictTime); @@ -483,6 +565,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()); @@ -495,7 +580,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; @@ -524,7 +609,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; @@ -569,8 +654,8 @@ } @Override - public List<ScheduleSuggestRespDTO> listScheduleSuggest(Map<String, Object> params) { - return Collections.emptyList(); + public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO vo) { + return stScheduleSuggestService.list(vo); } @Override @@ -651,9 +736,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 { @@ -664,28 +755,53 @@ } @Override - public Map<String,List<Object[]>> getElectricPredictData(String itemCode) { - ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode); + public List<StScheduleRecordVO> getLastScheduleData(String scheduleCode, Integer limit) { + if (StringUtils.isBlank(scheduleCode)) { + return null; + } + return stScheduleRecordService.getLastScheduleResult(scheduleCode,limit); + } + + @Override + public Map<String, List<Object[]>> getPredictDataItemNo(PreDataItemNoReqVO reqVO) { + if (StringUtils.isBlank(reqVO.getItemNo())) { + return new HashMap<>(); + } + ItemVO predictItem = mmPredictItemService.getItemByItemNo(reqVO.getItemNo()); if (null == predictItem) { return new HashMap<>(); } - List<Integer> resultIndexs = new ArrayList<>(); - resultIndexs.add(0); - resultIndexs.add(1); - resultIndexs.add(2); - List<MmItemOutputEntity> outPuts = mmItemOutputService.getByItemid(predictItem.getId(),"predictValues",resultIndexs); + + // 默认开始时间:运行时间 + if (null == reqVO.getStartTime()) { + reqVO.setStartTime(predictItem.getLastTime()); + } + // 默认结束时间:运行时间+预测长度*粒度 + if (null == reqVO.getEndTime()) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(predictItem.getLastTime()); + calendar.add(Calendar.SECOND,predictItem.getPredictLength() * predictItem.getGranularity()); + reqVO.setEndTime(calendar.getTime()); + } + + List<String> itemNos = new ArrayList<String>(){{ + add(reqVO.getItemNo()); + }}; + List<MmPredictItemRespVO> ItemRespVOs = mmPredictItemService.getArrayOutPutsByItemNos(itemNos); + if (CollectionUtils.isEmpty(ItemRespVOs)) { + return new HashMap<>(); + } + List<MmItemOutputRespVO> outPuts = ItemRespVOs.get(0).getOutPuts(); if (CollectionUtils.isEmpty(outPuts)) { return new HashMap<>(); } + InfluxModelResultByOutPutIdsPOJO pojo = new InfluxModelResultByOutPutIdsPOJO(); - pojo.setOutPutIds(outPuts.stream().map(MmItemOutputEntity::getId).collect(Collectors.toList())); + pojo.setOutPutIds(outPuts.stream().map(MmItemOutputRespVO::getId).collect(Collectors.toList())); pojo.setType(DataTypeEnum.FLOAT.getCode()); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(predictItem.getLastTime()); - calendar.add(Calendar.DAY_OF_YEAR, 7); - Map<String, List<InfluxModelResultVO>> outPutDatas = influxDBService.queryModelResultsByOutPutIds(pojo, predictItem.getLastTime(), calendar.getTime()); + Map<String, List<InfluxModelResultVO>> outPutDatas = influxDBService.queryModelResultsByOutPutIds(pojo, reqVO.getStartTime(), reqVO.getEndTime()); Map<String,List<Object[]>> result = new HashMap<>(outPuts.size()); - for (MmItemOutputEntity outPut : outPuts) { + for (MmItemOutputRespVO outPut : outPuts) { String outPutId = outPut.getId(); if (outPutDatas.containsKey(outPutId)) { List<InfluxModelResultVO> influxModelResultVOS = outPutDatas.get(outPutId); @@ -701,59 +817,64 @@ } @Override - public String getLastScheduleData(String scheduleCode) { - if (StringUtils.isBlank(scheduleCode)) { - return null; - } - return stScheduleRecordService.getLastScheduleResult(scheduleCode); + public List<ElectricityPriceSegmentedDTO> getElectricityPriceList(String year, String time) { + return electricityPriceSegmentedService.getElectricityPriceList(year, time); } @Override - public List<Map<String, Object>> getRealTimeStatus(List<Map<String, Object>> machines) { - List<String> pointNos = new ArrayList<>(16); - for (Map<String, Object> machine : machines) { - List<String> list = (List<String>) machine.get("pointNos"); - pointNos.addAll(list); - } - Map<String, Object> pointValues = dataPointApi.queryPointsRealValue(pointNos); - List<Map<String, Object>> results = new ArrayList<>(); - for (Map<String, Object> machine : machines) { - List<String> pointNoList = (List<String>) machine.get("pointNos"); - if (!pointValues.containsKey(pointNoList.get(0)) || !pointValues.containsKey(pointNoList.get(1))) { - machine.put("status",false); - machine.put("num",0); - results.add(machine); - continue; - } - Double PValue = Double.valueOf(pointValues.get(pointNoList.get(0)).toString()); - Double QValue = Double.valueOf(pointValues.get(pointNoList.get(1)).toString()); - Double cos = calculateCos(PValue, QValue); - if (cos.equals(0.0)) { - machine.put("status",false); - machine.put("num",0); - }else { - machine.put("status",true); - machine.put("num",cos); - } - results.add(machine); - } - return results; + public Boolean createElectricityPrice(List<ElectricityPriceSegmentedDTO> list) { + electricityPriceSegmentedService.deleteByITimeId(list.get(0).getITimeId()); + list.forEach(dto -> electricityPriceSegmentedService.create(dto)); + 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(PreItemResultReqVO reqVO) { + + return mmItemResultService.getData(reqVO.getOutputid(),reqVO.getStartTime(),reqVO.getEndTime(),reqVO.getTimeFormat()); + } + + @Override + public PredictItemVO getPredictItemByItemNo(String itemNo) { + return ConvertUtils.sourceToTarget(mmPredictItemService.getItemByItemNo(itemNo),PredictItemVO.class); + } + + @Override + public List<Object[]> getItemResultLastPoint(PreItemResultReqVO reqVO) { + return mmItemResultLastPointService.getData(reqVO.getOutputid(),reqVO.getStartTime(),reqVO.getEndTime(),reqVO.getTimeFormat()); } private Date[] calResultTime(ItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) { -- Gitblit v1.9.3