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