| | |
| | | @Value("${syCar.password}") |
| | | private String password; |
| | | |
| | | private Timer lockStateTimer; |
| | | |
| | | @PostConstruct |
| | | public void init(){ |
| | | ardSyCarController = this; |
| | |
| | | //删除结束时间为null的记录 |
| | | int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime(); |
| | | |
| | | this.lockStateTimer = new Timer();//定时获取各个锁的状态 |
| | | Timer lockStateTimer = new Timer();//定时获取各个锁的状态 |
| | | TimerTask lockStateTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | |
| | | |
| | | 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); |
| | |
| | | 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); |
| | | PositionContainer.getCarThreadMap().remove(ardTankLock.getCarId());//发送完,从容器去除 |
| | | } |
| | | }; |
| | | LockThread.start(); |
| | | if(PositionContainer.getCarThreadMap().get(ardTankLock.getCarId()) != null){//容器中无线程,放入容器 |
| | | PositionContainer.getCarThreadMap().put(ardTankLock.getCarId(),lockThread); |
| | | } |
| | | lockThread.start(); |
| | | } |
| | | } |
| | | }; |
| | |
| | | TimerTask lockCheckTimeTask =new TimerTask(){ |
| | | @Override |
| | | public void run() { |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigKey("syCarPT"); |
| | | List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config); |
| | | String syURL = ""; |
| | | 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"); |
| | | 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; |
| | | 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); |
| | | 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); |
| | | String nowYearHex = Integer.toHexString(Integer.parseInt(nowYear)); |
| | | if(nowYearHex.length() == 1){ |
| | | nowYearHex = "0" + nowYearHex; |
| | | } |
| | | }; |
| | | LockThread.start(); |
| | | 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); |
| | | PositionContainer.getCarThreadMap().remove(ardTankLock.getCarId());//发送完,从容器去除 |
| | | } |
| | | }; |
| | | if(PositionContainer.getCarThreadMap().get(ardTankLock.getCarId()) != null){//容器中无线程,放入容器 |
| | | PositionContainer.getCarThreadMap().put(ardTankLock.getCarId(),lockThread); |
| | | } |
| | | lockThread.start(); |
| | | } |
| | | } |
| | | }; |
| | | lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,10000); |
| | | lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,7000); |
| | | |
| | | 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); |
| | | |
| | | try{ |
| | | Thread.sleep(3000); |
| | | }catch(Exception e){ |
| | | |
| | | } |
| | | |
| | | |
| | | /*Timer alarmTimer = new Timer();//定时获取报警 |
| | | TimerTask alarmTask = new TimerTask(){ |
| | | @Override |
| | | public void run() { |
| | | Thread alarmThread = new Thread() { |
| | | @Override |
| | | public void run() { |
| | | ardTankLockService.getAlarm(userId,password); |
| | | } |
| | | }; |
| | | alarmThread.start(); |
| | | } |
| | | }; |
| | | alarmTimer.scheduleAtFixedRate(alarmTask,date,3000);*/ |
| | | |
| | | } |
| | | |