RouteServiceImpl.java 52 KB

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