From 38f29e38fcc668171dc05c53d40a36b895c86102 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: 星期四, 10 十月 2024 13:34:28 +0800
Subject: [PATCH] init

---
 ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java |  287 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 200 insertions(+), 87 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 3ed0961..0b9dd22 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
@@ -18,15 +18,13 @@
 import com.ruoyi.sy.domain.ArdTankLock;
 import com.ruoyi.sy.gps31.PushClientImplSerialPort;
 import com.ruoyi.sy.param.ArdSyCarParam;
-import com.ruoyi.sy.service.IArdTankAbnormalParkAlarmService;
-import com.ruoyi.sy.service.IArdTankLockService;
+import com.ruoyi.sy.service.*;
 import com.ruoyi.sy.service.impl.ArdTankLockServiceImpl;
 import com.ruoyi.sy.vo.ArdSyCarVo;
 import com.ruoyi.sy.domain.ArdSyUser;
 import com.ruoyi.sy.gps31.PositionContainer;
 import com.ruoyi.sy.gps31.PushClientImplAlarm;
 import com.ruoyi.sy.gps31.PushClientImplPosition;
-import com.ruoyi.sy.service.IArdSyUserService;
 import com.ruoyi.common.core.domain.entity.SysConfig;
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysDeptService;
@@ -49,7 +47,6 @@
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.sy.domain.ArdSyCar;
-import com.ruoyi.sy.service.IArdSyCarService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -89,6 +86,9 @@
 
     @Autowired
     private IArdTankLockService ardTankLockService;
+
+    @Autowired
+    private IArdTankWallTemporaryService ardTankWallTemporaryService;
 
     @Resource
     private SYClient sYClient;
@@ -153,6 +153,17 @@
         //鍒犻櫎缁撴潫鏃堕棿涓簄ull鐨勮褰�
         int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
 
+        List<ArdSyCar> ardSyCarAndLockList = ardSyCarService.selectArdSyCarAndTankLock();//鏌ヨ鍏ㄩ儴缃愯溅鍙婁笅鎸傜數纾侀攣
+
+        for(ArdSyCar ardSyCar : ardSyCarAndLockList){//鏋勯�犲鍣�
+            Map<String,Map<String,Thread>> carMap = new HashMap();//杞﹁締瀹瑰櫒
+            for(ArdTankLock ardTankLock : ardSyCar.getArdTankLockList()){
+                Map<String,Thread> lockMap = new HashMap();//閿佸鍣�
+                carMap.put(ardTankLock.getLockNum(),lockMap);
+            }
+            PositionContainer.getCarLockProcessThreadMap().put(ardSyCar.getCarId(),carMap);
+        }
+
         Timer lockStateTimer = new Timer();//瀹氭椂鑾峰彇鍚勪釜閿佺殑鐘舵��
         TimerTask lockStateTask =new TimerTask(){
             @Override
@@ -193,11 +204,20 @@
                                     }
 
                                     String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "01" + checkNum + "%22%7D";
-
-                                    sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                                    try{
+                                        sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                                        PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockState");
+                                    }catch(Exception e){
+                                        PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockState");
+                                    }
                                 }
                             };
-                            lockThread.start();
+                            //lockThread.start();
+                            //灏嗙姸鎬佺嚎绋嬫斁鍏ュ鍣�
+                            if(PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).get("lockState") == null){
+                                PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).put("lockState",lockThread);
+                            }
+
                         }
                     }
                 };
@@ -209,86 +229,94 @@
 
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Timer lockCheckTimeTimer = new Timer();//瀹氭椂鏍″噯鏃堕棿
-        TimerTask lockCheckTimeTask =new TimerTask(){
+        TimerTask lockCheckTimeTask = new TimerTask(){
             @Override
             public void run() {
-            SysConfig config = new SysConfig();
-            config.setConfigKey("syCarPT");
-            List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
-            String syURL = "";
+                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");
+                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;
+                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);
+                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 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";
+                            try{
+                                sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                                PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockTime");
+                            }catch(Exception e){
+                                PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockTime");
+                            }
                         }
-                        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();
+                    if(PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).get("lockTime") == null){
+                        PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).put("lockTime",lockThread);
                     }
-                };
-                lockThread.start();
-            }
+                }
             }
         };
-        lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,7000);
+        //lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,7000);
+        lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,67000);
 
         Timer sendTimer = new Timer();//瀹氭椂鍙戦�侀攣鐘舵��
         TimerTask sendLockStateTask = new TimerTask(){
@@ -314,10 +342,11 @@
                 ardTankLockService.readPassword(userId,password);
             }
         };
-        passwordTimer.scheduleAtFixedRate(passwordTask,date,11000);
+        //passwordTimer.scheduleAtFixedRate(passwordTask,date,11000);
+        passwordTimer.scheduleAtFixedRate(passwordTask,date,13000);
 
         Timer lockRestartStateTimer = new Timer();//瀹氭椂鍚勪釜閿佺殑澶嶄綅鐘舵��
-        TimerTask lockRestartStateTask =new TimerTask(){
+        TimerTask lockRestartStateTask = new TimerTask(){
             @Override
             public void run(){
                 Thread thread = new Thread(){
@@ -376,11 +405,18 @@
                                             }
 
                                             String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "03" + process + checkNum + "%22%7D";
-
-                                            sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                                            try{
+                                                sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                                                PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockRestart");
+                                            }catch (Exception e){
+                                                PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockRestart");
+                                            }
                                         }
                                     };
-                                    lockThread.start();
+                                    //lockThread.start();
+                                    if(PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).get("lockRestart") == null){
+                                        PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).put("lockRestart",lockThread);
+                                    }
                                 }
                             }
                         }
