From 38f29e38fcc668171dc05c53d40a36b895c86102 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Thu, 10 Oct 2024 13:34:28 +0800
Subject: [PATCH] init
---
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java | 261 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 219 insertions(+), 42 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 9441272..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;
@@ -90,6 +87,9 @@
@Autowired
private IArdTankLockService ardTankLockService;
+ @Autowired
+ private IArdTankWallTemporaryService ardTankWallTemporaryService;
+
@Resource
private SYClient sYClient;
@@ -103,8 +103,6 @@
@Value("${syCar.password}")
private String password;
-
- private Timer lockStateTimer;
@PostConstruct
public void init(){
@@ -155,7 +153,18 @@
//删除结束时间为null的记录
int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
- this.lockStateTimer = new Timer();//定时获取各个锁的状态
+ 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
public void run(){
@@ -180,7 +189,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);
@@ -195,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);
+ }
+
}
}
};
@@ -211,7 +229,7 @@
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();
@@ -232,7 +250,7 @@
List<ArdTankLock> result = ardTankLockService.getArdTankLockAll();//查询全部电磁锁
for(ArdTankLock ardTankLock : result){
- Thread LockThread = new Thread(finalSyURL){
+ Thread lockThread = new Thread(finalSyURL){
@Override
public void run() {
//获取时间并拆分年月日时分秒
@@ -282,51 +300,210 @@
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);
+ 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");
+ }
}
};
- LockThread.start();
+ //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);
+ }
}
}
};
- lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,10000);
+ //lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,7000);
+ lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,67000);
Timer sendTimer = new Timer();//定时发送锁状态
- TimerTask sendLockStateTask =new TimerTask(){
+ 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) {
+ Thread lockThread = new Thread() {
@Override
public void run() {
- String usersId = key.split("_")[0];
- ardTankLockService.sendLockState(usersId,userId,password);
+ ardTankLockService.sendLockState(key,userId,password);
}
};
lockThread.start();
}
}
};
- //sendTimer.scheduleAtFixedRate(sendLockStateTask,date,3000);
+ 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);
+ passwordTimer.scheduleAtFixedRate(passwordTask,date,13000);
+ Timer lockRestartStateTimer = new Timer();//定时各个锁的复位状态
+ TimerTask lockRestartStateTask = 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.getArdTankLockAllWithState();//查询全部电磁锁及最终状态
+ for(ArdTankLock ardTankLock : result){
+ String restartState = ardTankLock.getRestartState();
+ String sRestartState = "";
+ if(ardTankLock.getArdTankLockState() != null){
+ sRestartState = ardTankLock.getArdTankLockState().getRestartState();
+ }
+
+ if(sRestartState.equals("")){
+ continue;
+ }else{
+ sRestartState = sRestartState.substring(0,2);
+ if(!restartState.equals(sRestartState)){
+ Thread lockThread = new Thread(finalSyURL){
+ @Override
+ public void run() {
+ String process = "";
+ if(restartState.equals("开锁")){
+ process = "01";
+ }else if(restartState.equals("关锁")){
+ process = "02";
+ }else{
+ return;
+ }
+
+ 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("03", 16) + Integer.parseInt(process, 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() + "03" + process + checkNum + "%22%7D";
+ 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();
+ if(PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).get("lockRestart") == null){
+ PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).put("lockRestart",lockThread);
+ }
+ }
+ }
+ }
+ }
+ };
+ thread.start();
+ }
+ };
+ 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);
}
/**
@@ -432,7 +609,7 @@
/**
* 获取未挂接权限的三一车辆
*/
-// @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
+ @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
@PostMapping("/getArdSyCarNoRight")
@ApiOperation("获取未挂接权限的三一车辆")
public Map<String,Object> getArdSyCarNoRight(){
@@ -450,7 +627,7 @@
/**
* 获取全部的三一车辆
*/
-// @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
+ @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
@PostMapping("/getArdSyCarAll")
@ApiOperation("获取全部的三一车辆")
public Map<String,Object> getArdSyCarAll(){
@@ -468,7 +645,7 @@
/**
* 获取全部车辆模型
*/
-// @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')")
+ @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')")
@PostMapping("/getAllCarModel")
@ApiOperation("获取全部车辆模型")
public Map<String,Object> getAllCarModel(){
@@ -535,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