提交 | 用户 | 时间
|
b368e6
|
1 |
package com.iailab.module.model.api; |
潘 |
2 |
|
|
3 |
import com.iailab.framework.common.util.date.DateUtils; |
|
4 |
import com.iailab.module.data.api.point.DataPointApi; |
|
5 |
import com.iailab.module.data.api.point.dto.ApiPointDTO; |
|
6 |
import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
|
7 |
import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
|
8 |
import com.iailab.module.model.api.mcs.McsApi; |
|
9 |
import com.iailab.module.model.api.mcs.dto.*; |
|
10 |
import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
|
11 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
|
12 |
import com.iailab.module.model.mcs.pre.service.*; |
|
13 |
import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; |
ead005
|
14 |
import com.iailab.module.model.mdk.vo.ItemVO; |
b368e6
|
15 |
import lombok.extern.slf4j.Slf4j; |
潘 |
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.util.CollectionUtils; |
|
18 |
import org.springframework.validation.annotation.Validated; |
|
19 |
import org.springframework.web.bind.annotation.RestController; |
|
20 |
|
|
21 |
import java.math.BigDecimal; |
|
22 |
import java.util.*; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author PanZhibao |
|
26 |
* @Description |
|
27 |
* @createTime 2024年11月13日 |
|
28 |
*/ |
|
29 |
@Slf4j |
|
30 |
@RestController |
|
31 |
@Validated |
|
32 |
public class McsApiImpl implements McsApi { |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private DmModuleService dmModuleService; |
|
36 |
|
|
37 |
@Autowired |
|
38 |
private MmPredictItemService mmPredictItemService; |
|
39 |
|
|
40 |
@Autowired |
|
41 |
private MmItemOutputService mmItemOutputService; |
|
42 |
|
|
43 |
@Autowired |
|
44 |
private MmItemResultService mmItemResultService; |
|
45 |
|
|
46 |
@Autowired |
|
47 |
private MmItemResultLastPointService mmItemResultLastPointService; |
|
48 |
|
|
49 |
@Autowired |
|
50 |
private DataPointApi dataPointApi; |
|
51 |
|
|
52 |
private int HOUR_MINS = 60; |
|
53 |
|
|
54 |
@Override |
|
55 |
public List<PredictItemTreeDTO> getPredictItemTree() { |
|
56 |
List<PredictItemTreeDTO> result = new ArrayList<>(); |
|
57 |
|
|
58 |
List<DmModuleEntity> moduleList = dmModuleService.list(new HashMap<>()); |
|
59 |
if (CollectionUtils.isEmpty(moduleList)) { |
|
60 |
return result; |
|
61 |
} |
|
62 |
moduleList.forEach(item -> { |
|
63 |
PredictItemTreeDTO moduleOpt = new PredictItemTreeDTO(); |
|
64 |
moduleOpt.setId(item.getId()); |
|
65 |
moduleOpt.setLabel(item.getModulename()); |
|
66 |
List<PredictItemTreeDTO> children = new ArrayList<>(); |
|
67 |
Map<String, Object> params = new HashMap<>(2); |
|
68 |
params.put("status", 1); |
|
69 |
params.put("moduleid", item.getId()); |
|
70 |
List<MmPredictItemRespVO> itemList = mmPredictItemService.list(params); |
|
71 |
itemList.forEach(item1 -> { |
|
72 |
PredictItemTreeDTO chd = new PredictItemTreeDTO(); |
|
73 |
chd.setLabel(item1.getItemname()); |
|
74 |
chd.setId(item1.getId()); |
|
75 |
children.add(chd); |
|
76 |
}); |
|
77 |
moduleOpt.setChildren(children); |
|
78 |
result.add(moduleOpt); |
|
79 |
}); |
|
80 |
return result; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public PreDataBarLineRespVO getPreDataCharts(PreDataBarLineReqVO reqVO) { |
|
85 |
PreDataBarLineRespVO result = new PreDataBarLineRespVO(); |
|
86 |
List<String[]> queryIds = reqVO.getQueryIds(); |
|
87 |
List<String> legends = new ArrayList<>(); |
|
88 |
List<PreDataViewRespDTO> dataViewList = new ArrayList<>(); |
|
89 |
if (CollectionUtils.isEmpty(reqVO.getQueryIds())) { |
|
90 |
return result; |
|
91 |
} |
|
92 |
Date predictTime = reqVO.getPredictTime(); |
|
93 |
if (predictTime == null) { |
|
94 |
DmModuleEntity dmModule = dmModuleService.getModuleByItemId(queryIds.get(0)[0]); |
|
95 |
if (dmModule != null) { |
|
96 |
predictTime = dmModule.getPredicttime(); |
|
97 |
} else { |
|
98 |
Calendar calendar = Calendar.getInstance(); |
|
99 |
calendar.set(Calendar.MILLISECOND, 0); |
|
100 |
calendar.set(Calendar.SECOND, 0); |
|
101 |
predictTime = calendar.getTime(); |
|
102 |
} |
|
103 |
} |
|
104 |
Date startTime = reqVO.getStartTime(); |
|
105 |
if (startTime == null) { |
|
106 |
Calendar calendar = Calendar.getInstance(); |
|
107 |
calendar.setTime(predictTime); |
|
108 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
109 |
startTime = calendar.getTime(); |
|
110 |
} |
|
111 |
Date endTime = reqVO.getEndTime(); |
|
112 |
if (endTime == null) { |
|
113 |
Calendar calendar = Calendar.getInstance(); |
|
114 |
calendar.setTime(predictTime); |
|
115 |
calendar.add(Calendar.HOUR_OF_DAY, 1); |
|
116 |
endTime = calendar.getTime(); |
|
117 |
} |
|
118 |
|
|
119 |
for (int i = 0; i < queryIds.size(); i++) { |
|
120 |
PreDataViewRespDTO viewDto = new PreDataViewRespDTO(); |
|
121 |
String itemId = queryIds.get(i)[0]; |
|
122 |
String outKey = queryIds.get(i)[1]; |
|
123 |
MmItemOutputEntity output = mmItemOutputService.getByItemid(itemId, outKey); |
|
124 |
if (output == null) { |
|
125 |
continue; |
|
126 |
} |
|
127 |
legends.add(output.getResultstr()); |
|
128 |
viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); |
|
129 |
viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime)); |
|
130 |
viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime)); |
|
131 |
|
|
132 |
List<Double> values = new ArrayList<>(); |
|
133 |
if (!CollectionUtils.isEmpty(viewDto.getRealData())) { |
|
134 |
List<Double> hisValues = new ArrayList<>(); |
|
135 |
viewDto.getRealData().forEach(item -> { |
|
136 |
values.add(Double.parseDouble(item[1].toString())); |
|
137 |
hisValues.add(Double.parseDouble(item[1].toString())); |
|
138 |
}); |
|
139 |
viewDto.setHisMax(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
140 |
viewDto.setHisMin(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
141 |
viewDto.setHisAvg(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
142 |
viewDto.setHisCumulant(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
143 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
144 |
} |
|
145 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataN())) { |
|
146 |
viewDto.getPreDataN().forEach(item -> { |
|
147 |
values.add(Double.parseDouble(item[1].toString())); |
|
148 |
}); |
|
149 |
} |
|
150 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataL())) { |
|
151 |
List<Double> preValues = new ArrayList<>(); |
|
152 |
viewDto.getPreDataL().forEach(item -> { |
|
153 |
values.add(Double.parseDouble(item[1].toString())); |
|
154 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
155 |
}); |
|
156 |
viewDto.setPreMax(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
157 |
viewDto.setPreMin(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
158 |
viewDto.setPreAvg(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
159 |
} |
|
160 |
if (!CollectionUtils.isEmpty(viewDto.getCurData())) { |
|
161 |
List<Double> preValues = new ArrayList<>(); |
|
162 |
viewDto.getCurData().forEach(item -> { |
|
163 |
values.add(Double.parseDouble(item[1].toString())); |
|
164 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
165 |
}); |
|
166 |
viewDto.setPreCumulant(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
167 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
168 |
} |
|
169 |
if (!CollectionUtils.isEmpty(viewDto.getAdjData())) { |
|
170 |
viewDto.getAdjData().forEach(item -> { |
|
171 |
values.add(Double.parseDouble(item[1].toString())); |
|
172 |
}); |
|
173 |
} |
|
174 |
if (!CollectionUtils.isEmpty(values)) { |
|
175 |
viewDto.setMaxValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
176 |
viewDto.setMinValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
177 |
} |
|
178 |
dataViewList.add(viewDto); |
|
179 |
} |
|
180 |
result.setStartTime(startTime); |
|
181 |
result.setEndTime(endTime); |
|
182 |
result.setPredictTime(predictTime); |
|
183 |
result.setCategories(DateUtils.getTimeScale(startTime, endTime, 60)); |
|
184 |
result.setLegend(legends); |
|
185 |
result.setDataViewList(dataViewList); |
|
186 |
return result; |
|
187 |
} |
|
188 |
|
ead005
|
189 |
@Override |
潘 |
190 |
public PreDataItemChartRespVO getPreDataItemChart(PreDataItemChartReqVO reqVO) { |
|
191 |
PreDataItemChartRespVO result = new PreDataItemChartRespVO(); |
|
192 |
ItemVO predictItem = mmPredictItemService.getItemById(reqVO.getItemId()); |
|
193 |
if (predictItem == null) { |
|
194 |
return result; |
|
195 |
} |
|
196 |
if (predictItem.getLastTime() == null) { |
|
197 |
return result; |
|
198 |
} |
|
199 |
result.setLastTime(predictItem.getLastTime()); |
|
200 |
Date startTime = reqVO.getStartTime(); |
|
201 |
if (startTime == null) { |
|
202 |
Calendar calendar = Calendar.getInstance(); |
|
203 |
calendar.setTime(predictItem.getLastTime()); |
|
204 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
205 |
startTime = calendar.getTime(); |
|
206 |
} |
|
207 |
Date endTime = reqVO.getEndTime(); |
|
208 |
if (endTime == null) { |
|
209 |
Calendar calendar = Calendar.getInstance(); |
|
210 |
calendar.setTime(predictItem.getLastTime()); |
|
211 |
calendar.add(Calendar.HOUR_OF_DAY, 1); |
|
212 |
endTime = calendar.getTime(); |
|
213 |
} |
|
214 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity()); |
|
215 |
List<String> legend = new ArrayList<>(); |
|
216 |
LinkedHashMap<String, PreDataSampleViewRespDTO> viewMap = new LinkedHashMap<>(); |
|
217 |
List<MmItemOutputEntity> outs = mmItemOutputService.getByItemid(reqVO.getItemId()); |
|
218 |
if (CollectionUtils.isEmpty(outs)) { |
|
219 |
return result; |
|
220 |
} |
|
221 |
for (MmItemOutputEntity out : outs) { |
|
222 |
legend.add(out.getResultstr()); |
|
223 |
PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); |
|
224 |
viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
|
225 |
viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime)); |
|
226 |
viewMap.put(out.getResultstr(), viewDto); |
|
227 |
} |
|
228 |
result.setStartTime(startTime); |
|
229 |
result.setEndTime(endTime); |
|
230 |
result.setCategories(categories); |
|
231 |
result.setLegend(legend); |
|
232 |
result.setViewMap(viewMap); |
|
233 |
return result; |
|
234 |
} |
|
235 |
|
b368e6
|
236 |
/** |
潘 |
237 |
* 获取真实值 |
|
238 |
* |
|
239 |
* @param pointId |
|
240 |
* @param startTime |
|
241 |
* @param endTime |
|
242 |
* @return |
|
243 |
*/ |
|
244 |
private List<Object[]> getHisData(String pointId, Date startTime, Date endTime) { |
|
245 |
List<Object[]> result = new ArrayList<>(); |
|
246 |
ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); |
|
247 |
ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); |
|
248 |
queryPointDto.setPointNo(pointDTO.getPointNo()); |
|
249 |
queryPointDto.setStart(startTime); |
|
250 |
queryPointDto.setEnd(endTime); |
|
251 |
List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); |
|
252 |
if (CollectionUtils.isEmpty(valueDTOS)) { |
|
253 |
return result; |
|
254 |
} |
|
255 |
valueDTOS.forEach(item -> { |
|
256 |
Object[] values = new Object[2]; |
|
257 |
values[0] = DateUtils.format(item.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
|
258 |
values[1] = item.getDataValue(); |
|
259 |
result.add(values); |
|
260 |
}); |
|
261 |
return result; |
|
262 |
} |
|
263 |
|
|
264 |
@Override |
|
265 |
public Boolean createAlarmMessage(AlarmMessageRespDTO dto) { |
|
266 |
return true; |
|
267 |
} |
|
268 |
|
|
269 |
@Override |
|
270 |
public List<AlarmMessageRespDTO> listAlarmMessage(Map<String, Object> params) { |
|
271 |
return null; |
|
272 |
} |
|
273 |
|
|
274 |
@Override |
|
275 |
public Boolean createScheduleSuggest(ScheduleSuggestRespDTO dto) { |
|
276 |
return true; |
|
277 |
} |
|
278 |
|
|
279 |
@Override |
|
280 |
public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO params) { |
|
281 |
return null; |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
285 |
public Boolean modifyPredictModelSetting(List<PredictModelSettingReqDTO> dtos) { |
|
286 |
return true; |
|
287 |
} |
|
288 |
|
|
289 |
@Override |
|
290 |
public Boolean modifyScheduleModelSetting(List<ScheduleModelSettingReqDTO> dtos) { |
|
291 |
return true; |
|
292 |
} |
|
293 |
} |