RouteServiceImpl.java 51 KB

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