From 0789e8546f8b5e68590e5ad7f4eb1d5c54e6cc22 Mon Sep 17 00:00:00 2001 From: aijinhui <aijinhui> Date: 星期二, 26 三月 2024 15:49:02 +0800 Subject: [PATCH] BUG --- ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java | 509 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 427 insertions(+), 82 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java index f0133ad..baa6568 100644 --- a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java +++ b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java @@ -2,6 +2,8 @@ import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -13,11 +15,20 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.dtflys.forest.annotation.Var; +import com.github.pagehelper.PageInfo; +import com.ruoyi.app.application.domain.ArdAppApplication; +import com.ruoyi.app.application.mapper.ArdAppApplicationMapper; +import com.ruoyi.app.position.mapper.ArdAppPositionMapper; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.sy.domain.ArdAccessFence; +import com.ruoyi.sy.param.ArdSyCarParam; +import com.ruoyi.sy.vo.ArdSyCarVo; +import com.ruoyi.system.mapper.SysDeptMapper; import com.ruoyi.utils.gis.GisUtil; import com.ruoyi.utils.gis.Point; import com.ruoyi.scheduling.domian.SchedulingParam; @@ -82,6 +93,12 @@ @Resource private ArdSyCarDayMapper ardSyCarDayMapper; + @Resource + private ArdAppApplicationMapper ardAppApplicationMapper; + + @Resource + private SysDeptMapper sysDeptMapper; + @Value("${minio.endpoint}") private String minioEndpoint; @@ -109,6 +126,52 @@ @Override public List<ArdSyCar> selectArdSyCarList(ArdSyCar ardSyCar) { return ardSyCarMapper.selectArdSyCarList(ardSyCar); + } + + @Override + public AjaxResult ardSyCarList(ArdSyCarParam ardSyCarParam,Map<String,Object> result) { + QueryWrapper<ArdSyCar> queryWrapper = new QueryWrapper<>(); + queryWrapper.like(ardSyCarParam.getCarBrand()!=null,"car_brand",ardSyCarParam.getCarBrand()) + .like(ardSyCarParam.getCarType()!=null,"car_type",ardSyCarParam.getCarType()); + List<ArdSyCar> ardSyCars = ardSyCarMapper.selectList(queryWrapper); + List<ArdSyCarVo> ardSyCarVoList = new ArrayList<>(); + if(((String)result.get("code")).equals("200")){ + List<Map<String,Object>> list = (List<Map<String, Object>>) result.get("data"); + for (int i = 0; i < ardSyCars.size(); i++) { + ArdSyCar ardSyCar = ardSyCars.get(i); + String carId = ardSyCar.getCarId(); + for (int j = 0; j < list.size(); j++) { + String carId31 = (String) list.get(j).get("carId"); + if(carId.equals(carId31)){ + ArdSyCarVo ardSyCarVo = new ArdSyCarVo(); + ardSyCarVo.setId(ardSyCar.getId()); + ardSyCarVo.setCarId(carId); + ardSyCarVo.setCarBrand(ardSyCar.getCarBrand()); + ardSyCarVo.setCarModel(ardSyCar.getCarModel()); + ardSyCarVo.setCarPicture(ardSyCar.getCarPicture()); + ardSyCarVo.setCarType(ardSyCar.getCarType()); + ardSyCarVo.setDeptId(ardSyCar.getDeptId()); + ardSyCarVo.setRemark(ardSyCar.getRemark()); + ardSyCarVo.setCarPlate((String) list.get(j).get("carPlate")); + ardSyCarVoList.add(ardSyCarVo); + break; + } + } + } + if(ardSyCarParam.getCarPlate()!=null){ + List<ArdSyCarVo> newList = new ArrayList<>(); + for (int i = 0; i < ardSyCarVoList.size(); i++) { + String carPlate = ardSyCarVoList.get(i).getCarPlate(); + if(!carPlate.contains(ardSyCarParam.getCarPlate())){ + newList.add(ardSyCarVoList.get(i)); + } + } + ardSyCarVoList.removeAll(newList); + } + return AjaxResult.success(new PageInfo<>(ardSyCarVoList)); + }else { + return AjaxResult.error("31骞冲彴杩炴帴澶辫触锛岃溅鐗屽彿鑾峰彇澶辫触锛�",new PageInfo<>(ardSyCars)); + } } /** @@ -265,59 +328,26 @@ @Override public List<Map<String, String>> getAllCarModel() { - boolean exsit = MinioUtil.exitsBucket("sycar"); + boolean exsit = MinioUtil.exitsBucket("system"); if (exsit) { List<Map<String, String>> listObjetcName = new ArrayList<>(); try { - // ListObjectsArgs listObjectsArgs = ListObjectsArgs.builder().prefix("carmodel/").bucket("sycar").build(); - Iterable<Result<Item>> myObjects = MinioUtil.getObjectsByBucket("sycar","carmodel"); + //Iterable<Result<Item>> myObjects = MinioUtil.getObjectsByBucket("sycar","carmodel"); + Iterable<Result<Item>> myObjects = MinioUtil.getObjectsByBucket("system","model/car"); for (Result<Item> result : myObjects) { Item item = result.get(); Map<String, String> map = new HashMap(); String[] strArr = item.objectName().split("/"); - map.put("carType", strArr[1]); - map.put("carModel", "sycar/" + item.objectName()); - /*switch (item.objectName()) { - case "carmodel/aodi.glb": - map.put("carType", "濂ヨ开"); - break; - case "carmodel/baolai.glb": - map.put("carType", "瀹濇潵"); - break; - case "carmodel/bieke.glb": - map.put("carType", "鍒厠"); - break; - case "carmodel/bus1.glb": - map.put("carType", "澶у杞�"); - break; - case "carmodel/car.glb": - map.put("carType", "灏忓瀷杞�"); - break; - case "carmodel/fire(1).glb": - map.put("carType", "娑堥槻杞�"); - break; - case "carmodel/fute.glb": - map.put("carType", "绂忕壒"); - break; - case "carmodel/jingche_a.glb": - map.put("carType", "璀﹁溅"); - break; - case "carmodel/jiuhu.glb": - map.put("carType", "鏁戞姢杞�"); - break; - case "carmodel/oil.glb": - map.put("carType", "娌圭綈杞�"); - break; - case "carmodel/truck.glb": - map.put("carType", "宸ョ▼鐢ㄨ溅"); - break; - case "carmodel/van1.glb": - map.put("carType", "澶ц揣杞�"); - break; - default: - break; - }*/ - listObjetcName.add(map); + try{ + String carType = strArr[2]; + if(!carType.contains(".")){ + map.put("carType", carType); + map.put("carModel", "system/" + item.objectName()); + listObjetcName.add(map); + } + }catch(Exception e){ + e.printStackTrace(); + } } return listObjetcName; } catch (Exception ex) { @@ -411,13 +441,15 @@ public Map<String, Object> getArdSyCarAndDeptByCarId(String carId) { Map<String, Object> result = ardSyCarMapper.getArdSyCarAndDeptByCarId(carId); if (result != null) { - if (result.get("carPicture") != 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");*/ String carModel = this.minioEndpoint + "/" + (String) result.get("carModel"); result.put("carModel", carModel); } + }*/ + if(result.get("carModel") != null || "".equals(result.get("carModel"))){ + String carModel = this.minioEndpoint + "/" + (String) result.get("carModel"); + result.put("carModel", carModel); } } return result; @@ -481,7 +513,7 @@ * @return */ @Override - public Map<String, Object> allListByUser(ArdSyUser ardSyUser, String syURL, String usersId) { + public Map<String, Object> allListByUser(ArdSyUser ardSyUser, String syURL, String usersId, List<Long> deptList) { Map<String, Object> result0 = new HashMap(); //鍒ゆ柇鍏宠仈琛ㄦ槸鍚︽湁鏁版嵁 if (ardSyUser != null) { @@ -502,10 +534,29 @@ map.put("list", new ArrayList()); return map; } + QueryWrapper<ArdSyCar> queryWrapper = new QueryWrapper<>(); + queryWrapper.in("dept_id", deptList); + List<ArdSyCar> carListTable = ardSyCarMapper.selectList(queryWrapper); int online = 0; for (Map<String, Object> map : (List<Map<String, Object>>) result0.get("list")) { Map<String, Object> resultMap = sYClient.getTeamCarList(syURL, (String) map.get("teamId"), result.get("sessionId")); List<Map<String, Object>> carList = (List<Map<String, Object>>) resultMap.get("carList"); + if(carList.size()>0){ + for (int i = 0; i < carList.size(); i++) { + String carId = (String) carList.get(i).get("carId"); + Boolean isCar = false; + for (int j = 0; j < carListTable.size(); j++) { + ArdSyCar ardSyCar = carListTable.get(j); + if (carId.equals(ardSyCar.getCarId())) { + isCar = true; + break; + } + } + if(!isCar){ + carList.remove(carList.get(i)); + } + } + } for (Map<String, Object> m : carList) { if (((String) m.get("stateCn")).contains("鍦ㄧ嚎")) { online = online + 1; @@ -513,11 +564,12 @@ continue; } } - for (Map<String, Object> m : (List<Map<String, Object>>) result0.get("list")) { - if (((String) m.get("teamId")).equals(((String) map.get("teamId")))) { - map.put("count", Integer.parseInt((String) m.get("carNum"))); - } - } +// for (Map<String, Object> m : (List<Map<String, Object>>) result0.get("list")) { +// if (((String) m.get("teamId")).equals(((String) map.get("teamId")))) { +// map.put("count", Integer.parseInt((String) m.get("carNum"))); +// } +// } + map.put("count", carList.size()); map.put("online", online); online = 0; } @@ -621,10 +673,11 @@ queryWrapper.in("dept_id", deptList); List<ArdSyCar> carList = ardSyCarMapper.selectList(queryWrapper); //瀵规瘮鎶婂尮閰嶅埌鐨勬暟鎹坊鍔犲埌list涓� - for (Map<String, String> m : list) { - String carId = m.get("carId"); - for (int i = 0; i < carList.size(); i++) { - ArdSyCar ardSyCar = carList.get(i); + for (int i = 0; i < list.size(); i++) { + String carId = list.get(i).get("carId"); + Boolean isCar = false; + for (int j = 0; j < carList.size(); j++) { + ArdSyCar ardSyCar = carList.get(j); if (carId.equals(ardSyCar.getCarId())) { /*String url = ""; if (ardSyCar.getCarPicture() != null) { @@ -632,12 +685,17 @@ url = ardSyCar.getCarPicture().split("sycar")[0]; } }*/ - m.put("carModel", this.minioEndpoint + "/" + ardSyCar.getCarModel());//zns + list.get(i).put("carModel", this.minioEndpoint + "/" + ardSyCar.getCarModel());//zns //m.put("carModel",ardSyCar.getCarModel()); - m.put("carTypeArd", ardSyCar.getCarType()); - m.put("carBrand", ardSyCar.getCarBrand()); - m.put("carPicture", ardSyCar.getCarPicture()); + list.get(i).put("carTypeArd", ardSyCar.getCarType()); + list.get(i).put("carBrand", ardSyCar.getCarBrand()); + list.get(i).put("carPicture", ardSyCar.getCarPicture()); + isCar = true; + break; } + } + if(!isCar){ + list.remove(list.get(i)); } } return list; @@ -659,7 +717,12 @@ String passwordMd5 = DigestUtils.md5Hex(password31); Map<String, Object> result1 = sYClient.logIn(syURL, passwordMd5, username31); Map<String, Object> result0 = new HashMap(); - result0 = sYClient.getCarGPSTrack(syURL, carId, startTime, endTime, maxSpeed, (String) result1.get("sessionId")); + //result0 = sYClient.getCarGPSTrack(syURL, carId, startTime, endTime, maxSpeed, (String) result1.get("sessionId")); + try { + result0 = getCarGPSTrack(syURL, carId, startTime, endTime, maxSpeed, (String) result1.get("sessionId")); + } catch (Exception e) { + return Results.error("鏌ヨ鍘嗗彶鏁版嵁鏁伴噺杩囧瀵艰嚧瓒呮椂锛岃缂╁皬鑼冨洿鏌ヨ锛�"); + } List<Map<String, Object>> list = (List<Map<String, Object>>) result0.get("list"); if (list.isEmpty()) { return Results.succeed(); @@ -676,6 +739,37 @@ m.putAll(sgnMap); } return Results.succeed(list); + } + } + + public static Map<String,Object> getCarGPSTrack(String syURL,String carId,String startTime,String endTime,String maxSpeed,String sessionId){ + OkHttpClient okHttpClient = new OkHttpClient(); + + Request request = new Request.Builder() + .url(syURL + "/gps-web/api/get_gps_h.jsp?carId=" + carId + "&startTime=" + startTime + "&endTime=" + endTime + "&sessionId=" + sessionId) + .build(); + + Response response = null; + try { + response = okHttpClient.newCall(request).execute(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + response.headers(); //鍝嶅簲澶� + + ResponseBody responseBody = response.body(); + + try { + String message = responseBody.string();// 鍝嶅簲浣� + Map<String,Object> map = (Map<String, Object>) JSON.parse(message); + //System.out.println(message); + return map; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return new HashMap(); } } @@ -780,44 +874,108 @@ } @Override - public Results getCarGPSBycarId(String usersId, String carId, String syURL, ArdSyUser ardSyUser) { - Map<String, String> result = logInMap.get(Integer.parseInt(usersId)); + public Map<String, Object> 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(); + Map<String, String> 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); + return sYClient.getCarNearPositionByCarId(syURL, carId, result.get("userId"), result.get("sessionId")); } @Override - public Map<String, Object> getCarPicture(String carId, String syURL, ArdSyUser ardSyUser) { - //31鐢ㄦ埛鍚嶅瘑鐮� + public Map<String, Object> getCarPicture(String carId, String syURL, String sessionId) { + return sYClient.getCarPicture(syURL, carId, sessionId); + } + + @Override + public String getSessionId(String syURL,ArdSyUser ardSyUser) { String username31 = ardSyUser.getUserId(); String password31 = ardSyUser.getPassword(); String passwordMd5 = DigestUtils.md5Hex(password31); + System.out.println(passwordMd5); Map<String, Object> result1 = sYClient.logIn(syURL, passwordMd5, username31); - Map<String, Object> result0 = new HashMap(); - result0 = sYClient.getCarPicture(syURL, carId, (String) result1.get("sessionId")); - return result0; + return (String) result1.get("sessionId"); } + + @Override + public Map<String, Object> sendCmd(String userId,String syURL, String sessionId, String carId, List<String> channelList) throws UnsupportedEncodingException { +// for (int i = 0; i < channelList.size(); i++) { + Map<String,String> params = new HashMap(); + params.put("channel", channelList.get(1));//閫夋嫨閫氶亾1 + params.put("interval", "0");//姣忛殧0s鐓т竴娆� + params.put("photoNum", "1");//鐓�1寮� + params.put("action", "0");//涓婁紶妯″紡 + String paramsStr = com.alibaba.fastjson2.JSON.toJSONString(params); + paramsStr = URLEncoder.encode(paramsStr,"UTF-8"); + System.out.println("鎷嶇収鍙傛暟锛�"+paramsStr); + return sYClient.sendCmd(syURL,userId,carId,301,"MediaTake",paramsStr,sessionId); +// } +// return sendCmdMap; + } + + @Override + public Map<String, Object> getPhoto(String syURL, String carId, String sessionId,String startTime) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String endTime = sdf.format(new Date()); + System.out.println("寮�濮嬫椂闂达細"+startTime+" 缁撴潫鏃堕棿锛�"+endTime); + return sYClient.getPhoto(syURL,carId,startTime,endTime,sessionId); + } + + @Override + public Map<String, Object> getVideo(String syURL,String carId,ArdSyUser ardSyUser) { + //31鐢ㄦ埛鍚嶅瘑鐮� + String username = ardSyUser.getUserId(); + String password31 = ardSyUser.getPassword(); + String password = DigestUtils.md5Hex(password31); +// Map<String, Object> result1 = sYClient.logIn(syURL, passwordMd5, username31); + return sYClient.getVideo(syURL,username,password,"榛慐12401",1); + } + @Override public Results chaseCarByCarId(String usersId, String carId, String cycle) { + ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); + String userId =""; + String password = ""; + if(ardSyUser != null){ + userId = ardSyUser.getUserId(); + password = DigestUtils.md5Hex(ardSyUser.getPassword()); + }else{ + return Results.error("娌℃湁鎸傛帴涓変竴杞﹁締鐢ㄦ埛"); + } + List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); + String syURL = ""; + if(syURLResult.size() != 0){ + syURL = syURLResult.get(0).getConfigValue(); + }else{ + return Results.error("涓変竴杞﹁締鍦板潃鏈綍鍏�"); + } + + String sessionId = ""; + for(String key : ONLINE_USER_SESSIONS.keySet()){ + if(key.startsWith(usersId + "_")){ + sessionId = key; + } + } + if(sessionId.equals("")){//娌℃湁session灏辫繑鍥炲け璐� + return Results.error("杩借釜澶辫触"); + } 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); + Map<String,Object> loginResult = sYClient.logIn(syURL, password, userId); + String sySessionId = (String) loginResult.get("sessionId"); + String params = "%7B%220020%22:%220%22,%220029%22:%2230%22%7d"; + sYClient.changePositionSendMode(syURL, carId,104,"CmdSetParam",params,sySessionId);//鍋滄杩借釜锛屾敼涓哄畾鏃�30s鎺ㄩ�� + System.out.println("鍋滄杩借釜"); } return Results.succeed("鍋滄杩借釜"); } else { @@ -828,8 +986,32 @@ Map<String, Map<String, Object>> map = new HashMap(); map.put(carId, new HashMap()); PositionContainer.getUserPositionMap().put(usersId, map); + + Map<String,Object> loginResult = sYClient.logIn(syURL, password, userId); + String sySessionId = (String) loginResult.get("sessionId"); + List<SysConfig> distanceSYResult = sysConfigMapper.selectByType("31time"); + String time = ""; + if(distanceSYResult.size() != 0){ + time = distanceSYResult.get(0).getConfigValue(); + }else{ + return Results.error("涓変竴杞﹁締瀹氭椂鏈綍鍏�"); + } + String params = "%7B%220020%22:%220%22,%220029%22:%22"+time+"%22%7d"; + sYClient.changePositionSendMode(syURL, carId,104,"CmdSetParam",params,sySessionId);//寮�濮嬭拷韪紝鏀逛负瀹氭椂鎺ㄩ�� + + Map<String, Object> position = PositionContainer.getCarPositionMap().get(carId);//鏌ヨ褰撳墠杞﹁締浣嶇疆 + if (position != null) { + if (position.size() != 0) { + position.put("elng",position.get("lng")); + position.put("elat",position.get("lat")); + Map<String, Map<String, Object>> data = new HashMap(); + data.put("31000", position); + WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(sessionId), JSON.toJSONString(data)); + } + } + Date date = new Date(); - Timer carPositionTimer = new Timer();//瀹氭椂鎺ㄩ�佸疄鏃朵綅缃� + Timer carPositionTimer = new Timer(sessionId);//瀹氭椂鎺ㄩ�佸疄鏃朵綅缃� TimerTask carPositionTask = new TimerTask() { @Override public void run() { @@ -838,7 +1020,35 @@ 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)); + String sessionId = Thread.currentThread().getName(); + if(ONLINE_USER_SESSIONS.get(sessionId) == null){//鐢ㄦ埛绂荤嚎閲婃斁璧勬簮 + if (userCarTimerMap.get(usersId) != null) { + userCarTimerMap.get(usersId).cancel(); + userCarTimerMap.remove(usersId); + PositionContainer.getUserPositionMap().remove(usersId); + + ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); + String userId =""; + String password = ""; + if(ardSyUser != null){ + userId = ardSyUser.getUserId(); + password = ardSyUser.getPassword(); + } + List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); + String syURL = ""; + if(syURLResult.size() != 0){ + syURL = syURLResult.get(0).getConfigValue(); + } + if(!userId.equals("") && !password.equals("") && !syURL.equals("")){ + Map<String,Object> loginResult = sYClient.logIn(syURL, password, userId); + String sySessionId = (String) loginResult.get("sessionId"); + String params = "%7B%220020%22:%220%22,%220029%22:%2230%22%7d"; + sYClient.changePositionSendMode(syURL, carId,104,"CmdSetParam",params,sySessionId);//鍋滄杩借釜锛屾敼涓哄畾鏃�30s + } + System.out.println("鐢ㄦ埛绂荤嚎锛屽仠姝㈣拷韪�"); + } + } + WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(sessionId), JSON.toJSONString(data)); } } } @@ -850,8 +1060,32 @@ Map<String, Map<String, Object>> map = new HashMap(); map.put(carId, new HashMap()); PositionContainer.getUserPositionMap().put(usersId, map); + + Map<String,Object> loginResult = sYClient.logIn(syURL, password, userId); + String sySessionId = (String) loginResult.get("sessionId"); + List<SysConfig> distanceSYResult = sysConfigMapper.selectByType("31time"); + String time = ""; + if(distanceSYResult.size() != 0){ + time = distanceSYResult.get(0).getConfigValue(); + }else{ + return Results.error("涓変竴杞﹁締瀹氭椂鏈綍鍏�"); + } + String params = "%7B%220020%22:%220%22,%220029%22:%22"+time+"%22%7d"; + sYClient.changePositionSendMode(syURL, carId,104,"CmdSetParam",params,sySessionId);//寮�濮嬭拷韪紝鏀逛负瀹氭椂鎺ㄩ�� + + Map<String, Object> position = PositionContainer.getCarPositionMap().get(carId);//鏌ヨ褰撳墠杞﹁締浣嶇疆 + if (position != null) { + if (position.size() != 0) { + position.put("elng",position.get("lng")); + position.put("elat",position.get("lat")); + Map<String, Map<String, Object>> data = new HashMap(); + data.put("31000", position); + WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(sessionId), JSON.toJSONString(data)); + } + } + Date date = new Date(); - Timer carPositionTimer = new Timer();//瀹氭椂鎺ㄩ�佸疄鏃朵綅缃� + Timer carPositionTimer = new Timer(sessionId);//瀹氭椂鎺ㄩ�佸疄鏃朵綅缃� TimerTask carPositionTask = new TimerTask() { @Override public void run() { @@ -860,7 +1094,35 @@ 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)); + String sessionId = Thread.currentThread().getName(); + if(ONLINE_USER_SESSIONS.get(sessionId) == null){//鐢ㄦ埛绂荤嚎閲婃斁璧勬簮 + if (userCarTimerMap.get(usersId) != null) { + userCarTimerMap.get(usersId).cancel(); + userCarTimerMap.remove(usersId); + PositionContainer.getUserPositionMap().remove(usersId); + + ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); + String userId =""; + String password = ""; + if(ardSyUser != null){ + userId = ardSyUser.getUserId(); + password = ardSyUser.getPassword(); + } + List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); + String syURL = ""; + if(syURLResult.size() != 0){ + syURL = syURLResult.get(0).getConfigValue(); + } + if(!userId.equals("") && !password.equals("") && !syURL.equals("")){ + Map<String,Object> loginResult = sYClient.logIn(syURL, password, userId); + String sySessionId = (String) loginResult.get("sessionId"); + String params = "%7B%220020%22:%220%22,%220029%22:%2230%22%7d"; + sYClient.changePositionSendMode(syURL, carId,104,"CmdSetParam",params,sySessionId);//鍋滄杩借釜锛屾敼涓哄畾鏃�30s + } + System.out.println("鐢ㄦ埛绂荤嚎锛屽仠姝㈣拷韪�"); + } + } + WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(sessionId), JSON.toJSONString(data)); } } } @@ -1184,4 +1446,87 @@ return ardSyCarMapper.selectList(queryWrapper); } + @Override + public Map<String, Object> getAlarmHPfmCountDetail(String sessionId, String usersId, String carId, String startTime, String endTime, String syURL) { +// System.out.println("sessionId------"+sessionId+",usersId-----"+usersId+",carId-----"+carId+",startTime----"+startTime+",endTime----"+endTime+",syURL----"+syURL); + return sYClient.getAlarmHPfmCountDetail(syURL,carId,sessionId,startTime,endTime); + } + + @Override + public Map<String, Object> getOnlineSYCarPosition(String soilderId) { + Map<String,Object> result = new HashMap(); + ArdSyUser ardSyUserPara = new ArdSyUser(); + ardSyUserPara.setSysUserId(soilderId); + List<ArdSyUser> ardSyUserList = ardSyUserMapper.selectArdSyUserList(ardSyUserPara); + if(ardSyUserList.size() == 0){ + result.put("code","0"); + result.put("msg","鐧诲綍鐢ㄦ埛鏈寕鎺ヤ笁涓�杞﹁締璐﹀彿"); + result.put("SYCarPositionList",new ArrayList()); + return result; + } + ArdAppApplication ardAppApplicationPara = new ArdAppApplication(); + ardAppApplicationPara.setSoilderId(soilderId); + ardAppApplicationPara.setApplicationType("SYCar"); + ardAppApplicationPara.setState("1"); + List<ArdAppApplication> ardAppApplicationList = ardAppApplicationMapper.selectArdAppApplicationList(ardAppApplicationPara); + if(ardAppApplicationList.size() == 0){ + result.put("code","0"); + result.put("msg","鐧诲綍鐢ㄦ埛鏈粡鎸囨尌绔悓鎰�"); + result.put("SYCarPositionList",new ArrayList()); + return result; + } + SysUser sysUser = userMapper.selectUserById(soilderId);//鑾峰彇绯荤粺鐢ㄦ埛 + List<Long> deptIdList = new ArrayList(); + deptIdList.add(sysUser.getDeptId()); + deptIdList = getOwnAndChildrenDeptIdList(deptIdList,new ArrayList());//閫掑綊鏌ヨ涓嬪睘閮ㄩ棬涓婚敭 + List<String> carIdList = ardSyCarMapper.selectArdSyCarByDeptIds(deptIdList); + String carIds = ""; + for(String carId : carIdList){ + carIds = carIds + carId + ","; + } + carIds = carIds.substring(0,carIds.length() - 1); + String syURL = ""; + List<SysConfig> sysConfigResult = sysConfigMapper.selectByType("syCarPT"); + if(sysConfigResult.size() > 0){ + syURL = sysConfigResult.get(0).getConfigValue(); + }else{ + result.put("code","0"); + result.put("msg","涓変竴杞﹁締url娌℃湁褰曞叆"); + result.put("SYCarPositionList",new ArrayList()); + return result; + } + String passwordMd5 = DigestUtils.md5Hex(ardSyUserList.get(0).getPassword()); + Map<String,Object> syLoginResult = sYClient.logIn(syURL, passwordMd5, ardSyUserList.get(0).getUserId()); + String sessionId = (String) syLoginResult.get("sessionId"); + Map<String,Object> carNearPositionResult = sYClient.getCarNearPositionByCarId(syURL, carIds, ardSyUserList.get(0).getUserId(),sessionId); + if(((String)carNearPositionResult.get("rspCode")).equals("1")){ + result.put("code","1"); + result.put("msg","涓変竴杞﹁締鏌ヨ鎴愬姛"); + List<Map<String,Object>> SYCarPositionList = (List<Map<String, Object>>) carNearPositionResult.get("list"); + //绛涢�夊湪绾� + SYCarPositionList = SYCarPositionList.stream().filter(map -> ((String)map.get("stateCn")).startsWith("鍦ㄧ嚎")).collect(Collectors.toList()); + for(Map<String,Object> sycar : SYCarPositionList){ + Map<String,Object> map = ardSyCarMapper.getArdSyCarAndDeptByCarId((String)sycar.get("carId")); + sycar.putAll(map); + } + result.put("SYCarPositionList",SYCarPositionList); + return result; + }else{ + result.put("code","0"); + result.put("msg","涓変竴杞﹁締鏌ヨ澶辫触"); + result.put("SYCarPositionList",new ArrayList()); + return result; + } + } + + public List<Long> getOwnAndChildrenDeptIdList(List<Long> deptIdList,List<Long> deptIdListr){ + deptIdListr.addAll(deptIdList); + List<Long> result = sysDeptMapper.getChildrenDeptIdList(deptIdList); + if(result.size() != 0){ + deptIdListr.addAll(result); + result = getOwnAndChildrenDeptIdList(result,deptIdListr); + } + deptIdListr = deptIdListr.stream().distinct().collect(Collectors.toList()); + return deptIdListr; + } } -- Gitblit v1.9.3