提交 | 用户 | 时间
|
b368e6
|
1 |
package com.iailab.module.model.api; |
潘 |
2 |
|
|
3 |
import com.iailab.framework.common.util.date.DateUtils; |
8a74e9
|
4 |
import com.iailab.framework.common.util.object.ConvertUtils; |
潘 |
5 |
import com.iailab.module.data.api.plan.PlanItemApi; |
|
6 |
import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
b368e6
|
7 |
import com.iailab.module.data.api.point.DataPointApi; |
潘 |
8 |
import com.iailab.module.data.api.point.dto.ApiPointDTO; |
|
9 |
import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
|
10 |
import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
8a74e9
|
11 |
import com.iailab.module.data.common.ApiDataQueryDTO; |
b368e6
|
12 |
import com.iailab.module.model.api.mcs.McsApi; |
潘 |
13 |
import com.iailab.module.model.api.mcs.dto.*; |
91343d
|
14 |
import com.iailab.module.model.common.enums.CommonConstant; |
潘 |
15 |
import com.iailab.module.model.common.enums.PreLineTypeEnum; |
b368e6
|
16 |
import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
潘 |
17 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
c5fe30
|
18 |
import com.iailab.module.model.mcs.pre.entity.MmPredictAlarmMessageEntity; |
b368e6
|
19 |
import com.iailab.module.model.mcs.pre.service.*; |
c5fe30
|
20 |
import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmMessageSaveReqVO; |
ead005
|
21 |
import com.iailab.module.model.mdk.vo.ItemVO; |
91343d
|
22 |
import com.iailab.module.model.mpk.service.ChartService; |
b368e6
|
23 |
import lombok.extern.slf4j.Slf4j; |
977edc
|
24 |
import org.apache.commons.lang3.StringUtils; |
b368e6
|
25 |
import org.springframework.beans.factory.annotation.Autowired; |
潘 |
26 |
import org.springframework.util.CollectionUtils; |
|
27 |
import org.springframework.validation.annotation.Validated; |
|
28 |
import org.springframework.web.bind.annotation.RestController; |
|
29 |
|
|
30 |
import java.math.BigDecimal; |
|
31 |
import java.util.*; |
912419
|
32 |
import java.util.stream.Collectors; |
b368e6
|
33 |
|
潘 |
34 |
/** |
|
35 |
* @author PanZhibao |
|
36 |
* @Description |
|
37 |
* @createTime 2024年11月13日 |
|
38 |
*/ |
|
39 |
@Slf4j |
|
40 |
@RestController |
|
41 |
@Validated |
|
42 |
public class McsApiImpl implements McsApi { |
|
43 |
|
|
44 |
@Autowired |
|
45 |
private DmModuleService dmModuleService; |
|
46 |
|
|
47 |
@Autowired |
|
48 |
private MmPredictItemService mmPredictItemService; |
|
49 |
|
|
50 |
@Autowired |
|
51 |
private MmItemOutputService mmItemOutputService; |
|
52 |
|
|
53 |
@Autowired |
|
54 |
private MmItemResultService mmItemResultService; |
|
55 |
|
|
56 |
@Autowired |
|
57 |
private MmItemResultLastPointService mmItemResultLastPointService; |
|
58 |
|
|
59 |
@Autowired |
|
60 |
private DataPointApi dataPointApi; |
91343d
|
61 |
|
潘 |
62 |
@Autowired |
|
63 |
private MmItemResultJsonService mmItemResultJsonService; |
|
64 |
|
|
65 |
@Autowired |
|
66 |
private ChartService chartService; |
c5fe30
|
67 |
|
潘 |
68 |
@Autowired |
|
69 |
private MmPredictAlarmMessageService mmPredictAlarmMessageService; |
8a74e9
|
70 |
|
潘 |
71 |
@Autowired |
|
72 |
private PlanItemApi planItemApi; |
b368e6
|
73 |
|
潘 |
74 |
private int HOUR_MINS = 60; |
|
75 |
|
|
76 |
@Override |
|
77 |
public List<PredictItemTreeDTO> getPredictItemTree() { |
|
78 |
List<PredictItemTreeDTO> result = new ArrayList<>(); |
|
79 |
|
|
80 |
List<DmModuleEntity> moduleList = dmModuleService.list(new HashMap<>()); |
|
81 |
if (CollectionUtils.isEmpty(moduleList)) { |
|
82 |
return result; |
|
83 |
} |
|
84 |
moduleList.forEach(item -> { |
|
85 |
PredictItemTreeDTO moduleOpt = new PredictItemTreeDTO(); |
|
86 |
moduleOpt.setId(item.getId()); |
|
87 |
moduleOpt.setLabel(item.getModulename()); |
|
88 |
List<PredictItemTreeDTO> children = new ArrayList<>(); |
a4891a
|
89 |
List<ItemVO> itemList = mmPredictItemService.getByModuleId(item.getId()); |
b368e6
|
90 |
itemList.forEach(item1 -> { |
潘 |
91 |
PredictItemTreeDTO chd = new PredictItemTreeDTO(); |
a4891a
|
92 |
chd.setLabel(item1.getItemName()); |
b368e6
|
93 |
chd.setId(item1.getId()); |
a4891a
|
94 |
List<PredictItemTreeDTO> chd1 = new ArrayList<>(); |
潘 |
95 |
List<MmItemOutputEntity> outList = mmItemOutputService.getByItemid(item1.getId()); |
|
96 |
if (!CollectionUtils.isEmpty(outList)) { |
|
97 |
outList.forEach(out -> { |
|
98 |
PredictItemTreeDTO chd2 = new PredictItemTreeDTO(); |
|
99 |
chd2.setId(out.getId()); |
f283ee
|
100 |
chd2.setLabel(out.getResultName()); |
a4891a
|
101 |
chd1.add(chd2); |
潘 |
102 |
}); |
|
103 |
} |
|
104 |
chd.setChildren(chd1); |
b368e6
|
105 |
children.add(chd); |
潘 |
106 |
}); |
|
107 |
moduleOpt.setChildren(children); |
|
108 |
result.add(moduleOpt); |
|
109 |
}); |
|
110 |
return result; |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public PreDataBarLineRespVO getPreDataCharts(PreDataBarLineReqVO reqVO) { |
|
115 |
PreDataBarLineRespVO result = new PreDataBarLineRespVO(); |
a4891a
|
116 |
List<String> outIds = reqVO.getOutIds(); |
b368e6
|
117 |
List<String> legends = new ArrayList<>(); |
潘 |
118 |
List<PreDataViewRespDTO> dataViewList = new ArrayList<>(); |
9e844c
|
119 |
if (CollectionUtils.isEmpty(outIds)) { |
b368e6
|
120 |
return result; |
潘 |
121 |
} |
|
122 |
Date predictTime = reqVO.getPredictTime(); |
|
123 |
if (predictTime == null) { |
9e844c
|
124 |
MmItemOutputEntity output = mmItemOutputService.getOutPutById(reqVO.getOutIds().get(0)); |
潘 |
125 |
ItemVO predictItem = mmPredictItemService.getItemById(output.getItemid()); |
|
126 |
if (predictItem.getLastTime() != null) { |
|
127 |
predictTime = predictItem.getLastTime(); |
|
128 |
} else { |
|
129 |
Calendar calendar = Calendar.getInstance(); |
|
130 |
calendar.set(Calendar.MILLISECOND, 0); |
|
131 |
calendar.set(Calendar.SECOND, 0); |
|
132 |
predictTime = calendar.getTime(); |
|
133 |
} |
b368e6
|
134 |
} |
潘 |
135 |
Date startTime = reqVO.getStartTime(); |
|
136 |
if (startTime == null) { |
|
137 |
Calendar calendar = Calendar.getInstance(); |
|
138 |
calendar.setTime(predictTime); |
|
139 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
140 |
startTime = calendar.getTime(); |
|
141 |
} |
|
142 |
Date endTime = reqVO.getEndTime(); |
|
143 |
if (endTime == null) { |
|
144 |
Calendar calendar = Calendar.getInstance(); |
|
145 |
calendar.setTime(predictTime); |
|
146 |
calendar.add(Calendar.HOUR_OF_DAY, 1); |
|
147 |
endTime = calendar.getTime(); |
|
148 |
} |
|
149 |
|
a4891a
|
150 |
for (int i = 0; i < outIds.size(); i++) { |
b368e6
|
151 |
PreDataViewRespDTO viewDto = new PreDataViewRespDTO(); |
a4891a
|
152 |
String outId = outIds.get(i); |
潘 |
153 |
MmItemOutputEntity output = mmItemOutputService.getOutPutById(outId); |
b368e6
|
154 |
if (output == null) { |
9e844c
|
155 |
continue; |
b368e6
|
156 |
} |
f283ee
|
157 |
legends.add(output.getResultName()); |
9e844c
|
158 |
viewDto.setItemId(output.getItemid()); |
潘 |
159 |
viewDto.setOutId(outId); |
|
160 |
viewDto.setResultstr(output.getResultstr()); |
f283ee
|
161 |
viewDto.setResultName(output.getResultName()); |
b368e6
|
162 |
viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); |
977edc
|
163 |
viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
潘 |
164 |
viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
b368e6
|
165 |
|
潘 |
166 |
List<Double> values = new ArrayList<>(); |
|
167 |
if (!CollectionUtils.isEmpty(viewDto.getRealData())) { |
|
168 |
List<Double> hisValues = new ArrayList<>(); |
|
169 |
viewDto.getRealData().forEach(item -> { |
|
170 |
values.add(Double.parseDouble(item[1].toString())); |
|
171 |
hisValues.add(Double.parseDouble(item[1].toString())); |
|
172 |
}); |
|
173 |
viewDto.setHisMax(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
174 |
viewDto.setHisMin(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
175 |
viewDto.setHisAvg(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
176 |
viewDto.setHisCumulant(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
177 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
178 |
} |
|
179 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataN())) { |
|
180 |
viewDto.getPreDataN().forEach(item -> { |
|
181 |
values.add(Double.parseDouble(item[1].toString())); |
|
182 |
}); |
|
183 |
} |
|
184 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataL())) { |
|
185 |
List<Double> preValues = new ArrayList<>(); |
|
186 |
viewDto.getPreDataL().forEach(item -> { |
|
187 |
values.add(Double.parseDouble(item[1].toString())); |
|
188 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
189 |
}); |
|
190 |
viewDto.setPreMax(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
191 |
viewDto.setPreMin(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
192 |
viewDto.setPreAvg(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
193 |
} |
|
194 |
if (!CollectionUtils.isEmpty(viewDto.getCurData())) { |
|
195 |
List<Double> preValues = new ArrayList<>(); |
|
196 |
viewDto.getCurData().forEach(item -> { |
|
197 |
values.add(Double.parseDouble(item[1].toString())); |
|
198 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
199 |
}); |
|
200 |
viewDto.setPreCumulant(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
201 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
202 |
} |
|
203 |
if (!CollectionUtils.isEmpty(viewDto.getAdjData())) { |
|
204 |
viewDto.getAdjData().forEach(item -> { |
|
205 |
values.add(Double.parseDouble(item[1].toString())); |
|
206 |
}); |
|
207 |
} |
|
208 |
if (!CollectionUtils.isEmpty(values)) { |
|
209 |
viewDto.setMaxValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
210 |
viewDto.setMinValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
211 |
} |
|
212 |
dataViewList.add(viewDto); |
|
213 |
} |
|
214 |
result.setStartTime(startTime); |
|
215 |
result.setEndTime(endTime); |
|
216 |
result.setPredictTime(predictTime); |
|
217 |
result.setCategories(DateUtils.getTimeScale(startTime, endTime, 60)); |
|
218 |
result.setLegend(legends); |
|
219 |
result.setDataViewList(dataViewList); |
|
220 |
return result; |
|
221 |
} |
|
222 |
|
ead005
|
223 |
@Override |
潘 |
224 |
public PreDataItemChartRespVO getPreDataItemChart(PreDataItemChartReqVO reqVO) { |
|
225 |
PreDataItemChartRespVO result = new PreDataItemChartRespVO(); |
|
226 |
ItemVO predictItem = mmPredictItemService.getItemById(reqVO.getItemId()); |
|
227 |
if (predictItem == null) { |
|
228 |
return result; |
|
229 |
} |
|
230 |
if (predictItem.getLastTime() == null) { |
|
231 |
return result; |
|
232 |
} |
328ef4
|
233 |
result.setPredictTime(predictItem.getLastTime()); |
ead005
|
234 |
Date startTime = reqVO.getStartTime(); |
潘 |
235 |
if (startTime == null) { |
|
236 |
Calendar calendar = Calendar.getInstance(); |
|
237 |
calendar.setTime(predictItem.getLastTime()); |
91343d
|
238 |
calendar.add(Calendar.MINUTE, -1 * predictItem.getPredictLength()); |
ead005
|
239 |
startTime = calendar.getTime(); |
潘 |
240 |
} |
|
241 |
Date endTime = reqVO.getEndTime(); |
|
242 |
if (endTime == null) { |
|
243 |
Calendar calendar = Calendar.getInstance(); |
|
244 |
calendar.setTime(predictItem.getLastTime()); |
91343d
|
245 |
calendar.add(Calendar.MINUTE, predictItem.getPredictLength()); |
ead005
|
246 |
endTime = calendar.getTime(); |
潘 |
247 |
} |
1f9784
|
248 |
if (endTime.getTime() <= startTime.getTime()) { |
潘 |
249 |
Calendar calendar = Calendar.getInstance(); |
|
250 |
calendar.setTime(startTime); |
91343d
|
251 |
calendar.add(Calendar.MINUTE, predictItem.getPredictLength()); |
1f9784
|
252 |
endTime = calendar.getTime(); |
潘 |
253 |
} |
|
254 |
|
ead005
|
255 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity()); |
潘 |
256 |
List<String> legend = new ArrayList<>(); |
|
257 |
LinkedHashMap<String, PreDataSampleViewRespDTO> viewMap = new LinkedHashMap<>(); |
|
258 |
List<MmItemOutputEntity> outs = mmItemOutputService.getByItemid(reqVO.getItemId()); |
|
259 |
if (CollectionUtils.isEmpty(outs)) { |
|
260 |
return result; |
|
261 |
} |
|
262 |
for (MmItemOutputEntity out : outs) { |
f283ee
|
263 |
legend.add(out.getResultName()); |
ead005
|
264 |
PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); |
潘 |
265 |
viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
977edc
|
266 |
viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
f283ee
|
267 |
viewMap.put(out.getResultName(), viewDto); |
ead005
|
268 |
} |
潘 |
269 |
result.setStartTime(startTime); |
|
270 |
result.setEndTime(endTime); |
|
271 |
result.setCategories(categories); |
|
272 |
result.setLegend(legend); |
|
273 |
result.setViewMap(viewMap); |
|
274 |
return result; |
|
275 |
} |
|
276 |
|
328ef4
|
277 |
@Override |
91343d
|
278 |
public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { |
潘 |
279 |
PreDataSingleChartRespVO result = new PreDataSingleChartRespVO(); |
328ef4
|
280 |
|
91343d
|
281 |
Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode()); |
潘 |
282 |
if (CollectionUtils.isEmpty(chartParams)) { |
|
283 |
return result; |
|
284 |
} |
|
285 |
String itemCode = chartParams.get(CommonConstant.ITEM_CODE); |
|
286 |
if (itemCode == null) { |
|
287 |
return result; |
|
288 |
} |
|
289 |
String resultStr = chartParams.get(CommonConstant.RESULT_STR); |
|
290 |
if (resultStr == null) { |
|
291 |
return result; |
|
292 |
} |
|
293 |
ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode); |
|
294 |
if (predictItem == null || predictItem.getLastTime() == null) { |
|
295 |
return result; |
|
296 |
} |
977edc
|
297 |
String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); |
潘 |
298 |
PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(chartParams.get(CommonConstant.LINE_TYPE)); |
91343d
|
299 |
BigDecimal rangeH = chartParams.get(CommonConstant.RANGE_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_H)); |
潘 |
300 |
BigDecimal rangeL = chartParams.get(CommonConstant.RANGE_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_L)); |
|
301 |
BigDecimal limitH = chartParams.get(CommonConstant.LIMIT_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_H)); |
|
302 |
BigDecimal limitL = chartParams.get(CommonConstant.LIMIT_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_L)); |
|
303 |
int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue(); |
|
304 |
int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue(); |
8a74e9
|
305 |
|
潘 |
306 |
Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight); |
|
307 |
Date predictTime = timeArray[0]; |
|
308 |
Date startTime = timeArray[1]; |
|
309 |
Date endTime = timeArray[2]; |
|
310 |
|
977edc
|
311 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat); |
91343d
|
312 |
List<String> legend = new ArrayList<>(); |
潘 |
313 |
MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), resultStr); |
|
314 |
PreDataViewRespDTO dataView = new PreDataViewRespDTO(); |
|
315 |
dataView.setItemId(predictItem.getId()); |
|
316 |
dataView.setItemName(predictItem.getItemName()); |
|
317 |
dataView.setResultstr(resultStr); |
|
318 |
dataView.setRangeH(rangeH); |
|
319 |
dataView.setRangeL(rangeL); |
|
320 |
dataView.setLimitH(limitH); |
|
321 |
dataView.setLimitL(limitL); |
977edc
|
322 |
dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime, timeFormat)); |
潘 |
323 |
dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat)); |
91343d
|
324 |
switch (lineType) { |
潘 |
325 |
case TN: |
977edc
|
326 |
dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime, timeFormat)); |
91343d
|
327 |
break; |
潘 |
328 |
case TL: |
977edc
|
329 |
dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat)); |
潘 |
330 |
dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat)); |
91343d
|
331 |
break; |
潘 |
332 |
default: |
|
333 |
break; |
|
334 |
} |
912419
|
335 |
|
潘 |
336 |
if (!CollectionUtils.isEmpty(dataView.getCurData())) { |
|
337 |
List<Double> curList = dataView.getCurData().stream().map(t -> { |
|
338 |
return new Double(t[1].toString()); |
|
339 |
}).collect(Collectors.toList()); |
|
340 |
dataView.setPreMax(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
341 |
dataView.setPreMin(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
342 |
} |
|
343 |
|
8a74e9
|
344 |
result.setPredictTime(predictTime); |
91343d
|
345 |
result.setStartTime(startTime); |
潘 |
346 |
result.setEndTime(endTime); |
|
347 |
result.setCategories(categories); |
|
348 |
result.setLegend(legend); |
|
349 |
result.setDataView(dataView); |
8a74e9
|
350 |
return result; |
潘 |
351 |
} |
|
352 |
|
|
353 |
@Override |
|
354 |
public PlanDataSingleChartRespVO getPlanDataSingleChart(PreDataSingleChartReqVO reqVO) { |
|
355 |
PlanDataSingleChartRespVO result = new PlanDataSingleChartRespVO(); |
|
356 |
Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode()); |
|
357 |
if (CollectionUtils.isEmpty(chartParams)) { |
|
358 |
return result; |
|
359 |
} |
|
360 |
String itemCode = chartParams.get(CommonConstant.ITEM_CODE); |
|
361 |
if (itemCode == null) { |
|
362 |
return result; |
|
363 |
} |
|
364 |
String planItemStr = chartParams.get(CommonConstant.PLAN_ITEM_LIST); |
|
365 |
if (planItemStr == null) { |
|
366 |
return result; |
|
367 |
} |
|
368 |
List<String> planItemCodeList = Arrays.asList(planItemStr.split(",")); |
|
369 |
|
|
370 |
ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode); |
|
371 |
if (predictItem == null || predictItem.getLastTime() == null) { |
|
372 |
return result; |
|
373 |
} |
|
374 |
String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); |
|
375 |
int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue(); |
|
376 |
int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue(); |
|
377 |
Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight); |
|
378 |
Date predictTime = timeArray[0]; |
|
379 |
Date startTime = timeArray[1]; |
|
380 |
Date endTime = timeArray[2]; |
|
381 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat); |
|
382 |
List<String> legend = new ArrayList<>(); |
|
383 |
LinkedHashMap<String, List<PlanDataRecordDTO>> record = new LinkedHashMap<>(); |
|
384 |
ApiDataQueryDTO queryDTO = new ApiDataQueryDTO(); |
|
385 |
queryDTO.setItemNos(planItemCodeList); |
|
386 |
queryDTO.setStart(startTime); |
|
387 |
queryDTO.setEnd(endTime); |
|
388 |
LinkedHashMap<String, List<ApiPlanDataDTO>> planData = planItemApi.queryPlanItemRecordValue(queryDTO); |
|
389 |
if (CollectionUtils.isEmpty(planData)) { |
|
390 |
planData.forEach((key, value) -> { |
|
391 |
record.put(key, ConvertUtils.sourceToTarget(value, PlanDataRecordDTO.class)); |
|
392 |
}); |
|
393 |
} |
|
394 |
result.setPredictTime(predictTime); |
|
395 |
result.setStartTime(startTime); |
|
396 |
result.setEndTime(endTime); |
|
397 |
result.setCategories(categories); |
|
398 |
result.setLegend(legend); |
|
399 |
result.setRecord(record); |
328ef4
|
400 |
return result; |
潘 |
401 |
} |
|
402 |
|
b368e6
|
403 |
/** |
潘 |
404 |
* 获取真实值 |
|
405 |
* |
|
406 |
* @param pointId |
|
407 |
* @param startTime |
|
408 |
* @param endTime |
|
409 |
* @return |
|
410 |
*/ |
|
411 |
private List<Object[]> getHisData(String pointId, Date startTime, Date endTime) { |
|
412 |
List<Object[]> result = new ArrayList<>(); |
|
413 |
ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); |
|
414 |
ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); |
|
415 |
queryPointDto.setPointNo(pointDTO.getPointNo()); |
|
416 |
queryPointDto.setStart(startTime); |
|
417 |
queryPointDto.setEnd(endTime); |
|
418 |
List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); |
|
419 |
if (CollectionUtils.isEmpty(valueDTOS)) { |
|
420 |
return result; |
|
421 |
} |
|
422 |
valueDTOS.forEach(item -> { |
|
423 |
Object[] values = new Object[2]; |
214275
|
424 |
values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
潘 |
425 |
values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); |
b368e6
|
426 |
result.add(values); |
潘 |
427 |
}); |
|
428 |
return result; |
|
429 |
} |
|
430 |
|
977edc
|
431 |
/** |
潘 |
432 |
* 获取真实值 |
|
433 |
* |
|
434 |
* @param pointId |
|
435 |
* @param startTime |
|
436 |
* @param endTime |
|
437 |
* @param timeFormat |
|
438 |
* @return |
|
439 |
*/ |
|
440 |
private List<Object[]> getHisData(String pointId, Date startTime, Date endTime, String timeFormat) { |
|
441 |
List<Object[]> result = new ArrayList<>(); |
|
442 |
ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); |
|
443 |
ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); |
|
444 |
queryPointDto.setPointNo(pointDTO.getPointNo()); |
|
445 |
queryPointDto.setStart(startTime); |
|
446 |
queryPointDto.setEnd(endTime); |
|
447 |
List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); |
|
448 |
if (CollectionUtils.isEmpty(valueDTOS)) { |
|
449 |
return result; |
|
450 |
} |
|
451 |
valueDTOS.forEach(item -> { |
|
452 |
Object[] values = new Object[2]; |
|
453 |
values[0] = DateUtils.format(item.getT(), timeFormat); |
|
454 |
values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); |
|
455 |
result.add(values); |
|
456 |
}); |
|
457 |
return result; |
|
458 |
} |
|
459 |
|
c5fe30
|
460 |
/** |
潘 |
461 |
* 新增预警信息 |
|
462 |
* |
|
463 |
* @param dto |
|
464 |
* @return |
|
465 |
*/ |
b368e6
|
466 |
@Override |
潘 |
467 |
public Boolean createAlarmMessage(AlarmMessageRespDTO dto) { |
c5fe30
|
468 |
try { |
潘 |
469 |
mmPredictAlarmMessageService.create(ConvertUtils.sourceToTarget(dto, MmPredictAlarmMessageSaveReqVO.class)); |
|
470 |
return true; |
|
471 |
} catch (Exception e) { |
|
472 |
return false; |
|
473 |
} |
b368e6
|
474 |
} |
潘 |
475 |
|
|
476 |
@Override |
|
477 |
public List<AlarmMessageRespDTO> listAlarmMessage(Map<String, Object> params) { |
|
478 |
return null; |
|
479 |
} |
|
480 |
|
|
481 |
@Override |
c5fe30
|
482 |
public AlarmMessageRespDTO getLastAlarmMessage(String alarmObj) { |
潘 |
483 |
MmPredictAlarmMessageEntity entity = mmPredictAlarmMessageService.getLast(alarmObj); |
|
484 |
return ConvertUtils.sourceToTarget(entity, AlarmMessageRespDTO.class); |
|
485 |
} |
|
486 |
|
|
487 |
@Override |
b368e6
|
488 |
public Boolean createScheduleSuggest(ScheduleSuggestRespDTO dto) { |
潘 |
489 |
return true; |
|
490 |
} |
|
491 |
|
|
492 |
@Override |
|
493 |
public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO params) { |
|
494 |
return null; |
|
495 |
} |
|
496 |
|
|
497 |
@Override |
|
498 |
public Boolean modifyPredictModelSetting(List<PredictModelSettingReqDTO> dtos) { |
|
499 |
return true; |
|
500 |
} |
|
501 |
|
|
502 |
@Override |
|
503 |
public Boolean modifyScheduleModelSetting(List<ScheduleModelSettingReqDTO> dtos) { |
|
504 |
return true; |
|
505 |
} |
8a74e9
|
506 |
|
潘 |
507 |
|
|
508 |
private Date[] calResultTime(ItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) { |
|
509 |
Date[] result = new Date[3]; |
|
510 |
Date predictTime = predictItem.getLastTime(); |
|
511 |
Date startTime = startTimeReq; |
|
512 |
if (startTime == null) { |
|
513 |
Calendar calendar = Calendar.getInstance(); |
|
514 |
calendar.setTime(predictItem.getLastTime()); |
|
515 |
calendar.add(Calendar.MINUTE, -1 * lengthLeft); |
|
516 |
startTime = calendar.getTime(); |
|
517 |
} |
|
518 |
Date endTime = endTimeReq; |
|
519 |
if (endTime == null) { |
|
520 |
Calendar calendar = Calendar.getInstance(); |
|
521 |
calendar.setTime(predictItem.getLastTime()); |
|
522 |
calendar.add(Calendar.MINUTE, lengthRight); |
|
523 |
endTime = calendar.getTime(); |
|
524 |
} |
|
525 |
if (endTime.getTime() <= startTime.getTime()) { |
|
526 |
Calendar calendar = Calendar.getInstance(); |
|
527 |
calendar.setTime(startTime); |
|
528 |
calendar.add(Calendar.MINUTE, lengthRight); |
|
529 |
endTime = calendar.getTime(); |
|
530 |
} |
|
531 |
result[0] = predictTime; |
|
532 |
result[1] = startTime; |
|
533 |
result[2] = endTime; |
|
534 |
return result; |
|
535 |
} |
b368e6
|
536 |
} |