| | |
| | | package com.ruoyi.sy.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | 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.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.domain.*; |
| | | import com.ruoyi.sy.gps31.PositionContainer; |
| | | 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; |
| | | |
| | | /** |
| | | * 电磁锁Service业务层处理 |
| | |
| | | private SysConfigMapper sysConfigMapper; |
| | | |
| | | @Resource |
| | | private ArdSyCarMapper ardSyCarMapper; |
| | | |
| | | @Resource |
| | | private ArdTankLockStateMapper ardTankLockStateMapper; |
| | | |
| | | @Resource |
| | | private ArdTankLockPasswordMapper ardTankLockPasswordMapper; |
| | | |
| | | @Resource |
| | | private SYClient sYClient; |
| | | |
| | | //private Map<String,Thread> alarmMap = new HashMap();//电磁锁历史报警线程容器 |
| | | |
| | | /** |
| | | * 查询电磁锁 |
| | |
| | | ardTankLock.setImgPositionLeft(map.get("imgPositionLeft")); |
| | | ardTankLock.setCarId(carId); |
| | | ardTankLock.setEnable(map.get("enable")); |
| | | 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) { |
| | |
| | | @Override |
| | | public int deleteLockByCarId(String carId) { |
| | | int result = ardTankLockMapper.deleteLockByCarId(carId); |
| | | return result; |
| | | try{ |
| | | return result; |
| | | }finally { |
| | | PositionContainer.getCarLockProcessThreadMap().remove(carId);//移除容器 |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | return 1; |
| | | } |
| | | result = ardTankLockMapper.deleteLockByCarId(carId); |
| | | return result; |
| | | try{ |
| | | return result; |
| | | }finally { |
| | | PositionContainer.getCarLockProcessThreadMap().get(carId).clear(); |
| | | } |
| | | } |
| | | |
| | | List<ArdTankLock> ardTankLocks = new ArrayList(); |
| | |
| | | ardTankLock.setImgPositionLeft((String) map.get("imgPositionLeft")); |
| | | ardTankLock.setCarId((String) map.get("carId")); |
| | | ardTankLock.setEnable((String) map.get("enable")); |
| | | ardTankLock.setRestartState((String) map.get("restartState")); |
| | | result = result + ardTankLockMapper.updateArdTankLock(ardTankLock); |
| | | }else{//无主键,做新增操作 |
| | | ArdTankLock ardTankLock = new ArdTankLock(); |
| | |
| | | ardTankLock.setImgPositionTop((String) map.get("imgPositionTop")); |
| | | ardTankLock.setImgPositionLeft((String) map.get("imgPositionLeft")); |
| | | ardTankLock.setCarId(carId); |
| | | ardTankLock.setRestartState((String) map.get("restartState")); |
| | | ardTankLock.setEnable((String) map.get("enable")); |
| | | 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); |
| | | } |
| | |
| | | List<ArdTankLock> result = ardTankLockMapper.getAll(); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void sendLockState(String userId, String syUserId, String syPassword) { |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return; |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(syPassword); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId); |
| | | String sessionId = (String) LogInResult.get("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 + "外壳异常;"; |
| | | } |
| | | 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)); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | @Override |
| | | public void readPassword(String userId,String password) { |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return; |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(password); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, userId); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | |
| | | String finalSyURL = syURL; |
| | | Thread passwordThread = new Thread(){ |
| | | @Override |
| | | public void run() { |
| | | List<ArdTankLock> ardTankLockResult = ardTankLockMapper.selectArdTankLockWithPassword(); |
| | | for(ArdTankLock ardTankLock : ardTankLockResult){ |
| | | Thread lockThread = new Thread(){//读取密码 |
| | | @Override |
| | | public void run() { |
| | | if(ardTankLock.getArdTankLockPasswords().isEmpty()){//无可用密码 |
| | | if(PositionContainer.getCarLockPasswordMap().get(ardTankLock.getLockNum()) != null){//新设置的10组密码 |
| | | Set<String> passwordSet = PositionContainer.getCarLockPasswordMap().get(ardTankLock.getLockNum()); |
| | | //设置新密码 |
| | | String lockNumHead = ardTankLock.getLockNum().substring(0,2); |
| | | String lockNumTail = ardTankLock.getLockNum().substring(2,4); |
| | | String code = "04"; |
| | | Integer check = Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt(code, 16);; |
| | | for(String password : passwordSet){ |
| | | String[] passwordArray = password.split(""); |
| | | for(String p : passwordArray){ |
| | | check = check + Integer.parseInt(p); |
| | | } |
| | | } |
| | | String checkNum = Integer.toHexString(check); |
| | | if(checkNum.length() == 1){ |
| | | checkNum = "0" + checkNum; |
| | | }else if(checkNum.length() > 2){ |
| | | checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length()); |
| | | } |
| | | String data = ardTankLock.getLockNum() + "04"; |
| | | for(String password : passwordSet){ |
| | | String[] passwordArray = password.split(""); |
| | | for(String p : passwordArray){ |
| | | data = data + "0" + p; |
| | | } |
| | | } |
| | | data = data + checkNum; |
| | | String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + data + "%22%7D"; |
| | | |
| | | 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()); |
| | | } |
| | | PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword"); |
| | | }catch (Exception e){ |
| | | PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).remove("lockPassword"); |
| | | } |
| | | }else{//读取密码 |
| | | Set<String> passwordSet = new HashSet(); |
| | | while(passwordSet.size() != 10){ |
| | | String password = ""; |
| | | for(int i = 0;i <= 5;i++){ |
| | | password = password + String.valueOf(10 * Math.random()).split("\\.")[0]; |
| | | } |
| | | passwordSet.add(password); |
| | | } |
| | | //设置新密码 |
| | | String lockNumHead = ardTankLock.getLockNum().substring(0,2); |
| | | String lockNumTail = ardTankLock.getLockNum().substring(2,4); |
| | | String code = "04"; |
| | | Integer check = Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt(code, 16);; |
| | | for(String password : passwordSet){ |
| | | String[] passwordArray = password.split(""); |
| | | for(String p : passwordArray){ |
| | | check = check + Integer.parseInt(p); |
| | | } |
| | | } |
| | | String checkNum = Integer.toHexString(check); |
| | | if(checkNum.length() == 1){ |
| | | checkNum = "0" + checkNum; |
| | | }else if(checkNum.length() > 2){ |
| | | checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length()); |
| | | } |
| | | String data = ardTankLock.getLockNum() + "04"; |
| | | for(String password : passwordSet){ |
| | | String[] passwordArray = password.split(""); |
| | | for(String p : passwordArray){ |
| | | data = data + "0" + p; |
| | | } |
| | | } |
| | | data = data + checkNum; |
| | | String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + data + "%22%7D"; |
| | | 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.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"; |
| | | 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(); |
| | | if(PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).get("lockPassword") == null){ |
| | | PositionContainer.getCarLockProcessThreadMap().get(ardTankLock.getCarId()).get(ardTankLock.getLockNum()).put("lockPassword",lockThread); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | }; |
| | | 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 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(); |
| | | } |
| | | } |
| | | } |