| | |
| | | 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; |
| | | |
| | |
| | | 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; |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |