| | |
| | | package com.ruoyi.sy.service.impl; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.websocket.util.WebSocketUtils; |
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import com.ruoyi.device.hiksdk.util.minio.MinioUtils; |
| | | import com.ruoyi.sy.domain.ArdSyUser; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import static com.ruoyi.common.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | | /** |
| | | * 三一车辆Service业务层处理 |
| | |
| | | private SYClient sYClient; |
| | | |
| | | private Map<Integer,Map<String,String>> logInMap = new HashMap(); |
| | | |
| | | private Map<String, Timer> userCarTimerMap = new HashMap(); |
| | | |
| | | /** |
| | | * 查询三一车辆 |
| | |
| | | @Override |
| | | public Map<String, Object> getArdSyCarAndDeptByCarId(String carId) { |
| | | Map<String, Object> result = ardSyCarMapper.getArdSyCarAndDeptByCarId(carId); |
| | | if(result != null){ |
| | | if(result.get("carPicture") != null){ |
| | | if(!((String)result.get("carPicture")).equals("")){ |
| | | String url = ((String)result.get("carPicture")).split("sycar")[0]; |
| | | String carModel = url + (String)result.get("carModel"); |
| | | result.put("carModel",carModel); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void sendArdSyCarPosition() { |
| | | for(String key : ONLINE_USER_SESSIONS.keySet()){ |
| | | SysUser sysUser = userMapper.selectUserById(key); |
| | | if(sysUser == null){ |
| | | return; |
| | | if(PositionContainer.getUserPositionMap().keySet().contains(key)){//当追踪的车辆容器包含此用户Id,则实时位置推送需要剔除该车辆 |
| | | SysUser sysUser = userMapper.selectUserById(key); |
| | | if(sysUser == null){ |
| | | //return; |
| | | continue; |
| | | } |
| | | String deptId = String.valueOf(sysUser.getDeptId()); |
| | | Map<String,Map<String,Object>> map = PositionContainer.getDeptPositionMap().get(deptId); |
| | | List<String> carIdList = new ArrayList(); |
| | | carIdList.addAll(PositionContainer.getUserPositionMap().get(key).keySet()); |
| | | String carId = carIdList.get(0); |
| | | map.remove(carId); |
| | | if(map != null){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("30000", map.values()); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | }else{ |
| | | SysUser sysUser = userMapper.selectUserById(key); |
| | | if(sysUser == null){ |
| | | //return; |
| | | continue; |
| | | } |
| | | String deptId = String.valueOf(sysUser.getDeptId()); |
| | | Map<String,Map<String,Object>> map = PositionContainer.getDeptPositionMap().get(deptId); |
| | | if(map != null){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("30000", map.values()); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | String deptId = String.valueOf(sysUser.getDeptId()); |
| | | Map<String,Map<String,Object>> map = PositionContainer.getDeptPositionMap().get(deptId); |
| | | if(map != null){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("30000", map.values()); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | for(String userId : userCarTimerMap.keySet()){//用户离线后将车辆追踪资源释放 |
| | | if(!ONLINE_USER_SESSIONS.keySet().contains(userId)){ |
| | | userCarTimerMap.get(userId).cancel(); |
| | | userCarTimerMap.remove(userId); |
| | | PositionContainer.getUserPositionMap().remove(userId); |
| | | } |
| | | } |
| | | } |
| | |
| | | carList31 = sYClient.getCarList1(syURL,teamId, result.get("userId"),result.get("sessionId")); |
| | | //拿到车辆数据 |
| | | list= (List) carList31.get("list"); |
| | | List<String> carIdList = new ArrayList(); |
| | | //所有carId |
| | | for(Map<String,String> m : list){ |
| | | carIdList.add(m.get("carId")); |
| | | } |
| | | if(carIdList.size() == 0){ |
| | | Map<String,String> map0 = new HashMap(); |
| | | map0.put("list", "{}"); |
| | | map0.put("rspCode", "1"); |
| | | list.add(map0); |
| | | if(list.isEmpty()){ |
| | | return list; |
| | | } |
| | | //添加车辆属性 |
| | | for(Map<String,String> m : list){ |
| | | switch (m.get("state")) { |
| | | case "1": |
| | | m.put("carState", "离线-从未报定位");break; |
| | | case "2": |
| | | m.put("carState", "离线-欠费");break; |
| | | case "3": |
| | | m.put("carState", "离线");break; |
| | | case "4": |
| | | m.put("carState", "离线-报警");break; |
| | | case "5": |
| | | m.put("carState", "在线-从未报定位");break; |
| | | case "6": |
| | | m.put("carState", "在线-欠费");break; |
| | | case "7": |
| | | m.put("carState", "在线-行驶");break; |
| | | case "8": |
| | | m.put("carState", "在线-行驶-报警");break; |
| | | case "9": |
| | | m.put("carState", "在线-停车-ACC关");break; |
| | | case "10": |
| | | m.put("carState", "在线-停车-ACC开");break; |
| | | case "11": |
| | | m.put("carState", "在线-停车-ACC关-报警");break; |
| | | case "12": |
| | | m.put("carState", "在线-停车-ACC开-报警");break; |
| | | case "13": |
| | | m.put("carState", "在线-无效定位");break; |
| | | default: |
| | | break; |
| | | }else { |
| | | List<String> carIdList = new ArrayList(); |
| | | //所有carId |
| | | for(Map<String,String> m : list){ |
| | | carIdList.add(m.get("carId")); |
| | | } |
| | | if(carIdList.size() == 0){ |
| | | Map<String,String> map0 = new HashMap(); |
| | | map0.put("list", "{}"); |
| | | map0.put("rspCode", "1"); |
| | | list.add(map0); |
| | | return list; |
| | | } |
| | | //添加车辆属性 |
| | | for(Map<String,String> m : list){ |
| | | switch (m.get("state")) { |
| | | case "1": |
| | | m.put("carState", "离线-从未报定位");break; |
| | | case "2": |
| | | m.put("carState", "离线-欠费");break; |
| | | case "3": |
| | | m.put("carState", "离线");break; |
| | | case "4": |
| | | m.put("carState", "离线-报警");break; |
| | | case "5": |
| | | m.put("carState", "在线-从未报定位");break; |
| | | case "6": |
| | | m.put("carState", "在线-欠费");break; |
| | | case "7": |
| | | m.put("carState", "在线-行驶");break; |
| | | case "8": |
| | | m.put("carState", "在线-行驶-报警");break; |
| | | case "9": |
| | | m.put("carState", "在线-停车-ACC关");break; |
| | | case "10": |
| | | m.put("carState", "在线-停车-ACC开");break; |
| | | case "11": |
| | | m.put("carState", "在线-停车-ACC关-报警");break; |
| | | case "12": |
| | | m.put("carState", "在线-停车-ACC开-报警");break; |
| | | case "13": |
| | | m.put("carState", "在线-无效定位");break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | |
| | | for (int i = 0; i < carList.size(); i++) { |
| | | ArdSyCar ardSyCar = carList.get(i); |
| | | if(carId.equals(ardSyCar.getCarId())){ |
| | | m.put("carModel",ardSyCar.getCarModel()); |
| | | String url = ""; |
| | | if(ardSyCar.getCarPicture() != null){ |
| | | if(!ardSyCar.getCarPicture().equals("")){ |
| | | url = ardSyCar.getCarPicture().split("sycar")[0]; |
| | | } |
| | | } |
| | | m.put("carModel",url + ardSyCar.getCarModel());//zns |
| | | //m.put("carModel",ardSyCar.getCarModel()); |
| | | m.put("carTypeArd",ardSyCar.getCarType()); |
| | | m.put("carBrand",ardSyCar.getCarBrand()); |
| | | m.put("carPicture",ardSyCar.getCarPicture()); |
| | |
| | | return new HashMap<String,List<String>>(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Results getCarGPSBycarId(String usersId,String carId,String syURL,ArdSyUser ardSyUser){ |
| | | Map<String, String> result = logInMap.get(Integer.parseInt(usersId)); |
| | | //31用户名密码 |
| | | String username31 = ardSyUser.getUserId(); |
| | | String password31 = ardSyUser.getPassword(); |
| | | String passwordMd5 = DigestUtils.md5Hex(password31); |
| | | Map<String, Object> result1 = sYClient.logIn(syURL,passwordMd5, username31); |
| | | result = new HashMap(); |
| | | result.put("userId", username31); |
| | | result.put("sessionId", (String) result1.get("sessionId")); |
| | | Map<String,Object> result0 = new HashMap(); |
| | | result0 = sYClient.getCarNearPositionByCarId(syURL,carId,result.get("userId"),result.get("sessionId")); |
| | | return Results.succeed(result0); |
| | | } |
| | | |
| | | @Override |
| | | public Results chaseCarByCarId(String usersId, String carId, String cycle) { |
| | | try{ |
| | | /*Map<String,Map<String,Object>> map = new HashMap(); |
| | | map.put(carId,new HashMap()); |
| | | PositionContainer.getUserPositionMap().put(usersId,map);*/ |
| | | if(cycle.equals("0")){ |
| | | if(userCarTimerMap.get(usersId) != null){ |
| | | userCarTimerMap.get(usersId).cancel(); |
| | | userCarTimerMap.remove(usersId); |
| | | PositionContainer.getUserPositionMap().remove(usersId); |
| | | } |
| | | return Results.succeed("停止追踪"); |
| | | }else{ |
| | | if(userCarTimerMap.get(usersId) != null){ |
| | | userCarTimerMap.get(usersId).cancel(); |
| | | userCarTimerMap.remove(usersId); |
| | | PositionContainer.getUserPositionMap().remove(usersId); |
| | | Map<String,Map<String,Object>> map = new HashMap(); |
| | | map.put(carId,new HashMap()); |
| | | PositionContainer.getUserPositionMap().put(usersId,map); |
| | | Date date = new Date(); |
| | | Timer carPositionTimer = new Timer();//定时推送实时位置 |
| | | TimerTask carPositionTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | | Map<String,Object> position = PositionContainer.getUserPositionMap().get(usersId).get(carId); |
| | | if(position != null){ |
| | | if(position.size() != 0){ |
| | | Map<String,Map<String,Object>> data = new HashMap(); |
| | | data.put("31000",position); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(usersId), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | carPositionTimer.scheduleAtFixedRate(carPositionTask,date,Integer.parseInt(cycle));//启用 |
| | | this.userCarTimerMap.put(usersId,carPositionTimer); |
| | | return Results.succeed("开始追踪"); |
| | | }else{ |
| | | Map<String,Map<String,Object>> map = new HashMap(); |
| | | map.put(carId,new HashMap()); |
| | | PositionContainer.getUserPositionMap().put(usersId,map); |
| | | Date date = new Date(); |
| | | Timer carPositionTimer = new Timer();//定时推送实时位置 |
| | | TimerTask carPositionTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | | Map<String,Object> position = PositionContainer.getUserPositionMap().get(usersId).get(carId); |
| | | if(position != null){ |
| | | if(position.size() != 0){ |
| | | Map<String,Map<String,Object>> data = new HashMap(); |
| | | data.put("31000",position); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(usersId), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | carPositionTimer.scheduleAtFixedRate(carPositionTask,date,Integer.parseInt(cycle));//启用 |
| | | this.userCarTimerMap.put(usersId,carPositionTimer); |
| | | return Results.succeed("开始追踪"); |
| | | } |
| | | } |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | return Results.error("追踪失败"); |
| | | } |
| | | } |
| | | } |