提交 | 用户 | 时间
|
8766cf
|
1 |
package com.iailab.module.shasteel.mq.consumer; |
L |
2 |
|
|
3 |
import com.alibaba.fastjson.JSONObject; |
|
4 |
import com.iailab.framework.common.util.date.DateUtils; |
|
5 |
import com.iailab.module.model.api.mcs.McsApi; |
|
6 |
import com.iailab.module.model.api.mcs.dto.AlarmConfigRespDTO; |
|
7 |
import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; |
|
8 |
import com.iailab.module.model.api.mcs.dto.PreDataJsonReqVO; |
|
9 |
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
|
10 |
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
import org.springframework.util.CollectionUtils; |
|
13 |
|
|
14 |
import javax.annotation.Resource; |
|
15 |
import java.math.BigDecimal; |
bd1e8a
|
16 |
import java.util.ArrayList; |
L |
17 |
import java.util.HashMap; |
|
18 |
import java.util.List; |
|
19 |
import java.util.Map; |
8766cf
|
20 |
|
L |
21 |
/** |
|
22 |
* @author lirm |
|
23 |
* @Description |
|
24 |
* @createTime 2024年11月27日 |
|
25 |
*/ |
|
26 |
@Component |
|
27 |
@RabbitListener(queues = PredictFinishMessage.PREDICTFINISH_ROUTING_KEY) |
|
28 |
public class PredictFinishConsumer { |
|
29 |
|
|
30 |
@Resource |
|
31 |
private McsApi mcsApi; |
|
32 |
|
|
33 |
@Resource |
f0a800
|
34 |
private AlarmConsumer alarmConsumer; |
L |
35 |
|
8766cf
|
36 |
@RabbitHandler |
bd1e8a
|
37 |
public void process(JSONObject json) throws InterruptedException { |
8766cf
|
38 |
System.out.println("测试消费模型预测完成RabbitMQ消息----------------------"); |
L |
39 |
Thread.sleep(5000); |
|
40 |
List<AlarmConfigRespDTO> configList = mcsApi.listAlarmConfig(new HashMap<String, Object>()); |
0cd823
|
41 |
if (CollectionUtils.isEmpty(configList)) { |
L |
42 |
return; |
8766cf
|
43 |
} |
0cd823
|
44 |
List<String> OutputIdList = new ArrayList<>(); |
L |
45 |
configList.forEach(item -> { |
|
46 |
OutputIdList.add(item.getOutId()); |
|
47 |
}); |
|
48 |
configList.forEach(item -> { |
|
49 |
PreDataJsonReqVO reqVO = new PreDataJsonReqVO(); |
|
50 |
reqVO.setPredictTime(DateUtils.parse(json.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
51 |
reqVO.setOutputIdList(OutputIdList); |
|
52 |
Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(reqVO); |
|
53 |
if (CollectionUtils.isEmpty(preData)) { |
|
54 |
return; |
|
55 |
} |
|
56 |
List<Object[]> result = preData.get(item.getOutId()); |
|
57 |
int toIndex = result.size(); |
|
58 |
if (toIndex <= 0) { |
|
59 |
return; |
|
60 |
} |
|
61 |
int fromIndex = result.size() - item.getCompLength(); |
|
62 |
List<Object[]> predictList = result.subList(fromIndex, toIndex); |
|
63 |
for (Object[] data : predictList) { |
|
64 |
BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP); |
|
65 |
if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) { |
|
66 |
AlarmMessage alarmMessage = new AlarmMessage(); |
|
67 |
AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); |
|
68 |
alarmMessageRespDTO.setConfigId(item.getId()); |
|
69 |
if (dataValue.compareTo(item.getLowerLimit()) < 0) { |
|
70 |
alarmMessageRespDTO.setAlarmType("1");//超下限 |
|
71 |
} else if (dataValue.compareTo(item.getUpperLimit()) > 0) { |
|
72 |
alarmMessageRespDTO.setAlarmType("2");//超上限 |
|
73 |
} |
|
74 |
alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
75 |
JSONObject content = new JSONObject(); |
|
76 |
content.put("alarmObj", item.getAlarmObj()); |
|
77 |
content.put("alarmType", alarmMessageRespDTO.getAlarmType()); |
|
78 |
content.put("unit", item.getUnit()); |
|
79 |
content.put("overLimitTime", data[0]); |
|
80 |
content.put("overLimitValue", dataValue); |
|
81 |
alarmMessageRespDTO.setContent(JSONObject.toJSONString(content)); |
|
82 |
System.out.println("预警消息=" + alarmMessageRespDTO); |
|
83 |
alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO); |
|
84 |
try { |
|
85 |
alarmConsumer.process(alarmMessage); |
|
86 |
} catch (InterruptedException e) { |
|
87 |
throw new RuntimeException(e); |
|
88 |
} |
|
89 |
break; |
|
90 |
} |
|
91 |
} |
|
92 |
System.out.println(preData); |
|
93 |
}); |
8766cf
|
94 |
} |
L |
95 |
} |