From 42fd6bd4095414f7a78a2bb5d2c692c04119da2c Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 18 十一月 2025 08:52:18 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/task/DeviceLogScheduler.java |   69 ++++++++++++----------------------
 1 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/src/main/java/com/zy/core/task/DeviceLogScheduler.java b/src/main/java/com/zy/core/task/DeviceLogScheduler.java
index da31515..fccce85 100644
--- a/src/main/java/com/zy/core/task/DeviceLogScheduler.java
+++ b/src/main/java/com/zy/core/task/DeviceLogScheduler.java
@@ -1,68 +1,47 @@
 package com.zy.core.task;
 
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.zy.asrs.entity.DeviceConfig;
+
 import com.zy.asrs.entity.DeviceDataLog;
-import com.zy.asrs.service.DeviceConfigService;
 import com.zy.asrs.service.DeviceDataLogService;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.SlaveType;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.enums.RedisKeyType;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
+import java.util.Set;
 import java.util.List;
+import java.util.ArrayList;
 
 @Slf4j
 @Component
 public class DeviceLogScheduler {
 
     @Autowired
-    private DeviceConfigService deviceConfigService;
-    @Autowired
     private DeviceDataLogService deviceDataLogService;
+    @Autowired
+    private RedisUtil redisUtil;
 
     @Scheduled(cron = "0/3 * * * * ? ")
     public void execute() {
-//        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
-//                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
-//        for (DeviceConfig deviceConfig : shuttleList) {
-//            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceConfig.getDeviceNo());
-//            if(shuttleThread == null){
-//                continue;
-//            }
-//
-//            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-//            if (shuttleProtocol == null) {
-//                continue;
-//            }
-//
-//            if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 500) {
-//                if (shuttleThread.getOriginDeviceData() != null) {
-//                    //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
-//
-//                    //绂荤嚎涓嶅仛鏃ュ織瀛樺偍
-//                    if (shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.OFFLINE)) {
-//                        continue;
-//                    }
-//
-//                    //淇濆瓨鏁版嵁璁板綍
-//                    DeviceDataLog deviceDataLog = new DeviceDataLog();
-//                    deviceDataLog.setOriginData(JSON.toJSONString(shuttleThread.getOriginDeviceData()));
-//                    deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
-//                    deviceDataLog.setType(String.valueOf(SlaveType.Shuttle));
-//                    deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
-//                    deviceDataLog.setCreateTime(new Date());
-//                    deviceDataLogService.insert(deviceDataLog);
-//
-//                    //鏇存柊閲囬泦鏃堕棿
-//                    shuttleThread.updateDeviceDataLogTime(System.currentTimeMillis());
-//                }
-//            }
-//        }
+        int maxCount = 100;
+        Set<String> keys = redisUtil.scanKeys(RedisKeyType.DEVICE_LOG_KEY.key, maxCount);
+        if (keys == null || keys.isEmpty()) {
+            return;
+        }
+        List<Object> values = redisUtil.multiGet(keys);
+        List<DeviceDataLog> list = new ArrayList<>();
+        for (Object object : values) {
+            if (object instanceof DeviceDataLog) {
+                list.add((DeviceDataLog) object);
+            }
+        }
+        if (!list.isEmpty()) {
+            if (deviceDataLogService.saveBatch(list)) {
+                redisUtil.del(keys.toArray(new String[0]));
+            }
+        }
     }
 
 }

--
Gitblit v1.9.1