Jay
2024-10-08 79914dabac38d83676ea16ff65da8d941a099285
提交 | 用户 | 时间
7fd198 1 package com.iailab.module.model.mdk.predict;
2
3 import com.iailab.module.data.api.point.DataPointApi;
4 import com.iailab.module.data.api.point.dto.ApiPointDTO;
5 import com.iailab.module.data.enums.DataPointFreq;
6 import com.iailab.module.model.mcs.pre.service.MmItemResultService;
7 import com.iailab.module.model.mdk.factory.ItemEntityFactory;
8 import com.iailab.module.model.mdk.vo.MmItemOutputVO;
9 import com.iailab.module.model.mdk.vo.DataValueVO;
10 import com.iailab.module.model.mdk.vo.PredictResultVO;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.scheduling.annotation.Async;
13 import org.springframework.stereotype.Service;
14 import org.springframework.util.CollectionUtils;
15
16 import java.util.*;
17
18 @Service
19 public class PredictResultHandler {
20     @Autowired
21     private MmItemResultService mmItemResultService;
22
23     @Autowired
24     private ItemEntityFactory itemEntityFactory;
25
26     @Autowired
27     private DataPointApi dataPointApi;
28
29     /**
30      * convertToPredictData
31      *
32      * @param predictResult
33      * @return
34      */
9162d9 35     public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) {
7fd198 36         Map<String, List<DataValueVO>> resultMap = new HashMap<>();
37         List<MmItemOutputVO> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId());
38
39         if (!CollectionUtils.isEmpty(predictResult.getPredictList())) {
40             resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList());
41             return resultMap;
42         }
536b8e 43         ApiPointDTO point = dataPointApi.getInfoById(itemOutPutList.get(0).getPointId());
7fd198 44         List<Date> dateTimeList = new ArrayList<>();
45         Integer rows = predictResult.getPredictMatrix().length;
46         Integer columns = predictResult.getPredictMatrix()[0].length;
47         Date tempTime = predictResult.getPredictTime();
48         for (Integer i = 0; i < rows; i++) {
49             dateTimeList.add(tempTime);
50             Calendar calendar = Calendar.getInstance();
51             calendar.setTime(tempTime);
52             calendar.add(Calendar.SECOND, DataPointFreq.getEumByCode(point.getMinfreqid()).getValue());
53             tempTime = calendar.getTime();
54         }
55         for (Integer i = 0; i < columns; i++) {
56             List<DataValueVO> predictDataList = new ArrayList<>();
57             for (Integer j = 0; j < rows; j++) {
58                 DataValueVO predictData = new DataValueVO();
59                 predictData.setDataTime(dateTimeList.get(j));
60                 predictData.setDataValue(Double.valueOf(predictResult.getPredictMatrix()[j][i]));
61                 predictDataList.add(predictData);
62             }
63             resultMap.put(itemOutPutList.get(i).getId(), predictDataList);
64             predictResult.setPredictList(predictDataList);
65         }
66         return resultMap;
67     }
68
69     /**
70      * savePredictResult
71      *
72      * @param predictResult
73      */
74     @Async
75     public void savePredictResult(PredictResultVO predictResult) {
76         Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult);
77         mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime());
78     }
79
80     public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) {
81         String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId();
82         List<MmItemOutputVO> outputList = itemEntityFactory.getOutPutByItemId(itemId);
83         return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end);
84     }
85
86     public List<DataValueVO> getPredictValueByItemId(String itemId, Date start, Date end) {
87         List<MmItemOutputVO> outputList = itemEntityFactory.getOutPutByItemId(itemId);
88         return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end);
89     }
90 }