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