From 79d24d16b133a07a1a7cd887348683be6d8c8ef3 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期一, 29 七月 2024 10:26:52 +0800
Subject: [PATCH] 电磁锁密码查询修改提交

---
 ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java |  123 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 117 insertions(+), 6 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
index 28f36b3..25dfa7a 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -53,6 +53,8 @@
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import org.springframework.web.multipart.MultipartFile;
 
+import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
+
 /**
  * 涓変竴杞﹁締Controller
  *
@@ -101,8 +103,6 @@
 
     @Value("${syCar.password}")
     private String password;
-
-    private Timer lockStateTimer;
 
     @PostConstruct
     public void init(){
@@ -153,7 +153,7 @@
         //鍒犻櫎缁撴潫鏃堕棿涓簄ull鐨勮褰�
         int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
 
-        this.lockStateTimer = new Timer();//瀹氭椂鑾峰彇鍚勪釜閿佺殑鐘舵��
+        Timer lockStateTimer = new Timer();//瀹氭椂鑾峰彇鍚勪釜閿佺殑鐘舵��
         TimerTask lockStateTask =new TimerTask(){
             @Override
             public void run(){
@@ -178,7 +178,7 @@
 
                         List<ArdTankLock> result = ardTankLockService.getArdTankLockAll();//鏌ヨ鍏ㄩ儴鐢电閿�
                         for(ArdTankLock ardTankLock : result){
-                            Thread LockThread = new Thread(finalSyURL){
+                            Thread lockThread = new Thread(finalSyURL){
                                 @Override
                                 public void run() {
                                     String lockNumHead = ardTankLock.getLockNum().substring(0,2);
@@ -197,14 +197,125 @@
                                     sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
                                 }
                             };
-                            LockThread.start();
+                            lockThread.start();
                         }
                     }
                 };
                 thread.start();
             }
         };
-        lockStateTimer.scheduleAtFixedRate(lockStateTask,date,2500);
+        //lockStateTimer.scheduleAtFixedRate(lockStateTask,date,3000);
+        lockStateTimer.scheduleAtFixedRate(lockStateTask,date,5000);
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Timer lockCheckTimeTimer = new Timer();//瀹氭椂鏍″噯鏃堕棿
+        TimerTask lockCheckTimeTask =new TimerTask(){
+            @Override
+            public void run() {
+            SysConfig config = new SysConfig();
+            config.setConfigKey("syCarPT");
+            List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
+            String syURL = "";
+
+            if(sysConfigResult.size() == 0){
+                return;
+            }else{
+                syURL = sysConfigResult.get(0).getConfigValue();
+            }
+            String passwordMd5 = DigestUtils.md5Hex(password);
+            Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, userId);
+            String sessionId = (String) LogInResult.get("sessionId");
+
+            String finalSyURL = syURL;
+
+            List<ArdTankLock> result = ardTankLockService.getArdTankLockAll();//鏌ヨ鍏ㄩ儴鐢电閿�
+            for(ArdTankLock ardTankLock : result){
+                Thread lockThread = new Thread(finalSyURL){
+                    @Override
+                    public void run() {
+                        //鑾峰彇鏃堕棿骞舵媶鍒嗗勾鏈堟棩鏃跺垎绉�
+                        String nowTime = sdf.format(new Date());
+                        String nowYear = nowTime.substring(2,4);
+                        String nowMonth = nowTime.substring(5,7);
+                        String nowDay = nowTime.substring(8,10);
+                        String nowHour = nowTime.substring(11,13);
+                        String nowMinute = nowTime.substring(14,16);
+                        String nowSecond = nowTime.substring(17,19);
+
+                        String nowYearHex = Integer.toHexString(Integer.parseInt(nowYear));
+                        if(nowYearHex.length() == 1){
+                            nowYearHex = "0" + nowYearHex;
+                        }
+                        String nowMonthHex = Integer.toHexString(Integer.parseInt(nowMonth));
+                        if(nowMonthHex.length() == 1){
+                            nowMonthHex = "0" + nowMonthHex;
+                        }
+                        String nowDayHex = Integer.toHexString(Integer.parseInt(nowDay));
+                        if(nowDayHex.length() == 1){
+                            nowDayHex = "0" + nowDayHex;
+                        }
+                        String nowHourHex = Integer.toHexString(Integer.parseInt(nowHour));
+                        if(nowHourHex.length() == 1){
+                            nowHourHex = "0" + nowHourHex;
+                        }
+                        String nowMinuteHex = Integer.toHexString(Integer.parseInt(nowMinute));
+                        if(nowMinuteHex.length() == 1){
+                            nowMinuteHex = "0" + nowMinuteHex;
+                        }
+                        String nowSecondHex = Integer.toHexString(Integer.parseInt(nowSecond));
+                        if(nowSecondHex.length() == 1){
+                            nowSecondHex = "0" + nowSecondHex;
+                        }
+                        //16杩涘埗鏃堕棿
+                        String timeHex = nowYearHex + nowMonthHex + nowDayHex + nowHourHex + nowMinuteHex + nowSecondHex;
+                        String lockNumHead = ardTankLock.getLockNum().substring(0,2);
+                        String lockNumTail = ardTankLock.getLockNum().substring(2,4);
+                        //璁$畻鏍¢獙
+                        String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt("08", 16) +
+                                Integer.parseInt(nowYearHex, 16) + Integer.parseInt(nowMonthHex, 16) + Integer.parseInt(nowDayHex, 16) +
+                                Integer.parseInt(nowHourHex, 16) + Integer.parseInt(nowMinuteHex, 16) + Integer.parseInt(nowSecondHex, 16));
+                        if(checkNum.length() == 1){
+                            checkNum = "0" + checkNum;
+                        }else if(checkNum.length() > 2){
+                            checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length());
+                        }
+                        String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "08" + timeHex + checkNum + "%22%7D";
+
+                        sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                    }
+                };
+                lockThread.start();
+            }
+            }
+        };
+        lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,7000);
+
+        Timer sendTimer = new Timer();//瀹氭椂鍙戦�侀攣鐘舵��
+        TimerTask sendLockStateTask = new TimerTask(){
+            @Override
+            public void run() {
+                for (String key : ONLINE_USER_SESSIONS.keySet()){
+                    Thread lockThread = new Thread() {
+                        @Override
+                        public void run() {
+                            ardTankLockService.sendLockState(key,userId,password);
+                        }
+                    };
+                    lockThread.start();
+                }
+            }
+        };
+        sendTimer.scheduleAtFixedRate(sendLockStateTask,date,3000);
+
+        Timer passwordTimer = new Timer();//瀹氭椂鏌ョ湅鐢电閿佸瘑鐮佺姸鎬�
+        TimerTask passwordTask = new TimerTask(){
+            @Override
+            public void run() {
+                ardTankLockService.readPassword(userId,password);
+            }
+        };
+        passwordTimer.scheduleAtFixedRate(passwordTask,date,11000);
+
     }
 
     /**

--
Gitblit v1.9.3