From 21911c83c53ce1b187439f1895c31c6bb74a54f3 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期六, 05 八月 2023 21:46:10 +0800
Subject: [PATCH] 三一车辆查询有历史轨迹日期提交
---
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java | 10 ++
ard-work/src/main/java/com/ruoyi/sy/service/IArdSyCarService.java | 5 +
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java | 172 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 187 insertions(+), 0 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
index 2cd4eef..9fc5f1c 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -378,4 +378,14 @@
String cycle = map.get("cycle");
return ardSyCarService.chaseCarByCarId(usersId,carId,cycle);
}
+
+ @PreAuthorize("@ss.hasPermi('sy:syCar:getExistTraceByCarIdAndMonth')")
+ @PostMapping("getExistTraceByCarIdAndMonth")
+ @ApiOperation("鏍规嵁杞﹁締涓婚敭鍙婃湀浠芥煡璇㈣建杩瑰瓨鍦�")
+ public Results getExistTraceByCarIdAndMonth(@RequestBody Map<String,String> map){
+ String userId = SecurityUtils.getUserId();
+ String carId = map.get("carId");
+ String time = map.get("time");
+ return ardSyCarService.getExistTraceByCarIdAndMonth(userId,carId,time);
+ }
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/IArdSyCarService.java b/ard-work/src/main/java/com/ruoyi/sy/service/IArdSyCarService.java
index 1e33ba0..247a4b9 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/IArdSyCarService.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/IArdSyCarService.java
@@ -130,4 +130,9 @@
*/
Results chaseCarByCarId(String usersId,String carId,String cycle);
+ /**
+ * 鏍规嵁鏃堕棿鍙婅溅杈嗕富閿煡璇㈣鏈堟瘡澶╂槸鍚︽湁杞ㄨ抗
+ */
+ public Results getExistTraceByCarIdAndMonth(String userId,String carId,String time);
+
}
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 1e332cc..bf45df9 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
@@ -1,7 +1,12 @@
package com.ruoyi.sy.service.impl;
+import java.io.IOException;
import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -26,6 +31,10 @@
import io.minio.Result;
import io.minio.http.Method;
import io.minio.messages.Item;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.sy.mapper.ArdSyCarMapper;
@@ -788,4 +797,167 @@
return Results.error("杩借釜澶辫触");
}
}
+
+ @Override
+ public Results getExistTraceByCarIdAndMonth(String userId, String carId, String time) {
+ SysConfig config = new SysConfig();
+ config.setConfigKey("syCarPT");
+ List<SysConfig> sysConfigResult = sysConfigMapper.selectConfigList(config);
+ String syURL = "";
+ if(sysConfigResult.size() == 0){
+ return Results.succeed("涓変竴杞﹁締url娌℃湁褰曞叆");
+ }else{
+ syURL = sysConfigResult.get(0).getConfigValue();
+ ArdSyUser ardSyUserPara = new ArdSyUser();
+ ardSyUserPara.setSysUserId(userId);
+ List<ArdSyUser> ardSyUserList = ardSyUserMapper.selectArdSyUserList(ardSyUserPara);
+ if(ardSyUserList.size() == 0){
+ return Results.succeed("鐢ㄦ埛鏈寕鎺ヤ笁涓�杞﹁締");
+ }else{
+ ArdSyUser ardSyUser = ardSyUserList.get(0);
+ String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword());
+ Map<String,Integer> existTraceMap = getExistTraceByCarIdAndMonth(syURL,ardSyUser.getUserId(),passwordMd5,carId,time);
+ return Results.succeed(existTraceMap);
+ }
+ }
+ }
+
+ public Map<String,Integer> getExistTraceByCarIdAndMonth(String url,String usersId,String password,String carId,String time){
+ Map<String,Object> LogInResult = sYClient.logIn(url,password,usersId);
+ String sessionId = (String) LogInResult.get("sessionId");
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ Date date = null;
+ try {
+ date = sdf.parse(time);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//鑾峰彇璇ユ湀澶╂暟
+ Map<String,Integer> existTraceMap = new HashMap();
+ ExecutorService newCachedThreadPoll = Executors.newCachedThreadPool();
+ for (int i = 1; i <= maxDay; i = i + 7) {
+ int temp = i;
+ String finalTime = time.replace("-","");
+ String finalsyURL = url;
+ newCachedThreadPoll.execute(new Runnable(){
+ @Override
+ public void run() {
+ int temp0 = temp + 6;
+ if(temp0 > maxDay){
+ temp0 = maxDay;
+ }
+ for (int j = temp; j <= temp0; j++) {
+ if(j <= 9){
+ existTraceMap.put("0" + String.valueOf(j), -1);
+ }else{
+ existTraceMap.put(String.valueOf(j), -1);
+ }
+ }
+ if(temp <= 9){
+ if(temp0 <= 9){
+ String startTime = finalTime + "0" + temp + "000000";
+ String endTime = finalTime + "0" + temp0 + "235959";
+ Map<String,Object> result = getCarGPSTrack(finalsyURL,carId,startTime,endTime,sessionId);
+ String rspCode = (String)result.get("rspCode");
+ if(rspCode.equals("1")){
+ List<Map<String,Object>> list = (List<Map<String, Object>>) result.get("list");
+ for(Map<String,Object> m : list){
+ String time = (String) m.get("time");
+ time = time.split(" ")[0];
+ time = time.split("-")[2];
+ existTraceMap.put(time, 1);
+ }
+ }
+ }else{
+ String startTime = finalTime + "0" + temp + "000000";
+ String endTime = finalTime + temp0 + "235959";
+ Map<String,Object> result = getCarGPSTrack(finalsyURL,carId,startTime,endTime,sessionId);
+ String rspCode = (String)result.get("rspCode");
+ if(rspCode.equals("1")){
+ List<Map<String,Object>> list = (List<Map<String, Object>>) result.get("list");
+ for(Map<String,Object> m : list){
+ String time = (String) m.get("time");
+ time = time.split(" ")[0];
+ time = time.split("-")[2];
+ existTraceMap.put(time, 1);
+ }
+ }
+ }
+ }else{
+ String startTime = finalTime + temp + "000000";
+ String endTime = finalTime + temp0 + "235959";
+ Map<String,Object> result = getCarGPSTrack(finalsyURL,carId,startTime,endTime,sessionId);
+ String rspCode = (String)result.get("rspCode");
+ if(rspCode.equals("1")){
+ List<Map<String,Object>> list = (List<Map<String, Object>>) result.get("list");
+ for(Map<String,Object> m : list){
+ String time = (String) m.get("time");
+ time = time.split(" ")[0];
+ time = time.split("-")[2];
+ existTraceMap.put(time, 1);
+ }
+ }
+ }
+ for(int j = temp; j <= temp0; j++){
+ String key = "";
+ if(j <= 9){
+ key = "0" + j;
+ }else{
+ key = String.valueOf(j);
+ }
+ if(existTraceMap.get(key) == -1){
+ existTraceMap.put(key, 0);
+ }
+
+ }
+ }
+ });
+ }
+ while(true){
+ if(!existTraceMap.values().contains(-1)){
+ if(existTraceMap.size() == maxDay){
+ break;
+ }
+ }
+ }
+ try {
+ return existTraceMap;
+ } finally {
+ newCachedThreadPoll.shutdown();
+ }
+ }
+
+ public static Map<String,Object> getCarGPSTrack(String syURL,String carId,String startTime,String endTime,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+"&filter0=true&maxSpeed=&stopLong=5&queryAlarm=false&userId=yanshi&loginType=user&loginWay=android&loginLang=zh_CN&appDevId=&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();
+ }
+ }
}
--
Gitblit v1.9.3