提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.predict; |
潘 |
2 |
|
4eb113
|
3 |
import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
7fd198
|
4 |
import com.iailab.module.model.mcs.pre.enums.ItemStatus; |
4eb113
|
5 |
import com.iailab.module.model.mcs.pre.service.MmItemStatusService; |
7fd198
|
6 |
import com.iailab.module.model.mdk.factory.PredictItemFactory; |
潘 |
7 |
import com.iailab.module.model.mdk.vo.ItemVO; |
|
8 |
import com.iailab.module.model.mdk.vo.PredictResultVO; |
|
9 |
import lombok.extern.slf4j.Slf4j; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
|
|
13 |
import java.text.MessageFormat; |
|
14 |
import java.time.Duration; |
|
15 |
import java.time.Instant; |
|
16 |
import java.util.Date; |
|
17 |
import java.util.HashMap; |
|
18 |
import java.util.List; |
|
19 |
import java.util.Map; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author PanZhibao |
|
23 |
* @Description |
|
24 |
* @createTime 2024年08月30日 |
|
25 |
*/ |
|
26 |
@Slf4j |
|
27 |
@Component |
|
28 |
public class PredictModuleHandler { |
|
29 |
|
|
30 |
|
|
31 |
@Autowired |
|
32 |
private PredictItemFactory predictItemFactory; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private PredictResultHandler predictResultHandler; |
|
36 |
|
4eb113
|
37 |
@Autowired |
潘 |
38 |
private MmItemStatusService mmItemStatusService; |
|
39 |
|
7fd198
|
40 |
|
4f1717
|
41 |
/** |
潘 |
42 |
* 预测处理 |
|
43 |
* |
|
44 |
* @param predictItemList |
|
45 |
* @param predictTime |
|
46 |
* @param intervalTime |
|
47 |
* @return |
|
48 |
*/ |
7fd198
|
49 |
public Map<String, PredictResultVO> predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime) { |
潘 |
50 |
Map<String, PredictResultVO> result = new HashMap<>(); |
|
51 |
|
|
52 |
PredictResultVO predictResult = new PredictResultVO(); |
|
53 |
for (ItemVO predictItem : predictItemList) { |
1a2b62
|
54 |
if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
7fd198
|
55 |
continue; |
潘 |
56 |
} |
4eb113
|
57 |
Long totalDur = 0L; |
7fd198
|
58 |
try { |
ead005
|
59 |
mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.PROCESSING, totalDur, predictTime); |
cf2287
|
60 |
PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
7fd198
|
61 |
Instant start = Instant.now(); |
潘 |
62 |
try { |
4f1717
|
63 |
// 预测项开始预测 |
7fd198
|
64 |
predictResult = predictItemHandler.predict(predictTime, predictItem); |
潘 |
65 |
} catch (Exception e) { |
|
66 |
e.printStackTrace(); |
|
67 |
log.error(String.valueOf(e)); |
ead005
|
68 |
mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime); |
潘 |
69 |
continue; |
7fd198
|
70 |
} |
潘 |
71 |
Instant end = Instant.now(); |
|
72 |
Long drtPre = Duration.between(start, end).getSeconds(); |
|
73 |
log.info(MessageFormat.format("预测项:{0},预测时间:{1}秒", predictItem.getItemName(), drtPre)); |
4eb113
|
74 |
totalDur = totalDur + drtPre; |
7fd198
|
75 |
|
4f1717
|
76 |
predictResult.setGranularity(predictItem.getGranularity()); |
7fd198
|
77 |
predictResult.setT(intervalTime); |
潘 |
78 |
predictResult.setSaveIndex(predictItem.getSaveIndex()); |
|
79 |
predictResult.setLt(1); |
4f1717
|
80 |
|
潘 |
81 |
// 保存预测结果 |
7fd198
|
82 |
predictResultHandler.savePredictResult(predictResult); |
潘 |
83 |
Instant endSave = Instant.now(); |
|
84 |
Long drtSave = Duration.between(end, endSave).getSeconds(); |
|
85 |
log.info(MessageFormat.format("预测项:{0},保存时间:{1}秒", predictItem.getItemName(), |
|
86 |
drtSave)); |
4eb113
|
87 |
totalDur = totalDur + drtSave; |
ead005
|
88 |
mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.SUCCESS, totalDur, predictTime); |
aa96f9
|
89 |
result.put(predictItem.getItemNo(), predictResult); |
7fd198
|
90 |
} catch (Exception e) { |
潘 |
91 |
e.printStackTrace(); |
|
92 |
log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
|
93 |
predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime)); |
ead005
|
94 |
mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime); |
7fd198
|
95 |
} |
潘 |
96 |
} |
|
97 |
return result; |
|
98 |
} |
|
99 |
} |