提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.api; |
潘 |
2 |
|
|
3 |
import com.alibaba.fastjson.JSON; |
|
4 |
import com.iailab.module.model.api.mdk.MdkApi; |
|
5 |
import com.iailab.module.model.api.mdk.dto.*; |
|
6 |
import com.iailab.framework.common.pojo.CommonResult; |
|
7 |
import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
|
8 |
import com.iailab.module.model.mcs.pre.service.DmModuleService; |
|
9 |
import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
|
10 |
import com.iailab.module.model.mdk.predict.PredictModuleHandler; |
|
11 |
import com.iailab.module.model.mdk.vo.ItemVO; |
|
12 |
import com.iailab.module.model.mdk.vo.PredictResultVO; |
|
13 |
import lombok.extern.slf4j.Slf4j; |
|
14 |
import org.springframework.beans.factory.annotation.Autowired; |
|
15 |
import org.springframework.validation.annotation.Validated; |
|
16 |
import org.springframework.web.bind.annotation.RequestBody; |
|
17 |
import org.springframework.web.bind.annotation.RestController; |
|
18 |
|
|
19 |
import javax.validation.Valid; |
|
20 |
|
|
21 |
import java.util.HashMap; |
|
22 |
import java.util.List; |
|
23 |
import java.util.Map; |
|
24 |
import java.util.stream.Collectors; |
|
25 |
|
|
26 |
import static com.iailab.framework.common.pojo.CommonResult.error; |
|
27 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author PanZhibao |
|
31 |
* @Description |
|
32 |
* @createTime 2024年08月26日 |
|
33 |
*/ |
|
34 |
@Slf4j |
|
35 |
@RestController |
|
36 |
@Validated |
|
37 |
public class MdkApiImpl implements MdkApi { |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private DmModuleService dmModuleService; |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private MmPredictItemService mmPredictItemService; |
|
44 |
|
|
45 |
@Autowired |
|
46 |
private PredictModuleHandler predictModuleHandler; |
|
47 |
|
|
48 |
/** |
|
49 |
* 按模块预测 |
|
50 |
* |
|
51 |
* @param reqDTO |
|
52 |
* @return |
|
53 |
*/ |
|
54 |
@Override |
|
55 |
public CommonResult<MdkPredictModuleRespDTO> predictModule(MdkPredictReqDTO reqDTO) { |
|
56 |
MdkPredictModuleRespDTO resp = new MdkPredictModuleRespDTO(); |
|
57 |
Map<String, MdkPredictItemRespDTO> predictItemRespMap = new HashMap<>(); |
|
58 |
try { |
|
59 |
if (reqDTO.getPredictTime() == null) { |
|
60 |
throw new Exception("PredictTime不能为空"); |
|
61 |
} |
|
62 |
if (reqDTO.getModuleType() == null) { |
|
63 |
throw new Exception("ModuleType不能为空"); |
|
64 |
} |
|
65 |
log.info("预测参数:" + JSON.toJSONString(reqDTO)); |
|
66 |
MdkPredictModuleRespDTO result = new MdkPredictModuleRespDTO(); |
|
67 |
result.setPredictTime(reqDTO.getPredictTime()); |
|
68 |
result.setModuleType(reqDTO.getModuleType()); |
|
69 |
List<DmModuleEntity> moduleList = dmModuleService.getModuleByModuleType(reqDTO.getModuleType()); |
|
70 |
log.info("预测计算开始: " + System.currentTimeMillis()); |
|
71 |
for (DmModuleEntity module : moduleList) { |
|
72 |
int intervalTime = 0; |
|
73 |
if (module.getPredicttime() != null) { |
|
74 |
intervalTime = (int) (reqDTO.getPredictTime().getTime() - module.getPredicttime().getTime()) / (1000 * 60); |
|
75 |
} |
|
76 |
List<ItemVO> predictItemList = mmPredictItemService.getByModuleId(module.getId()); |
|
77 |
Map<String, PredictResultVO> predictResultMap = predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), intervalTime); |
|
78 |
for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) { |
|
79 |
List<MdkPredictDataDTO> predictData = entry.getValue().getPredictList().stream().map(t-> { |
|
80 |
MdkPredictDataDTO dto1 = new MdkPredictDataDTO(); |
|
81 |
dto1.setDataTime(t.getDataTime()); |
|
82 |
dto1.setDataValue(t.getDataValue()); |
|
83 |
return dto1; |
|
84 |
}).collect(Collectors.toList()); |
|
85 |
MdkPredictItemRespDTO itemResp = new MdkPredictItemRespDTO(); |
|
86 |
itemResp.setItemId(entry.getValue().getPredictId()); |
|
87 |
itemResp.setPredictData(predictData); |
|
88 |
predictItemRespMap.put(entry.getKey(), itemResp); |
|
89 |
} |
|
90 |
} |
|
91 |
log.info("预测计算结束: " + System.currentTimeMillis()); |
|
92 |
} catch (Exception ex) { |
|
93 |
return error(999, ex.getMessage()); |
|
94 |
} |
|
95 |
resp.setPredictItemRespMap(predictItemRespMap); |
|
96 |
return success(resp); |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* 单个预测 |
|
101 |
* |
|
102 |
* @param reqDTO |
|
103 |
* @return |
|
104 |
*/ |
|
105 |
@Override |
|
106 |
public CommonResult<MdkPredictItemRespDTO> predictItem(@Valid @RequestBody MdkPredictReqDTO reqDTO) { |
|
107 |
MdkPredictItemRespDTO resp = new MdkPredictItemRespDTO(); |
|
108 |
|
|
109 |
return success(resp); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* 预测调整 |
|
114 |
* |
|
115 |
* @param reqDTO |
|
116 |
* @return |
|
117 |
*/ |
|
118 |
@Override |
|
119 |
public CommonResult<Boolean> predictAutoAdjust(@Valid @RequestBody MdkPredictReqDTO reqDTO) { |
|
120 |
|
|
121 |
|
|
122 |
return success(true); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* 执行调度模型 |
|
127 |
* |
|
128 |
* @param reqDTO |
|
129 |
* @return |
|
130 |
*/ |
|
131 |
@Override |
|
132 |
public CommonResult<MdkScheduleRespDTO> doSchedule(@Valid @RequestBody MdkScheduleReqDTO reqDTO) { |
|
133 |
MdkScheduleRespDTO resp = new MdkScheduleRespDTO(); |
|
134 |
|
|
135 |
return success(resp); |
|
136 |
} |
|
137 |
} |