潘志宝
2024-12-25 874dd8d939b4ae61efbb799855c9ddf328722972
提交 | 用户 | 时间
b368e6 1 package com.iailab.module.model.api;
2
3 import com.iailab.framework.common.util.date.DateUtils;
8a74e9 4 import com.iailab.framework.common.util.object.ConvertUtils;
5 import com.iailab.module.data.api.plan.PlanItemApi;
6 import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO;
b368e6 7 import com.iailab.module.data.api.point.DataPointApi;
8 import com.iailab.module.data.api.point.dto.ApiPointDTO;
9 import com.iailab.module.data.api.point.dto.ApiPointValueDTO;
10 import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO;
8a74e9 11 import com.iailab.module.data.common.ApiDataQueryDTO;
b368e6 12 import com.iailab.module.model.api.mcs.McsApi;
13 import com.iailab.module.model.api.mcs.dto.*;
91343d 14 import com.iailab.module.model.common.enums.CommonConstant;
15 import com.iailab.module.model.common.enums.PreLineTypeEnum;
b368e6 16 import com.iailab.module.model.mcs.pre.entity.DmModuleEntity;
17 import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
c5fe30 18 import com.iailab.module.model.mcs.pre.entity.MmPredictAlarmMessageEntity;
b368e6 19 import com.iailab.module.model.mcs.pre.service.*;
c5fe30 20 import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmMessageSaveReqVO;
055765 21 import com.iailab.module.model.mcs.sche.entity.StScheduleSuggestEntity;
4072bc 22 import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService;
055765 23 import com.iailab.module.model.mcs.sche.service.StScheduleSuggestService;
19f359 24 import com.iailab.module.model.mcs.sche.vo.StScheduleSuggestSaveReqVO;
ead005 25 import com.iailab.module.model.mdk.vo.ItemVO;
91343d 26 import com.iailab.module.model.mpk.service.ChartService;
b368e6 27 import lombok.extern.slf4j.Slf4j;
977edc 28 import org.apache.commons.lang3.StringUtils;
b368e6 29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.util.CollectionUtils;
31 import org.springframework.validation.annotation.Validated;
32 import org.springframework.web.bind.annotation.RestController;
33
34 import java.math.BigDecimal;
35 import java.util.*;
912419 36 import java.util.stream.Collectors;
b368e6 37
38 /**
39  * @author PanZhibao
40  * @Description
41  * @createTime 2024年11月13日
42  */
43 @Slf4j
44 @RestController
45 @Validated
46 public class McsApiImpl implements McsApi {
47
48     @Autowired
49     private DmModuleService dmModuleService;
50
51     @Autowired
52     private MmPredictItemService mmPredictItemService;
53
54     @Autowired
55     private MmItemOutputService mmItemOutputService;
56
57     @Autowired
58     private MmItemResultService mmItemResultService;
59
60     @Autowired
61     private MmItemResultLastPointService mmItemResultLastPointService;
62
63     @Autowired
64     private DataPointApi dataPointApi;
91343d 65
66     @Autowired
67     private MmItemResultJsonService mmItemResultJsonService;
68
69     @Autowired
70     private ChartService chartService;
c5fe30 71
72     @Autowired
73     private MmPredictAlarmMessageService mmPredictAlarmMessageService;
055765 74
75     @Autowired
76     private StScheduleSuggestService stScheduleSuggestService;
8a74e9 77
78     @Autowired
79     private PlanItemApi planItemApi;
9587d2 80
L 81     @Autowired
82     private MmPredictAlarmConfigService mmPredictAlarmConfigService;
3a6dfc 83
4072bc 84     @Autowired
L 85     private StScheduleSchemeService stScheduleSchemeService;
b368e6 86
87     private int HOUR_MINS = 60;
88
89     @Override
90     public List<PredictItemTreeDTO> getPredictItemTree() {
91         List<PredictItemTreeDTO> result = new ArrayList<>();
92
93         List<DmModuleEntity> moduleList = dmModuleService.list(new HashMap<>());
94         if (CollectionUtils.isEmpty(moduleList)) {
95             return result;
96         }
97         moduleList.forEach(item -> {
98             PredictItemTreeDTO moduleOpt = new PredictItemTreeDTO();
99             moduleOpt.setId(item.getId());
100             moduleOpt.setLabel(item.getModulename());
101             List<PredictItemTreeDTO> children = new ArrayList<>();
a4891a 102             List<ItemVO> itemList = mmPredictItemService.getByModuleId(item.getId());
b368e6 103             itemList.forEach(item1 -> {
104                 PredictItemTreeDTO chd = new PredictItemTreeDTO();
a4891a 105                 chd.setLabel(item1.getItemName());
b368e6 106                 chd.setId(item1.getId());
a4891a 107                 List<PredictItemTreeDTO> chd1 = new ArrayList<>();
108                 List<MmItemOutputEntity> outList = mmItemOutputService.getByItemid(item1.getId());
109                 if (!CollectionUtils.isEmpty(outList)) {
110                     outList.forEach(out -> {
111                         PredictItemTreeDTO chd2 = new PredictItemTreeDTO();
112                         chd2.setId(out.getId());
f283ee 113                         chd2.setLabel(out.getResultName());
a4891a 114                         chd1.add(chd2);
115                     });
116                 }
117                 chd.setChildren(chd1);
b368e6 118                 children.add(chd);
119             });
120             moduleOpt.setChildren(children);
121             result.add(moduleOpt);
122         });
123         return result;
124     }
125
126     @Override
127     public PreDataBarLineRespVO getPreDataCharts(PreDataBarLineReqVO reqVO) {
128         PreDataBarLineRespVO result = new PreDataBarLineRespVO();
a4891a 129         List<String> outIds = reqVO.getOutIds();
b368e6 130         List<String> legends = new ArrayList<>();
131         List<PreDataViewRespDTO> dataViewList = new ArrayList<>();
9e844c 132         if (CollectionUtils.isEmpty(outIds)) {
b368e6 133             return result;
134         }
135         Date predictTime = reqVO.getPredictTime();
136         if (predictTime == null) {
9e844c 137             MmItemOutputEntity output = mmItemOutputService.getOutPutById(reqVO.getOutIds().get(0));
b82ba2 138             ItemVO predictItem = mmPredictItemService.getItemByIdFromCache(output.getItemid());
9e844c 139             if (predictItem.getLastTime() != null) {
140                 predictTime = predictItem.getLastTime();
141             } else {
142                 Calendar calendar = Calendar.getInstance();
143                 calendar.set(Calendar.MILLISECOND, 0);
144                 calendar.set(Calendar.SECOND, 0);
145                 predictTime = calendar.getTime();
146             }
b368e6 147         }
148         Date startTime = reqVO.getStartTime();
149         if (startTime == null) {
150             Calendar calendar = Calendar.getInstance();
151             calendar.setTime(predictTime);
152             calendar.add(Calendar.HOUR_OF_DAY, -1);
153             startTime = calendar.getTime();
154         }
155         Date endTime = reqVO.getEndTime();
156         if (endTime == null) {
157             Calendar calendar = Calendar.getInstance();
158             calendar.setTime(predictTime);
159             calendar.add(Calendar.HOUR_OF_DAY, 1);
160             endTime = calendar.getTime();
161         }
162
a4891a 163         for (int i = 0; i < outIds.size(); i++) {
b368e6 164             PreDataViewRespDTO viewDto = new PreDataViewRespDTO();
a4891a 165             String outId = outIds.get(i);
166             MmItemOutputEntity output = mmItemOutputService.getOutPutById(outId);
b368e6 167             if (output == null) {
9e844c 168                 continue;
b368e6 169             }
f283ee 170             legends.add(output.getResultName());
9e844c 171             viewDto.setItemId(output.getItemid());
172             viewDto.setOutId(outId);
173             viewDto.setResultstr(output.getResultstr());
f283ee 174             viewDto.setResultName(output.getResultName());
b368e6 175             viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime));
977edc 176             viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
177             viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
b368e6 178
179             List<Double> values = new ArrayList<>();
180             if (!CollectionUtils.isEmpty(viewDto.getRealData())) {
181                 List<Double> hisValues = new ArrayList<>();
182                 viewDto.getRealData().forEach(item -> {
183                     values.add(Double.parseDouble(item[1].toString()));
184                     hisValues.add(Double.parseDouble(item[1].toString()));
185                 });
186                 viewDto.setHisMax(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
187                 viewDto.setHisMin(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
188                 viewDto.setHisAvg(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
189                 viewDto.setHisCumulant(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).sum())
190                         .divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP));
191             }
192             if (!CollectionUtils.isEmpty(viewDto.getPreDataN())) {
193                 viewDto.getPreDataN().forEach(item -> {
194                     values.add(Double.parseDouble(item[1].toString()));
195                 });
196             }
197             if (!CollectionUtils.isEmpty(viewDto.getPreDataL())) {
198                 List<Double> preValues = new ArrayList<>();
199                 viewDto.getPreDataL().forEach(item -> {
200                     values.add(Double.parseDouble(item[1].toString()));
201                     preValues.add(Double.parseDouble(item[1].toString()));
202                 });
203                 viewDto.setPreMax(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
204                 viewDto.setPreMin(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
205                 viewDto.setPreAvg(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
206             }
207             if (!CollectionUtils.isEmpty(viewDto.getCurData())) {
208                 List<Double> preValues = new ArrayList<>();
209                 viewDto.getCurData().forEach(item -> {
210                     values.add(Double.parseDouble(item[1].toString()));
211                     preValues.add(Double.parseDouble(item[1].toString()));
212                 });
213                 viewDto.setPreCumulant(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).sum())
214                         .divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP));
215             }
216             if (!CollectionUtils.isEmpty(viewDto.getAdjData())) {
217                 viewDto.getAdjData().forEach(item -> {
218                     values.add(Double.parseDouble(item[1].toString()));
219                 });
220             }
221             if (!CollectionUtils.isEmpty(values)) {
222                 viewDto.setMaxValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
223                 viewDto.setMinValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
224             }
225             dataViewList.add(viewDto);
226         }
227         result.setStartTime(startTime);
228         result.setEndTime(endTime);
229         result.setPredictTime(predictTime);
230         result.setCategories(DateUtils.getTimeScale(startTime, endTime, 60));
231         result.setLegend(legends);
232         result.setDataViewList(dataViewList);
233         return result;
234     }
235
ead005 236     @Override
237     public PreDataItemChartRespVO getPreDataItemChart(PreDataItemChartReqVO reqVO) {
238         PreDataItemChartRespVO result = new PreDataItemChartRespVO();
864b61 239         ItemVO predictItem = mmPredictItemService.getItemById(reqVO.getItemId());
ead005 240         if (predictItem == null) {
241             return result;
242         }
243         if (predictItem.getLastTime() == null) {
244             return result;
245         }
328ef4 246         result.setPredictTime(predictItem.getLastTime());
ead005 247         Date startTime = reqVO.getStartTime();
248         if (startTime == null) {
249             Calendar calendar = Calendar.getInstance();
250             calendar.setTime(predictItem.getLastTime());
91343d 251             calendar.add(Calendar.MINUTE, -1 * predictItem.getPredictLength());
ead005 252             startTime = calendar.getTime();
253         }
254         Date endTime = reqVO.getEndTime();
255         if (endTime == null) {
256             Calendar calendar = Calendar.getInstance();
257             calendar.setTime(predictItem.getLastTime());
91343d 258             calendar.add(Calendar.MINUTE, predictItem.getPredictLength());
ead005 259             endTime = calendar.getTime();
260         }
1f9784 261         if (endTime.getTime() <= startTime.getTime()) {
262             Calendar calendar = Calendar.getInstance();
263             calendar.setTime(startTime);
91343d 264             calendar.add(Calendar.MINUTE, predictItem.getPredictLength());
1f9784 265             endTime = calendar.getTime();
266         }
267
ead005 268         List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity());
269         List<String> legend = new ArrayList<>();
270         LinkedHashMap<String, PreDataSampleViewRespDTO> viewMap = new LinkedHashMap<>();
271         List<MmItemOutputEntity> outs = mmItemOutputService.getByItemid(reqVO.getItemId());
272         if (CollectionUtils.isEmpty(outs)) {
273             return result;
274         }
275         for (MmItemOutputEntity out : outs) {
f283ee 276             legend.add(out.getResultName());
ead005 277             PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO();
85b200 278             if (StringUtils.isNotBlank(out.getPointid())) {
D 279                 viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime));
280             }
977edc 281             viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
f283ee 282             viewMap.put(out.getResultName(), viewDto);
ead005 283         }
284         result.setStartTime(startTime);
285         result.setEndTime(endTime);
286         result.setCategories(categories);
287         result.setLegend(legend);
288         result.setViewMap(viewMap);
289         return result;
290     }
291
328ef4 292     @Override
91343d 293     public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) {
294         PreDataSingleChartRespVO result = new PreDataSingleChartRespVO();
328ef4 295
91343d 296         Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode());
297         if (CollectionUtils.isEmpty(chartParams)) {
298             return result;
299         }
300         String itemCode = chartParams.get(CommonConstant.ITEM_CODE);
301         if (itemCode == null) {
302             return result;
303         }
304         String resultStr = chartParams.get(CommonConstant.RESULT_STR);
305         if (resultStr == null) {
306             return result;
307         }
bd9085 308         String resultIndex = chartParams.get(CommonConstant.RESULT_INDEX);
309
91343d 310         ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode);
311         if (predictItem == null || predictItem.getLastTime() == null) {
312             return result;
313         }
977edc 314         String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat();
315         PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(chartParams.get(CommonConstant.LINE_TYPE));
91343d 316         BigDecimal rangeH = chartParams.get(CommonConstant.RANGE_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_H));
317         BigDecimal rangeL = chartParams.get(CommonConstant.RANGE_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_L));
318         BigDecimal limitH = chartParams.get(CommonConstant.LIMIT_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_H));
319         BigDecimal limitL = chartParams.get(CommonConstant.LIMIT_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_L));
320         int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue();
321         int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue();
8a74e9 322
323         Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight);
324         Date predictTime = timeArray[0];
325         Date startTime = timeArray[1];
326         Date endTime = timeArray[2];
327
977edc 328         List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat);
91343d 329         List<String> legend = new ArrayList<>();
bdab69 330         MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), resultStr, resultIndex);
91343d 331         PreDataViewRespDTO dataView = new PreDataViewRespDTO();
332         dataView.setItemId(predictItem.getId());
333         dataView.setItemName(predictItem.getItemName());
334         dataView.setResultstr(resultStr);
335         dataView.setRangeH(rangeH);
336         dataView.setRangeL(rangeL);
337         dataView.setLimitH(limitH);
338         dataView.setLimitL(limitL);
b6bfe8 339         if (StringUtils.isNotBlank(outPut.getPointid())) {
D 340             dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime, timeFormat));
341         } else {
342             dataView.setRealData(new ArrayList<>());
343         }
977edc 344         dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat));
91343d 345         switch (lineType) {
346             case TN:
977edc 347                 dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime, timeFormat));
91343d 348                 break;
349             case TL:
977edc 350                 dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat));
351                 dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat));
91343d 352                 break;
353             default:
354                 break;
355         }
912419 356
357         if (!CollectionUtils.isEmpty(dataView.getCurData())) {
358             List<Double> curList = dataView.getCurData().stream().map(t -> {
359                 return new Double(t[1].toString());
360             }).collect(Collectors.toList());
361             dataView.setPreMax(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
362             dataView.setPreMin(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP));
363         }
364
8a74e9 365         result.setPredictTime(predictTime);
91343d 366         result.setStartTime(startTime);
367         result.setEndTime(endTime);
368         result.setCategories(categories);
369         result.setLegend(legend);
370         result.setDataView(dataView);
8a74e9 371         return result;
372     }
373
374     @Override
d9fe8f 375     public Map<String, List<Object[]>> getPreDataCur(PreDataJsonReqVO reqVO) {
376         Map<String, List<Object[]>> result = new HashMap<>();
377         if (reqVO == null || reqVO.getPredictTime() == null || CollectionUtils.isEmpty(reqVO.getOutputIdList())) {
378             return result;
379         }
380         reqVO.getOutputIdList().forEach(outPutId -> {
381             result.put(outPutId, mmItemResultJsonService.getData(outPutId, reqVO.getPredictTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
382         });
383         return result;
384     }
385
386     @Override
8a74e9 387     public PlanDataSingleChartRespVO getPlanDataSingleChart(PreDataSingleChartReqVO reqVO) {
388         PlanDataSingleChartRespVO result = new PlanDataSingleChartRespVO();
389         Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode());
390         if (CollectionUtils.isEmpty(chartParams)) {
391             return result;
392         }
393         String itemCode = chartParams.get(CommonConstant.ITEM_CODE);
394         if (itemCode == null) {
395             return result;
396         }
397         String planItemStr = chartParams.get(CommonConstant.PLAN_ITEM_LIST);
398         if (planItemStr == null) {
399             return result;
400         }
401         List<String> planItemCodeList = Arrays.asList(planItemStr.split(","));
402
403         ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode);
404         if (predictItem == null || predictItem.getLastTime() == null) {
405             return result;
406         }
407         String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat();
408         int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue();
409         int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue();
410         Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight);
411         Date predictTime = timeArray[0];
412         Date startTime = timeArray[1];
413         Date endTime = timeArray[2];
414         List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat);
415         List<String> legend = new ArrayList<>();
416         LinkedHashMap<String, List<PlanDataRecordDTO>> record = new LinkedHashMap<>();
417         ApiDataQueryDTO queryDTO = new ApiDataQueryDTO();
418         queryDTO.setItemNos(planItemCodeList);
419         queryDTO.setStart(startTime);
420         queryDTO.setEnd(endTime);
421         LinkedHashMap<String, List<ApiPlanDataDTO>> planData = planItemApi.queryPlanItemRecordValue(queryDTO);
422         if (CollectionUtils.isEmpty(planData)) {
423             planData.forEach((key, value) -> {
424                 record.put(key, ConvertUtils.sourceToTarget(value, PlanDataRecordDTO.class));
425             });
426         }
427         result.setPredictTime(predictTime);
428         result.setStartTime(startTime);
429         result.setEndTime(endTime);
430         result.setCategories(categories);
431         result.setLegend(legend);
432         result.setRecord(record);
328ef4 433         return result;
434     }
435
b368e6 436     /**
437      * 获取真实值
438      *
439      * @param pointId
440      * @param startTime
441      * @param endTime
442      * @return
443      */
444     private List<Object[]> getHisData(String pointId, Date startTime, Date endTime) {
445         List<Object[]> result = new ArrayList<>();
446         ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId);
447         ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO();
448         queryPointDto.setPointNo(pointDTO.getPointNo());
449         queryPointDto.setStart(startTime);
450         queryPointDto.setEnd(endTime);
451         List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto);
452         if (CollectionUtils.isEmpty(valueDTOS)) {
453             return result;
454         }
455         valueDTOS.forEach(item -> {
456             Object[] values = new Object[2];
214275 457             values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
458             values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP);
b368e6 459             result.add(values);
460         });
461         return result;
462     }
463
977edc 464     /**
465      * 获取真实值
466      *
467      * @param pointId
468      * @param startTime
469      * @param endTime
470      * @param timeFormat
471      * @return
472      */
473     private List<Object[]> getHisData(String pointId, Date startTime, Date endTime, String timeFormat) {
474         List<Object[]> result = new ArrayList<>();
475         ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId);
476         ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO();
477         queryPointDto.setPointNo(pointDTO.getPointNo());
478         queryPointDto.setStart(startTime);
479         queryPointDto.setEnd(endTime);
480         List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto);
481         if (CollectionUtils.isEmpty(valueDTOS)) {
482             return result;
483         }
484         valueDTOS.forEach(item -> {
485             Object[] values = new Object[2];
486             values[0] = DateUtils.format(item.getT(), timeFormat);
487             values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP);
488             result.add(values);
489         });
490         return result;
491     }
492
c5fe30 493     /**
494      * 新增预警信息
495      *
496      * @param dto
497      * @return
498      */
b368e6 499     @Override
500     public Boolean createAlarmMessage(AlarmMessageRespDTO dto) {
c5fe30 501         try {
502             mmPredictAlarmMessageService.create(ConvertUtils.sourceToTarget(dto, MmPredictAlarmMessageSaveReqVO.class));
503             return true;
504         } catch (Exception e) {
505             return false;
506         }
b368e6 507     }
508
509     @Override
510     public List<AlarmMessageRespDTO> listAlarmMessage(Map<String, Object> params) {
511         return null;
512     }
513
514     @Override
9587d2 515     public List<AlarmConfigRespDTO> listAlarmConfig(Map<String, Object> params) {
L 516         return mmPredictAlarmConfigService.list(params);
517     }
518
519     @Override
c5fe30 520     public AlarmMessageRespDTO getLastAlarmMessage(String alarmObj) {
521         MmPredictAlarmMessageEntity entity = mmPredictAlarmMessageService.getLast(alarmObj);
522         return ConvertUtils.sourceToTarget(entity, AlarmMessageRespDTO.class);
523     }
524
525     @Override
b368e6 526     public Boolean createScheduleSuggest(ScheduleSuggestRespDTO dto) {
19f359 527         stScheduleSuggestService.create(ConvertUtils.sourceToTarget(dto, StScheduleSuggestSaveReqVO.class));
b368e6 528         return true;
529     }
530
531     @Override
4072bc 532     public List<ScheduleSuggestRespDTO> listScheduleSuggest(Map<String, Object> params) {
3a6dfc 533         return Collections.emptyList();
L 534     }
535
536     @Override
055765 537     public List<ScheduleSuggestRespDTO> getLastLimitScheduleSuggest(String scheduleObj, Integer limit) {
538         List<StScheduleSuggestEntity> list = stScheduleSuggestService.getList(scheduleObj, limit);
539         return ConvertUtils.sourceToTarget(list, ScheduleSuggestRespDTO.class);
b368e6 540     }
541
542     @Override
543     public Boolean modifyPredictModelSetting(List<PredictModelSettingReqDTO> dtos) {
544         return true;
545     }
546
547     @Override
548     public Boolean modifyScheduleModelSetting(List<ScheduleModelSettingReqDTO> dtos) {
549         return true;
550     }
8a74e9 551
4072bc 552     @Override
L 553     public List<StScheduleSchemeDTO> listScheduleScheme(Map<String, Object> params) {
554         return stScheduleSchemeService.list(params);
555     }
556
8a74e9 557
558     private Date[] calResultTime(ItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) {
559         Date[] result = new Date[3];
560         Date predictTime = predictItem.getLastTime();
561         Date startTime = startTimeReq;
562         if (startTime == null) {
563             Calendar calendar = Calendar.getInstance();
564             calendar.setTime(predictItem.getLastTime());
565             calendar.add(Calendar.MINUTE, -1 * lengthLeft);
566             startTime = calendar.getTime();
567         }
568         Date endTime = endTimeReq;
569         if (endTime == null) {
570             Calendar calendar = Calendar.getInstance();
571             calendar.setTime(predictItem.getLastTime());
572             calendar.add(Calendar.MINUTE, lengthRight);
573             endTime = calendar.getTime();
574         }
575         if (endTime.getTime() <= startTime.getTime()) {
576             Calendar calendar = Calendar.getInstance();
577             calendar.setTime(startTime);
578             calendar.add(Calendar.MINUTE, lengthRight);
579             endTime = calendar.getTime();
580         }
581         result[0] = predictTime;
582         result[1] = startTime;
583         result[2] = endTime;
584         return result;
585     }
b368e6 586 }