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