liyg 2 tahun lalu
induk
melakukan
2df9161ec7

+ 2 - 3
src/main/java/com/steerinfo/dil/controller/OffSiteTransportationController.java

@@ -274,7 +274,6 @@ public class OffSiteTransportationController extends BaseRESTfulController {
 
     @PostMapping(value = "/addTmstruckReceiptResult" )
     public synchronized RESTfulResult addTmstruckReceiptResult(@RequestBody Map<String,Object>  value , Integer num, String orderNumber, String resultArrivalAddress, Integer imgcount3, Integer imgcount4) throws Exception {
-
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("orderNumber",orderNumber);
         map.put("resultArrivalAddress",resultArrivalAddress);
@@ -295,8 +294,8 @@ public class OffSiteTransportationController extends BaseRESTfulController {
             String json = zhongJiaoXingLu.visualRoute(mapValue);
             ViewVisualization to=null;
             if (json!=null){
-                //设置60天后过期
-                redisTemplate.opsForValue().set(prefixLine+":"+orderNumber, json, 60*60*24*60, TimeUnit.SECONDS);
+                //设置24小时后过期
+                redisTemplate.opsForValue().set(prefixLine+":"+orderNumber, json, 60*60*24, TimeUnit.SECONDS);
                 //删除redis订单前缀:prefixOrder
                 redisTemplate.delete(prefixOrder+":"+orderNumber);
                 redisTemplate.delete(prefixOrder+":"+orderNumber+suffix);

+ 3 - 0
src/main/java/com/steerinfo/route/mapper/TmstruckReceiptResultChildMapper.java

@@ -14,4 +14,7 @@ public interface TmstruckReceiptResultChildMapper extends IBaseMapper<TmstruckRe
 
     //查询收货地址等信息
     Map<String,Object> getAddress(Map<String,Object> map);
+
+    //查询是否删除redis
+    int getDeleteRedis();
 }

+ 59 - 100
src/main/java/com/steerinfo/route/service/impl/RouteServiceImpl.java

@@ -456,117 +456,76 @@ public class RouteServiceImpl implements RouteService {
 
     @Override
     public CompletableFuture<RouteVo> fullPathVisualization(HashMap mapValue) throws Exception {
-
-        String redisJson = null;
-        if (redisTemplate.hasKey(prefixOrder + ":" + mapValue.get("orderNumber"))) {
-            redisJson = (String) redisTemplate.opsForValue().get(prefixOrder + ":" + mapValue.get("orderNumber"));
+        if(tmstruckReceiptResultChildMapper.getDeleteRedis()>0){
+            //删除redis记录,保证查询成功
+            redisTemplate.delete(prefixLine + ":" + mapValue.get("orderNumber"));
         }
-
-        HashMap routeMap = JSON.parseObject(redisJson, HashMap.class);
-        String json = "";
-        //redisTemplate.delete(prefixLine + ":" + mapValue.get("orderNumber"));//删除redis记录,保证进入查询分支,测试用
         //查询路线信息
-        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<String, Object> hashMap = new HashMap();
-                hashMap.put("orderNumber", mapValue.get("orderNumber"));
+        String json = "";
+        if (redisTemplate.hasKey(prefixLine + ":" + mapValue.get("orderNumber"))) {
+            json = (String) redisTemplate.opsForValue().get(prefixLine + ":" + mapValue.get("orderNumber"));
+        }
+        if (json == null || json.equals("")) {
+            HashMap<String, Object> hashMap = new HashMap();
+            hashMap.put("orderNumber", mapValue.get("orderNumber"));
 //                RESTfulResult startAndEndCapacityNumber = tmsFeign.getStartAndEndCapacityNumber(hashMap);
 //                HashMap<String,Object> resultMap= (HashMap<String, Object>) startAndEndCapacityNumber.getData();
-                Map<String, Object> 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://restapi.amap.com/v3/geocode/geo", "address=" + URLEncoder.encode("四川省达州钢铁集团有限责任公司", "utf-8") + "&key=" + gaodeTonken);
-                    SearchPoint2 searchPoint = JSON.parseObject(searchPointJson, SearchPoint2.class);
-
-                    String searchPointJson2 = HTTPRequestUtils.sendGet("https://restapi.amap.com/v3/geocode/geo", "address=" + URLEncoder.encode(resultMap.get("receiveAddress") == null || "".equals(String.valueOf(resultMap.get("receiveAddress"))) ? "长沙市" : resultMap.get("receiveAddress").toString(), "utf-8") + "&key=" + gaodeTonken);
-                    SearchPoint2 searchPoint2 = JSON.parseObject(searchPointJson2, SearchPoint2.class);
-                    //运单生成之后保存
-                    HashMap<String, String> redisMap = new HashMap<>();
-
-                    String location = searchPoint.getGeocodes().get(0).getLocation();
-                    String[] split = StringUtils.split(location, ",");
-                    String Lng = split[0];
-                    String Lat = split[1];
-
-                    String startLon = Lng.length() > 9 ? Lng.substring(0, 9) : Lng;
-                    String startLat = Lat.length() > 9 ? Lat.substring(0, 8) : Lat;
-                    redisMap.put("startLonlat", startLon + "," + startLat);
-
-                    String location2 = searchPoint2.getGeocodes().get(0).getLocation();
-                    String[] split2 = StringUtils.split(location, ",");
-                    String Lng2 = split[0];
-                    String Lat2 = split[1];
-                    String endLon = Lng2.length() > 9 ? Lng2.substring(0, 9) : Lng2;
-                    String endLat = Lat2.length() > 9 ? Lat2.substring(0, 9) : Lat2;
-                    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)));
-                    //设置结束时间为签收时间
-                    if(resultMap.get("receiptTime")==null){
-                        String qryEtm = simpleDateFormat.format(new Date());
-                        redisMap.put("qryEtm", qryEtm);
-                    }else{
-                        redisMap.put("qryEtm",""+resultMap.get("receiptTime"));
-                    }
-                    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 {
+            Map<String, Object> 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://restapi.amap.com/v3/geocode/geo", "address=" + URLEncoder.encode("四川省达州钢铁集团有限责任公司", "utf-8") + "&key=" + gaodeTonken);
+                SearchPoint2 searchPoint = JSON.parseObject(searchPointJson, SearchPoint2.class);
 
-                        //设置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;
+                String searchPointJson2 = HTTPRequestUtils.sendGet("https://restapi.amap.com/v3/geocode/geo", "address=" + URLEncoder.encode(resultMap.get("receiveAddress") == null || "".equals(String.valueOf(resultMap.get("receiveAddress"))) ? "长沙市" : resultMap.get("receiveAddress").toString(), "utf-8") + "&key=" + gaodeTonken);
+                SearchPoint2 searchPoint2 = JSON.parseObject(searchPointJson2, SearchPoint2.class);
+                //运单生成之后保存
+                HashMap<String, String> redisMap = new HashMap<>();
 
-                        json = zhongJiaoXingLu.visualRoute(redisMap);
-                        if (json != null) {
-                            redisTemplate.opsForValue().set(prefixLine + ":" + mapValue.get("orderNumber").toString(), json, save > 0 ? save : 3184000, TimeUnit.SECONDS);
-                        }
+                String location = searchPoint.getGeocodes().get(0).getLocation();
+                String[] split = StringUtils.split(location, ",");
+                String Lng = split[0];
+                String Lat = split[1];
 
-                    }
+                String startLon = Lng.length() > 9 ? Lng.substring(0, 9) : Lng;
+                String startLat = Lat.length() > 9 ? Lat.substring(0, 8) : Lat;
+                redisMap.put("startLonlat", startLon + "," + startLat);
 
+                String location2 = searchPoint2.getGeocodes().get(0).getLocation();
+                String[] split2 = StringUtils.split(location, ",");
+                String Lng2 = split[0];
+                String Lat2 = split[1];
+                String endLon = Lng2.length() > 9 ? Lng2.substring(0, 9) : Lng2;
+                String endLat = Lat2.length() > 9 ? Lat2.substring(0, 9) : Lat2;
+                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();
+                redisMap.put("qryBtm", simpleDateFormat.format(simpleDateFormat.parse(qryBtm)));
+                long saveTime=0;
+                //设置结束时间为签收时间
+                if(resultMap.get("receiptTime")==null){
+                    String qryEtm = simpleDateFormat.format(new Date());
+                    redisMap.put("qryEtm", qryEtm);
+                    //如果已签收,保存时间为60天
+                    saveTime=60*60*24*60;
+                }else{
+                    //如果未签收,保存60s
+                    redisMap.put("qryEtm",""+resultMap.get("receiptTime"));
+                    saveTime=60;
                 }
+                String orderUrl = prefixOrder + ":" + mapValue.get("orderNumber").toString();
+                String redisStr = JSON.toJSONString(redisMap);
+                json = zhongJiaoXingLu.visualRoute(redisMap);
+                //轨迹保存到redis
+                redisTemplate.opsForValue().set(orderUrl, redisStr, saveTime , TimeUnit.SECONDS);
+                redisTemplate.opsForValue().set(orderUrl + suffix, redisStr);
+
             }
         }
+
         //处理结果,返回路线详情
         JSONObject jsonObject = JSONObject.parseObject(json);
         if (json != null && jsonObject != null && jsonObject.get("status").toString().equals(1001 + "")) {

+ 6 - 0
src/main/resources/com/steerinfo/route/mapper/TmstruckReceiptResultChildMapper.xml

@@ -378,4 +378,10 @@
       WHERE OO.ORDER_STATUS = 5
         AND RCA.CAPACITY_NUMBER=#{capacityNumber}
     </select>
+    <select id="getDeleteRedis" resultType="java.lang.Integer">
+      SELECT COUNT(*)
+      FROM DIL_VERSION WHERE
+      INSERT_UPDATE_REMARK = '查询轨迹时是否删除redis线路'
+      AND VERSION_VALUE = 'true'
+    </select>
 </mapper>