From 9aac460a313ac8284e0fd633183c93815f95e0de Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期三, 24 七月 2024 17:21:57 +0800
Subject: [PATCH] 实时状态预提交修改提交

---
 ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java |  302 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 282 insertions(+), 20 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 4dea016..9441272 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
@@ -1,7 +1,7 @@
 package com.ruoyi.sy.controller;
 
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import javax.annotation.PostConstruct;
@@ -9,9 +9,19 @@
 import javax.servlet.http.HttpServletResponse;
 
 import com.alibaba.fastjson2.JSON;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
+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.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;
@@ -21,11 +31,16 @@
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.system.service.impl.SysConfigServiceImpl;
 import com.ruoyi.utils.forest.SYClient;
 import com.ruoyi.utils.result.Results;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -36,12 +51,13 @@
 import com.ruoyi.sy.domain.ArdSyCar;
 import com.ruoyi.sy.service.IArdSyCarService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.common.core.page.TableDataInfo;
 import org.springframework.web.multipart.MultipartFile;
+
+import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
 
 /**
  * 涓変竴杞﹁締Controller
- * 
+ *
  * @author ard
  * @date 2023-06-26
  */
@@ -68,22 +84,39 @@
     @Autowired
     private ISysDeptService sysDeptService;
 
+    @Autowired
+    private IArdTankAbnormalParkAlarmService ardTankAbnormalParkAlarmService;
+
+    @Autowired
+    private IArdTankLockService ardTankLockService;
+
     @Resource
     private SYClient sYClient;
 
     private ArdSyCarController ardSyCarController;
+
+    @Value("${syCar.enabled}")
+    private Boolean syCarEnabled;
+
+    @Value("${syCar.userId}")
+    private String userId;
+
+    @Value("${syCar.password}")
+    private String password;
+
+    private Timer lockStateTimer;
 
     @PostConstruct
     public void init(){
         ardSyCarController = this;
         ardSyCarController.sysConfigService = this.sysConfigService;
         ardSyCarController.iArdSyUserService = this.iArdSyUserService;
-
         SysConfig config = new SysConfig();
         config.setConfigKey("syCarPT");
         List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
         String syURL = "";
-        if(sysConfigResult.size() == 0){
+        //if(sysConfigResult.size() == 0){
+        if(!syCarEnabled){//涓変竴杞﹁締鍔犲叆寮�鍏�
             return;
         }else{
             syURL = sysConfigResult.get(0).getConfigValue();
@@ -95,7 +128,8 @@
         {
             return;
         }
-        PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
+        //PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
+        PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,userId,password);
         Thread pushClientImplPositionThread = new Thread(pushClientImplPosition);
         pushClientImplPositionThread.start();
 
@@ -107,11 +141,192 @@
                 ardSyCarService.sendArdSyCarPosition();
             }
         };
-        carPositionTimer.scheduleAtFixedRate(carPositionTask,date,3*1000);//鍚敤
-        //杞﹁締瀹炴椂浣嶇疆绾跨▼
-        PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
+        //carPositionTimer.scheduleAtFixedRate(carPositionTask,date,3*1000);//寮冪敤
+        //杞﹁締瀹炴椂鎶ヨ绾跨▼
+        //PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
+        PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,userId,password);
         Thread pushClientImplAlarmThread = new Thread(pushClientImplAlarm);
         pushClientImplAlarmThread.start();
+        //涓插彛绾跨▼
+        PushClientImplSerialPort pushClientImplSerialPort = new PushClientImplSerialPort(ip,userId,password);
+        Thread pushClientImplSerialPortThread = new Thread(pushClientImplSerialPort);
+        pushClientImplSerialPortThread.start();
+
+        //鍒犻櫎缁撴潫鏃堕棿涓簄ull鐨勮褰�
+        int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
+
+        this.lockStateTimer = new Timer();//瀹氭椂鑾峰彇鍚勪釜閿佺殑鐘舵��
+        TimerTask lockStateTask =new TimerTask(){
+            @Override
+            public void run(){
+                Thread thread = new Thread(){
+                    @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 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("01", 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() + "01" + checkNum + "%22%7D";
+
+                                    sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+                                }
+                            };
+                            LockThread.start();
+                        }
+                    }
+                };
+                thread.start();
+            }
+        };
+        //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,10000);
+
+        Timer sendTimer = new Timer();//瀹氭椂鍙戦�侀攣鐘舵��
+        TimerTask sendLockStateTask =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;
+
+                for (String key : ONLINE_USER_SESSIONS.keySet()){
+                    Thread lockThread = new Thread(finalSyURL) {
+                        @Override
+                        public void run() {
+                            String usersId = key.split("_")[0];
+                            ardTankLockService.sendLockState(usersId,userId,password);
+                        }
+                    };
+                    lockThread.start();
+                }
+            }
+        };
+        //sendTimer.scheduleAtFixedRate(sendLockStateTask,date,3000);
+
+
     }
 
     /**
@@ -119,11 +334,13 @@
      */
     @PreAuthorize("@ss.hasPermi('sy:syCar:list')")
     @GetMapping("/list")
