From 6bab172dc8767e93c8889c15a146c76e4d38e9c0 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期六, 27 七月 2024 09:23:04 +0800
Subject: [PATCH] 电磁锁报警查询bug修改提交

---
 ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java |  259 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 249 insertions(+), 10 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java
index f882b22..622e4ae 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java
@@ -1,27 +1,33 @@
 package com.ruoyi.sy.service.impl;
 
+import java.io.IOException;
 import java.util.*;
 
+import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
 import com.ruoyi.common.core.domain.entity.SysConfig;
 import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.sy.domain.ArdSyCar;
 import com.ruoyi.sy.domain.ArdSyUser;
 import com.ruoyi.sy.domain.ArdTankLockState;
-import com.ruoyi.sy.mapper.ArdSyUserMapper;
-import com.ruoyi.sy.mapper.ArdTankWallLockMapper;
-import com.ruoyi.sy.mapper.ArdTankWallLockTemporaryMapper;
+import com.ruoyi.sy.mapper.*;
 import com.ruoyi.system.mapper.SysConfigMapper;
 import com.ruoyi.utils.forest.SYClient;
+import com.ruoyi.utils.websocket.util.WebSocketUtils;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.springframework.stereotype.Service;
 
 import java.util.stream.Collectors;
 
-import com.ruoyi.sy.mapper.ArdTankLockMapper;
 import com.ruoyi.sy.domain.ArdTankLock;
 import com.ruoyi.sy.service.IArdTankLockService;
 
 import javax.annotation.Resource;
