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 |  137 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 132 insertions(+), 5 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 69cf50d..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
@@ -346,7 +346,7 @@
                             listObjetcName.add(map);
                         }
                     }catch(Exception e){
-
+                        e.printStackTrace();
                     }
                 }
                 return listObjetcName;
@@ -441,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;
@@ -715,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();
@@ -732,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();
         }
     }
 
@@ -901,6 +939,23 @@
 
     @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 + "_")){
@@ -916,6 +971,10 @@
                     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("鍋滄杩借釜");
@@ -927,9 +986,24 @@
                     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));
@@ -952,6 +1026,25 @@
                                             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("鐢ㄦ埛绂荤嚎锛屽仠姝㈣拷韪�");
                                         }
                                     }
@@ -967,9 +1060,24 @@
                     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));
@@ -992,6 +1100,25 @@
                                             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("鐢ㄦ埛绂荤嚎锛屽仠姝㈣拷韪�");
                                         }
                                     }

--
Gitblit v1.9.3