提交 | 用户 | 时间
|
b368e6
|
1 |
package com.iailab.module.model.api; |
潘 |
2 |
|
|
3 |
import com.iailab.framework.common.util.date.DateUtils; |
|
4 |
import com.iailab.module.data.api.point.DataPointApi; |
|
5 |
import com.iailab.module.data.api.point.dto.ApiPointDTO; |
|
6 |
import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
|
7 |
import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
|
8 |
import com.iailab.module.model.api.mcs.McsApi; |
|
9 |
import com.iailab.module.model.api.mcs.dto.*; |
|
10 |
import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
|
11 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
|
12 |
import com.iailab.module.model.mcs.pre.service.*; |
|
13 |
import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; |
|
14 |
import lombok.extern.slf4j.Slf4j; |
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.util.CollectionUtils; |
|
17 |
import org.springframework.validation.annotation.Validated; |
|
18 |
import org.springframework.web.bind.annotation.RestController; |
|
19 |
|
|
20 |
import java.math.BigDecimal; |
|
21 |
import java.util.*; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author PanZhibao |
|
25 |
* @Description |
|
26 |
* @createTime 2024年11月13日 |
|
27 |
*/ |
|
28 |
@Slf4j |
|
29 |
@RestController |
|
30 |
@Validated |
|
31 |
public class McsApiImpl implements McsApi { |
|
32 |
|
|
33 |
@Autowired |
|
34 |
private DmModuleService dmModuleService; |
|
35 |
|
|
36 |
@Autowired |
|
37 |
private MmPredictItemService mmPredictItemService; |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private MmItemOutputService mmItemOutputService; |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private MmItemResultService mmItemResultService; |
|
44 |
|
|
45 |
@Autowired |
|
46 |
private MmItemResultLastPointService mmItemResultLastPointService; |
|
47 |
|
|
48 |
@Autowired |
|
49 |
private DataPointApi dataPointApi; |
|
50 |
|
|
51 |
private int HOUR_MINS = 60; |
|
52 |
|
|
53 |
@Override |
|
54 |
public List<PredictItemTreeDTO> getPredictItemTree() { |
|
55 |
List<PredictItemTreeDTO> result = new ArrayList<>(); |
|
56 |
|
|
57 |
List<DmModuleEntity> moduleList = dmModuleService.list(new HashMap<>()); |
|
58 |
if (CollectionUtils.isEmpty(moduleList)) { |
|
59 |
return result; |
|
60 |
} |
|
61 |
moduleList.forEach(item -> { |
|
62 |
PredictItemTreeDTO moduleOpt = new PredictItemTreeDTO(); |
|
63 |
moduleOpt.setId(item.getId()); |
|
64 |
moduleOpt.setLabel(item.getModulename()); |
|
65 |
List<PredictItemTreeDTO> children = new ArrayList<>(); |
|
66 |
Map<String, Object> params = new HashMap<>(2); |
|
67 |
params.put("status", 1); |
|
68 |
params.put("moduleid", item.getId()); |
|
69 |
List<MmPredictItemRespVO> itemList = mmPredictItemService.list(params); |
|
70 |
itemList.forEach(item1 -> { |
|
71 |
PredictItemTreeDTO chd = new PredictItemTreeDTO(); |
|
72 |
chd.setLabel(item1.getItemname()); |
|
73 |
chd.setId(item1.getId()); |
|
74 |
children.add(chd); |
|
75 |
}); |
|
76 |
moduleOpt.setChildren(children); |
|
77 |
result.add(moduleOpt); |
|
78 |
}); |
|
79 |
return result; |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public PreDataBarLineRespVO getPreDataCharts(PreDataBarLineReqVO reqVO) { |
|
84 |
PreDataBarLineRespVO result = new PreDataBarLineRespVO(); |
|
85 |
List<String[]> queryIds = reqVO.getQueryIds(); |
|
86 |
List<String> legends = new ArrayList<>(); |
|
87 |
List<PreDataViewRespDTO> dataViewList = new ArrayList<>(); |
|
88 |
if (CollectionUtils.isEmpty(reqVO.getQueryIds())) { |
|
89 |
return result; |
|
90 |
} |
|
91 |
Date predictTime = reqVO.getPredictTime(); |
|
92 |
if (predictTime == null) { |
|
93 |
DmModuleEntity dmModule = dmModuleService.getModuleByItemId(queryIds.get(0)[0]); |
|
94 |
if (dmModule != null) { |
|
95 |
predictTime = dmModule.getPredicttime(); |
|
96 |
} else { |
|
97 |
Calendar calendar = Calendar.getInstance(); |
|
98 |
calendar.set(Calendar.MILLISECOND, 0); |
|
99 |
calendar.set(Calendar.SECOND, 0); |
|
100 |
predictTime = calendar.getTime(); |
|
101 |
} |
|
102 |
} |
|
103 |
Date startTime = reqVO.getStartTime(); |
|
104 |
if (startTime == null) { |
|
105 |
Calendar calendar = Calendar.getInstance(); |
|
106 |
calendar.setTime(predictTime); |
|
107 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
108 |
startTime = calendar.getTime(); |
|
109 |
} |
|
110 |
Date endTime = reqVO.getEndTime(); |
|
111 |
if (endTime == null) { |
|
112 |
Calendar calendar = Calendar.getInstance(); |
|
113 |
calendar.setTime(predictTime); |
|
114 |
calendar.add(Calendar.HOUR_OF_DAY, 1); |
|
115 |
endTime = calendar.getTime(); |
|
116 |
} |
|
117 |
|
|
118 |
for (int i = 0; i < queryIds.size(); i++) { |
|
119 |
PreDataViewRespDTO viewDto = new PreDataViewRespDTO(); |
|
120 |
String itemId = queryIds.get(i)[0]; |
|
121 |
String outKey = queryIds.get(i)[1]; |
|
122 |
MmItemOutputEntity output = mmItemOutputService.getByItemid(itemId, outKey); |
|
123 |
if (output == null) { |
|
124 |
continue; |
|
125 |
} |
|
126 |
legends.add(output.getResultstr()); |
|
127 |
viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); |
|
128 |
viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime)); |
|
129 |
viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime)); |
|
130 |
|
|
131 |
List<Double> values = new ArrayList<>(); |
|
132 |
if (!CollectionUtils.isEmpty(viewDto.getRealData())) { |
|
133 |
List<Double> hisValues = new ArrayList<>(); |
|
134 |
viewDto.getRealData().forEach(item -> { |
|
135 |
values.add(Double.parseDouble(item[1].toString())); |
|
136 |
hisValues.add(Double.parseDouble(item[1].toString())); |
|
137 |
}); |
|
138 |
viewDto.setHisMax(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
139 |
viewDto.setHisMin(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
140 |
viewDto.setHisAvg(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
141 |
viewDto.setHisCumulant(new BigDecimal(hisValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
142 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
143 |
} |
|
144 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataN())) { |
|
145 |
viewDto.getPreDataN().forEach(item -> { |
|
146 |
values.add(Double.parseDouble(item[1].toString())); |
|
147 |
}); |
|
148 |
} |
|
149 |
if (!CollectionUtils.isEmpty(viewDto.getPreDataL())) { |
|
150 |
List<Double> preValues = new ArrayList<>(); |
|
151 |
viewDto.getPreDataL().forEach(item -> { |
|
152 |
values.add(Double.parseDouble(item[1].toString())); |
|
153 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
154 |
}); |
|
155 |
viewDto.setPreMax(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
156 |
viewDto.setPreMin(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
157 |
viewDto.setPreAvg(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).average().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
158 |
} |
|
159 |
if (!CollectionUtils.isEmpty(viewDto.getCurData())) { |
|
160 |
List<Double> preValues = new ArrayList<>(); |
|
161 |
viewDto.getCurData().forEach(item -> { |
|
162 |
values.add(Double.parseDouble(item[1].toString())); |
|
163 |
preValues.add(Double.parseDouble(item[1].toString())); |
|
164 |
}); |
|
165 |
viewDto.setPreCumulant(new BigDecimal(preValues.stream().mapToDouble(Double::doubleValue).sum()) |
|
166 |
.divide(new BigDecimal(HOUR_MINS), 2, BigDecimal.ROUND_HALF_UP)); |
|
167 |
} |
|
168 |
if (!CollectionUtils.isEmpty(viewDto.getAdjData())) { |
|
169 |
viewDto.getAdjData().forEach(item -> { |
|
170 |
values.add(Double.parseDouble(item[1].toString())); |
|
171 |
}); |
|
172 |
} |
|
173 |
if (!CollectionUtils.isEmpty(values)) { |
|
174 |
viewDto.setMaxValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).max().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
175 |
viewDto.setMinValue(new BigDecimal(values.stream().mapToDouble(Double::doubleValue).min().getAsDouble()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
176 |
} |
|
177 |
dataViewList.add(viewDto); |
|
178 |
} |
|
179 |
result.setStartTime(startTime); |
|
180 |
result.setEndTime(endTime); |
|
181 |
result.setPredictTime(predictTime); |
|
182 |
result.setCategories(DateUtils.getTimeScale(startTime, endTime, 60)); |
|
183 |
result.setLegend(legends); |
|
184 |
result.setDataViewList(dataViewList); |
|
185 |
return result; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* 获取真实值 |
|
190 |
* |
|
191 |
* @param pointId |
|
192 |
* @param startTime |
|
193 |
* @param endTime |
|
194 |
* @return |
|
195 |
*/ |
|
196 |
private List<Object[]> getHisData(String pointId, Date startTime, Date endTime) { |
|
197 |
List<Object[]> result = new ArrayList<>(); |
|
198 |
ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); |
|
199 |
ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); |
|
200 |
queryPointDto.setPointNo(pointDTO.getPointNo()); |
|
201 |
queryPointDto.setStart(startTime); |
|
202 |
queryPointDto.setEnd(endTime); |
|
203 |
List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); |
|
204 |
if (CollectionUtils.isEmpty(valueDTOS)) { |
|
205 |
return result; |
|
206 |
} |
|
207 |
valueDTOS.forEach(item -> { |
|
208 |
Object[] values = new Object[2]; |
|
209 |
values[0] = DateUtils.format(item.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
|
210 |
values[1] = item.getDataValue(); |
|
211 |
result.add(values); |
|
212 |
}); |
|
213 |
return result; |
|
214 |
} |
|
215 |
|
|
216 |
@Override |
|
217 |
public Boolean createAlarmMessage(AlarmMessageRespDTO dto) { |
|
218 |
return true; |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public List<AlarmMessageRespDTO> listAlarmMessage(Map<String, Object> params) { |
|
223 |
return null; |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public Boolean createScheduleSuggest(ScheduleSuggestRespDTO dto) { |
|
228 |
return true; |
|
229 |
} |
|
230 |
|
|
231 |
@Override |
|
232 |
public List<ScheduleSuggestRespDTO> listScheduleSuggest(ScheduleSuggestReqDTO params) { |
|
233 |
return null; |
|
234 |
} |
|
235 |
|
|
236 |
@Override |
|
237 |
public Boolean modifyPredictModelSetting(List<PredictModelSettingReqDTO> dtos) { |
|
238 |
return true; |
|
239 |
} |
|
240 |
|
|
241 |
@Override |
|
242 |
public Boolean modifyScheduleModelSetting(List<ScheduleModelSettingReqDTO> dtos) { |
|
243 |
return true; |
|
244 |
} |
|
245 |
} |