提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.predict.impl; |
潘 |
2 |
|
|
3 |
import com.iailab.framework.common.util.collection.CollectionUtils; |
|
4 |
import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
|
5 |
import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
|
6 |
import com.iailab.module.model.mdk.common.enums.ItemPredictStatus; |
|
7 |
import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
|
8 |
import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
|
9 |
import com.iailab.module.model.mdk.predict.PredictItemHandler; |
|
10 |
import com.iailab.module.model.mdk.predict.PredictModelHandler; |
|
11 |
import com.iailab.module.model.mdk.vo.ItemVO; |
|
12 |
import com.iailab.module.model.mdk.vo.PredictResultVO; |
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
|
14 |
import org.springframework.stereotype.Component; |
|
15 |
|
|
16 |
import java.sql.Timestamp; |
|
17 |
import java.text.MessageFormat; |
|
18 |
import java.util.ArrayList; |
|
19 |
import java.util.Calendar; |
|
20 |
import java.util.Date; |
|
21 |
import java.util.List; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author PanZhibao |
|
25 |
* @Description |
|
26 |
* @createTime 2024年09月01日 |
|
27 |
*/ |
|
28 |
@Component |
|
29 |
public class PredictItemNormalHandlerImpl implements PredictItemHandler { |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private MmPredictModelService mmPredictModelService; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private PredictModelHandler predictModelHandler; |
|
36 |
|
|
37 |
@Override |
|
38 |
public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) |
|
39 |
throws ItemInvokeException{ |
|
40 |
String itemId = predictItemDto.getId(); |
|
41 |
ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING; |
|
42 |
PredictResultVO finalResult = new PredictResultVO(); |
|
43 |
PredictResultVO predictResult = new PredictResultVO(); |
|
44 |
List<PredictResultVO> predictResultList = new ArrayList<>(); |
|
45 |
try { |
|
46 |
// 获取预测项模型 |
|
47 |
List<MmPredictModelEntity> predictModelList = mmPredictModelService.getActiveModelByItemId(itemId); |
|
48 |
if (CollectionUtils.isAnyEmpty(predictModelList)) { |
|
49 |
throw new ModelInvokeException(MessageFormat.format("{0},itemId={1}", |
|
50 |
ModelInvokeException.errorGetModelEntity, itemId)); |
|
51 |
} |
|
52 |
for (MmPredictModelEntity predictModel : predictModelList) { |
|
53 |
predictResult = predictModelHandler.predictByModel(predictTime, predictModel); |
|
54 |
predictResult.setPredictId(itemId); |
|
55 |
predictResultList.add(predictResult); |
|
56 |
} |
|
57 |
itemStatus = ItemPredictStatus.SUCCESS; |
|
58 |
Calendar calendar = Calendar.getInstance(); |
|
59 |
calendar.setTime(predictTime); |
|
60 |
calendar.add(Calendar.MINUTE, predictResult.getPredictMatrix().length - 1); |
|
61 |
Timestamp endTime = new Timestamp(calendar.getTime().getTime()); |
|
62 |
finalResult = predictResultList.get(0); |
|
63 |
|
|
64 |
} catch (Exception ex) { |
|
65 |
ex.printStackTrace(); |
|
66 |
//预测项预测失败的状态 |
|
67 |
itemStatus = ItemPredictStatus.FAILED; |
|
68 |
throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
|
69 |
ItemInvokeException.errorItemFailed, itemId)); |
|
70 |
} |
|
71 |
|
|
72 |
return finalResult; |
|
73 |
} |
|
74 |
} |