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