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