Jay
2024-10-12 794e63e4cc2f153441604a72364dbb63a259da9b
提交 | 用户 | 时间
7fd198 1 package com.iailab.module.model.mdk.predict;
2
3 import com.iailab.module.model.mcs.pre.enums.ItemStatus;
4 import com.iailab.module.model.mdk.factory.PredictItemFactory;
5 import com.iailab.module.model.mdk.vo.ItemVO;
6 import com.iailab.module.model.mdk.vo.PredictResultVO;
7 import lombok.extern.slf4j.Slf4j;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component;
10
11 import java.text.MessageFormat;
12 import java.time.Duration;
13 import java.time.Instant;
14 import java.util.Date;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18
19 /**
20  * @author PanZhibao
21  * @Description
22  * @createTime 2024年08月30日
23  */
24 @Slf4j
25 @Component
26 public class PredictModuleHandler {
27
28
29     @Autowired
30     private PredictItemFactory predictItemFactory;
31
32     @Autowired
33     private PredictResultHandler predictResultHandler;
34
35
36     public Map<String, PredictResultVO> predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime) {
37         Map<String, PredictResultVO> result = new HashMap<>();
38
39         PredictResultVO predictResult = new PredictResultVO();
40         for (ItemVO predictItem : predictItemList) {
41             if (!predictItem.getStatus().equals(ItemStatus.STATUS1)) {
42                 continue;
43             }
44             try {
45                 PredictItemHandler predictItemHandler = (PredictItemHandler)predictItemFactory.create(predictItem.getId());
46                 Instant start = Instant.now();
47                 try {
48                     predictResult = predictItemHandler.predict(predictTime, predictItem);
49                 } catch (Exception e) {
50                     e.printStackTrace();
51                     log.error(String.valueOf(e));
52                 }
53                 Instant end = Instant.now();
54                 Long drtPre = Duration.between(start, end).getSeconds();
55                 log.info(MessageFormat.format("预测项:{0},预测时间:{1}秒", predictItem.getItemName(), drtPre));
56
57                 predictResult.setT(intervalTime);
58                 predictResult.setSaveIndex(predictItem.getSaveIndex());
59                 predictResult.setLt(1);
60                 predictResultHandler.savePredictResult(predictResult);
61                 Instant endSave = Instant.now();
62                 Long drtSave = Duration.between(end, endSave).getSeconds();
63                 log.info(MessageFormat.format("预测项:{0},保存时间:{1}秒", predictItem.getItemName(),
64                         drtSave));
aa96f9 65
66                 result.put(predictItem.getItemNo(), predictResult);
7fd198 67             } catch (Exception e) {
68                 e.printStackTrace();
69                 log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}",
70                         predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime));
71             }
72         }
73         return result;
74     }
75 }