RouteServiceImpl.java 46 KB

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