-    public TableDataInfo list(ArdSyCar ardSyCar)
+    @ApiOperation("鏌ヨ涓変竴杞﹁締鍒楄〃")
+    public AjaxResult list(ArdSyCarParam ardSyCarParam)
     {
-        startPage();
-        List<ArdSyCar> list = ardSyCarService.selectArdSyCarList(ardSyCar);
-        return getDataTable(list);
+        PageHelper.startPage(ardSyCarParam.getPageNum(),ardSyCarParam.getPageSize());
+        String userId = SecurityUtils.getUserId();
+        Map<String,Object> result = ardSyCarService.getArdSyCarAll(userId);
+        return ardSyCarService.ardSyCarList(ardSyCarParam,result);
     }
 
     /**
@@ -180,7 +397,7 @@
      */
     @PreAuthorize("@ss.hasPermi('sy:syCar:remove')")
     @Log(title = "涓変竴杞﹁締", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
+    @DeleteMapping("/{ids}")
     @ApiOperation("鍒犻櫎涓変竴杞﹁締")
     public AjaxResult remove(@PathVariable String[] ids)
     {
@@ -215,7 +432,7 @@
     /**
      * 鑾峰彇鏈寕鎺ユ潈闄愮殑涓変竴杞﹁締
      */
-    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
+//    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
     @PostMapping("/getArdSyCarNoRight")
     @ApiOperation("鑾峰彇鏈寕鎺ユ潈闄愮殑涓変竴杞﹁締")
     public Map<String,Object> getArdSyCarNoRight(){
@@ -233,7 +450,7 @@
     /**
      * 鑾峰彇鍏ㄩ儴鐨勪笁涓�杞﹁締
      */
-    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
+//    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
     @PostMapping("/getArdSyCarAll")
     @ApiOperation("鑾峰彇鍏ㄩ儴鐨勪笁涓�杞﹁締")
     public Map<String,Object> getArdSyCarAll(){
@@ -285,7 +502,11 @@
         String usersId = SecurityUtils.getUserId();
         ArdSyUser ardSyUser = iArdSyUserService.userById(usersId);
         String syURL = sysConfigService.getSYURL();
-        return ardSyCarService.allListByUser(ardSyUser,syURL,usersId);
+        //鏍规嵁userId鏌ヨ閮ㄩ棬Id
+        SysUser sysUser = sysUserService.selectUserById(usersId);
+        //鏍规嵁褰撳墠deptId鎴栬�呭綋鍓嶅強鎵�灞炰笅绾х殑鎵�鏈塪eptId
+        List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId());
+        return ardSyCarService.allListByUser(ardSyUser,syURL,usersId,deptList);
     }
 
     @PreAuthorize("@ss.hasPermi('sy:syCar:carList')")
@@ -314,7 +535,7 @@
         }
     }
 
-    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
+    //    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
     @PostMapping("/carListById/{id}")
     @ApiOperation("鏍规嵁杞﹁締ID鑾峰彇杞﹁締鍒楄〃")
     public Results carListById(@PathVariable String id){
@@ -357,7 +578,7 @@
         SysUser sysUser = sysUserService.selectUserById(usersId);
         Map<String, Map<String,Map<String,Object>>> deptPositionMap = PositionContainer.getDeptPositionMap();
         if(deptPositionMap.isEmpty()){
-            return Results.succeed();
+            return Results.error("31骞冲彴鏃犺溅杈嗕綅缃繑鍥�");
         }else {
 //            return Results.succeed(deptPositionMap.get(sysUser.getDeptId().toString()).get(map.get("carId")));
             return Results.succeed(deptPositionMap.get(sysUser.getDeptId().toString()));
@@ -448,7 +669,7 @@
     @GetMapping("getThreeOne")
     @ApiOperation("鑾峰彇涓変竴瑙嗛鍦板潃")
     public AjaxResult getThreeOne() {
-        return AjaxResult.success("鑾峰彇鍦板潃鎴愬姛锛�",sysConfigService.selectConfigByKey("threeOneVideo"));
+        return AjaxResult.success("鑾峰彇鍦板潃鎴愬姛锛�",sysConfigService.getSYVideo());
     }
 
     @PreAuthorize("@ss.hasPermi('sy:syCar:getAlarmHPfmCountDetail')")
@@ -466,4 +687,45 @@
         return AjaxResult.success(mapDetail);
     }
 
+    @GetMapping("/getOnlineSYCarPosition")
+    @ApiOperation("鍗曞叺绔煡鐪嬪凡閫氳繃瀹℃壒鐨勫湪绾夸笁涓�杞﹁締浣嶇疆")
+    public AjaxResult getOnlineSYCarPosition() {
+        String soilderId = SecurityUtils.getUserId();
+        try{
+            Map<String,Object> result = ardSyCarService.getOnlineSYCarPosition(soilderId);
+            return AjaxResult.success(result);
+        }catch(Exception e){
+            e.printStackTrace();
+            return AjaxResult.error();
+        }
+    }
+
+    public Map<String,Object> sendCmd(String syURL,String userId,String carId,Integer cmdId,String cmd,String paramsStr,String sessionId){
+        OkHttpClient okHttpClient = new OkHttpClient();
+
+        Request request = new Request.Builder()
+                .url(syURL + "/gps-web/api/send_cmd.jsp?params="+paramsStr+"&userId="+userId+"&carId="+carId+"&cmdId="+cmdId+"&cmd="+cmd+"&sessionId="+sessionId)
+                .build();
+        //System.out.println("url = " + syURL + "/gps-web/api/send_cmd.jsp?params="+paramsStr+"&userId="+userId+"&carId="+carId+"&cmdId="+cmdId+"&cmd="+cmd+"&sessionId="+sessionId);
+        Response response = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        okhttp3.ResponseBody responseBody = response.body();
+
+        try {
+            String message = responseBody.string();// 鍝嶅簲浣�
+            Map<String,Object> map = (Map<String, Object>) JSON.parse(message);
+            return map;
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            return new HashMap();
+        }
+    }
+
 }

--
Gitblit v1.9.3