| | |
| | | |
| | | 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.ArdTankLock; |
| | | import com.ruoyi.sy.domain.ArdTankWallLockTemporary; |
| | | import com.ruoyi.sy.gps31.PositionContainer; |
| | | import com.ruoyi.sy.mapper.ArdSyUserMapper; |
| | | import com.ruoyi.sy.mapper.ArdTankLockMapper; |
| | | import com.ruoyi.sy.mapper.ArdTankWallLockTemporaryMapper; |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.utils.forest.SYClient; |
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Resource |
| | | private ArdSyUserMapper ardSyUserMapper; |
| | | |
| | | @Resource |
| | | private SysConfigMapper sysConfigMapper; |
| | | |
| | | @Resource |
| | | private SYClient sYClient; |
| | | |
| | | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | |
| | | |
| | | @Override |
| | | public int insertArdTankWallTemporary(String userId, String userName, Map<String, Object> para) { |
| | | ArdSyUser ardSyUser = ardSyUserMapper.userById(userId); |
| | | if(ardSyUser == null){ |
| | | return 0; |
| | | } |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return 0; |
| | | } |
| | | /*String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId");*/ |
| | | |
| | | ArdTankWallTemporary ardTankWallTemporary = new ArdTankWallTemporary(); |
| | | ardTankWallTemporary.setId(IdUtils.simpleUUID()); |
| | | ardTankWallTemporary.setWallName((String) para.get("wallName")); |
| | |
| | | ardTankWallLockTemporaryMapper.insertArdTankWallLockTemporaryList(ardTankWallLockTemporaryList); |
| | | } |
| | | //创建定时线程 |
| | | String finalSyURL = syURL; |
| | | Thread thread = new Thread(){ |
| | | @Override |
| | | public void run() { |
| | |
| | | //e.printStackTrace(); |
| | | return; |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(finalSyURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(finalSyURL, (String) para.get("carId"), ardSyUser.getUserId(), sessionId); |
| | | String carPlate = ""; |
| | | if(((String)syResult.get("rspCode")).equals("1")){ |
| | | Map<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0); |
| | | carPlate = (String) carMap.get("carPlate"); |
| | | } |
| | | |
| | | List<String> userIdList = sysUserMapper.selectUserIdByCarId((String) para.get("carId"));//查看哪些用户权限下有这个车 |
| | | |
| | | for (String key : ONLINE_USER_SESSIONS.keySet()){ |
| | | String userId = key.split("_")[0]; |
| | | if(userIdList.contains(userId)){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("40003",(String) para.get("wallName") + "已到期"); |
| | | data.put("40003","车辆-" + carPlate + ": '" + (String) para.get("wallName") + "'"+ "临时电子围栏,已失效"); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public int updateArdTankWallTemporary(String userId, String userName, Map<String, Object> para) { |
| | | ArdSyUser ardSyUser = ardSyUserMapper.userById(userId); |
| | | if(ardSyUser == null){ |
| | | return 0; |
| | | } |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return 0; |
| | | } |
| | | /*String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId");*/ |
| | | |
| | | ArdTankWallTemporary ardTankWallTemporary = new ArdTankWallTemporary(); |
| | | ardTankWallTemporary.setId((String) para.get("id")); |
| | | ardTankWallTemporary.setProcessTime((String) para.get("processTime") + "/" + this.sdf.format(new Date())); |
| | |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, (String) para.get("carId"), ardSyUser.getUserId(), sessionId); |
| | | String carPlate = ""; |
| | | if(((String)syResult.get("rspCode")).equals("1")){ |
| | | Map<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0); |
| | | carPlate = (String) carMap.get("carPlate"); |
| | | } |
| | | |
| | | List<String> userIdList = sysUserMapper.selectUserIdByCarId((String) para.get("carId"));//查看哪些用户权限下有这个车 |
| | | for (String key : ONLINE_USER_SESSIONS.keySet()){ |
| | | String usersId = key.split("_")[0]; |
| | | if(userIdList.contains(usersId)){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("40003",(String) para.get("wallName") + "已被" + userName + "撤销"); |
| | | data.put("40003","车辆-" + carPlate + ":'" + (String) para.get("wallName") + "'" + "临时电子围栏," + "已被" + userName + "撤销"); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | public void restartArdTankWallTemporaryThread(String userId, String password) { |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return; |
| | | } |
| | | |
| | | List<Map<String,Object>> result = ardTankWallTemporaryMapper.getAliveArdTankWallTemporaryWithCarId(); |
| | | Date now = new Date(); |
| | | try{ |
| | | String finalSyURL = syURL; |
| | | for(Map<String,Object> map : result){ |
| | | if(now.getTime() - sdf.parse((String)map.get("processTime")).getTime() < Long.parseLong((String)map.get("interval")) * 60 * 1000){ |
| | | //时间没有过期,从新创建线程 |
| | | Thread thread = new Thread(){ |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | //计时从结束时间到当前时间 |
| | | Thread.sleep( sdf.parse((String)map.get("processTime")).getTime() + Long.parseLong((String)map.get("interval")) * 60 * 1000 - now.getTime()); |
| | | } catch (InterruptedException e) { |
| | | //e.printStackTrace(); |
| | | return; |
| | | } catch (ParseException e) { |
| | | //e.printStackTrace(); |
| | | return; |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(password); |
| | | Map<String, Object> LogInResult = sYClient.logIn(finalSyURL, passwordMd5, userId); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(finalSyURL, (String) map.get("carId"), userId, sessionId); |
| | | String carPlate = ""; |
| | | if(((String)syResult.get("rspCode")).equals("1")){ |
| | | Map<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0); |
| | | carPlate = (String) carMap.get("carPlate"); |
| | | } |
| | | |
| | | List<String> userIdList = sysUserMapper.selectUserIdByCarId((String) map.get("carId"));//查看哪些用户权限下有这个车 |
| | | |
| | | for (String key : ONLINE_USER_SESSIONS.keySet()){ |
| | | String userId = key.split("_")[0]; |
| | | if(userIdList.contains(userId)){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("40003","车辆-" + carPlate + ": '" + (String) map.get("wallName") + "'"+ "临时电子围栏,已失效"); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | ArdTankWallTemporary ardTankWallTemporary = new ArdTankWallTemporary(); |
| | | ardTankWallTemporary.setId((String) map.get("id")); |
| | | ardTankWallTemporary.setProcessMark("-1");//-1为到期 |
| | | ardTankWallTemporaryMapper.updateArdTankWallTemporary(ardTankWallTemporary); |
| | | PositionContainer.getCarWallThreadMap().remove((String) map.get("carId")); |
| | | } |
| | | }; |
| | | thread.start(); |
| | | PositionContainer.getCarWallThreadMap().put((String) map.get("carId"), thread); |
| | | }else{ |
| | | //忽略超时 |
| | | continue; |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | |
| | | } |