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