提交 | 用户 | 时间
|
b368e6
|
1 |
package com.iailab.module.model.api; |
潘 |
2 |
|
0a7d0f
|
3 |
import com.iailab.framework.common.pojo.PageResult; |
b368e6
|
4 |
import com.iailab.framework.common.util.date.DateUtils; |
8a74e9
|
5 |
import com.iailab.framework.common.util.object.ConvertUtils; |
潘 |
6 |
import com.iailab.module.data.api.plan.PlanItemApi; |
|
7 |
import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
b368e6
|
8 |
import com.iailab.module.data.api.point.DataPointApi; |
潘 |
9 |
import com.iailab.module.data.api.point.dto.ApiPointDTO; |
|
10 |
import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
|
11 |
import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
8a74e9
|
12 |
import com.iailab.module.data.common.ApiDataQueryDTO; |
b368e6
|
13 |
import com.iailab.module.model.api.mcs.McsApi; |
潘 |
14 |
import com.iailab.module.model.api.mcs.dto.*; |
153763
|
15 |
import com.iailab.module.model.api.mdk.dto.StScheduleRecordVO; |
4af6b1
|
16 |
import com.iailab.module.model.common.enums.CommonDict; |
22e321
|
17 |
import com.iailab.module.model.common.enums.DataTypeEnum; |
91343d
|
18 |
import com.iailab.module.model.common.enums.PreLineTypeEnum; |
153763
|
19 |
import com.iailab.module.model.enums.CommonConstant; |
22e321
|
20 |
import com.iailab.module.model.influxdb.pojo.InfluxModelResultByOutPutIdsPOJO; |
D |
21 |
import com.iailab.module.model.influxdb.service.InfluxDBService; |
|
22 |
import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; |
b368e6
|
23 |
import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
潘 |
24 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
c5fe30
|
25 |
import com.iailab.module.model.mcs.pre.entity.MmPredictAlarmMessageEntity; |
b368e6
|
26 |
import com.iailab.module.model.mcs.pre.service.*; |
22e321
|
27 |
import com.iailab.module.model.mcs.pre.vo.MmItemOutputRespVO; |
c5fe30
|
28 |
import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmMessageSaveReqVO; |
22e321
|
29 |
import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; |
87d7ae
|
30 |
import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
e9506a
|
31 |
import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity; |
055765
|
32 |
import com.iailab.module.model.mcs.sche.entity.StScheduleSuggestEntity; |
e9506a
|
33 |
import com.iailab.module.model.mcs.sche.service.*; |
19f359
|
34 |
import com.iailab.module.model.mcs.sche.vo.StScheduleSuggestSaveReqVO; |
ead005
|
35 |
import com.iailab.module.model.mdk.vo.ItemVO; |
730d19
|
36 |
import com.iailab.module.model.mpk.service.ChartParamService; |
91343d
|
37 |
import com.iailab.module.model.mpk.service.ChartService; |
af72d8
|
38 |
import com.iailab.module.model.mpk.service.ElectricityPriceSegmentedService; |
b368e6
|
39 |
import lombok.extern.slf4j.Slf4j; |
977edc
|
40 |
import org.apache.commons.lang3.StringUtils; |
b368e6
|
41 |
import org.springframework.beans.factory.annotation.Autowired; |
潘 |
42 |
import org.springframework.util.CollectionUtils; |
|
43 |
import org.springframework.validation.annotation.Validated; |
|
44 |
import org.springframework.web.bind.annotation.RestController; |
|
45 |
|
|
46 |
import java.math.BigDecimal; |
|
47 |
import java.util.*; |
912419
|
48 |
import java.util.stream.Collectors; |
b368e6
|
49 |
|
潘 |
50 |
/** |
|
51 |
* @author PanZhibao |
|
52 |
* @Description |
|
53 |
* @createTime 2024年11月13日 |
|
54 |
*/ |
|
55 |
@Slf4j |
|
56 |
@RestController |
|
57 |
@Validated |
|
58 |
public class McsApiImpl implements McsApi { |
|
59 |
|
|
60 |
@Autowired |
6eeac9
|
61 |
private DataPointApi dataPointApi; |
D |
62 |
|
|
63 |
@Autowired |
b368e6
|
64 |
private DmModuleService dmModuleService; |
潘 |
65 |
|
|
66 |
@Autowired |
|
67 |
private MmPredictItemService mmPredictItemService; |
|
68 |
|
|
69 |
@Autowired |
|
70 |
private MmItemOutputService mmItemOutputService; |
|
71 |
|
|
72 |
@Autowired |
|
73 |
private MmItemResultService mmItemResultService; |
|
74 |
|
|
75 |
@Autowired |
|
76 |
private MmItemResultLastPointService mmItemResultLastPointService; |
91343d
|
77 |
|
潘 |
78 |
@Autowired |
|
79 |
private MmItemResultJsonService mmItemResultJsonService; |
|
80 |
|
|
81 |
@Autowired |
|
82 |
private ChartService chartService; |
c5fe30
|
83 |
|
潘 |
84 |
@Autowired |
|
85 |
private MmPredictAlarmMessageService mmPredictAlarmMessageService; |
055765
|
86 |
|
潘 |
87 |
@Autowired |
|
88 |
private StScheduleSuggestService stScheduleSuggestService; |
8a74e9
|
89 |
|
潘 |
90 |
@Autowired |
|
91 |
private PlanItemApi planItemApi; |
9587d2
|
92 |
|
L |
93 |
@Autowired |
|
94 |
private MmPredictAlarmConfigService mmPredictAlarmConfigService; |
3a6dfc
|
95 |
|
4072bc
|
96 |
@Autowired |
L |
97 |
private StScheduleSchemeService stScheduleSchemeService; |
dec0c2
|
98 |
|
D |
99 |
@Autowired |
|
100 |
private StScheduleRecordService stScheduleRecordService; |
730d19
|
101 |
|
D |
102 |
@Autowired |
|
103 |
private ChartParamService chartParamService; |
22e321
|
104 |
|
D |
105 |
@Autowired |
|
106 |
private InfluxDBService influxDBService; |
af72d8
|
107 |
|
J |
108 |
@Autowired |
|
109 |
private ElectricityPriceSegmentedService electricityPriceSegmentedService; |
e9506a
|
110 |
|
J |
111 |
@Autowired |
|
112 |
private StScheduleModelService stScheduleModelService; |
|
113 |
|
|
114 |
@Autowired |
|
115 |
private StScheduleModelSettingService stScheduleModelSettingService; |
|
116 |
|
87d7ae
|
117 |
@Autowired |
潘 |
118 |
private StAdjustConfigService stAdjustConfigService; |
6eeac9
|
119 |
|
b368e6
|
120 |
private int HOUR_MINS = 60; |
潘 |
121 |
|
|
122 |
@Override |
|
123 |
public List<PredictItemTreeDTO> getPredictItemTree() { |
|
124 |
List<PredictItemTreeDTO> result = new ArrayList<>(); |
|
125 |
|
|
126 |
List<DmModuleEntity> moduleList = dmModuleService.list(new HashMap<>()); |
|
127 |
if (CollectionUtils.isEmpty(moduleList)) { |
|
128 |
return result; |
|
129 |
} |
|
130 |
moduleList.forEach(item -> { |
|
131 |
PredictItemTreeDTO moduleOpt = new PredictItemTreeDTO(); |
|
132 |
moduleOpt.setId(item.getId()); |
|
133 |
moduleOpt.setLabel(item.getModulename()); |
ca56f2
|
134 |
moduleOpt.setDisabled(true); |
b368e6
|
135 |
List<PredictItemTreeDTO> children = new ArrayList<>(); |
a4891a
|
136 |
List<ItemVO> itemList = mmPredictItemService.getByModuleId(item.getId()); |
b368e6
|
137 |
itemList.forEach(item1 -> { |
潘 |
138 |
PredictItemTreeDTO chd = new PredictItemTreeDTO(); |
a4891a
|
139 |
chd.setLabel(item1.getItemName()); |
b368e6
|
140 |
chd.setId(item1.getId()); |
a4891a
|
141 |
List<PredictItemTreeDTO> chd1 = new ArrayList<>(); |
潘 |
142 |
List<MmItemOutputEntity> outList = mmItemOutputService.getByItemid(item1.getId()); |
|
143 |
if (!CollectionUtils.isEmpty(outList)) { |
|
144 |
outList.forEach(out -> { |
|
145 |
PredictItemTreeDTO chd2 = new PredictItemTreeDTO(); |
|
146 |
chd2.setId(out.getId()); |
f283ee
|
147 |
chd2.setLabel(out.getResultName()); |
a4891a
|
148 |
chd1.add(chd2); |
潘 |
149 |
}); |
|
150 |
} |
|
151 |
chd.setChildren(chd1); |
b368e6
|
152 |
children.add(chd); |
潘 |
153 |
}); |
|
154 |
moduleOpt.setChildren(children); |
|
155 |
result.add(moduleOpt); |
|
156 |
}); |
|
157 |
return result; |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public PreDataBarLineRespVO getPreDataCharts(PreDataBarLineReqVO reqVO) { |
|
162 |
PreDataBarLineRespVO result = new PreDataBarLineRespVO(); |
a4891a
|
163 |
List<String> outIds = reqVO.getOutIds(); |
b368e6
|
164 |
List<String> legends = new ArrayList<>(); |
潘 |
165 |
List<PreDataViewRespDTO> dataViewList = new ArrayList<>(); |
9e844c
|
166 |
if (CollectionUtils.isEmpty(outIds)) { |
b368e6
|
167 |
return result; |
潘 |
168 |
} |
|
169 |
Date predictTime = reqVO.getPredictTime(); |
|
170 |
if (predictTime == null) { |
d22d56
|
171 |
MmItemOutputEntity output = null; |
潘 |
172 |
for (String outId : outIds) { |
|
173 |
output = mmItemOutputService.getOutPutById(outId); |
|
174 |
if (output != null) { |
|
175 |
break; |
|
176 |
} |
|
177 |
} |
ca56f2
|
178 |
ItemVO predictItem = mmPredictItemService.getItemById(output.getItemid()); |
9e844c
|
179 |
if (predictItem.getLastTime() != null) { |
潘 |
180 |
predictTime = predictItem.getLastTime(); |
|
181 |
} else { |
|
182 |
Calendar calendar = Calendar.getInstance(); |
|
183 |
calendar.set(Calendar.MILLISECOND, 0); |
|
184 |
calendar.set(Calendar.SECOND, 0); |
|
185 |
predictTime = calendar.getTime(); |
|
186 |
} |
b368e6
|
187 |
} |
潘 |
188 |
Date startTime = reqVO.getStartTime(); |
|
189 |
if (startTime == null) { |
|
190 |
Calendar calendar = Calendar.getInstance(); |
|
191 |
calendar.setTime(predictTime); |
|
192 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
193 |
startTime = calendar.getTime(); |
|
194 |
} |
|
195 |
Date endTime = reqVO.getEndTime(); |
|
196 |
if (endTime == null) { |
|
197 |
Calendar calendar = Calendar.getInstance(); |
|
198 |
calendar.setTime(predictTime); |
|
199 |
calendar.add(Calendar.HOUR_OF_DAY, 1); |
|
200 |
endTime = calendar.getTime(); |
|
201 |
} |
|
202 |
|
a4891a
|
203 |
for (int i = 0; i < outIds.size(); i++) { |
b368e6
|
204 |
PreDataViewRespDTO viewDto = new PreDataViewRespDTO(); |
a4891a
|
205 |
String outId = outIds.get(i); |
潘 |
206 |
MmItemOutputEntity output = mmItemOutputService.getOutPutById(outId); |
b368e6
|
207 |
if (output == null) { |
9e844c
|
208 |
continue; |
b368e6
|
209 |
} |
f283ee
|
210 |
legends.add(output.getResultName()); |
9e844c
|
211 |
viewDto.setItemId(output.getItemid()); |
潘 |
212 |
viewDto.setOutId(outId); |
|
213 |
viewDto.setResultstr(output.getResultstr()); |
f283ee
|
214 |
viewDto.setResultName(output.getResultName()); |
b368e6
|
215 |
viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); |
977edc
|
216 |
viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
潘 |
217 |
viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
ca56f2
|
218 |
viewDto.setCurData(mmItemResultJsonService.getData(output.getId(), predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, 3)); |
b368e6
|
219 |
List<Double> values = new ArrayList<>(); |
潘 |
220 |
if (!CollectionUtils.isEmpty(viewDto.getRealData())) { |
|
221 |
List<Double> hisValues = new ArrayList<>(); |
|
222 |
viewDto.getRealData().forEach(item -> { |
|
223 |
values.add(Double.parseDouble(item[1].toString())); |
|
224 |
hisValues.add(Double.parseDouble(item[1].toString())); |
|
225 |
}); |
|
226 |
viewDto.setHisMax(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
227 |
viewDto.setHisMin(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
228 |
viewDto.setHisAvg(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
229 |
viewDto.setHisCumulant(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
230 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
231 |
} |
|
232 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataN())) { |
|
233 |
viewDto.getPreDataN().forEach(item -> { |
|
234 |
values.add(Double.parseDouble(item[1].toString())); |
|
235 |
}); |
|
236 |
} |
|
237 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataL())) { |
|
238 |
List<Double> preValues = new ArrayList<>(); |
|
239 |
viewDto.getPreDataL().forEach(item -> { |
|
240 |
values.add(Double.parseDouble(item[1].toString())); |
|
241 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
242 |
}); |
|
243 |
viewDto.setPreMax(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
244 |
viewDto.setPreMin(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
245 |
viewDto.setPreAvg(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
246 |
} |
|
247 |
if (!CollectionUtils.isEmpty(viewDto.getCurData())) { |
|
248 |
List<Double> preValues = new ArrayList<>(); |
|
249 |
viewDto.getCurData().forEach(item -> { |
|
250 |
values.add(Double.parseDouble(item[1].toString())); |
|
251 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
252 |
}); |
|
253 |
viewDto.setPreCumulant(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
254 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
255 |
} |
|
256 |
if (!CollectionUtils.isEmpty(viewDto.getAdjData())) { |
|
257 |
viewDto.getAdjData().forEach(item -> { |
|
258 |
values.add(Double.parseDouble(item[1].toString())); |
|
259 |
}); |
|
260 |
} |
|
261 |
if (!CollectionUtils.isEmpty(values)) { |
|
262 |
viewDto.setMaxValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
263 |
viewDto.setMinValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
264 |
} |
94a5f0
|
265 |
//处理预测累计 |
D |
266 |
if (output.getIscumulant() == 1) { |
|
267 |
if (StringUtils.isNotBlank(output.getCumulpoint())) { |
|
268 |
viewDto.setCumulantRealData(getHisData(output.getCumulpoint(), startTime, endTime)); |
|
269 |
} |
|
270 |
viewDto.setCumulantPreData(mmItemResultService.getData(output.getId() + CommonDict.CUMULANT_SUFFIX, startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
271 |
} |
|
272 |
|
b368e6
|
273 |
dataViewList.add(viewDto); |
潘 |
274 |
} |
|
275 |
result.setStartTime(startTime); |
|
276 |
result.setEndTime(endTime); |
|
277 |
result.setPredictTime(predictTime); |
|
278 |
result.setCategories(DateUtils.getTimeScale(startTime, endTime, 60)); |
|
279 |
result.setLegend(legends); |
|
280 |
result.setDataViewList(dataViewList); |
|
281 |
return result; |
|
282 |
} |
|
283 |
|
ead005
|
284 |
@Override |
潘 |
285 |
public PreDataItemChartRespVO getPreDataItemChart(PreDataItemChartReqVO reqVO) { |
|
286 |
PreDataItemChartRespVO result = new PreDataItemChartRespVO(); |
864b61
|
287 |
ItemVO predictItem = mmPredictItemService.getItemById(reqVO.getItemId()); |
ead005
|
288 |
if (predictItem == null) { |
潘 |
289 |
return result; |
|
290 |
} |
|
291 |
if (predictItem.getLastTime() == null) { |
|
292 |
return result; |
|
293 |
} |
328ef4
|
294 |
result.setPredictTime(predictItem.getLastTime()); |
ead005
|
295 |
Date startTime = reqVO.getStartTime(); |
潘 |
296 |
if (startTime == null) { |
|
297 |
Calendar calendar = Calendar.getInstance(); |
|
298 |
calendar.setTime(predictItem.getLastTime()); |
e691b9
|
299 |
calendar.add(Calendar.SECOND, -1 * predictItem.getPredictLength() * predictItem.getGranularity()); |
ead005
|
300 |
startTime = calendar.getTime(); |
潘 |
301 |
} |
|
302 |
Date endTime = reqVO.getEndTime(); |
|
303 |
if (endTime == null) { |
|
304 |
Calendar calendar = Calendar.getInstance(); |
|
305 |
calendar.setTime(predictItem.getLastTime()); |
e691b9
|
306 |
calendar.add(Calendar.SECOND, predictItem.getPredictLength() * predictItem.getGranularity()); |
ead005
|
307 |
endTime = calendar.getTime(); |
潘 |
308 |
} |
1f9784
|
309 |
if (endTime.getTime() <= startTime.getTime()) { |
潘 |
310 |
Calendar calendar = Calendar.getInstance(); |
|
311 |
calendar.setTime(startTime); |
e691b9
|
312 |
calendar.add(Calendar.SECOND, predictItem.getPredictLength() * predictItem.getGranularity()); |
1f9784
|
313 |
endTime = calendar.getTime(); |
潘 |
314 |
} |
|
315 |
|
ead005
|
316 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity()); |
潘 |
317 |
List<String> legend = new ArrayList<>(); |
|
318 |
LinkedHashMap<String, PreDataSampleViewRespDTO> viewMap = new LinkedHashMap<>(); |
|
319 |
List<MmItemOutputEntity> outs = mmItemOutputService.getByItemid(reqVO.getItemId()); |
|
320 |
if (CollectionUtils.isEmpty(outs)) { |
|
321 |
return result; |
|
322 |
} |
|
323 |
for (MmItemOutputEntity out : outs) { |
f283ee
|
324 |
legend.add(out.getResultName()); |
ead005
|
325 |
PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); |
85b200
|
326 |
if (StringUtils.isNotBlank(out.getPointid())) { |
D |
327 |
viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
|
328 |
} |
977edc
|
329 |
viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
94a5f0
|
330 |
//处理预测累计 |
4af6b1
|
331 |
if (out.getIscumulant() == 1) { |
D |
332 |
if (StringUtils.isNotBlank(out.getCumulpoint())) { |
1cf9b0
|
333 |
viewDto.setCumulantRealData(getHisData(out.getCumulpoint(), startTime, endTime)); |
4af6b1
|
334 |
} |
D |
335 |
viewDto.setCumulantPreData(mmItemResultService.getData(out.getId() + CommonDict.CUMULANT_SUFFIX, startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
336 |
} |
|
337 |
|
f283ee
|
338 |
viewMap.put(out.getResultName(), viewDto); |
ead005
|
339 |
} |
潘 |
340 |
result.setStartTime(startTime); |
|
341 |
result.setEndTime(endTime); |
|
342 |
result.setCategories(categories); |
|
343 |
result.setLegend(legend); |
|
344 |
result.setViewMap(viewMap); |
|
345 |
return result; |
|
346 |
} |
|
347 |
|
328ef4
|
348 |
@Override |
91343d
|
349 |
public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { |
潘 |
350 |
PreDataSingleChartRespVO result = new PreDataSingleChartRespVO(); |
328ef4
|
351 |
|
91343d
|
352 |
Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode()); |
潘 |
353 |
if (CollectionUtils.isEmpty(chartParams)) { |
|
354 |
return result; |
|
355 |
} |
|
356 |
String itemCode = chartParams.get(CommonConstant.ITEM_CODE); |
|
357 |
if (itemCode == null) { |
|
358 |
return result; |
|
359 |
} |
|
360 |
String resultStr = chartParams.get(CommonConstant.RESULT_STR); |
|
361 |
if (resultStr == null) { |
|
362 |
return result; |
|
363 |
} |
bd9085
|
364 |
String resultIndex = chartParams.get(CommonConstant.RESULT_INDEX); |
潘 |
365 |
|
91343d
|
366 |
ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode); |
潘 |
367 |
if (predictItem == null || predictItem.getLastTime() == null) { |
|
368 |
return result; |
|
369 |
} |
977edc
|
370 |
String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); |
潘 |
371 |
PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(chartParams.get(CommonConstant.LINE_TYPE)); |
8fd9f6
|
372 |
BigDecimal rangeH = chartParams.get(CommonConstant.RANGE_H) == null ? null : new BigDecimal(chartParams.get(CommonConstant.RANGE_H)); |
潘 |
373 |
BigDecimal rangeL = chartParams.get(CommonConstant.RANGE_L) == null ? null : new BigDecimal(chartParams.get(CommonConstant.RANGE_L)); |
|
374 |
BigDecimal limitH = chartParams.get(CommonConstant.LIMIT_H) == null ? null : new BigDecimal(chartParams.get(CommonConstant.LIMIT_H)); |
|
375 |
BigDecimal limitL = chartParams.get(CommonConstant.LIMIT_L) == null ? null : new BigDecimal(chartParams.get(CommonConstant.LIMIT_L)); |
91343d
|
376 |
int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue(); |
潘 |
377 |
int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue(); |
8a74e9
|
378 |
|
潘 |
379 |
Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight); |
|
380 |
Date predictTime = timeArray[0]; |
|
381 |
Date startTime = timeArray[1]; |
|
382 |
Date endTime = timeArray[2]; |
|
383 |
|
977edc
|
384 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat); |
91343d
|
385 |
List<String> legend = new ArrayList<>(); |
bdab69
|
386 |
MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), resultStr, resultIndex); |
91343d
|
387 |
PreDataViewRespDTO dataView = new PreDataViewRespDTO(); |
潘 |
388 |
dataView.setItemId(predictItem.getId()); |
|
389 |
dataView.setItemName(predictItem.getItemName()); |
|
390 |
dataView.setResultstr(resultStr); |
|
391 |
dataView.setRangeH(rangeH); |
|
392 |
dataView.setRangeL(rangeL); |
|
393 |
dataView.setLimitH(limitH); |
|
394 |
dataView.setLimitL(limitL); |
b6bfe8
|
395 |
if (StringUtils.isNotBlank(outPut.getPointid())) { |
D |
396 |
dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime, timeFormat)); |
|
397 |
} else { |
|
398 |
dataView.setRealData(new ArrayList<>()); |
|
399 |
} |
648f25
|
400 |
dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat, 3)); |
d9f2f1
|
401 |
dataView.setLineType(lineType.getCode()); |
91343d
|
402 |
switch (lineType) { |
潘 |
403 |
case TN: |
977edc
|
404 |
dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime, timeFormat)); |
91343d
|
405 |
break; |
潘 |
406 |
case TL: |
977edc
|
407 |
dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat)); |
潘 |
408 |
dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat)); |
91343d
|
409 |
break; |
潘 |
410 |
default: |
|
411 |
break; |
|
412 |
} |
d9f2f1
|
413 |
if (!CollectionUtils.isEmpty(dataView.getRealData())) { |
潘 |
414 |
Object[] rdo = dataView.getRealData().get(dataView.getRealData().size() - 1); |
|
415 |
dataView.setCurrValue(new BigDecimal(rdo[1].toString())); |
|
416 |
} |
912419
|
417 |
|
3722c4
|
418 |
if (!CollectionUtils.isEmpty(dataView.getCurData())) { |
潘 |
419 |
List<Double> curList = dataView.getCurData().stream().map(t -> { |
912419
|
420 |
return new Double(t[1].toString()); |
潘 |
421 |
}).collect(Collectors.toList()); |
|
422 |
dataView.setPreMax(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
423 |
dataView.setPreMin(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
0dc07f
|
424 |
dataView.setPreLast(new BigDecimal(curList.get(curList.size() - 1)).setScale(2, BigDecimal.ROUND_HALF_UP)); |
潘 |
425 |
dataView.setPreCumulant(new BigDecimal(curList.stream().mapToDouble(Double::doubleValue).sum()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
912419
|
426 |
} |
潘 |
427 |
|
9904da
|
428 |
String alarmObj = chartParams.get(CommonConstant.ALARM_OBJ); |
潘 |
429 |
if (StringUtils.isNotBlank(alarmObj)) { |
|
430 |
List<AlarmMessageRespDTO> alarmList = ConvertUtils.sourceToTarget(mmPredictAlarmMessageService.getList(alarmObj, predictTime), AlarmMessageRespDTO.class); |
8ccce9
|
431 |
dataView.setAlarmList(alarmList); |
8fd9f6
|
432 |
if (CollectionUtils.isEmpty(alarmList)) { |
潘 |
433 |
dataView.setAlarmMessage("暂无预警信息"); |
|
434 |
} else { |
|
435 |
dataView.setAlarmMessage(alarmList.get(0).getContent()); |
|
436 |
} |
9904da
|
437 |
} |
潘 |
438 |
|
e09e89
|
439 |
try { |
潘 |
440 |
String adjValuePoint = chartParams.get(CommonConstant.ADJ_VALUE_POINT); |
|
441 |
if (StringUtils.isNotBlank(adjValuePoint)) { |
|
442 |
List<String> pointNos = new ArrayList<>(); |
|
443 |
pointNos.add(adjValuePoint); |
|
444 |
Map<String, Object> adjValue = dataPointApi.queryPointsRealValue(pointNos); |
|
445 |
dataView.setAdjValue(new BigDecimal(adjValue.get(adjValuePoint).toString())); |
|
446 |
} |
|
447 |
|
|
448 |
String adjValueArrPoint = chartParams.get(CommonConstant.ADJ_VALUE_ARR_POINT); |
|
449 |
if (StringUtils.isNotBlank(adjValueArrPoint)) { |
|
450 |
String[] adjPointArr = adjValueArrPoint.split(","); |
|
451 |
Map<String, Object> adjValue = dataPointApi.queryPointsRealValue(Arrays.asList(adjPointArr)); |
|
452 |
BigDecimal[] adjValueArr = new BigDecimal[adjPointArr.length]; |
|
453 |
for(int i = 0; i < adjPointArr.length; i++) { |
|
454 |
adjValueArr[i] = new BigDecimal(adjValue.get(adjPointArr[i]).toString()); |
|
455 |
} |
|
456 |
dataView.setAdjValueArr(adjValueArr); |
|
457 |
} |
|
458 |
} catch (Exception ex) { |
|
459 |
ex.printStackTrace(); |
|
460 |
} |
|
461 |
|
8a74e9
|
462 |
result.setPredictTime(predictTime); |
91343d
|
463 |
result.setStartTime(startTime); |
潘 |
464 |
result.setEndTime(endTime); |
|
465 |
result.setCategories(categories); |
|
466 |
result.setLegend(legend); |
|
467 |
result.setDataView(dataView); |
8a74e9
|
468 |
return result; |
潘 |
469 |
} |
|
470 |
|
|
471 |
@Override |
d9fe8f
|
472 |
public Map<String, List<Object[]>> getPreDataCur(PreDataJsonReqVO reqVO) { |
潘 |
473 |
Map<String, List<Object[]>> result = new HashMap<>(); |
|
474 |
if (reqVO == null || reqVO.getPredictTime() == null || CollectionUtils.isEmpty(reqVO.getOutputIdList())) { |
|
475 |
return result; |
|
476 |
} |
|
477 |
reqVO.getOutputIdList().forEach(outPutId -> { |
|
478 |
result.put(outPutId, mmItemResultJsonService.getData(outPutId, reqVO.getPredictTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
479 |
}); |
|
480 |
return result; |
|
481 |
} |
|
482 |
|
|
483 |
@Override |
8a74e9
|
484 |
public PlanDataSingleChartRespVO getPlanDataSingleChart(PreDataSingleChartReqVO reqVO) { |
潘 |
485 |
PlanDataSingleChartRespVO result = new PlanDataSingleChartRespVO(); |
|
486 |
Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode()); |
|
487 |
if (CollectionUtils.isEmpty(chartParams)) { |
|
488 |
return result; |
|
489 |
} |
|
490 |
String itemCode = chartParams.get(CommonConstant.ITEM_CODE); |
|
491 |
if (itemCode == null) { |
|
492 |
return result; |
|
493 |
} |
|
494 |
String planItemStr = chartParams.get(CommonConstant.PLAN_ITEM_LIST); |
|
495 |
if (planItemStr == null) { |
|
496 |
return result; |
|
497 |
} |
|
498 |
List<String> planItemCodeList = Arrays.asList(planItemStr.split(",")); |
|
499 |
|
|
500 |
ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode); |
|
501 |
if (predictItem == null || predictItem.getLastTime() == null) { |
|
502 |
return result; |
|
503 |
} |
|
504 |
String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); |
|
505 |
int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue(); |
|
506 |
int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue(); |
|
507 |
Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight); |
|
508 |
Date predictTime = timeArray[0]; |
|
509 |
Date startTime = timeArray[1]; |
|
510 |
Date endTime = timeArray[2]; |
|
511 |
List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat); |
|
512 |
List<String> legend = new ArrayList<>(); |
|
513 |
LinkedHashMap<String, List<PlanDataRecordDTO>> record = new LinkedHashMap<>(); |
|
514 |
ApiDataQueryDTO queryDTO = new ApiDataQueryDTO(); |
|
515 |
queryDTO.setItemNos(planItemCodeList); |
|
516 |
queryDTO.setStart(startTime); |
|
517 |
queryDTO.setEnd(endTime); |
|
518 |
LinkedHashMap<String, List<ApiPlanDataDTO>> planData = planItemApi.queryPlanItemRecordValue(queryDTO); |
|
519 |
if (CollectionUtils.isEmpty(planData)) { |
|
520 |
planData.forEach((key, value) -> { |
|
521 |
record.put(key, ConvertUtils.sourceToTarget(value, PlanDataRecordDTO.class)); |
|
522 |
}); |
|
523 |
} |
|
524 |
result.setPredictTime(predictTime); |
|
525 |
result.setStartTime(startTime); |
|
526 |
result.setEndTime(endTime); |
|
527 |
result.setCategories(categories); |
|
528 |
result.setLegend(legend); |
|
529 |
result.setRecord(record); |
328ef4
|
530 |
return result; |
潘 |
531 |
} |
|
532 |
|
b368e6
|
533 |
/** |
潘 |
534 |
* 获取真实值 |
|
535 |
* |
|
536 |
* @param pointId |
|
537 |
* @param startTime |
|
538 |
* @param endTime |
|
539 |
* @return |
|
540 |
*/ |
|
541 |
private List<Object[]> getHisData(String pointId, Date startTime, Date endTime) { |
|
542 |
List<Object[]> result = new ArrayList<>(); |
94a5f0
|
543 |
if (StringUtils.isBlank(pointId)) { |
D |
544 |
return result; |
|
545 |
} |
b368e6
|
546 |
ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); |
潘 |
547 |
ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); |
|
548 |
queryPointDto.setPointNo(pointDTO.getPointNo()); |
|
549 |
queryPointDto.setStart(startTime); |
|
550 |
queryPointDto.setEnd(endTime); |
|
551 |
List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); |
|
552 |
if (CollectionUtils.isEmpty(valueDTOS)) { |
|
553 |
return result; |
|
554 |
} |
|
555 |
valueDTOS.forEach(item -> { |
|
556 |
Object[] values = new Object[2]; |
214275
|
557 |
values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
142bcd
|
558 |
values[1] = new BigDecimal(item.getV()).setScale(3, BigDecimal.ROUND_HALF_UP); |
b368e6
|
559 |
result.add(values); |
潘 |
560 |
}); |
|
561 |
return result; |
|
562 |
} |
|
563 |
|
977edc
|
564 |
/** |
潘 |
565 |
* 获取真实值 |
|
566 |
* |
|
567 |
* @param pointId |
|
568 |
* @param startTime |
|
569 |
* @param endTime |
|
570 |
* @param timeFormat |
|
571 |
* @return |
|
572 |
*/ |
|
573 |
private List<Object[]> getHisData(String pointId, Date startTime, Date endTime, String timeFormat) { |
|
574 |
List<Object[]> result = new ArrayList<>(); |
|
575 |
ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); |
|
576 |
ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); |
|
577 |
queryPointDto.setPointNo(pointDTO.getPointNo()); |
|
578 |
queryPointDto.setStart(startTime); |
|
579 |
queryPointDto.setEnd(endTime); |
|
580 |
List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); |
|
581 |
if (CollectionUtils.isEmpty(valueDTOS)) { |
|
582 |
return result; |
|
583 |
} |
|
584 |
valueDTOS.forEach(item -> { |
|
585 |
Object[] values = new Object[2]; |
|
586 |
values[0] = DateUtils.format(item.getT(), timeFormat); |
|
587 |
values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); |
|
588 |
result.add(values); |
|
589 |
}); |
|
590 |
return result; |
|
591 |
} |
|
592 |
|
c5fe30
|
593 |
/** |
潘 |
594 |
* 新增预警信息 |
|
595 |
* |
|
596 |
* @param dto |
|
597 |
* @return |
|
598 |
*/ |
b368e6
|
599 |
@Override |
潘 |
600 |
public Boolean createAlarmMessage(AlarmMessageRespDTO dto) { |
c5fe30
|
601 |
try { |
潘 |
602 |
mmPredictAlarmMessageService.create(ConvertUtils.sourceToTarget(dto, MmPredictAlarmMessageSaveReqVO.class)); |
|
603 |
return true; |
|
604 |
} catch (Exception e) { |
|
605 |
return false; |
|
606 |
} |
b368e6
|
607 |
} |
潘 |
608 |
|
|
609 |
@Override |
|
610 |
public List<AlarmMessageRespDTO> listAlarmMessage(Map<String, Object> params) { |
|
611 |
return null; |
|
612 |
} |
|
613 |
|
|
614 |
@Override |
9587d2
|
615 |
public List<AlarmConfigRespDTO> listAlarmConfig(Map<String, Object> params) { |
L |
616 |
return mmPredictAlarmConfigService.list(params); |
|
617 |
} |
|
618 |
|
|
619 |
@Override |
c5fe30
|
620 |
public AlarmMessageRespDTO getLastAlarmMessage(String alarmObj) { |
潘 |
621 |
MmPredictAlarmMessageEntity entity = mmPredictAlarmMessageService.getLast(alarmObj); |
|
622 |
return ConvertUtils.sourceToTarget(entity, AlarmMessageRespDTO.class); |
|
623 |
} |
|
624 |
|
|
625 |
@Override |
b368e6
|
626 |
public Boolean createScheduleSuggest(ScheduleSuggestRespDTO dto) { |
19f359
|
627 |
stScheduleSuggestService.create(ConvertUtils.sourceToTarget(dto, StScheduleSuggestSaveReqVO.class)); |
b368e6
|
628 |
return true; |
潘 |
629 |
} |
|
630 |
|
|
631 |
@Override |
ead679
|
632 |
public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO vo) { |
D |
633 |
return stScheduleSuggestService.list(vo); |
3a6dfc
|
634 |
} |
L |
635 |
|
|
636 |
@Override |
055765
|
637 |
public List<ScheduleSuggestRespDTO> getLastLimitScheduleSuggest(String scheduleObj, Integer limit) { |
潘 |
638 |
List<StScheduleSuggestEntity> list = stScheduleSuggestService.getList(scheduleObj, limit); |
|
639 |
return ConvertUtils.sourceToTarget(list, ScheduleSuggestRespDTO.class); |
b368e6
|
640 |
} |
潘 |
641 |
|
|
642 |
@Override |
|
643 |
public Boolean modifyPredictModelSetting(List<PredictModelSettingReqDTO> dtos) { |
|
644 |
return true; |
|
645 |
} |
|
646 |
|
|
647 |
@Override |
|
648 |
public Boolean modifyScheduleModelSetting(List<ScheduleModelSettingReqDTO> dtos) { |
|
649 |
return true; |
|
650 |
} |
8a74e9
|
651 |
|
4072bc
|
652 |
@Override |
ed4107
|
653 |
public List<StScheduleSchemeDTO> listScheduleScheme(String triggerMethod, String triggerCondition) { |
潘 |
654 |
Map<String, Object> params = new HashMap<>(); |
|
655 |
params.put("triggerMethod", triggerMethod); |
|
656 |
params.put("triggerCondition", triggerCondition); |
4072bc
|
657 |
return stScheduleSchemeService.list(params); |
6eeac9
|
658 |
} |
8a74e9
|
659 |
|
730d19
|
660 |
@Override |
D |
661 |
public List<ChartParamDTO> getChartParamList(String chartCode) { |
|
662 |
if (StringUtils.isBlank(chartCode)) { |
|
663 |
return null; |
|
664 |
} |
|
665 |
return chartParamService.list(chartCode); |
|
666 |
} |
|
667 |
|
0a7d0f
|
668 |
@Override |
潘 |
669 |
public PageResult<StAlarmAndSuggestRespVO> getAlarmAndSuggestPage(StAlarmAndSuggestPageReqVO reqVO) { |
|
670 |
return stScheduleSchemeService.getAlarmAndSuggestPage(reqVO); |
|
671 |
} |
|
672 |
|
22e321
|
673 |
@Override |
D |
674 |
public Map<String, Map<String, Double>> getPreDoubleData(PreDoubleDataReqVO reqVO) { |
|
675 |
List<MmPredictItemRespVO> doubleItemOutPuts = mmPredictItemService.getDoubleOutPutsByItemNos(reqVO.getItemNos()); |
|
676 |
|
|
677 |
//<itemNo,<resultStr,double>> |
|
678 |
Map<String, Map<String, Double>> result = new HashMap<>(reqVO.getItemNos().size()); |
|
679 |
|
|
680 |
for (MmPredictItemRespVO mmPredictItemRespVO : doubleItemOutPuts) { |
|
681 |
List<String> outPutIds = mmPredictItemRespVO.getOutPuts().stream().map(MmItemOutputRespVO::getId).collect(Collectors.toList()); |
|
682 |
InfluxModelResultByOutPutIdsPOJO pojo = new InfluxModelResultByOutPutIdsPOJO(); |
|
683 |
pojo.setOutPutIds(outPutIds); |
|
684 |
pojo.setType(DataTypeEnum.FLOAT.getCode()); |
|
685 |
Map<String, List<InfluxModelResultVO>> outPutIdDoubles = influxDBService.queryModelResultsByOutPutIds(pojo, mmPredictItemRespVO.getLastTime(), mmPredictItemRespVO.getLastTime()); |
|
686 |
Map<String, Double> outPutIdDouble = new HashMap<>(outPutIds.size()); |
|
687 |
for (MmItemOutputRespVO outPut : mmPredictItemRespVO.getOutPuts()) { |
|
688 |
String outPutId = outPut.getId(); |
|
689 |
if (outPutIdDoubles.containsKey(outPutId)) { |
|
690 |
List<InfluxModelResultVO> influxModelResultVOS = outPutIdDoubles.get(outPutId); |
|
691 |
if (!CollectionUtils.isEmpty(influxModelResultVOS)) { |
|
692 |
outPutIdDouble.put(outPut.getResultstr(),Double.valueOf(influxModelResultVOS.get(0).getValue().toString())); |
|
693 |
} |
|
694 |
} |
|
695 |
} |
|
696 |
result.put(mmPredictItemRespVO.getItemno(),outPutIdDouble); |
|
697 |
} |
|
698 |
return result; |
|
699 |
} |
|
700 |
|
bffae5
|
701 |
public Map<String, BigDecimal> getPredictLastValue(PredictLastValueReqVO reqVO) { |
潘 |
702 |
Map<String, BigDecimal> result = new HashMap<>(reqVO.getItemNos().size()); |
|
703 |
if (CollectionUtils.isEmpty(reqVO.getItemNos())) { |
|
704 |
return result; |
|
705 |
} |
|
706 |
List<String[]> itemNos = reqVO.getItemNos(); |
|
707 |
for (String[] itemNo : itemNos) { |
fed257
|
708 |
String key = itemNo[0] + "_" + itemNo[1] + "_" + itemNo[2]; |
bffae5
|
709 |
ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemNo[0]); |
潘 |
710 |
if (predictItem == null || predictItem.getLastTime() == null) { |
fed257
|
711 |
result.put(key, BigDecimal.ZERO); |
bffae5
|
712 |
} |
潘 |
713 |
MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), itemNo[1], itemNo[2]); |
c350c9
|
714 |
String outputId = outPut.getId(); |
J |
715 |
// 如果第5个参数为1,则取累计值 |
|
716 |
if ("1".equals(itemNo[4])){ |
|
717 |
outputId = outPut.getId() + CommonDict.CUMULANT_SUFFIX; |
|
718 |
} |
bffae5
|
719 |
Date predictTime = predictItem.getLastTime(); |
c350c9
|
720 |
List<Object[]> curData = mmItemResultJsonService.getData(outputId, predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
bffae5
|
721 |
if(CollectionUtils.isEmpty(curData)) { |
fed257
|
722 |
result.put(key, BigDecimal.ZERO); |
bffae5
|
723 |
} else { |
fed257
|
724 |
result.put(key, new BigDecimal(curData.get(curData.size() - 1)[1].toString())); |
bffae5
|
725 |
} |
潘 |
726 |
} |
|
727 |
return result; |
|
728 |
} |
|
729 |
|
dec0c2
|
730 |
@Override |
153763
|
731 |
public List<StScheduleRecordVO> getLastScheduleData(String scheduleCode, Integer limit) { |
dec0c2
|
732 |
if (StringUtils.isBlank(scheduleCode)) { |
D |
733 |
return null; |
|
734 |
} |
153763
|
735 |
return stScheduleRecordService.getLastScheduleResult(scheduleCode,limit); |
dec0c2
|
736 |
} |
D |
737 |
|
|
738 |
@Override |
153763
|
739 |
public Map<String, List<Object[]>> getPredictDataItemNo(PreDataItemNoReqVO reqVO) { |
04fa7f
|
740 |
if (StringUtils.isBlank(reqVO.getItemNo())) { |
153763
|
741 |
return new HashMap<>(); |
D |
742 |
} |
|
743 |
ItemVO predictItem = mmPredictItemService.getItemByItemNo(reqVO.getItemNo()); |
|
744 |
if (null == predictItem) { |
|
745 |
return new HashMap<>(); |
|
746 |
} |
04fa7f
|
747 |
|
D |
748 |
// 默认开始时间:运行时间 |
|
749 |
if (null == reqVO.getStartTime()) { |
|
750 |
reqVO.setStartTime(predictItem.getLastTime()); |
|
751 |
} |
|
752 |
// 默认结束时间:运行时间+预测长度*粒度 |
912646
|
753 |
if (null == reqVO.getEndTime()) { |
04fa7f
|
754 |
Calendar calendar = Calendar.getInstance(); |
D |
755 |
calendar.setTime(predictItem.getLastTime()); |
|
756 |
calendar.add(Calendar.SECOND,predictItem.getPredictLength() * predictItem.getGranularity()); |
|
757 |
reqVO.setEndTime(calendar.getTime()); |
|
758 |
} |
|
759 |
|
153763
|
760 |
List<String> itemNos = new ArrayList<String>(){{ |
D |
761 |
add(reqVO.getItemNo()); |
|
762 |
}}; |
|
763 |
List<MmPredictItemRespVO> ItemRespVOs = mmPredictItemService.getArrayOutPutsByItemNos(itemNos); |
|
764 |
if (CollectionUtils.isEmpty(ItemRespVOs)) { |
|
765 |
return new HashMap<>(); |
|
766 |
} |
|
767 |
List<MmItemOutputRespVO> outPuts = ItemRespVOs.get(0).getOutPuts(); |
|
768 |
if (CollectionUtils.isEmpty(outPuts)) { |
|
769 |
return new HashMap<>(); |
|
770 |
} |
|
771 |
|
|
772 |
InfluxModelResultByOutPutIdsPOJO pojo = new InfluxModelResultByOutPutIdsPOJO(); |
|
773 |
pojo.setOutPutIds(outPuts.stream().map(MmItemOutputRespVO::getId).collect(Collectors.toList())); |
|
774 |
pojo.setType(DataTypeEnum.FLOAT.getCode()); |
|
775 |
Map<String, List<InfluxModelResultVO>> outPutDatas = influxDBService.queryModelResultsByOutPutIds(pojo, reqVO.getStartTime(), reqVO.getEndTime()); |
|
776 |
Map<String,List<Object[]>> result = new HashMap<>(outPuts.size()); |
|
777 |
for (MmItemOutputRespVO outPut : outPuts) { |
|
778 |
String outPutId = outPut.getId(); |
|
779 |
if (outPutDatas.containsKey(outPutId)) { |
|
780 |
List<InfluxModelResultVO> influxModelResultVOS = outPutDatas.get(outPutId); |
|
781 |
result.put(null == outPut.getResultIndex() ? outPut.getResultstr() : outPut.getResultstr()+"_"+outPut.getResultIndex(),influxModelResultVOS.stream().map(e -> { |
|
782 |
Object[] values = new Object[2]; |
|
783 |
values[0] = DateUtils.format(Date.from(e.getTimestamp()), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
|
784 |
values[1] = Double.valueOf(e.getValue().toString()); |
|
785 |
return values; |
|
786 |
}).collect(Collectors.toList())); |
|
787 |
} |
|
788 |
} |
|
789 |
return result; |
|
790 |
} |
|
791 |
|
af72d8
|
792 |
@Override |
1eec62
|
793 |
public List<ElectricityPriceSegmentedDTO> getElectricityPriceList(String year, String time) { |
J |
794 |
return electricityPriceSegmentedService.getElectricityPriceList(year, time); |
af72d8
|
795 |
} |
J |
796 |
|
|
797 |
@Override |
e63c53
|
798 |
public Boolean createElectricityPrice(List<ElectricityPriceSegmentedDTO> list) { |
J |
799 |
electricityPriceSegmentedService.deleteByITimeId(list.get(0).getITimeId()); |
|
800 |
list.forEach(dto -> electricityPriceSegmentedService.create(dto)); |
af72d8
|
801 |
return true; |
J |
802 |
} |
|
803 |
|
e9506a
|
804 |
@Override |
J |
805 |
public Boolean updateScheduleModelSetting(String modelCode, String key, String value) { |
|
806 |
StScheduleModelEntity model = stScheduleModelService.getByModelCode(modelCode); |
|
807 |
stScheduleModelSettingService.updateByModelIdAndKey(model.getId(), key, value); |
|
808 |
return true; |
|
809 |
} |
|
810 |
|
87d7ae
|
811 |
@Override |
潘 |
812 |
public List<StAdjustConfigDetDTO> getAdjustConfigListByModelId(String modelId) { |
|
813 |
List<StAdjustConfigDetEntity> list = stAdjustConfigService.getDetByModelId(modelId); |
|
814 |
return ConvertUtils.sourceToTarget(list, StAdjustConfigDetDTO.class); |
|
815 |
} |
|
816 |
|
dec0c2
|
817 |
/** |
D |
818 |
* 计算功率因数 p²/(根号:p²+Q²) |
|
819 |
**/ |
|
820 |
public Double calculateCos(Double PValue,Double QValue) { |
|
821 |
// 绝对值 |
|
822 |
PValue = Math.abs(PValue); |
|
823 |
QValue = Math.abs(QValue); |
|
824 |
//PValue [0,0.001] 直接判断为关闭返回0 |
|
825 |
if (PValue >= 0 && PValue <= 0.001) { |
|
826 |
return 0.0; |
|
827 |
}else { |
|
828 |
BigDecimal result = new BigDecimal(PValue).divide(BigDecimal.valueOf(Math.sqrt(Math.pow(PValue, 2) + Math.pow(QValue, 2))), 2, BigDecimal.ROUND_HALF_UP); |
|
829 |
return result.doubleValue(); |
|
830 |
} |
|
831 |
} |
|
832 |
|
8a74e9
|
833 |
private Date[] calResultTime(ItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) { |
潘 |
834 |
Date[] result = new Date[3]; |
|
835 |
Date predictTime = predictItem.getLastTime(); |
dec0c2
|
836 |
Integer granularity = predictItem.getGranularity(); |
8a74e9
|
837 |
Date startTime = startTimeReq; |
潘 |
838 |
if (startTime == null) { |
|
839 |
Calendar calendar = Calendar.getInstance(); |
|
840 |
calendar.setTime(predictItem.getLastTime()); |
dec0c2
|
841 |
calendar.add(Calendar.SECOND, -1 * lengthLeft * granularity); |
8a74e9
|
842 |
startTime = calendar.getTime(); |
潘 |
843 |
} |
|
844 |
Date endTime = endTimeReq; |
|
845 |
if (endTime == null) { |
|
846 |
Calendar calendar = Calendar.getInstance(); |
|
847 |
calendar.setTime(predictItem.getLastTime()); |
dec0c2
|
848 |
calendar.add(Calendar.SECOND, lengthRight * granularity); |
8a74e9
|
849 |
endTime = calendar.getTime(); |
潘 |
850 |
} |
|
851 |
if (endTime.getTime() <= startTime.getTime()) { |
|
852 |
Calendar calendar = Calendar.getInstance(); |
|
853 |
calendar.setTime(startTime); |
dec0c2
|
854 |
calendar.add(Calendar.SECOND, lengthRight * granularity); |
8a74e9
|
855 |
endTime = calendar.getTime(); |
潘 |
856 |
} |
|
857 |
result[0] = predictTime; |
|
858 |
result[1] = startTime; |
|
859 |
result[2] = endTime; |
|
860 |
return result; |
|
861 |
} |
b368e6
|
862 |
} |