| | |
| | | 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.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; |
| | |
| | | import com.iailab.module.model.mcs.pre.vo.MmItemOutputRespVO; |
| | | 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; |
| | |
| | | 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 |
| | |
| | | |
| | | @Autowired |
| | | private InfluxDBService influxDBService; |
| | | |
| | | @Autowired |
| | | private ElectricityPriceSegmentedService electricityPriceSegmentedService; |
| | | |
| | | @Autowired |
| | | private StScheduleModelService stScheduleModelService; |
| | | |
| | | @Autowired |
| | | private StScheduleModelSettingService stScheduleModelSettingService; |
| | | |
| | | |
| | | private int HOUR_MINS = 60; |
| | | |
| | |
| | | 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.setPreCumulant(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).sum())); |
| | | } |
| | | |
| | | String alarmObj = chartParams.get(CommonConstant.ALARM_OBJ); |
| | |
| | | } 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); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ScheduleSuggestRespDTO> listScheduleSuggest(Map<String, Object> params) { |
| | | return Collections.emptyList(); |
| | | public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO vo) { |
| | | return stScheduleSuggestService.list(vo); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateScheduleModelSetting(String modelCode, String key, String value) { |
| | | StScheduleModelEntity model = stScheduleModelService.getByModelCode(modelCode); |
| | | stScheduleModelSettingService.updateByModelIdAndKey(model.getId(), key, value); |
| | | return true; |
| | | } |
| | | |
| | | /** |