From 57c673aa3e83677bcf5d30b4b45d06bae6609db8 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: 星期四, 08 八月 2024 16:14:40 +0800
Subject: [PATCH] 优化:获取会话
---
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java | 163 ++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 114 insertions(+), 49 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 1d55048..2120ab0 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
@@ -110,7 +110,24 @@
ardTankLock.setRestartState(map.get("restartState"));
ardTankLocks.add(ardTankLock);
}
- return ardTankLockMapper.insertArdTankLocks(ardTankLocks);
+ try{
+ return ardTankLockMapper.insertArdTankLocks(ardTankLocks);
+ }finally {
+ if(PositionContainer.getCarLockProcessThreadMap().keySet().contains(carId)){
+ Map<String, Map<String,Thread>> lockMap = PositionContainer.getCarLockProcessThreadMap().get(carId);
+ for(Map<String,String> map : lockList){
+ Map<String,Thread> lockThreadMap = new HashMap();
+ lockMap.put(map.get("lockNum"),lockThreadMap);
+ }
+ }else{
+ Map<String,Map<String,Thread>> carMap = new HashMap();//杞﹁締瀹瑰櫒
+ for(Map<String,String> map : lockList){
+ Map<String,Thread> lockMap = new HashMap();//閿佸鍣�
+ carMap.put(map.get("lockNum"),lockMap);
+ }
+ PositionContainer.getCarLockProcessThreadMap().put(carId,carMap);
+ }
+ }
}
/*@Override
public int insertArdTankLock(ArdTankLock ardTankLock) {
@@ -312,7 +329,11 @@
@Override
public int deleteLockByCarId(String carId) {
int result = ardTankLockMapper.deleteLockByCarId(carId);
- return result;
+ try{
+ return result;
+ }finally {
+ PositionContainer.getCarLockProcessThreadMap().remove(carId);//绉婚櫎瀹瑰櫒
+ }
}
@Override
@@ -331,7 +352,11 @@
return 1;
}
result = ardTankLockMapper.deleteLockByCarId(carId);
- return result;
+ try{
+ return result;
+ }finally {
+ PositionContainer.getCarLockProcessThreadMap().get(carId).clear();
+ }
}
List<ArdTankLock> ardTankLocks = new ArrayList();
@@ -362,6 +387,22 @@
ardTankLocks.add(ardTankLock);
}
}
+ //鏇存柊瀹瑰櫒
+ if(PositionContainer.getCarLockProcessThreadMap().keySet().contains(carId)){
+ Map<String, Map<String,Thread>> lockMap = PositionContainer.getCarLockProcessThreadMap().get(carId);
+ for(Map<String,Object> map : lockList){
+ Map<String,Thread> lockThreadMap = new HashMap();
+ lockMap.put((String) map.get("lockNum"),lockThreadMap);
+ }
+ }else{
+ Map<String,Map<String,Thread>> carMap = new HashMap();//杞﹁締瀹瑰櫒
+ for(Map<String,Object> map : lockList){
+ Map<String,Thread> lockMap = new HashMap();//閿佸鍣�
+ carMap.put((String) map.get("lockNum"),lockMap);
+ }
+ PositionContainer.getCarLockProcessThreadMap().put(carId,carMap);
+ }
+
if(ardTankLocks.size() != 0){
result = result + ardTankLockMapper.insertArdTankLocks(ardTankLocks);
}
@@ -659,7 +700,7 @@
String sessionId = (String) LogInResult.get("sessionId");
String finalSyURL = syURL;
- Thread passwordThread = new Thread(syURL){
+ Thread passwordThread = new Thread(){
@Override
public void run() {
List<ArdTankLock> ardTankLockResult = ardTankLockMapper.selectArdTankLockWithPassword();
@@ -696,36 +737,29 @@
}
data = data + checkNum;
String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + data + "%22%7D";
- Map<String,Object> syResult = sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
- if(((String)syResult.get("rspCode")).equals("0")){
- List<ArdTankLockPassword> ardTankLockPasswordList = new ArrayList();
- int i = 0;
- for(String password : passwordSet){
- ArdTankLockPassword ardTankLockPassword = new ArdTankLockPassword();
- ardTankLockPassword.setId(IdUtils.simpleUUID());
- ardTankLockPassword.setLockId(ardTankLock.getLockNum());//鏆傚瓨閿佺紪鍙�
- ardTankLockPassword.setPassword(password);
- ardTankLockPassword.setNo(String.valueOf(i));
- ardTankLockPasswordList.add(ardTankLockPassword);
- i = i + 1;
+
+ try{
+ Map<String,Object> syResult = sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+ if(((String)syResult.get("rspCode")).equals("0")){
+ List<ArdTankLockPassword> ardTankLockPasswordList = new ArrayList();
+ int i = 0;
+ for(String password : passwordSet){
+ ArdTankLockPassword ardTankLockPassword = new ArdTankLockPassword();
+ ardTankLockPassword.setId(IdUtils.simpleUUID());
+ ardTankLockPassword.setLockId(ardTankLock.getLockNum());//鏆傚瓨閿佺紪鍙�
+ ardTankLockPassword.setPassword(password);
+ ardTankLockPassword.setNo(String.valueOf(i));
+ ardTankLockPasswordList.add(ardTankLockPassword);
+ i = i + 1;
+ }
+ int result = ardTankLockPasswordMapper.insertArdTankLockPasswordList(ardTankLockPasswordList);
+ PositionContainer.getCarLockPasswordMap().remove(ardTankLock.getLockNum());
}
- int result = ardTankLockPasswordMapper.insertArdTankLockPasswordList(ardTankLockPasswordList);
- PositionContainer.getCarLockPasswordMap().remove(ardTankLock.getLockNum());
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword");
+ }catch (Exception e){
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword");
}
}else{//璇诲彇瀵嗙爜
- /*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("05", 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() + "05" + checkNum + "%22%7D";
-
- sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);*/
Set<String> passwordSet = new HashSet();
while(passwordSet.size() != 10){
String password = "";
@@ -734,8 +768,6 @@
}
passwordSet.add(password);
}
- System.out.println("1111111111111111");
- System.out.println(passwordSet);
//璁剧疆鏂板瘑鐮�
String lockNumHead = ardTankLock.getLockNum().substring(0,2);
String lockNumTail = ardTankLock.getLockNum().substring(2,4);
@@ -762,20 +794,25 @@
}
data = data + checkNum;
String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + data + "%22%7D";
- Map<String,Object> syResult = sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
- if(((String)syResult.get("rspCode")).equals("0")){
- List<ArdTankLockPassword> ardTankLockPasswordList = new ArrayList();
- int i = 0;
- for(String password : passwordSet){
- ArdTankLockPassword ardTankLockPassword = new ArdTankLockPassword();
- ardTankLockPassword.setId(IdUtils.simpleUUID());
- ardTankLockPassword.setLockId(ardTankLock.getLockNum());//鏆傚瓨閿佺紪鍙�
- ardTankLockPassword.setPassword(password);
- ardTankLockPassword.setNo(String.valueOf(i));
- ardTankLockPasswordList.add(ardTankLockPassword);
- i = i + 1;
+ try{
+ Map<String,Object> syResult = sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
+ if(((String)syResult.get("rspCode")).equals("0")){
+ List<ArdTankLockPassword> ardTankLockPasswordList = new ArrayList();
+ int i = 0;
+ for(String password : passwordSet){
+ ArdTankLockPassword ardTankLockPassword = new ArdTankLockPassword();
+ ardTankLockPassword.setId(IdUtils.simpleUUID());
+ ardTankLockPassword.setLockId(ardTankLock.getLockNum());//鏆傚瓨閿佺紪鍙�
+ ardTankLockPassword.setPassword(password);
+ ardTankLockPassword.setNo(String.valueOf(i));
+ ardTankLockPasswordList.add(ardTankLockPassword);
+ i = i + 1;
+ }
+ int result = ardTankLockPasswordMapper.insertArdTankLockPasswordList(ardTankLockPasswordList);
}
- int result = ardTankLockPasswordMapper.insertArdTankLockPasswordList(ardTankLockPasswordList);
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword");
+ }catch(Exception e){
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword");
}
}
}else{
@@ -790,12 +827,20 @@
checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length());
}
String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "05" + 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("lockPassword");
+ }catch (Exception e){
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword");
+ }
}
}
};
- lockThread.start();
+ //lockThread.start();
+ if(PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).get("lockPassword") == null){
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).put("lockPassword",lockThread);
+ }
+
}
}
@@ -803,6 +848,26 @@
passwordThread.start();
}
+ @Override
+ public List<ArdTankLock> getArdTankLockAllWithState() {
+ List<ArdTankLock> result = ardTankLockMapper.getArdTankLockAllWithState();
+ return result;
+ }
+
+ @Override
+ public Long getArdTankLockCount() {
+ Long result = ardTankLockMapper.getArdTankLockCount();
+ return result;
+ }
+
+ @Override
+ public int updateLockEnableByCarId(Map<String, Object> para) {
+ String carId = (String) para.get("carId");
+ String enable = String.valueOf((Boolean) para.get("enable"));
+ int result = ardTankLockMapper.updateLockEnableByCarId(carId, enable);
+ return result;
+ }
+
/*@Override
public void getAlarm(String syUserId,String syPassword) {
List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT");
--
Gitblit v1.9.3