+
+import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
 
 /**
  * 鐢电閿丼ervice涓氬姟灞傚鐞�
@@ -47,7 +53,15 @@
     private SysConfigMapper sysConfigMapper;
 
     @Resource
+    private ArdSyCarMapper ardSyCarMapper;
+
+    @Resource
+    private ArdTankLockStateMapper ardTankLockStateMapper;
+
+    @Resource
     private SYClient sYClient;
+
+    private Map<String,Thread> alarmMap = new HashMap();//鐢电閿佸巻鍙叉姤璀︾嚎绋嬪鍣�
 
     /**
      * 鏌ヨ鐢电閿�
@@ -461,10 +475,7 @@
 
     @Override
     public void sendLockState(String userId, String syUserId, String syPassword) {
-
-
-
-        /*List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT");
+        List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT");
         String syURL = "";
         if(syURLResult.size() != 0){
             syURL = syURLResult.get(0).getConfigValue();
@@ -474,7 +485,235 @@
         String passwordMd5 = DigestUtils.md5Hex(syPassword);
         Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId);
         String sessionId = (String) LogInResult.get("sessionId");
-        List<ArdTankLock> ardTankLockList = ardTankLockMapper.getLockByCarId(carId);
-        Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, carId, ardSyUser.getUserId(), sessionId);*/
+
+        List<SysConfig> lockBatteryVoltageResult = sysConfigMapper.selectByType("lockBatteryVoltage");
+        Integer lockBatteryVoltage = 9;
+        if(!lockBatteryVoltageResult.isEmpty()){
+            lockBatteryVoltage = Integer.parseInt(lockBatteryVoltageResult.get(0).getConfigValue());
+        }
+
+        List<SysConfig> lockPowerVoltageResult = sysConfigMapper.selectByType("lockPowerVoltage");
+        Integer lockPowerVoltage = 5;
+        if(!lockPowerVoltageResult.isEmpty()){
+            lockPowerVoltage = Integer.parseInt(lockPowerVoltageResult.get(0).getConfigValue());
+        }
+
+        List<Map<String,Object>> result = new ArrayList();
+        List<ArdSyCar> ardSyCarResult = ardSyCarMapper.selectArdSyCarAndTankLockByUserId(userId.split("_")[0]);
+        for(ArdSyCar ardSyCar : ardSyCarResult){
+            Map<String,Object> map = new HashMap();
+            map.put("id",ardSyCar.getId());
+            map.put("carId",ardSyCar.getCarId());
+            map.put("carModel",ardSyCar.getCarModel());
+            map.put("carType",ardSyCar.getCarType());
+            map.put("carBrand",ardSyCar.getCarBrand());
+            map.put("deptId",ardSyCar.getDeptId());
+            map.put("carPicture",ardSyCar.getCarPicture());
+            Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, ardSyCar.getCarId(), syUserId, sessionId);
+            if(((String)syResult.get("rspCode")).equals("1")){
+                Map<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0);
+                map.put("carPlate", (String) carMap.get("carPlate"));
+            }
+            List<Map<String,Object>> lockList = new ArrayList();
+            List<ArdTankLock> ardTankLockList = ardSyCar.getArdTankLockList();
+            for(ArdTankLock ardTankLock : ardTankLockList){
+                Map<String,Object> lockMap = new HashMap();
+                lockMap.put("id",ardTankLock.getId());
+                lockMap.put("lockNum",ardTankLock.getLockNum());
+                lockMap.put("lockName",ardTankLock.getLockName());
+                lockMap.put("imgPositionTop",ardTankLock.getImgPositionTop());
+                lockMap.put("imgPositionLeft",ardTankLock.getImgPositionLeft());
+                lockMap.put("carId",ardTankLock.getCarId());
+                lockMap.put("enable",ardTankLock.getEnable());
+                if(ardTankLock.getRestartState() == null){
+                    lockMap.put("restartState","");
+                }else{
+                    lockMap.put("restartState",ardTankLock.getRestartState());
+                }
+                if(ardTankLock.getOnlineTime() == null){
+                    lockMap.put("onlineTime","");
+                }else{
+                    lockMap.put("onlineTime",ardTankLock.getOnlineTime());
+                }
+                //Map<String,Object> ardTankLockState = new HashMap();
+                ArdTankLockState ardTankLockStateResult = ardTankLockStateMapper.selectArdTankLockStateByLockIdLimitOne(ardTankLock.getId());
+                if(ardTankLockStateResult == null){
+                    /*ardTankLockState.put("id","");
+                    ardTankLockState.put("lockId","");
+                    ardTankLockState.put("lockNum","");*/
+                    /*ardTankLockState.put("lockState","");
+                    ardTankLockState.put("lockPositionState","");
+                    ardTankLockState.put("lockShellState","");
+                    ardTankLockState.put("restartState","");
+                    ardTankLockState.put("batterVoltage","");
+                    ardTankLockState.put("batterVoltageAlarm",false);
+                    ardTankLockState.put("powerVoltage","");
+                    ardTankLockState.put("powerVoltageAlarm",false);
+                    ardTankLockState.put("uploadTime","");
+                    ardTankLockState.put("uniqueMark","");
+                    ardTankLockState.put("lockStateMark",false);
+                    lockMap.put("ardTankLockState",ardTankLockState);*/
+                    lockMap.put("lockState","");
+                    lockMap.put("lockPositionState","");
+                    lockMap.put("lockShellState","");
+                    lockMap.put("restartState","");
+                    lockMap.put("batterVoltage","");
+                    lockMap.put("batterVoltageAlarm",false);
+                    lockMap.put("powerVoltage","");
+                    lockMap.put("powerVoltageAlarm",false);
+                    lockMap.put("uploadTime","");
+                    lockMap.put("uniqueMark","");
+                    lockMap.put("lockStateMark",false);
+                    lockMap.put("alarmMark",false);
+                    lockMap.put("alarmInfo","");
+                }else{
+                    /*ardTankLockState.put("id",ardTankLockStateResult.getId());
+                    ardTankLockState.put("lockId",ardTankLockStateResult.getLockId());
+                    ardTankLockState.put("lockNum",ardTankLockStateResult.getLockNum());*/
+                    /*ardTankLockState.put("lockState",ardTankLockStateResult.getLockState());
+                    ardTankLockState.put("lockPositionState",ardTankLockStateResult.getLockPositionState());
+                    ardTankLockState.put("lockShellState",ardTankLockStateResult.getLockShellState());
+                    ardTankLockState.put("restartState",ardTankLockStateResult.getRestartState());
+                    ardTankLockState.put("batterVoltage",ardTankLockStateResult.getBatterVoltage());
+                    if(Double.parseDouble(ardTankLockStateResult.getBatterVoltage()) <= lockBatteryVoltage){
+                        ardTankLockState.put("batterVoltageAlarm",true);
+                    }else{
+                        ardTankLockState.put("batterVoltageAlarm",false);
+                    }
+                    ardTankLockState.put("powerVoltage",ardTankLockStateResult.getPowerVoltage());
+                    if(Double.parseDouble(ardTankLockStateResult.getPowerVoltage()) <= lockPowerVoltage){
+                        ardTankLockState.put("powerVoltageAlarm",true);
+                    }else{
+                        ardTankLockState.put("powerVoltageAlarm",false);
+                    }
+                    ardTankLockState.put("uploadTime",ardTankLockStateResult.getUploadTime());
+                    ardTankLockState.put("uniqueMark",ardTankLockStateResult.getUniqueMark());
+                    ardTankLockState.put("lockStateMark",ardTankLockStateResult.getLockStateMark());
+                    lockMap.put("ardTankLockState",ardTankLockState);*/
+                    String alarmInfo = "";
+                    lockMap.put("lockState",ardTankLockStateResult.getLockState());
+                    if(ardTankLockStateResult.getLockState().equals("寮傚父鐘舵��")){
+                        alarmInfo = alarmInfo + "閿佽姱寮傚父;";
+                    }
+                    lockMap.put("lockPositionState",ardTankLockStateResult.getLockPositionState());
+                    if(ardTankLockStateResult.getLockPositionState().equals("寮傚父")){
+                        alarmInfo = alarmInfo + "浣嶇疆寮傚父;";
+                    }
+                    lockMap.put("lockShellState",ardTankLockStateResult.getLockShellState());
+                    if(ardTankLockStateResult.getLockShellState().equals("寮傚父")){
+                        alarmInfo = alarmInfo + "澶栧3寮傚父;";
+                    }
+                    lockMap.put("restartState",ardTankLockStateResult.getRestartState());
+                    lockMap.put("batterVoltage",ardTankLockStateResult.getBatterVoltage());
+                    if(Double.parseDouble(ardTankLockStateResult.getBatterVoltage()) <= lockBatteryVoltage){
+                        lockMap.put("batterVoltageAlarm",true);
+                        alarmInfo = alarmInfo + "鐢垫睜鐢靛帇浣庝簬" + lockBatteryVoltage + ";";
+                    }else{
+                        lockMap.put("batterVoltageAlarm",false);
+                    }
+                    lockMap.put("powerVoltage",ardTankLockStateResult.getPowerVoltage());
+                    if(Double.parseDouble(ardTankLockStateResult.getPowerVoltage()) <= lockPowerVoltage){
+                        lockMap.put("powerVoltageAlarm",true);
+                        alarmInfo = alarmInfo + "鐢垫簮鐢靛帇浣庝簬" + lockBatteryVoltage + ";";
+                    }else{
+                        lockMap.put("powerVoltageAlarm",false);
+                    }
+                    lockMap.put("uploadTime",ardTankLockStateResult.getUploadTime());
+                    lockMap.put("uniqueMark",ardTankLockStateResult.getUniqueMark());
+                    lockMap.put("lockStateMark",ardTankLockStateResult.getLockStateMark());
+                    if(alarmInfo.equals("")){
+                        lockMap.put("alarmMark",false);
+                    }else{
+                        lockMap.put("alarmMark",true);
+                    }
+                    lockMap.put("alarmInfo",alarmInfo);
+                }
+                lockList.add(lockMap);
+            }
+            map.put("lockList",lockList);
+            result.add(map);
+            Map<String,Object> data = new HashMap();
+            data.put("40002",result);
+            WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(userId), JSON.toJSONString(data));
+        }
+    }
+
+    @Override
+    public void getAlarm(String syUserId,String syPassword) {
+        List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT");
+        String syURL = "";
+        if(syURLResult.size() != 0){
+            syURL = syURLResult.get(0).getConfigValue();
+        }else{
+            return;
+        }
+        String finalSyURL = syURL;
+
+        String passwordMd5 = DigestUtils.md5Hex(syPassword);
+        Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId);
+        String sessionId = (String) LogInResult.get("sessionId");
+
+        List<ArdTankLock> ardTankLockResult = ardTankLockMapper.getAll();
+        for(ArdTankLock ardTankLock : ardTankLockResult){
+            if(this.alarmMap.get(ardTankLock.getLockNum()) != null){
+                continue;//褰撳墠閿佸凡鍦ㄨ幏鍙栨姤璀︼紝涓嶅湪鍒涘缓绾跨▼
+            }
+            Thread thread = new Thread(finalSyURL){
+                @Override
+                public void run() {
+                    try{
+                        String lockNum = ardTankLock.getLockNum();
+                        String lockNumHead = lockNum.substring(0,2);
+                        String lockNumTail = lockNum.substring(2,4);
+                        String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16)//閿佺紪鍙烽珮8浣�
+                                + Integer.parseInt(lockNumTail, 16)//閿佺紪鍙蜂綆8浣�
+                                + Integer.parseInt("06", 16));//璁剧疆閿佽姱鐘舵�佸姛鑳界爜06
+                        if(checkNum.length() == 1){
+                            checkNum = "0" + checkNum;
+                        }
+                        if(checkNum.length() > 2){
+                            checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length());
+                        }
+
+                        String paramsStr = lockNum + "06" + checkNum;
+                        paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + paramsStr + "%22%7D";
+                        Map<String,Object> result = sendCmd(finalSyURL, syUserId, ardTankLock.getCarId(), 199, "DataDownTransfer", paramsStr, sessionId);
+                        alarmMap.remove(ardTankLock.getLockNum());
+                    }catch(Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            };
+            thread.start();
+            alarmMap.put(ardTankLock.getLockNum(),thread);
+        }
+    }
+
+    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>) com.alibaba.fastjson2.JSON.parse(message);
+            return map;
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            return new HashMap();
+        }
     }
 }

--
Gitblit v1.9.3