package com.steerinfo.route.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.steerinfo.dil.service.ITmstruckLeaveFactoryResultService; import com.steerinfo.dil.service.OffSiteTransportationService; import com.steerinfo.dil.service.impl.OffSiteTransportationServiceImpl; import com.steerinfo.dil.util.PageListAdd; import com.steerinfo.framework.controller.RESTfulResult; import com.steerinfo.framework.service.pagehelper.PageHelper; import com.steerinfo.route.service.RouteService; import com.steerinfo.route.threeRequest.ZhongJiaoXingLu; import com.steerinfo.route.util.DataConversionTool; import com.steerinfo.route.util.HTTPRequestUtils; import com.steerinfo.route.util.LngLonUtil; import com.steerinfo.route.vo.FullPathVisualizationTo.ViewVisualization; import com.steerinfo.route.vo.Map.Point; import com.steerinfo.route.vo.Map.RouteVo; import com.steerinfo.route.vo.Map.RunRoutePoint; import com.steerinfo.route.vo.Map.StartAndEndRoute; import com.steerinfo.route.vo.resultJson.SearchPoint; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import java.math.BigDecimal; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Service(value = "xmsService") public class RouteServiceImpl implements RouteService { @Autowired private RedisTemplate redisTemplate; @Autowired private ZhongJiaoXingLu zhongJiaoXingLu; @Autowired private ITmstruckLeaveFactoryResultService tmstruckLeaveFactoryResultService; @Autowired private OffSiteTransportationServiceImpl offSiteTransportationService; @Value("${str.tengxun.key}") private String key; @Value("${redis.prefix.order}") private String prefixOrder; @Value("${redis.prefix.line}") private String prefixLine; @Value("${redis.prefix.suffix}") private String suffix; //必须参数 运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress public CompletableFuture createTotalResult(Map mapValue) throws Exception { if (mapValue.containsKey("capacityNumber")&&mapValue.containsKey("receiveAddress")&&mapValue.containsKey("shipperName")&&mapValue.containsKey("orderNumber")){ } //carryno车牌号 ,gatepostName 门岗名称 resultOutGateTime出门时间 SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (true) { //创建物质信息需要字段(本地字段名称:视图字段名称 中文解释) unitOfMeasureDesc单位、materialName:cMaterieldes:名称、 materialSpecification:cSpec:规格、materialModel:cMaterielcode:型号, HashMap materieldesMap=new HashMap(); // 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"); //创建托运人需要字段 (本地字段名称:视图字段名称 中文解释)cSupplyid:shipperCode 托运方代码 、cSupplydes:shipperName 托运方名称、addressLongitude 托运方地址经度、addressLatitude托运方地址纬度 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"); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); if (searchPoint.getStatus()==0){ materieldesMap.put("addressLongitude",searchPoint.getResult().getLocation().getLng()); materieldesMap.put("addressLatitude",searchPoint.getResult().getLocation().getLat()); }else { materieldesMap.put("addressLongitude",new BigDecimal(114.036293)); materieldesMap.put("addressLatitude",new BigDecimal(32.483276)); } //创建收货地址需要的字段 addressProvince 省份、addressDistrict 市区、addressTown 县镇 、addressDeliveryAddress 收货地址、 addressLongitude 收货地址经度、addressLatitude 收货地址纬度 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"); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); if (searchPoint2.getStatus()==0&&searchPoint2.getResult()!=null){ if (searchPoint2.getResult().getAddress_components()!=null){ materieldesMap.put("addressProvince",searchPoint2.getResult().getAddress_components().getProvince()==null?"湖南省":searchPoint2.getResult().getAddress_components().getProvince()); materieldesMap.put("addressDistrict",searchPoint2.getResult().getAddress_components().getDistrict()==null?"开福区":searchPoint2.getResult().getAddress_components().getDistrict()); materieldesMap.put("addressTown",searchPoint2.getResult().getAddress_components().getCity()==null?"长沙市":searchPoint2.getResult().getAddress_components().getCity()); }else { materieldesMap.put("addressProvince","湖南省"); materieldesMap.put("addressDistrict","开福区"); materieldesMap.put("addressTown","长沙市"); } materieldesMap.put("addressDeliveryAddress",mapValue.get("receiveAddress").toString()==null?"长沙市":mapValue.get("receiveAddress").toString()); if (searchPoint2.getResult().getLocation()!=null){ materieldesMap.put("addressLongitude",searchPoint2.getResult().getLocation().getLng()==null?new BigDecimal(112.98626):searchPoint2.getResult().getLocation().getLng()); materieldesMap.put("addressLatitude",searchPoint2.getResult().getLocation().getLat()==null?new BigDecimal(28.25591):searchPoint2.getResult().getLocation().getLat()); }else { materieldesMap.put("addressLongitude",new BigDecimal(112.98626)); materieldesMap.put("addressLatitude",new BigDecimal(28.25591)); } if (searchPoint2.getResult().getAd_info()!=null){ materieldesMap.put("destCode",searchPoint2.getResult().getAd_info().getAdcode()==null?"无信息":searchPoint2.getResult().getAd_info().getAdcode()); }else { materieldesMap.put("destCode","无信息"); } }else { //114.03629,32.48327","endLonlat":",28.25591"} materieldesMap.put("addressProvince","湖南省"); materieldesMap.put("addressDistrict","开福区"); materieldesMap.put("addressTown","长沙市"); materieldesMap.put("destCode","430105"); materieldesMap.put("addressDeliveryAddress","长沙市"); materieldesMap.put("addressLongitude",new BigDecimal(112.98626)); materieldesMap.put("addressLatitude",new BigDecimal(28.25591)); } //入网验证 String netValidationResult = zhongJiaoXingLu.netValidation(mapValue.get("capacityNumber").toString()); Map netValidationMap = (Map) JSONObject.parse(netValidationResult); if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){ //运单生成之后保存 HashMap redisMap=new HashMap<>(); String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString(); String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString(); redisMap.put("startLonlat", startLon+","+startLat); String endLon= materieldesMap.get("addressLongitude").toString().length()>9?materieldesMap.get("addressLongitude").toString().substring(0,9):materieldesMap.get("addressLongitude").toString(); String endLat= materieldesMap.get("addressLatitude").toString().length()>9?materieldesMap.get("addressLatitude").toString().substring(0,8):materieldesMap.get("addressLatitude").toString(); redisMap.put("endLonlat",endLon+","+endLat); redisMap.put("vclN", mapValue.get("capacityNumber").toString()); redisMap.put("vco","2"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); String qryBtm=mapValue.get("resultOutGateTime").toString(); //获得两天、23小时、45分钟之后的时间 Date parse = simpleDateFormat.parse(qryBtm); //时间添加 Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); //calendar.add(Calendar.DAY_OF_MONTH, 2); calendar.add(Calendar.HOUR_OF_DAY, 23); calendar.add(Calendar.SECOND, 45); //计算时间差 long agetime = parse.getTime(); long lateTime = calendar.getTimeInMillis(); //两天、23小时、45分钟之后的时间差毫秒 long reductionTime1=lateTime-agetime; long currentTime = new Date().getTime(); //减去已经过的时间(毫秒) long reductionTime2=currentTime-agetime; //redis 存储的时间(秒) long saveTime=(reductionTime1-reductionTime2)/1000; redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm))); String qryEtm= simpleDateFormat.format(calendar.getTime()); redisMap.put("qryEtm",qryEtm ); String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString(); String redisJson=JSON.toJSONString(redisMap); if (saveTime>0){ redisTemplate.opsForValue().set(orderUrl, redisJson, saveTime, TimeUnit.SECONDS); }else { redisTemplate.opsForValue().set(orderUrl, redisJson, 36000, TimeUnit.SECONDS); } redisTemplate.opsForValue().set(orderUrl+suffix, redisJson); //预警开关判断0开启1关闭 Map resTfulResultValues = offSiteTransportationService.selectWarnSwitch(); if(!resTfulResultValues.get("switch").toString().equals("0")){ redisMap.put("startCode",searchPoint.getResult().getAd_info().getAdcode()); redisMap.put("destCode",materieldesMap.get("destCode").toString()); redisMap.put("qryBtm",parse.toString()); redisMap.put("qryEtm",calendar.getTime().toString()); redisMap.put("type",resTfulResultValues.get("type").toString()); String subAbnormalLineWarnV2Json = zhongJiaoXingLu.subAbnormalLineWarnV2(redisMap); JSONObject jsonObject = JSONObject.parseObject(subAbnormalLineWarnV2Json); if (jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")){ HashMap tripMap=new HashMap(); tripMap.put("orderNumber",mapValue.get("orderNumber").toString()); tripMap.put("rid",jsonObject.get("result").toString()); int i=offSiteTransportationService.insertOrderTripId(tripMap); } } } return CompletableFuture.completedFuture("successful"); } return CompletableFuture.completedFuture("fail"); } /** * * @param matrial 物质名称 * @param selectStr 0,没有选1"带钢",2"微粉",3("螺纹钢","盘螺","盘圆"),4"钢坯",5"其他" */ public boolean checkTurnOff(String matrial,String selectStr) { //0,没有选1"带钢",2"微粉",3("螺纹钢","盘螺","盘圆"),4"钢坯",5"其他" int index=0; String[] matrialList=new String[]{"带钢","微粉","螺纹钢","盘螺","盘圆","钢坯","其他"}; //判断是那种物质 lable:for (int i=0;i=i&&i>=2){ //螺纹钢 index=3; }else if (i==5){ //钢坯 index=4; }else if (i==6) { //其他 index=5; }else{ index=i+1; } break lable; } } //判断是否选择这种物质 if (index!=0&&selectStr.contains(String.valueOf(index))){ return true; } return false; } /** * 必须参数 运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress * @param mapValue * @return * @throws Exception */ @Override public CompletableFuture saveRoute(Map mapValue) throws Exception { //获得起点的经纬度和code SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date gateTime = dateFormat.parse(mapValue.get("resultOutGateTime").toString()); 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); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); //创建收货地址 addressProvince 省份、addressDistrict 市区、addressTown 县镇 、addressDeliveryAddress 收货地址、 addressLongitude 收货地址经度、addressLatitude 收货地址纬度 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); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); //入网验证 String netValidationResult = zhongJiaoXingLu.netValidation(mapValue.get("capacityNumber").toString()); Map netValidationMap = (Map) JSONObject.parse(netValidationResult); if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){ //运单生成之后保存 HashMap redisMap=new HashMap<>(); redisMap.put("startLonlat", searchPoint.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint.getResult().getLocation().getLat().toString().substring(0,8)); redisMap.put("endLonlat", searchPoint2.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint2.getResult().getLocation().getLat().toString().substring(0,8)); redisMap.put("vclN", mapValue.get("capacityNumber").toString()); redisMap.put("vco","2"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); String qryBtm=mapValue.get("resultOutGateTime").toString(); //获得两天、23小时、45分钟之后的时间 Date parse = simpleDateFormat.parse(qryBtm); //时间添加 Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.add(Calendar.DAY_OF_MONTH, 2); calendar.add(Calendar.HOUR_OF_DAY, 23); calendar.add(Calendar.SECOND, 45); //计算时间差 long agetime = parse.getTime(); long lateTime = calendar.getTimeInMillis(); //两天、23小时、45分钟之后的时间差毫秒 long reductionTime1=lateTime-agetime; long currentTime = new Date().getTime(); //减去已经过的时间(毫秒) long reductionTime2=currentTime-agetime; //redis 存储的时间(秒) long saveTime=(reductionTime1-reductionTime2)/1000; redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm))); String qryEtm= simpleDateFormat.format(calendar.getTime()); redisMap.put("qryEtm",qryEtm ); String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString(); String redisJson= JSON.toJSONString(redisMap); //保存请求中交的参数 redisTemplate.opsForValue().set(orderUrl, redisJson, saveTime, TimeUnit.SECONDS); redisTemplate.opsForValue().set(orderUrl+suffix, redisJson); //预警开关判断0开启1关闭 if(mapValue.get("turnOf").toString().equals("0")){ redisMap.put("startCode",searchPoint.getResult().getAd_info().getAdcode()); redisMap.put("destCode",searchPoint2.getResult().getAd_info().getAdcode()); redisMap.put("qryBtm",parse.toString()); redisMap.put("qryEtm",calendar.getTime().toString()); String subAbnormalLineWarnV2Json = zhongJiaoXingLu.subAbnormalLineWarnV2(redisMap); JSONObject jsonObject = JSONObject.parseObject(subAbnormalLineWarnV2Json); if (jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")) { HashMap tripMap = new HashMap(); tripMap.put("orderNumber", mapValue.get("orderNumber").toString()); tripMap.put("rid", jsonObject.get("result").toString()); //omsFeign.insertOrderTripId(tripMap); } } return CompletableFuture.completedFuture("successful"); } return CompletableFuture.completedFuture("fail"); } /** * 必须参数 运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress * @param mapValue * @return * @throws Exception */ @Override public CompletableFuture saveRequstionDate(Map mapValue) throws Exception { //获得起点的经纬度和code SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date gateTime = dateFormat.parse(mapValue.get("resultOutGateTime").toString()); 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); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); //创建收货地址 addressProvince 省份、addressDistrict 市区、addressTown 县镇 、addressDeliveryAddress 收货地址、 addressLongitude 收货地址经度、addressLatitude 收货地址纬度 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); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); //入网验证 String netValidationResult = zhongJiaoXingLu.netValidation(mapValue.get("capacityNumber").toString()); Map netValidationMap = (Map) JSONObject.parse(netValidationResult); if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){ //运单生成之后保存 HashMap redisMap=new HashMap<>(); redisMap.put("startLonlat", searchPoint.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint.getResult().getLocation().getLat().toString().substring(0,8)); redisMap.put("endLonlat", searchPoint2.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint2.getResult().getLocation().getLat().toString().substring(0,8)); redisMap.put("vclN", mapValue.get("capacityNumber").toString()); redisMap.put("vco","2"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); String qryBtm=mapValue.get("resultOutGateTime").toString(); //获得两天、23小时、45分钟之后的时间 Date parse = simpleDateFormat.parse(qryBtm); //时间添加 Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.add(Calendar.DAY_OF_MONTH, 2); calendar.add(Calendar.HOUR_OF_DAY, 23); calendar.add(Calendar.SECOND, 45); //计算时间差 long agetime = parse.getTime(); long lateTime = calendar.getTimeInMillis(); //两天、23小时、45分钟之后的时间差毫秒 long reductionTime1=lateTime-agetime; long currentTime = new Date().getTime(); //减去已经过的时间(毫秒) long reductionTime2=currentTime-agetime; //redis 存储的时间(秒) long saveTime=(reductionTime1-reductionTime2)/1000; redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm))); String qryEtm= simpleDateFormat.format(calendar.getTime()); redisMap.put("qryEtm",qryEtm ); String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString(); String redisJson= JSON.toJSONString(redisMap); //保存请求中交的参数 redisTemplate.opsForValue().set(orderUrl, redisJson, saveTime, TimeUnit.SECONDS); redisTemplate.opsForValue().set(orderUrl+suffix, redisJson); //预警开关判断0开启1关闭 if(mapValue.get("turnOf").toString().equals("0")){ redisMap.put("startCode",searchPoint.getResult().getAd_info().getAdcode()); redisMap.put("destCode",searchPoint2.getResult().getAd_info().getAdcode()); redisMap.put("qryBtm",parse.toString()); redisMap.put("qryEtm",calendar.getTime().toString()); String subAbnormalLineWarnV2Json = zhongJiaoXingLu.subAbnormalLineWarnV2(redisMap); JSONObject jsonObject = JSONObject.parseObject(subAbnormalLineWarnV2Json); if (jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")) { HashMap tripMap = new HashMap(); tripMap.put("orderNumber", mapValue.get("orderNumber").toString()); tripMap.put("rid", jsonObject.get("result").toString()); //omsFeign.insertOrderTripId(tripMap); } } return CompletableFuture.completedFuture("successful"); } return CompletableFuture.completedFuture("fail"); } @Override public CompletableFuture fullPathVisualization(HashMap mapValue) throws Exception { String redisJson =null; if (redisTemplate.hasKey(prefixOrder + ":" + mapValue.get("orderNumber"))){ redisJson=(String) redisTemplate.opsForValue().get(prefixOrder + ":" + mapValue.get("orderNumber")); } HashMap routeMap = JSON.parseObject(redisJson, HashMap.class); String json=""; if (routeMap!=null) { json =zhongJiaoXingLu.visualRoute(routeMap); }else{ String j=prefixLine + ":" + mapValue.get("orderNumber"); if (redisTemplate.hasKey(prefixLine + ":" + mapValue.get("orderNumber"))){ json = (String) redisTemplate.opsForValue().get(prefixLine + ":" + mapValue.get("orderNumber")); } if (json==null||json.equals("")){ HashMap hashMap=new HashMap(); hashMap.put("orderNumber",mapValue.get("orderNumber")); // RESTfulResult startAndEndCapacityNumber = tmsFeign.getStartAndEndCapacityNumber(hashMap); // HashMap resultMap= (HashMap) startAndEndCapacityNumber.getData(); Map resultMap=tmstruckLeaveFactoryResultService.getTruckFactoryResult(mapValue.get("orderNumber").toString()); //入网验证 String netValidationResult = zhongJiaoXingLu.netValidation(resultMap.get("capacityNumber").toString()); Map netValidationMap = (Map) JSONObject.parse(netValidationResult); if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){ String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y"); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); 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"); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); //运单生成之后保存 HashMap redisMap=new HashMap<>(); String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString(); String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString(); redisMap.put("startLonlat", startLon+","+startLat); String endLon= searchPoint2.getResult().getLocation().getLng().toString().length()>9?searchPoint2.getResult().getLocation().getLng().toString().substring(0,9):searchPoint2.getResult().getLocation().getLng().toString(); String endLat= searchPoint2.getResult().getLocation().getLat().toString().length()>9?searchPoint2.getResult().getLocation().getLat().toString().substring(0,8):searchPoint2.getResult().getLocation().getLat().toString(); redisMap.put("endLonlat",endLon+","+endLat); redisMap.put("vclN", resultMap.get("capacityNumber").toString()); redisMap.put("vco","2"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); String qryBtm=resultMap.get("resultOutGateTime").toString(); //获得两天、23小时、45分钟之后的时间 Date parse = simpleDateFormat.parse(qryBtm); //时间添加 Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); // calendar.add(Calendar.DAY_OF_MONTH, 2); calendar.add(Calendar.HOUR_OF_DAY, 23); calendar.add(Calendar.SECOND, 45); //计算时间差 long agetime = parse.getTime(); long lateTime = calendar.getTimeInMillis(); //两天、23小时、45分钟之后的时间差毫秒 long reductionTime1=lateTime-agetime; long currentTime = new Date().getTime(); //减去已经过的时间(毫秒) long reductionTime2=currentTime-agetime; //redis 存储的时间(秒) long saveTime=(reductionTime1-reductionTime2)/1000; redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm))); String qryEtm= simpleDateFormat.format(calendar.getTime()); redisMap.put("qryEtm", qryEtm); if (saveTime>1800){ String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString(); String redisStr=JSON.toJSONString(redisMap); json = zhongJiaoXingLu.visualRoute(redisMap); redisTemplate.opsForValue().set(orderUrl, redisStr, saveTime<0?1000:saveTime, TimeUnit.SECONDS); redisTemplate.opsForValue().set(orderUrl+suffix, redisStr); }else { //设置60天后过期 Calendar calendar2=Calendar.getInstance(); long agoTime= calendar2.getTime().getTime(); calendar2.add(Calendar.MONTH,2); long late= calendar2.getTime().getTime(); long save=(lateTime-agoTime)/1000; json = zhongJiaoXingLu.visualRoute(redisMap); if (json!=null){ redisTemplate.opsForValue().set(prefixLine+":"+mapValue.get("orderNumber").toString(), json, save>0?save:3184000, TimeUnit.SECONDS); } } } }else { } } JSONObject jsonObject = JSONObject.parseObject(json); if (json!=null&&jsonObject!=null&&jsonObject.get("status").toString().equals(1001+"")){ //初始开始链路和结束线路、开始点、结束点、当前点的集合 List startAndEndRouteList=new ArrayList<>(); //一条路线,开始链路和结束线路、开始点、结束点、当前点 StartAndEndRoute startAndEndRoute=new StartAndEndRoute(); ViewVisualization to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class); //初始化vo对象 RouteVo vo=new RouteVo(); //当前所在的点 if ((!StringUtils.isEmpty(to.getResult().getLat()))&& (!StringUtils.isEmpty(to.getResult().getLon()))){ Double[] centerpoint = LngLonUtil.gps84_To_Gcj02((Double.valueOf(to.getResult().getLat()) / 600000), (Double.valueOf(to.getResult().getLon()) / 600000)); //当前所在的点 Point currentPoint=new Point(); currentPoint.setLat(centerpoint[0]+""); currentPoint.setLon(centerpoint[1]+""); startAndEndRoute.setCurrentPoint(currentPoint); } //当前所在地名称 startAndEndRoute.setCurrentPointName(to.getResult().getAdr()); //初始已行驶轨迹集合 if (to.getResult().getRunRoute()!=null){ List routes =new ArrayList(); List routesPath =new ArrayList(); for(RunRoutePoint item : to.getResult().getRunRoute()){ RunRoutePoint runRoutePoint=item; //将已行驶轨迹转义数据格式 Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000)); routesPath.add(new Double[]{points[1],points[0]}); //经纬度 runRoutePoint.setLat(points[0]+""); runRoutePoint.setLon(points[1]+""); //坐标点 routes.add(runRoutePoint); } //初始化起始点,已经经过路段的第一个点 Point startPoint=new Point(); startPoint.setLat(routes.get(0).getLat()); startPoint.setLon(routes.get(0).getLon()); startAndEndRoute.setStartPoint(startPoint); //点集合 startAndEndRoute.setRunPath(routesPath); //已经完成路线点集合 startAndEndRoute.setRunRoute(routes); } //预估轨迹 if (to.getResult().getEstimateRoute()!=null){ List estimateRoute= new ArrayList<>(); List estimatePath =new ArrayList(); for(Point item :to.getResult().getEstimateRoute()){ Point er=new Point(); Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000)); estimatePath.add(new Double[]{points[1],points[0]}); er.setLat(points[0]+""); er.setLon(points[1]+""); estimateRoute.add(er); } //路径 startAndEndRoute.setEstimatePath(estimatePath); //结束点 startAndEndRoute.setEndPoint(estimateRoute.get(estimateRoute.size()-1)); //预估轨迹赋值 startAndEndRoute.setEstimateRoute(estimateRoute); } //当前所行驶历程数 String mil=to.getResult().getRunDistance()+"km"; startAndEndRoute.setMiled(mil); startAndEndRouteList.add(startAndEndRoute); vo.setStartAndEndRoutes(startAndEndRouteList); // //设置返回值对象 return CompletableFuture.completedFuture(vo) ; }else { return CompletableFuture.completedFuture(new RouteVo()); } } /** * 必须参数 orderNumber 运输订单号 * 获得运输全路径 * @param mapValue * @return * @throws Exception */ public CompletableFuture fullPaht(HashMap mapValue) throws Exception { //获得saveRoute()保存在redis请求中交的查询 String redisJson = (String) redisTemplate.opsForValue().get(prefixOrder + ":" + mapValue.get("orderNumber")); HashMap routeMap = JSON.parseObject(redisJson, HashMap.class); String json=""; //判断请求参数是否为空 if (routeMap!=null) { //获得路径 json =zhongJiaoXingLu.visualRoute(routeMap); //可能中交请求参数已经过期、已经成了路线、可以直接获取路径 }else{ json = (String) redisTemplate.opsForValue().get(prefixLine + ":" + mapValue.get("orderNumber")); //当redis获取不到参数的备选方案从数据库获取 if (json==null){ HashMap hashMap=new HashMap(); hashMap.put("orderNumber",mapValue.get("orderNumber")); //从数据库获取参数 RESTfulResult startAndEndCapacityNumber =null; //tmsFeign.getStartAndEndCapacityNumber(hashMap); HashMap resultMap= (HashMap) startAndEndCapacityNumber.getData(); //入网验证 String netValidationResult = zhongJiaoXingLu.netValidation(resultMap.get("capacityNumber").toString()); Map netValidationMap = (Map) JSONObject.parse(netValidationResult); if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){ String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(resultMap.get("shipperName").toString(),"utf-8")+"&key="+key); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode(resultMap.get("addressDeliveryAddress").toString(),"utf-8")+"&key="+key); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); //运单生成之后保存 HashMap redisMap=new HashMap<>(); redisMap.put("startLonlat", searchPoint.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint.getResult().getLocation().getLat().toString().substring(0,8)); redisMap.put("endLonlat", searchPoint2.getResult().getLocation().getLng().toString().substring(0,9)+","+searchPoint2.getResult().getLocation().getLat().toString().substring(0,8)); redisMap.put("vclN", resultMap.get("capacityNumber").toString()); redisMap.put("vco","2"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); String qryBtm=resultMap.get("resultOutGateTime").toString(); //获得两天、23小时、45分钟之后的时间 Date parse = simpleDateFormat.parse(qryBtm); //时间添加 Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.add(Calendar.DAY_OF_MONTH, 2); calendar.add(Calendar.HOUR_OF_DAY, 23); calendar.add(Calendar.SECOND, 45); //计算时间差 long agetime = parse.getTime(); long lateTime = calendar.getTimeInMillis(); //两天、23小时、45分钟之后的时间差毫秒 long reductionTime1=lateTime-agetime; long currentTime = new Date().getTime(); //减去已经过的时间(毫秒) long reductionTime2=currentTime-agetime; //redis 存储的时间(秒) long saveTime=(reductionTime1-reductionTime2)/1000; redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm))); String qryEtm= simpleDateFormat.format(calendar.getTime()); redisMap.put("qryEtm",qryEtm ); if (saveTime>1800){ String orderUrl=prefixOrder+":"+mapValue.get("orderNumber").toString(); String redisStr= JSON.toJSONString(redisMap); redisTemplate.opsForValue().set(orderUrl, redisStr, saveTime, TimeUnit.SECONDS); }else { //设置60天后过期 Calendar calendar2= Calendar.getInstance(); long agoTime= calendar2.getTime().getTime(); calendar2.add(Calendar.MONTH,2); long late= calendar2.getTime().getTime(); long save=(lateTime-agoTime)/1000; json = zhongJiaoXingLu.visualRoute(redisMap); redisTemplate.opsForValue().set(prefixLine+":"+mapValue.get("orderNumber").toString(), json, save, TimeUnit.SECONDS); } } } } //获得路线之后封装成路线对象 JSONObject jsonObject = JSONObject.parseObject(json); if (json!=null&&jsonObject.get("status").toString().equals(1001+"")){ //初始开始链路和结束线路、开始点、结束点、当前点的集合 List startAndEndRouteList=new ArrayList<>(); //一条路线,开始链路和结束线路、开始点、结束点、当前点 StartAndEndRoute startAndEndRoute=new StartAndEndRoute(); ViewVisualization to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class); //初始化vo对象 RouteVo vo=new RouteVo(); //当前所在的点 if ((!StringUtils.isEmpty(to.getResult().getLat()))&& (!StringUtils.isEmpty(to.getResult().getLon()))){ Double[] centerpoint = LngLonUtil.gps84_To_Gcj02((Double.valueOf(to.getResult().getLat()) / 600000), (Double.valueOf(to.getResult().getLon()) / 600000)); //当前所在的点 Point currentPoint=new Point(); currentPoint.setLat(centerpoint[0]+""); currentPoint.setLon(centerpoint[1]+""); startAndEndRoute.setCurrentPoint(currentPoint); } //当前所在地名称 startAndEndRoute.setCurrentPointName(to.getResult().getAdr()); //初始已行驶轨迹集合 if (to.getResult().getRunRoute()!=null){ List routes =new ArrayList(); List routesPath =new ArrayList(); for(RunRoutePoint item : to.getResult().getRunRoute()){ RunRoutePoint runRoutePoint=item; //将已行驶轨迹转义数据格式 Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000)); routesPath.add(new Double[]{points[1],points[0]}); //经纬度 runRoutePoint.setLat(points[0]+""); runRoutePoint.setLon(points[1]+""); //坐标点 routes.add(runRoutePoint); } //初始化起始点,已经经过路段的第一个点 Point startPoint=new Point(); startPoint.setLat(routes.get(0).getLat()); startPoint.setLon(routes.get(0).getLon()); startAndEndRoute.setStartPoint(startPoint); //点集合 startAndEndRoute.setRunPath(routesPath); //已经完成路线点集合 startAndEndRoute.setRunRoute(routes); } //预估轨迹 if (to.getResult().getEstimateRoute()!=null){ List estimateRoute= new ArrayList<>(); List estimatePath =new ArrayList(); for(Point item :to.getResult().getEstimateRoute()){ Point er=new Point(); Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000)); estimatePath.add(new Double[]{points[1],points[0]}); er.setLat(points[0]+""); er.setLon(points[1]+""); estimateRoute.add(er); } //路径 startAndEndRoute.setEstimatePath(estimatePath); //结束点 startAndEndRoute.setEndPoint(estimateRoute.get(estimateRoute.size()-1)); //预估轨迹赋值 startAndEndRoute.setEstimateRoute(estimateRoute); } //当前所行驶历程数 String mil=to.getResult().getRunDistance()+"km"; startAndEndRoute.setMiled(mil); startAndEndRouteList.add(startAndEndRoute); vo.setStartAndEndRoutes(startAndEndRouteList); // //设置返回值对象 return CompletableFuture.completedFuture(vo) ; }else { return CompletableFuture.completedFuture(new RouteVo()); } } @Override public CompletableFuture fullPathVisualizationByCarNumber(HashMap mapValue) throws Exception { String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y"); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode("四川省达川区","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y"); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); //运单生成之后保存 HashMap redisMap=new HashMap<>(); String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString(); String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString(); redisMap.put("startLonlat", startLon+","+startLat); String endLon= searchPoint2.getResult().getLocation().getLng().toString().length()>9?searchPoint2.getResult().getLocation().getLng().toString().substring(0,9):searchPoint2.getResult().getLocation().getLng().toString(); String endLat= searchPoint2.getResult().getLocation().getLat().toString().length()>9?searchPoint2.getResult().getLocation().getLat().toString().substring(0,8):searchPoint2.getResult().getLocation().getLat().toString(); redisMap.put("endLonlat",endLon+","+endLat); redisMap.put("vclN", mapValue.get("capacityNumber").toString()); redisMap.put("vco","2"); redisMap.put("qryBtm", mapValue.get("startTime").toString()); redisMap.put("qryEtm",mapValue.get("endTime").toString()); String json = zhongJiaoXingLu.visualRoute2(redisMap); JSONObject jsonObject = JSONObject.parseObject(json); if (json!=null&&jsonObject.get("status").toString().equals(1001+"")){ //初始开始链路和结束线路、开始点、结束点、当前点的集合 List startAndEndRouteList=new ArrayList<>(); //一条路线,开始链路和结束线路、开始点、结束点、当前点 StartAndEndRoute startAndEndRoute=new StartAndEndRoute(); ViewVisualization to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class); //初始化vo对象 RouteVo vo=new RouteVo(); //当前所在的点 //当前所在的点 if ((!StringUtils.isEmpty(to.getResult().getLat()))&& (!StringUtils.isEmpty(to.getResult().getLon()))){ Double[] centerpoint = LngLonUtil.gps84_To_Gcj02((Double.valueOf(to.getResult().getLat()) / 600000), (Double.valueOf(to.getResult().getLon()) / 600000)); //当前所在的点 Point currentPoint=new Point(); currentPoint.setLat(centerpoint[0]+""); currentPoint.setLon(centerpoint[1]+""); startAndEndRoute.setCurrentPoint(currentPoint); } //当前所在地名称 startAndEndRoute.setCurrentPointName(to.getResult().getAdr()); //初始已行驶轨迹集合 if (to.getResult().getRunRoute()!=null){ List routes =new ArrayList(); List routesPath =new ArrayList(); for(RunRoutePoint item : to.getResult().getRunRoute()){ RunRoutePoint runRoutePoint=item; //将已行驶轨迹转义数据格式 Double[] points = LngLonUtil.gps84_To_Gcj02((Double.valueOf(item.getLat()) / 600000), (Double.valueOf(item.getLon()) / 600000)); routesPath.add(new Double[]{points[1],points[0]}); //经纬度 runRoutePoint.setLat(points[0]+""); runRoutePoint.setLon(points[1]+""); //坐标点 routes.add(runRoutePoint); } //初始化起始点,已经经过路段的第一个点 Point startPoint=new Point(); startPoint.setLat(routes.get(0).getLat()); startPoint.setLon(routes.get(0).getLon()); startAndEndRoute.setStartPoint(startPoint); //点集合 startAndEndRoute.setRunPath(routesPath); //已经完成路线点集合 startAndEndRoute.setRunRoute(routes); } //当前所行驶历程数 String mil=to.getResult().getRunDistance()+"km"; startAndEndRoute.setMiled(mil); startAndEndRouteList.add(startAndEndRoute); vo.setStartAndEndRoutes(startAndEndRouteList); // //设置返回值对象 return CompletableFuture.completedFuture(vo) ; }else { return CompletableFuture.completedFuture(new RouteVo()); } } }