RouteServiceImpl.java 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. package com.steerinfo.route.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.steerinfo.dil.service.ITmstruckLeaveFactoryResultService;
  5. import com.steerinfo.framework.controller.RESTfulResult;
  6. import com.steerinfo.route.service.RouteService;
  7. import com.steerinfo.route.threeRequest.ZhongJiaoXingLu;
  8. import com.steerinfo.route.util.DataConversionTool;
  9. import com.steerinfo.route.util.HTTPRequestUtils;
  10. import com.steerinfo.route.util.LngLonUtil;
  11. import com.steerinfo.route.vo.FullPathVisualizationTo.ViewVisualization;
  12. import com.steerinfo.route.vo.Map.Point;
  13. import com.steerinfo.route.vo.Map.RouteVo;
  14. import com.steerinfo.route.vo.Map.RunRoutePoint;
  15. import com.steerinfo.route.vo.Map.StartAndEndRoute;
  16. import com.steerinfo.route.vo.resultJson.SearchPoint;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.data.redis.core.RedisTemplate;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.util.StringUtils;
  22. import java.math.BigDecimal;
  23. import java.net.URLEncoder;
  24. import java.text.SimpleDateFormat;
  25. import java.util.*;
  26. import java.util.concurrent.CompletableFuture;
  27. import java.util.concurrent.TimeUnit;
  28. import java.util.stream.Collectors;
  29. @Service(value = "xmsService")
  30. public class RouteServiceImpl implements RouteService {
  31. @Autowired
  32. private RedisTemplate redisTemplate;
  33. @Autowired
  34. private ZhongJiaoXingLu zhongJiaoXingLu;
  35. @Autowired
  36. private ITmstruckLeaveFactoryResultService tmstruckLeaveFactoryResultService;
  37. @Value("${str.tengxun.key}")
  38. private String key;
  39. @Value("${redis.prefix.order}")
  40. private String prefixOrder;
  41. @Value("${redis.prefix.line}")
  42. private String prefixLine;
  43. @Value("${redis.prefix.suffix}")
  44. private String suffix;
  45. //必须参数 运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress
  46. public CompletableFuture<String> createTotalResult(Map mapValue) throws Exception {
  47. if (mapValue.containsKey("capacityNumber")&&mapValue.containsKey("receiveAddress")&&mapValue.containsKey("shipperName")&&mapValue.containsKey("orderNumber")){
  48. }
  49. //carryno车牌号 ,gatepostName 门岗名称 resultOutGateTime出门时间
  50. SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  51. if (true) {
  52. //创建物质信息需要字段(本地字段名称:视图字段名称 中文解释) unitOfMeasureDesc单位、materialName:cMaterieldes:名称、 materialSpecification:cSpec:规格、materialModel:cMaterielcode:型号,
  53. HashMap materieldesMap=new HashMap();
  54. // System.out.println("https://apis.map.qq.com/ws/geocoder/v1/"+"address="+ URLEncoder.encode(vcMeasurerec.getcSupplydes(),"utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  55. //创建托运人需要字段 (本地字段名称:视图字段名称 中文解释)cSupplyid:shipperCode 托运方代码 、cSupplydes:shipperName 托运方名称、addressLongitude 托运方地址经度、addressLatitude托运方地址纬度
  56. String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode(mapValue.get("shipperName")==null?"安钢集团信阳钢铁有限责任公司":mapValue.get("shipperName").toString(),"utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  57. SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class);
  58. if (searchPoint.getStatus()==0){
  59. materieldesMap.put("addressLongitude",searchPoint.getResult().getLocation().getLng());
  60. materieldesMap.put("addressLatitude",searchPoint.getResult().getLocation().getLat());
  61. }else {
  62. materieldesMap.put("addressLongitude",new BigDecimal(114.036293));
  63. materieldesMap.put("addressLatitude",new BigDecimal(32.483276));
  64. }
  65. //创建收货地址需要的字段 addressProvince 省份、addressDistrict 市区、addressTown 县镇 、addressDeliveryAddress 收货地址、 addressLongitude 收货地址经度、addressLatitude 收货地址纬度
  66. String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode(mapValue.get("receiveAddress").toString()==null?"长沙市":mapValue.get("receiveAddress").toString(),"utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  67. SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class);
  68. if (searchPoint2.getStatus()==0&&searchPoint2.getResult()!=null){
  69. System.out.println(searchPoint2);
  70. if (searchPoint2.getResult().getAddress_components()!=null){
  71. materieldesMap.put("addressProvince",searchPoint2.getResult().getAddress_components().getProvince()==null?"湖南省":searchPoint2.getResult().getAddress_components().getProvince());
  72. materieldesMap.put("addressDistrict",searchPoint2.getResult().getAddress_components().getDistrict()==null?"开福区":searchPoint2.getResult().getAddress_components().getDistrict());
  73. materieldesMap.put("addressTown",searchPoint2.getResult().getAddress_components().getCity()==null?"长沙市":searchPoint2.getResult().getAddress_components().getCity());
  74. }else {
  75. materieldesMap.put("addressProvince","湖南省");
  76. materieldesMap.put("addressDistrict","开福区");
  77. materieldesMap.put("addressTown","长沙市");
  78. }
  79. materieldesMap.put("addressDeliveryAddress",mapValue.get("receiveAddress").toString()==null?"长沙市":mapValue.get("receiveAddress").toString());
  80. if (searchPoint2.getResult().getLocation()!=null){
  81. materieldesMap.put("addressLongitude",searchPoint2.getResult().getLocation().getLng()==null?new BigDecimal(112.98626):searchPoint2.getResult().getLocation().getLng());
  82. materieldesMap.put("addressLatitude",searchPoint2.getResult().getLocation().getLat()==null?new BigDecimal(28.25591):searchPoint2.getResult().getLocation().getLat());
  83. }else {
  84. materieldesMap.put("addressLongitude",new BigDecimal(112.98626));
  85. materieldesMap.put("addressLatitude",new BigDecimal(28.25591));
  86. }
  87. if (searchPoint2.getResult().getAd_info()!=null){
  88. materieldesMap.put("destCode",searchPoint2.getResult().getAd_info().getAdcode()==null?"无信息":searchPoint2.getResult().getAd_info().getAdcode());
  89. }else {
  90. materieldesMap.put("destCode","无信息");
  91. }
  92. }else {
  93. //114.03629,32.48327","endLonlat":",28.25591"}
  94. materieldesMap.put("addressProvince","湖南省");
  95. materieldesMap.put("addressDistrict","开福区");
  96. materieldesMap.put("addressTown","长沙市");
  97. materieldesMap.put("destCode","430105");
  98. materieldesMap.put("addressDeliveryAddress","长沙市");
  99. materieldesMap.put("addressLongitude",new BigDecimal(112.98626));
  100. materieldesMap.put("addressLatitude",new BigDecimal(28.25591));
  101. }
  102. //入网验证
  103. String netValidationResult = zhongJiaoXingLu.netValidation(mapValue.get("capacityNumber").toString());
  104. Map netValidationMap = (Map) JSONObject.parse(netValidationResult);
  105. if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){
  106. //运单生成之后保存
  107. HashMap<String,String> redisMap=new HashMap<>();
  108. String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString();
  109. String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString();
  110. redisMap.put("startLonlat", startLon+","+startLat);
  111. String endLon= materieldesMap.get("addressLongitude").toString().length()>9?materieldesMap.get("addressLongitude").toString().substring(0,9):materieldesMap.get("addressLongitude").toString();
  112. String endLat= materieldesMap.get("addressLatitude").toString().length()>9?materieldesMap.get("addressLatitude").toString().substring(0,8):materieldesMap.get("addressLatitude").toString();
  113. redisMap.put("endLonlat",endLon+","+endLat);
  114. redisMap.put("vclN", mapValue.get("capacityNumber").toString());
  115. redisMap.put("vco","2");
  116. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  117. String qryBtm=mapValue.get("resultOutGateTime").toString();
  118. //获得两天、23小时、45分钟之后的时间
  119. Date parse = simpleDateFormat.parse(qryBtm);
  120. //时间添加
  121. Calendar calendar = Calendar.getInstance();
  122. calendar.setTime(parse);
  123. //calendar.add(Calendar.DAY_OF_MONTH, 2);
  124. calendar.add(Calendar.HOUR_OF_DAY, 23);
  125. calendar.add(Calendar.SECOND, 45);
  126. //计算时间差
  127. long agetime = parse.getTime();
  128. long lateTime = calendar.getTimeInMillis();
  129. //两天、23小时、45分钟之后的时间差毫秒
  130. long reductionTime1=lateTime-agetime;
  131. long currentTime = new Date().getTime();
  132. //减去已经过的时间(毫秒)
  133. long reductionTime2=currentTime-agetime;
  134. //redis 存储的时间(秒)
  135. long saveTime=(reductionTime1-reductionTime2)/1000;
  136. redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm)));
  137. String qryEtm= simpleDateFormat.format(calendar.getTime());
  138. redisMap.put("qryEtm",qryEtm );
  139. String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString();
  140. String redisJson=JSON.toJSONString(redisMap);
  141. if (saveTime>0){
  142. redisTemplate.opsForValue().set(orderUrl, redisJson, saveTime, TimeUnit.SECONDS);
  143. }else {
  144. redisTemplate.opsForValue().set(orderUrl, redisJson, 36000, TimeUnit.SECONDS);
  145. }
  146. redisTemplate.opsForValue().set(orderUrl+suffix, redisJson);
  147. //预警开关判断0开启1关闭
  148. // if(checkTurnOff(vcMeasurerec.getcMaterieldes(),resTfulResultValues.get("switch").toString())){
  149. //
  150. // redisMap.put("startCode",searchPoint.getResult().getAd_info().getAdcode());
  151. // redisMap.put("destCode",materieldesMap.get("destCode").toString());
  152. // redisMap.put("qryBtm",parse.toString());
  153. // redisMap.put("qryEtm",calendar.getTime().toString());
  154. // redisMap.put("type",resTfulResultValues.get("type").toString());
  155. // String subAbnormalLineWarnV2Json = zhongJiaoXingLu.subAbnormalLineWarnV2(redisMap);
  156. //
  157. // JSONObject jsonObject = JSONObject.parseObject(subAbnormalLineWarnV2Json);
  158. //
  159. //
  160. // if (jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")){
  161. // HashMap<String,Object> tripMap=new HashMap();
  162. // tripMap.put("orderNumber",tmsData.get("orderNumber").toString());
  163. // tripMap.put("rid",jsonObject.get("result").toString());
  164. // omsFeign.insertOrderTripId(tripMap);
  165. // }
  166. // }
  167. }
  168. return CompletableFuture.completedFuture("successful");
  169. }
  170. return CompletableFuture.completedFuture("fail");
  171. }
  172. /**
  173. *
  174. * @param matrial 物质名称
  175. * @param selectStr 0,没有选1"带钢",2"微粉",3("螺纹钢","盘螺","盘圆"),4"钢坯",5"其他"
  176. */
  177. public boolean checkTurnOff(String matrial,String selectStr) {
  178. //0,没有选1"带钢",2"微粉",3("螺纹钢","盘螺","盘圆"),4"钢坯",5"其他"
  179. int index=0;
  180. String[] matrialList=new String[]{"带钢","微粉","螺纹钢","盘螺","盘圆","钢坯","其他"};
  181. //判断是那种物质
  182. lable:for (int i=0;i<matrialList.length;i++){
  183. if (matrial.contains(matrialList[i])) {
  184. if(4>=i&&i>=2){
  185. //螺纹钢
  186. index=3;
  187. }else if (i==5){
  188. //钢坯
  189. index=4;
  190. }else if (i==6) {
  191. //其他
  192. index=5;
  193. }else{
  194. index=i+1;
  195. }
  196. break lable;
  197. }
  198. }
  199. //判断是否选择这种物质
  200. if (index!=0&&selectStr.contains(String.valueOf(index))){
  201. return true;
  202. }
  203. return false;
  204. }
  205. /**
  206. * 必须参数 运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress
  207. * @param mapValue
  208. * @return
  209. * @throws Exception
  210. */
  211. @Override
  212. public CompletableFuture<String> saveRoute(Map mapValue) throws Exception {
  213. //获得起点的经纬度和code
  214. SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  215. Date gateTime = dateFormat.parse(mapValue.get("resultOutGateTime").toString());
  216. String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(mapValue.get("shipperName").toString()==null?"四川省达州钢铁集团有限责任公司":mapValue.get("shipperName").toString(),"utf-8")+"&key="+key);
  217. SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class);
  218. //创建收货地址 addressProvince 省份、addressDistrict 市区、addressTown 县镇 、addressDeliveryAddress 收货地址、 addressLongitude 收货地址经度、addressLatitude 收货地址纬度
  219. String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(mapValue.get("receiveAddress").toString()==null?"长沙市":mapValue.get("receiveAddress").toString(),"utf-8")+"&key="+key);
  220. SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class);
  221. //入网验证
  222. String netValidationResult = zhongJiaoXingLu.netValidation(mapValue.get("capacityNumber").toString());
  223. Map netValidationMap = (Map) JSONObject.parse(netValidationResult);
  224. if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){
  225. //运单生成之后保存
  226. HashMap<String, String> redisMap=new HashMap<>();
  227. redisMap.put("startLonlat", searchPoint.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint.getResult().getLocation().getLat().toString().substring(0,8));
  228. redisMap.put("endLonlat", searchPoint2.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint2.getResult().getLocation().getLat().toString().substring(0,8));
  229. redisMap.put("vclN", mapValue.get("capacityNumber").toString());
  230. redisMap.put("vco","2");
  231. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  232. String qryBtm=mapValue.get("resultOutGateTime").toString();
  233. //获得两天、23小时、45分钟之后的时间
  234. Date parse = simpleDateFormat.parse(qryBtm);
  235. //时间添加
  236. Calendar calendar = Calendar.getInstance();
  237. calendar.setTime(parse);
  238. calendar.add(Calendar.DAY_OF_MONTH, 2);
  239. calendar.add(Calendar.HOUR_OF_DAY, 23);
  240. calendar.add(Calendar.SECOND, 45);
  241. //计算时间差
  242. long agetime = parse.getTime();
  243. long lateTime = calendar.getTimeInMillis();
  244. //两天、23小时、45分钟之后的时间差毫秒
  245. long reductionTime1=lateTime-agetime;
  246. long currentTime = new Date().getTime();
  247. //减去已经过的时间(毫秒)
  248. long reductionTime2=currentTime-agetime;
  249. //redis 存储的时间(秒)
  250. long saveTime=(reductionTime1-reductionTime2)/1000;
  251. redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm)));
  252. String qryEtm= simpleDateFormat.format(calendar.getTime());
  253. redisMap.put("qryEtm",qryEtm );
  254. String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString();
  255. String redisJson= JSON.toJSONString(redisMap);
  256. //保存请求中交的参数
  257. redisTemplate.opsForValue().set(orderUrl, redisJson, saveTime, TimeUnit.SECONDS);
  258. redisTemplate.opsForValue().set(orderUrl+suffix, redisJson);
  259. //预警开关判断0开启1关闭
  260. if(mapValue.get("turnOf").toString().equals("0")){
  261. redisMap.put("startCode",searchPoint.getResult().getAd_info().getAdcode());
  262. redisMap.put("destCode",searchPoint2.getResult().getAd_info().getAdcode());
  263. redisMap.put("qryBtm",parse.toString());
  264. redisMap.put("qryEtm",calendar.getTime().toString());
  265. String subAbnormalLineWarnV2Json = zhongJiaoXingLu.subAbnormalLineWarnV2(redisMap);
  266. JSONObject jsonObject = JSONObject.parseObject(subAbnormalLineWarnV2Json);
  267. if (jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")) {
  268. HashMap<String, Object> tripMap = new HashMap();
  269. tripMap.put("orderNumber", mapValue.get("orderNumber").toString());
  270. tripMap.put("rid", jsonObject.get("result").toString());
  271. //omsFeign.insertOrderTripId(tripMap);
  272. }
  273. }
  274. return CompletableFuture.completedFuture("successful");
  275. }
  276. return CompletableFuture.completedFuture("fail");
  277. }
  278. /**
  279. * 必须参数 运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress
  280. * @param mapValue
  281. * @return
  282. * @throws Exception
  283. */
  284. @Override
  285. public CompletableFuture<String> saveRequstionDate(Map mapValue) throws Exception {
  286. //获得起点的经纬度和code
  287. SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  288. Date gateTime = dateFormat.parse(mapValue.get("resultOutGateTime").toString());
  289. String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(mapValue.get("shipperName").toString()==null?"四川省达州钢铁集团有限责任公司":mapValue.get("shipperName").toString(),"utf-8")+"&key="+key);
  290. SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class);
  291. //创建收货地址 addressProvince 省份、addressDistrict 市区、addressTown 县镇 、addressDeliveryAddress 收货地址、 addressLongitude 收货地址经度、addressLatitude 收货地址纬度
  292. String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(mapValue.get("receiveAddress").toString()==null?"长沙市":mapValue.get("receiveAddress").toString(),"utf-8")+"&key="+key);
  293. SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class);
  294. //入网验证
  295. String netValidationResult = zhongJiaoXingLu.netValidation(mapValue.get("capacityNumber").toString());
  296. Map netValidationMap = (Map) JSONObject.parse(netValidationResult);
  297. if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){
  298. //运单生成之后保存
  299. HashMap<String, String> redisMap=new HashMap<>();
  300. redisMap.put("startLonlat", searchPoint.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint.getResult().getLocation().getLat().toString().substring(0,8));
  301. redisMap.put("endLonlat", searchPoint2.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint2.getResult().getLocation().getLat().toString().substring(0,8));
  302. redisMap.put("vclN", mapValue.get("capacityNumber").toString());
  303. redisMap.put("vco","2");
  304. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  305. String qryBtm=mapValue.get("resultOutGateTime").toString();
  306. //获得两天、23小时、45分钟之后的时间
  307. Date parse = simpleDateFormat.parse(qryBtm);
  308. //时间添加
  309. Calendar calendar = Calendar.getInstance();
  310. calendar.setTime(parse);
  311. calendar.add(Calendar.DAY_OF_MONTH, 2);
  312. calendar.add(Calendar.HOUR_OF_DAY, 23);
  313. calendar.add(Calendar.SECOND, 45);
  314. //计算时间差
  315. long agetime = parse.getTime();
  316. long lateTime = calendar.getTimeInMillis();
  317. //两天、23小时、45分钟之后的时间差毫秒
  318. long reductionTime1=lateTime-agetime;
  319. long currentTime = new Date().getTime();
  320. //减去已经过的时间(毫秒)
  321. long reductionTime2=currentTime-agetime;
  322. //redis 存储的时间(秒)
  323. long saveTime=(reductionTime1-reductionTime2)/1000;
  324. redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm)));
  325. String qryEtm= simpleDateFormat.format(calendar.getTime());
  326. redisMap.put("qryEtm",qryEtm );
  327. String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString();
  328. String redisJson= JSON.toJSONString(redisMap);
  329. //保存请求中交的参数
  330. redisTemplate.opsForValue().set(orderUrl, redisJson, saveTime, TimeUnit.SECONDS);
  331. redisTemplate.opsForValue().set(orderUrl+suffix, redisJson);
  332. //预警开关判断0开启1关闭
  333. if(mapValue.get("turnOf").toString().equals("0")){
  334. redisMap.put("startCode",searchPoint.getResult().getAd_info().getAdcode());
  335. redisMap.put("destCode",searchPoint2.getResult().getAd_info().getAdcode());
  336. redisMap.put("qryBtm",parse.toString());
  337. redisMap.put("qryEtm",calendar.getTime().toString());
  338. String subAbnormalLineWarnV2Json = zhongJiaoXingLu.subAbnormalLineWarnV2(redisMap);
  339. JSONObject jsonObject = JSONObject.parseObject(subAbnormalLineWarnV2Json);
  340. if (jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")) {
  341. HashMap<String, Object> tripMap = new HashMap();
  342. tripMap.put("orderNumber", mapValue.get("orderNumber").toString());
  343. tripMap.put("rid", jsonObject.get("result").toString());
  344. //omsFeign.insertOrderTripId(tripMap);
  345. }
  346. }
  347. return CompletableFuture.completedFuture("successful");
  348. }
  349. return CompletableFuture.completedFuture("fail");
  350. }
  351. @Override
  352. public CompletableFuture<RouteVo> fullPathVisualization(HashMap mapValue) throws Exception {
  353. String redisJson =null;
  354. if (redisTemplate.hasKey(prefixOrder + ":" + mapValue.get("orderNumber"))){
  355. redisJson=(String) redisTemplate.opsForValue().get(prefixOrder + ":" + mapValue.get("orderNumber"));
  356. }
  357. HashMap routeMap = JSON.parseObject(redisJson, HashMap.class);
  358. String json="";
  359. if (routeMap!=null)
  360. {
  361. json =zhongJiaoXingLu.visualRoute(routeMap);
  362. }else{
  363. String j=prefixLine + ":" + mapValue.get("orderNumber");
  364. if (redisTemplate.hasKey(prefixLine + ":" + mapValue.get("orderNumber"))){
  365. json = (String) redisTemplate.opsForValue().get(prefixLine + ":" + mapValue.get("orderNumber"));
  366. }
  367. if (json==null||json.equals("")){
  368. HashMap<String,Object> hashMap=new HashMap();
  369. hashMap.put("orderNumber",mapValue.get("orderNumber"));
  370. // RESTfulResult startAndEndCapacityNumber = tmsFeign.getStartAndEndCapacityNumber(hashMap);
  371. // HashMap<String,Object> resultMap= (HashMap<String, Object>) startAndEndCapacityNumber.getData();
  372. Map<String, Object> resultMap=tmstruckLeaveFactoryResultService.getTruckFactoryResult(mapValue.get("orderNumber").toString());
  373. //入网验证
  374. String netValidationResult = zhongJiaoXingLu.netValidation(resultMap.get("capacityNumber").toString());
  375. Map netValidationMap = (Map) JSONObject.parse(netValidationResult);
  376. if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){
  377. String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  378. SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class);
  379. String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode(resultMap.get("receiveAddress")==null||"".equals(String.valueOf(resultMap.get("receiveAddress")))?"长沙市":resultMap.get("receiveAddress").toString(),"utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  380. SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class);
  381. //运单生成之后保存
  382. HashMap<String,String> redisMap=new HashMap<>();
  383. String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString();
  384. String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString();
  385. redisMap.put("startLonlat", startLon+","+startLat);
  386. String endLon= searchPoint2.getResult().getLocation().getLng().toString().length()>9?searchPoint2.getResult().getLocation().getLng().toString().substring(0,9):searchPoint2.getResult().getLocation().getLng().toString();
  387. String endLat= searchPoint2.getResult().getLocation().getLat().toString().length()>9?searchPoint2.getResult().getLocation().getLat().toString().substring(0,8):searchPoint2.getResult().getLocation().getLat().toString();
  388. redisMap.put("endLonlat",endLon+","+endLat);
  389. redisMap.put("vclN", resultMap.get("capacityNumber").toString());
  390. redisMap.put("vco","2");
  391. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  392. String qryBtm=resultMap.get("resultOutGateTime").toString();
  393. //获得两天、23小时、45分钟之后的时间
  394. Date parse = simpleDateFormat.parse(qryBtm);
  395. //时间添加
  396. Calendar calendar = Calendar.getInstance();
  397. calendar.setTime(parse);
  398. // calendar.add(Calendar.DAY_OF_MONTH, 2);
  399. calendar.add(Calendar.HOUR_OF_DAY, 23);
  400. calendar.add(Calendar.SECOND, 45);
  401. //计算时间差
  402. long agetime = parse.getTime();
  403. long lateTime = calendar.getTimeInMillis();
  404. //两天、23小时、45分钟之后的时间差毫秒
  405. long reductionTime1=lateTime-agetime;
  406. long currentTime = new Date().getTime();
  407. //减去已经过的时间(毫秒)
  408. long reductionTime2=currentTime-agetime;
  409. //redis 存储的时间(秒)
  410. long saveTime=(reductionTime1-reductionTime2)/1000;
  411. redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm)));
  412. String qryEtm= simpleDateFormat.format(calendar.getTime());
  413. redisMap.put("qryEtm", qryEtm);
  414. if (saveTime>1800){
  415. String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString();
  416. String redisStr=JSON.toJSONString(redisMap);
  417. json = zhongJiaoXingLu.visualRoute(redisMap);
  418. redisTemplate.opsForValue().set(orderUrl, redisStr, saveTime<0?1000:saveTime, TimeUnit.SECONDS);
  419. redisTemplate.opsForValue().set(orderUrl+suffix, redisStr);
  420. }else {
  421. //设置60天后过期
  422. Calendar calendar2=Calendar.getInstance();
  423. long agoTime= calendar2.getTime().getTime();
  424. calendar2.add(Calendar.MONTH,2);
  425. long late= calendar2.getTime().getTime();
  426. long save=(lateTime-agoTime)/1000;
  427. System.out.println(redisMap);
  428. System.out.println("置60天后过期");
  429. json = zhongJiaoXingLu.visualRoute(redisMap);
  430. System.out.println(json.length()>100?json.substring(0,100):json);
  431. if (json!=null){
  432. redisTemplate.opsForValue().set(prefixLine+":"+mapValue.get("orderNumber").toString(), json, save>0?save:3184000, TimeUnit.SECONDS);
  433. }
  434. }
  435. }
  436. }else {
  437. }
  438. }
  439. JSONObject jsonObject = JSONObject.parseObject(json);
  440. if (json!=null&&jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")){
  441. //初始开始链路和结束线路、开始点、结束点、当前点的集合
  442. List<StartAndEndRoute> startAndEndRouteList=new ArrayList<>();
  443. //一条路线,开始链路和结束线路、开始点、结束点、当前点
  444. StartAndEndRoute startAndEndRoute=new StartAndEndRoute();
  445. ViewVisualization to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class);
  446. //初始化vo对象
  447. RouteVo vo=new RouteVo();
  448. //当前所在的点
  449. if ((!StringUtils.isEmpty(to.getResult().getLat()))&& (!StringUtils.isEmpty(to.getResult().getLon()))){
  450. Double[] centerpoint = LngLonUtil.gps84_To_Gcj02((Double.valueOf(to.getResult().getLat()) / 600000), (Double.valueOf(to.getResult().getLon()) / 600000));
  451. //当前所在的点
  452. Point currentPoint=new Point();
  453. currentPoint.setLat(centerpoint[0]+"");
  454. currentPoint.setLon(centerpoint[1]+"");
  455. startAndEndRoute.setCurrentPoint(currentPoint);
  456. }
  457. //当前所在地名称
  458. startAndEndRoute.setCurrentPointName(to.getResult().getAdr());
  459. //初始已行驶轨迹集合
  460. if (to.getResult().getRunRoute()!=null){
  461. List<RunRoutePoint> routes =new ArrayList();
  462. List<Double[]> routesPath =new ArrayList();
  463. for(RunRoutePoint item : to.getResult().getRunRoute()){
  464. RunRoutePoint runRoutePoint=item;
  465. //将已行驶轨迹转义数据格式
  466. Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000));
  467. routesPath.add(new Double[]{points[1],points[0]});
  468. //经纬度
  469. runRoutePoint.setLat(points[0]+"");
  470. runRoutePoint.setLon(points[1]+"");
  471. //坐标点
  472. routes.add(runRoutePoint);
  473. }
  474. //初始化起始点,已经经过路段的第一个点
  475. Point startPoint=new Point();
  476. startPoint.setLat(routes.get(0).getLat());
  477. startPoint.setLon(routes.get(0).getLon());
  478. startAndEndRoute.setStartPoint(startPoint);
  479. //点集合
  480. startAndEndRoute.setRunPath(routesPath);
  481. //已经完成路线点集合
  482. startAndEndRoute.setRunRoute(routes);
  483. }
  484. //预估轨迹
  485. if (to.getResult().getEstimateRoute()!=null){
  486. List<Point> estimateRoute= new ArrayList<>();
  487. List<Double[]> estimatePath =new ArrayList();
  488. for(Point item :to.getResult().getEstimateRoute()){
  489. Point er=new Point();
  490. Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000));
  491. estimatePath.add(new Double[]{points[1],points[0]});
  492. er.setLat(points[0]+"");
  493. er.setLon(points[1]+"");
  494. estimateRoute.add(er);
  495. }
  496. //路径
  497. startAndEndRoute.setEstimatePath(estimatePath);
  498. //结束点
  499. startAndEndRoute.setEndPoint(estimateRoute.get(estimateRoute.size()-1));
  500. //预估轨迹赋值
  501. startAndEndRoute.setEstimateRoute(estimateRoute);
  502. }
  503. //当前所行驶历程数
  504. String mil=to.getResult().getRunDistance()+"km";
  505. startAndEndRoute.setMiled(mil);
  506. startAndEndRouteList.add(startAndEndRoute);
  507. vo.setStartAndEndRoutes(startAndEndRouteList);
  508. //
  509. //设置返回值对象
  510. return CompletableFuture.completedFuture(vo) ;
  511. }else {
  512. return CompletableFuture.completedFuture(new RouteVo());
  513. }
  514. }
  515. /**
  516. * 必须参数 orderNumber 运输订单号
  517. * 获得运输全路径
  518. * @param mapValue
  519. * @return
  520. * @throws Exception
  521. */
  522. public CompletableFuture<RouteVo> fullPaht(HashMap mapValue) throws Exception {
  523. //获得saveRoute()保存在redis请求中交的查询
  524. String redisJson = (String) redisTemplate.opsForValue().get(prefixOrder + ":" + mapValue.get("orderNumber"));
  525. HashMap routeMap = JSON.parseObject(redisJson, HashMap.class);
  526. String json="";
  527. //判断请求参数是否为空
  528. if (routeMap!=null)
  529. {
  530. //获得路径
  531. json =zhongJiaoXingLu.visualRoute(routeMap);
  532. //可能中交请求参数已经过期、已经成了路线、可以直接获取路径
  533. }else{
  534. json = (String) redisTemplate.opsForValue().get(prefixLine + ":" + mapValue.get("orderNumber"));
  535. //当redis获取不到参数的备选方案从数据库获取
  536. if (json==null){
  537. HashMap<String, Object> hashMap=new HashMap();
  538. hashMap.put("orderNumber",mapValue.get("orderNumber"));
  539. //从数据库获取参数
  540. RESTfulResult startAndEndCapacityNumber =null; //tmsFeign.getStartAndEndCapacityNumber(hashMap);
  541. HashMap<String, Object> resultMap= (HashMap<String, Object>) startAndEndCapacityNumber.getData();
  542. //入网验证
  543. String netValidationResult = zhongJiaoXingLu.netValidation(resultMap.get("capacityNumber").toString());
  544. Map netValidationMap = (Map) JSONObject.parse(netValidationResult);
  545. if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){
  546. String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(resultMap.get("shipperName").toString(),"utf-8")+"&key="+key);
  547. SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class);
  548. String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(resultMap.get("addressDeliveryAddress").toString(),"utf-8")+"&key="+key);
  549. SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class);
  550. //运单生成之后保存
  551. HashMap<String, String> redisMap=new HashMap<>();
  552. redisMap.put("startLonlat", searchPoint.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint.getResult().getLocation().getLat().toString().substring(0,8));
  553. redisMap.put("endLonlat", searchPoint2.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint2.getResult().getLocation().getLat().toString().substring(0,8));
  554. redisMap.put("vclN", resultMap.get("capacityNumber").toString());
  555. redisMap.put("vco","2");
  556. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  557. String qryBtm=resultMap.get("resultOutGateTime").toString();
  558. //获得两天、23小时、45分钟之后的时间
  559. Date parse = simpleDateFormat.parse(qryBtm);
  560. //时间添加
  561. Calendar calendar = Calendar.getInstance();
  562. calendar.setTime(parse);
  563. calendar.add(Calendar.DAY_OF_MONTH, 2);
  564. calendar.add(Calendar.HOUR_OF_DAY, 23);
  565. calendar.add(Calendar.SECOND, 45);
  566. //计算时间差
  567. long agetime = parse.getTime();
  568. long lateTime = calendar.getTimeInMillis();
  569. //两天、23小时、45分钟之后的时间差毫秒
  570. long reductionTime1=lateTime-agetime;
  571. long currentTime = new Date().getTime();
  572. //减去已经过的时间(毫秒)
  573. long reductionTime2=currentTime-agetime;
  574. //redis 存储的时间(秒)
  575. long saveTime=(reductionTime1-reductionTime2)/1000;
  576. redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm)));
  577. String qryEtm= simpleDateFormat.format(calendar.getTime());
  578. redisMap.put("qryEtm",qryEtm );
  579. if (saveTime>1800){
  580. String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString();
  581. String redisStr= JSON.toJSONString(redisMap);
  582. redisTemplate.opsForValue().set(orderUrl, redisStr, saveTime, TimeUnit.SECONDS);
  583. }else {
  584. //设置60天后过期
  585. Calendar calendar2= Calendar.getInstance();
  586. long agoTime= calendar2.getTime().getTime();
  587. calendar2.add(Calendar.MONTH,2);
  588. long late= calendar2.getTime().getTime();
  589. long save=(lateTime-agoTime)/1000;
  590. json = zhongJiaoXingLu.visualRoute(redisMap);
  591. redisTemplate.opsForValue().set(prefixLine+":"+mapValue.get("orderNumber").toString(), json, save, TimeUnit.SECONDS);
  592. }
  593. }
  594. }
  595. }
  596. //获得路线之后封装成路线对象
  597. JSONObject jsonObject = JSONObject.parseObject(json);
  598. if (json!=null&&jsonObject.get("status").toString().equals(1001+"")){
  599. //初始开始链路和结束线路、开始点、结束点、当前点的集合
  600. List<StartAndEndRoute> startAndEndRouteList=new ArrayList<>();
  601. //一条路线,开始链路和结束线路、开始点、结束点、当前点
  602. StartAndEndRoute startAndEndRoute=new StartAndEndRoute();
  603. ViewVisualization to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class);
  604. //初始化vo对象
  605. RouteVo vo=new RouteVo();
  606. //当前所在的点
  607. if ((!StringUtils.isEmpty(to.getResult().getLat()))&& (!StringUtils.isEmpty(to.getResult().getLon()))){
  608. Double[] centerpoint = LngLonUtil.gps84_To_Gcj02((Double.valueOf(to.getResult().getLat()) / 600000), (Double.valueOf(to.getResult().getLon()) / 600000));
  609. //当前所在的点
  610. Point currentPoint=new Point();
  611. currentPoint.setLat(centerpoint[0]+"");
  612. currentPoint.setLon(centerpoint[1]+"");
  613. startAndEndRoute.setCurrentPoint(currentPoint);
  614. }
  615. //当前所在地名称
  616. startAndEndRoute.setCurrentPointName(to.getResult().getAdr());
  617. //初始已行驶轨迹集合
  618. if (to.getResult().getRunRoute()!=null){
  619. List<RunRoutePoint> routes =new ArrayList();
  620. List<Double[]> routesPath =new ArrayList();
  621. for(RunRoutePoint item : to.getResult().getRunRoute()){
  622. RunRoutePoint runRoutePoint=item;
  623. //将已行驶轨迹转义数据格式
  624. Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000));
  625. routesPath.add(new Double[]{points[1],points[0]});
  626. //经纬度
  627. runRoutePoint.setLat(points[0]+"");
  628. runRoutePoint.setLon(points[1]+"");
  629. //坐标点
  630. routes.add(runRoutePoint);
  631. }
  632. //初始化起始点,已经经过路段的第一个点
  633. Point startPoint=new Point();
  634. startPoint.setLat(routes.get(0).getLat());
  635. startPoint.setLon(routes.get(0).getLon());
  636. startAndEndRoute.setStartPoint(startPoint);
  637. //点集合
  638. startAndEndRoute.setRunPath(routesPath);
  639. //已经完成路线点集合
  640. startAndEndRoute.setRunRoute(routes);
  641. }
  642. //预估轨迹
  643. if (to.getResult().getEstimateRoute()!=null){
  644. List<Point> estimateRoute= new ArrayList<>();
  645. List<Double[]> estimatePath =new ArrayList();
  646. for(Point item :to.getResult().getEstimateRoute()){
  647. Point er=new Point();
  648. Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000));
  649. estimatePath.add(new Double[]{points[1],points[0]});
  650. er.setLat(points[0]+"");
  651. er.setLon(points[1]+"");
  652. estimateRoute.add(er);
  653. }
  654. //路径
  655. startAndEndRoute.setEstimatePath(estimatePath);
  656. //结束点
  657. startAndEndRoute.setEndPoint(estimateRoute.get(estimateRoute.size()-1));
  658. //预估轨迹赋值
  659. startAndEndRoute.setEstimateRoute(estimateRoute);
  660. }
  661. //当前所行驶历程数
  662. String mil=to.getResult().getRunDistance()+"km";
  663. startAndEndRoute.setMiled(mil);
  664. startAndEndRouteList.add(startAndEndRoute);
  665. vo.setStartAndEndRoutes(startAndEndRouteList);
  666. //
  667. //设置返回值对象
  668. return CompletableFuture.completedFuture(vo) ;
  669. }else {
  670. return CompletableFuture.completedFuture(new RouteVo());
  671. }
  672. }
  673. }