@@ -389,8 +425,85 @@
                 thread.start();
             }
         };
-        lockRestartStateTimer.scheduleAtFixedRate(lockRestartStateTask,date,9000);
+        lockRestartStateTimer.scheduleAtFixedRate(lockRestartStateTask,date,17000);
 
+        Set<String> lockNumSet = new HashSet();//瀛樻斁鍙戦�佽繃鐨勯攣缂栧彿
+
+        Timer mainLockTimer = new Timer();//涓诲畾鏃跺櫒
+        TimerTask mainLockTask = new TimerTask(){
+            @Override
+            public void run() {
+                Long count = ardTankLockService.getArdTankLockCount();
+                if(lockNumSet.size() >= count){//闃叉閿佽鍒犻櫎锛岄噰鐢ㄥぇ浜庣瓑浜�
+                    lockNumSet.clear();//鍏ㄩ儴鎵ц杩囷紝娓呯┖瀹瑰櫒
+                }
+                for(String carId : PositionContainer.getCarLockProcessThreadMap().keySet()){
+                    Thread thread = new Thread(){
+                        @Override
+                        public void run() {
+                            Map<String, Map<String,Thread>> lockMap = PositionContainer.getCarLockProcessThreadMap().get(carId);
+                            for(String lockNum : lockMap.keySet()){
+                                if(lockNumSet.contains(lockNum)){//鑻ユ墽琛岃繃锛屾湰娆″拷鐣�
+                                    continue;
+                                }
+                                if(lockMap.get(lockNum).get("lockProcess") != null){
+                                    break;//閿佹搷浣滅骇鍒渶楂�
+                                }else{
+                                    if(lockMap.get(lockNum).get("lockTime") != null){
+                                        if(lockMap.get(lockNum).get("lockTime").isAlive()){
+                                            lockNumSet.add(lockNum);
+                                            break;//閿佹牎鏃舵涔�
+                                        }else{
+                                            lockMap.get(lockNum).get("lockTime").start();
+                                            lockNumSet.add(lockNum);
+                                            break;//閿佹牎鏃舵涔�
+                                        }
+                                    }else{
+                                        if(lockMap.get(lockNum).get("lockPassword") != null){
+                                            if(lockMap.get(lockNum).get("lockPassword").isAlive()){
+                                                lockNumSet.add(lockNum);
+                                                break;//閿佸瘑鐮佹涔�
+                                            }else{
+                                                lockMap.get(lockNum).get("lockPassword").start();
+                                                lockNumSet.add(lockNum);
+                                                break;//閿佸瘑鐮佹涔�
+                                            }
+                                        }else{
+                                            if(lockMap.get(lockNum).get("lockRestart") != null) {
+                                                if(lockMap.get(lockNum).get("lockRestart").isAlive()){
+                                                    lockNumSet.add(lockNum);
+                                                }else{
+                                                    lockMap.get(lockNum).get("lockRestart").start();
+                                                    lockNumSet.add(lockNum);
+                                                    break;//閿佸浣嶆涔�
+                                                }
+                                            }else{
+                                                if(lockMap.get(lockNum).get("lockState") != null) {
+                                                    if(lockMap.get(lockNum).get("lockState").isAlive()){
+                                                        lockNumSet.add(lockNum);
+                                                    }else{
+                                                        lockMap.get(lockNum).get("lockState").start();
+                                                        lockNumSet.add(lockNum);
+                                                        break;//閿佺姸鎬佹涔�
+                                                    }
+                                                }else{
+                                                    break;
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    };
+                    thread.start();
+                }
+            }
+        };
+        mainLockTimer.scheduleAtFixedRate(mainLockTask,date,2000);
+
+        //寮傚父閲嶅惎閲嶅缓鏈埌鏈熶复鏃剁數瀛愬洿鏍忕嚎绋�
+        ardTankWallTemporaryService.restartArdTankWallTemporaryThread(userId, password);
     }
 
     /**
@@ -496,7 +609,7 @@
     /**
      * 鑾峰彇鏈寕鎺ユ潈闄愮殑涓変竴杞﹁締
      */
-//    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
+    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
     @PostMapping("/getArdSyCarNoRight")
     @ApiOperation("鑾峰彇鏈寕鎺ユ潈闄愮殑涓変竴杞﹁締")
     public Map<String,Object> getArdSyCarNoRight(){
@@ -514,7 +627,7 @@
     /**
      * 鑾峰彇鍏ㄩ儴鐨勪笁涓�杞﹁締
      */
-//    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
+    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
     @PostMapping("/getArdSyCarAll")
     @ApiOperation("鑾峰彇鍏ㄩ儴鐨勪笁涓�杞﹁締")
     public Map<String,Object> getArdSyCarAll(){
@@ -532,7 +645,7 @@
     /**
      * 鑾峰彇鍏ㄩ儴杞﹁締妯″瀷
      */
-//    @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')")
+    @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')")
     @PostMapping("/getAllCarModel")
     @ApiOperation("鑾峰彇鍏ㄩ儴杞﹁締妯″瀷")
     public Map<String,Object> getAllCarModel(){
@@ -599,7 +712,7 @@
         }
     }
 
-    //    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
+    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
     @PostMapping("/carListById/{id}")
     @ApiOperation("鏍规嵁杞﹁締ID鑾峰彇杞﹁締鍒楄〃")
     public Results carListById(@PathVariable String id){

--
Gitblit v1.9.3