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