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