From ce9c9af4a3710d17e17814bab629ab4ef474f3f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 09 七月 2025 11:16:51 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/task/NotifyScheduler.java |   49 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/zy/asrs/task/NotifyScheduler.java b/src/main/java/com/zy/asrs/task/NotifyScheduler.java
index 601d9aa..eb022e4 100644
--- a/src/main/java/com/zy/asrs/task/NotifyScheduler.java
+++ b/src/main/java/com/zy/asrs/task/NotifyScheduler.java
@@ -4,6 +4,10 @@
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.zy.asrs.domain.NotifyDto;
+import com.zy.asrs.entity.DeviceConfig;
+import com.zy.asrs.entity.HttpRequestLog;
+import com.zy.asrs.service.DeviceConfigService;
+import com.zy.asrs.service.HttpRequestLogService;
 import com.zy.asrs.utils.NotifyUtils;
 import com.zy.common.utils.HttpHandler;
 import com.zy.common.utils.RedisUtil;
@@ -18,6 +22,7 @@
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.util.Date;
 import java.util.List;
 
 @Component
@@ -29,25 +34,36 @@
     @Autowired
     private NotifyUtils notifyUtils;
     @Autowired
-    private SlaveProperties slaveProperties;
-    @Autowired
     private ConfigService configService;
+    @Autowired
+    private HttpRequestLogService httpRequestLogService;
+    @Autowired
+    private DeviceConfigService deviceConfigService;
 
     @Scheduled(cron = "0/3 * * * * ? ")
     public synchronized void notifyShuttle(){
-        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
-            notifyMsg(String.valueOf(SlaveType.Shuttle), slave.getId());
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+        for (DeviceConfig device : shuttleList) {
+            notifyMsg(String.valueOf(SlaveType.Shuttle), device.getDeviceNo());
         }
     }
 
     @Scheduled(cron = "0/3 * * * * ? ")
     public synchronized void notifyForkLift(){
-        for (ForkLiftSlave slave : slaveProperties.getForkLift()) {
-            notifyMsg(String.valueOf(SlaveType.ForkLift), slave.getId());
+        List<DeviceConfig> forkLiftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
+        for (DeviceConfig device : forkLiftList) {
+            notifyMsg(String.valueOf(SlaveType.ForkLift), device.getDeviceNo());
         }
     }
 
-    private synchronized void notifyMsg(String deviceType, Integer device) {
+    @Scheduled(cron = "0/3 * * * * ? ")
+    public synchronized void notifyTask(){
+        notifyMsg("task", 1);
+    }
+
+    private synchronized void notifyMsg(String notifyType, Integer device) {
         Config notifyEnableConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyEnable"));
         if(notifyEnableConfig == null){
             return;
@@ -69,7 +85,7 @@
         }
         String notifyUriPath = notifyUriPathConfig.getValue();
 
-        List<String> keys = notifyUtils.takeKeys(deviceType, device);
+        List<String> keys = notifyUtils.takeKeys(notifyType, device);
         if(keys == null){
             return;
         }
@@ -89,6 +105,11 @@
                 continue;
             }
 
+            HttpRequestLog httpRequestLog = new HttpRequestLog();
+            httpRequestLog.setName(notifyUri + notifyUriPath);
+            httpRequestLog.setRequest(JSON.toJSONString(notifyDto));
+            httpRequestLog.setCreateTime(new Date());
+
             try {
                 //瑙﹀彂閫氱煡
                 String response = new HttpHandler.Builder()
@@ -97,15 +118,21 @@
                         .setJson(JSON.toJSONString(notifyDto))
                         .build()
                         .doPost();
+                httpRequestLog.setResponse(response);
+
                 JSONObject jsonObject = JSON.parseObject(response);
                 Integer code = jsonObject.getInteger("code");
                 if(code == 200){
                     //閫氱煡鎴愬姛
                     redisUtil.del(key);
-                    return;
+
+                    continue;
                 }
             }catch (Exception e){
                 e.printStackTrace();
+            }finally {
+                //淇濆瓨璁板綍
+                httpRequestLogService.insert(httpRequestLog);
             }
 
             //閫氱煡澶辫触
@@ -113,13 +140,13 @@
             if (times >= notifyDto.getFailTimes()) {
                 //瓒呰繃娆℃暟
                 redisUtil.del(key);
-                return;
+                continue;
             }
 
             notifyDto.setLastRetryTime(System.currentTimeMillis());
             notifyDto.setRetryTimes(times);
             redisUtil.set(key, notifyDto);
-            return;
+            continue;
         }
     }
 

--
Gitblit v1.9.1