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