From 0cd82338d4f3cef13359d32e4b948c03cd0dd959 Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期三, 11 十二月 2024 11:59:32 +0800
Subject: [PATCH] MQ

---
 shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java |  101 ++++++++++++++++++++++++++------------------------
 1 files changed, 52 insertions(+), 49 deletions(-)

diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
index d8f1918..3256ea9 100644
--- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
+++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
@@ -38,55 +38,58 @@
         System.out.println("测试消费模型预测完成RabbitMQ消息----------------------");
         Thread.sleep(5000);
         List<AlarmConfigRespDTO> configList = mcsApi.listAlarmConfig(new HashMap<String, Object>());
-        if (!CollectionUtils.isEmpty(configList)) {
-            List<String> OutputIdList = new ArrayList<>();
-            configList.forEach(item -> {
-                OutputIdList.add(item.getOutId());
-            });
-            configList.forEach(item -> {
-                PreDataJsonReqVO reqVO = new PreDataJsonReqVO();
-                reqVO.setPredictTime(DateUtils.parse(json.get("predictTime").toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
-                reqVO.setOutputIdList(OutputIdList);
-                Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(reqVO);
-                if (!CollectionUtils.isEmpty(preData)) {
-                    List<Object[]> result = preData.get(item.getOutId());
-                    int toIndex = result.size();
-                    if(toIndex > 0){
-                        int fromIndex = result.size() - item.getCompLength();
-                        List<Object[]> predictList = result.subList(fromIndex, toIndex);
-                        for(Object[] data : predictList){
-                            BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
-                            if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) {
-                                AlarmMessage alarmMessage = new AlarmMessage();
-                                AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO();
-                                alarmMessageRespDTO.setConfigId(item.getId());
-                                if (dataValue.compareTo(item.getLowerLimit()) < 0) {
-                                    alarmMessageRespDTO.setAlarmType("1");//超下限
-                                }else if (dataValue.compareTo(item.getUpperLimit()) > 0) {
-                                    alarmMessageRespDTO.setAlarmType("2");//超上限
-                                }
-                                alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
-                                JSONObject content = new JSONObject();
-                                content.put("alarmObj", item.getAlarmObj());
-                                content.put("alarmType", alarmMessageRespDTO.getAlarmType());
-                                content.put("unit", item.getUnit());
-                                content.put("overLimitTime", data[0]);
-                                content.put("overLimitValue", dataValue);
-                                alarmMessageRespDTO.setContent(JSONObject.toJSONString(content));
-                                System.out.println("预警消息=" + alarmMessageRespDTO);
-                                alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO);
-                                try {
-                                    alarmConsumer.process(alarmMessage);
-                                } catch (InterruptedException e) {
-                                    throw new RuntimeException(e);
-                                }
-                                break;
-                            }
-                        }
-                    }
-                }
-                System.out.println(preData);
-            });
+        if (CollectionUtils.isEmpty(configList)) {
+            return;
         }
+        List<String> OutputIdList = new ArrayList<>();
+        configList.forEach(item -> {
+            OutputIdList.add(item.getOutId());
+        });
+        configList.forEach(item -> {
+            PreDataJsonReqVO reqVO = new PreDataJsonReqVO();
+            reqVO.setPredictTime(DateUtils.parse(json.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
+            reqVO.setOutputIdList(OutputIdList);
+            Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(reqVO);
+            if (CollectionUtils.isEmpty(preData)) {
+                return;
+            }
+            List<Object[]> result = preData.get(item.getOutId());
+            int toIndex = result.size();
+            if (toIndex <= 0) {
+                return;
+            }
+            int fromIndex = result.size() - item.getCompLength();
+            List<Object[]> predictList = result.subList(fromIndex, toIndex);
+            for (Object[] data : predictList) {
+                BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
+                if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) {
+                    AlarmMessage alarmMessage = new AlarmMessage();
+                    AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO();
+                    alarmMessageRespDTO.setConfigId(item.getId());
+                    if (dataValue.compareTo(item.getLowerLimit()) < 0) {
+                        alarmMessageRespDTO.setAlarmType("1");//超下限
+                    } else if (dataValue.compareTo(item.getUpperLimit()) > 0) {
+                        alarmMessageRespDTO.setAlarmType("2");//超上限
+                    }
+                    alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
+                    JSONObject content = new JSONObject();
+                    content.put("alarmObj", item.getAlarmObj());
+                    content.put("alarmType", alarmMessageRespDTO.getAlarmType());
+                    content.put("unit", item.getUnit());
+                    content.put("overLimitTime", data[0]);
+                    content.put("overLimitValue", dataValue);
+                    alarmMessageRespDTO.setContent(JSONObject.toJSONString(content));
+                    System.out.println("预警消息=" + alarmMessageRespDTO);
+                    alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO);
+                    try {
+                        alarmConsumer.process(alarmMessage);
+                    } catch (InterruptedException e) {
+                        throw new RuntimeException(e);
+                    }
+                    break;
+                }
+            }
+            System.out.println(preData);
+        });
     }
 }

--
Gitblit v1.9.3