From aee5abdde781ab426771f2024d57e3429aa2b95a Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期三, 15 十月 2025 10:29:40 +0800
Subject: [PATCH] 最新版本541200007

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java |  201 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 167 insertions(+), 34 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
index cf6ef90..c7669ef 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -1,12 +1,15 @@
 package com.doumee.service.business.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.annotation.excel.ExcelImporter;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
+import com.doumee.core.tsp.*;
 import com.doumee.core.utils.*;
-import com.doumee.core.utils.tsp.TspSolver;
-import com.doumee.core.utils.tsp.TspSolverSolutions;
+import com.doumee.core.wms.model.response.WmsBaseDataResponse;
+import com.doumee.core.wms.model.response.WmsBaseResponse;
 import com.doumee.dao.admin.request.JkOrdersImport;
 import com.doumee.dao.business.*;
 import com.doumee.dao.business.model.*;
@@ -19,8 +22,8 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import netscape.javascript.JSObject;
 import org.apache.commons.lang3.StringUtils;
-import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -50,6 +53,8 @@
     private JkSketchCustomerMapper jkSketchCustomerMapper;
     @Autowired
     private JkCustomerMapper jkCustomerMapper;
+    @Autowired
+    private JkCustomerNavigationMapper jkCustomerNavigationMapper;
     @Autowired
     private JkLineMapper jkLineMapper;
 
@@ -95,11 +100,11 @@
         if( model.getDateInfo() ==  null){
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺棩鏈熶俊鎭笉姝g‘锛屼笉鏀寔浼樺寲锛�");
         }
-       if(Constants.equalsInteger(Constants.ZERO,jkSketch.getForceUpdate()) && Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+        if(Constants.equalsInteger(Constants.ZERO,jkSketch.getForceUpdate()) && Constants.equalsInteger(model.getStatus(),Constants.ONE)){
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺瓨鍦ㄦ鍦ㄤ紭鍖栦腑锛岃鑰愬績绛夊緟浼樺寲瀹屾垚鎴栬�呴�夋嫨寮哄埗浼樺寲鎿嶄綔锛�");
         }
 
-         if(  jkSketch.getLineIdList() ==null || jkSketch.getLineIdList().size()==0 ){
+        if(  jkSketch.getLineIdList() ==null || jkSketch.getLineIdList().size()==0 ){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨鏈夋晥鍚堢悊鐨勭嚎璺繘琛屼紭鍖栨搷浣滐紒");
         }
         //褰撳墠鎵�鏈夌嚎璺�(绗﹀悎鏉′欢鐨勭嚎璺級
@@ -114,7 +119,6 @@
             totalCus += Constants.formatIntegerNum(line.getMaxCustomer());//鎬诲鎴烽噺
             totalNum += Constants.formatIntegerNum(line.getMaxOrder());//鎬婚�佽揣閲�
         }
-
         if( totalCus < Constants.formatIntegerNum(model.getOrderNum())  ){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇ョ嚎璺鍗曞鎴锋暟閲忚秴杩囦簡绾胯矾鎬诲鎴烽噺闄愬埗锛屾棤娉曡繘琛屼紭鍖栵紒");
         }
@@ -139,6 +143,7 @@
     @Async
     public void startUpdateLineAsync(JkSketch model) {
         try {
+            initCustomerDistance(model);
             List<JkSketchCustomer> customerList = model.getCustomerList();
             List<JkLine> lineList = model.getLineList();
             TspSolver.DataModel dataModel = new TspSolver.DataModel();
@@ -147,25 +152,17 @@
             long[] demands1 = new long[customerList.size()+1]; //鍚勪釜鐐圭殑璁㈠崟閲�
             long[][] distanceMatrix1 = new long[customerList.size()+1][customerList.size()+1];
             demands1[0] =0;//鍘熺偣
-            double cLatitude =0;
-            double cLongitude =0;
-            String location = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.COMPANY_LOCATION).getCode();
-            try {
-                String[] ss = location.split(",");
-                cLongitude = Double.parseDouble(ss[0]);
-                cLatitude = Double.parseDouble(ss[1]);
-            }catch (Exception e){
-
-            }
-
             for (int i = 0; i < customerList.size(); i++) {
-                distanceMatrix1[0][i] =  DistanceCalculator.calculateDistance(cLatitude,cLongitude,customerList.get(i).getLatitude().doubleValue(),customerList.get(i).getLongitude().doubleValue())/1000;
-                distanceMatrix1[i][0] = distanceMatrix1[0][i];
+                List<DistanceMapParam>  disList =  customerList.get(i).getDistanceMapParamList();
+                distanceMatrix1[0][i] =  disList.get(0).getDistance();
+                distanceMatrix1[i][0] = disList.get(disList.size() -1).getDistance();
                 demands1[i+1] = Constants.formatBigdecimal( customerList.get(i).getTotalNum()).longValue();  //鍚勪釜鐐圭殑璁㈠崟閲�
-                List<Map<String,Object>> disList = customerList.get(i).getDistanceList();
-                for (int j = 0; j< disList.size(); j++) {
-                    if(disList.size()>j){
-                        distanceMatrix1[i+1][j+1]  = (Long) disList.get(j).get("b")/1000;//鏋勯�犺窛绂荤煩闃�
+                for (int j = 0; j< disList.size()-2; j++) {
+                    if(j+1 >=10){
+                        break;
+                    }
+                    if(disList.size()>j+1){
+                        distanceMatrix1[i+1][j+1]  = disList.get(j+1).getDistance()/1000;//鏋勯�犺窛绂荤煩闃�
                     }else{
                         distanceMatrix1[i+1][j+1]  = 1l;
                     }
@@ -188,6 +185,141 @@
                     .set(JkSketch::getPlanLineEndDate,new Date()));
         }
 
+    }
+
+    private void initCustomerDistance(JkSketch model) {
+        String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_DISTANCE_GEOAPI_URL).getCode();
+        List<JkCustomer> updateCustomerList = new ArrayList<>();
+        List<JkCustomerNavigation> navigationList = new ArrayList<>();
+        List<JkSketchCustomer> customerList = model.getCustomerList();
+
+        Date date = new Date();
+        BigDecimal cLatitude =new BigDecimal(0);
+        BigDecimal cLongitude =new BigDecimal(0);
+
+        String location = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.COMPANY_LOCATION).getCode();
+        try {
+            String[] ss = location.split(",");
+            cLongitude = new BigDecimal(ss[0]);
+            cLatitude =  new BigDecimal(ss[1]);
+        }catch (Exception e){
+        }
+        for(JkSketchCustomer c : customerList){
+            List<DistanceMapParam> tmpList = new ArrayList<>();
+            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
+            boolean isNew = false;
+            JkCustomer u =new JkCustomer();
+            DistanceMapParam t0 = new DistanceMapParam();
+            t0.setId(-2);//琛ㄧず杩斿洖鍥尯
+            t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
+            if(Constants.formatLongNum(c.getStartDistance()) <= 0){
+                //鍥尯鍓嶅線璇ュ鎴风殑璺濈锛屽鏋滀箣鍓嶆湭鑾峰彇杩�
+                isNew = true;
+                JkSketchCustomer start = new JkSketchCustomer();
+                start.setId(-1);
+                start.setLongitude(cLongitude);
+                start.setLatitude(cLatitude);
+                DistanceModel dm = DistanceCalculator.calculateDistanceGaode(url,start,c);
+                c.setStartDistance(dm.getDistance() );
+                t0.setDistance(dm.getDistance());
+                u.setStartDistance(dm.getDistance());
+                if(dm.getLocations().size()>0){
+                    //濡傛灉鏈夎矾寰勪俊鎭�
+                    u.setStartSteps(dm.getPolyline());
+                }
+            }
+            tmpList.add(t0);
+            for(JkSketchCustomer cm : customerList){
+                //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
+                DistanceMapParam t = new DistanceMapParam();
+                t.setId(cm.getId());
+                DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList);
+                if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
+                    t = param;
+                }else{
+                    JkCustomerNavigation navigation = new JkCustomerNavigation();
+                    navigation.setStartId(c.getId());
+                    navigation.setEndId(cm.getId());
+                    navigation.setIsdeleted(Constants.ZERO);
+                    navigation.setCreateDate(date);
+                    navigation.setEditDate(date);
+                    navigation.setEndLatitude(cm.getLatitude());
+                    navigation.setEndLogitude(cm.getLongitude());
+                    navigation.setStartLatitude(c.getLatitude());
+                    navigation.setStartLogitude(c.getLongitude());
+                    isNew = true;
+                    if(Constants.equalsInteger(c.getCustomerId(),cm.getCustomerId())){
+                        t.setDistance(0l);
+                    }else{
+                        DistanceModel dm = DistanceCalculator.calculateDistanceGaode(url,c,cm);
+                        t.setDistance(dm.getDistance() );
+                        if(dm.getLocations().size()>0){
+                            //濡傛灉鏈夎矾寰勪俊鎭�
+                            navigation.setSteps(dm.getPolyline());
+                        }
+                    }
+                    navigation.setIdIndex(c.getId()+"-"+cm.getId());
+                    navigation.setDistance(t.getDistance());
+                    navigationList.add(navigation);
+                }
+                tmpList.add(t);
+            }
+            DistanceMapParam tt = new DistanceMapParam();
+            tt.setId(-2);//琛ㄧず杩斿洖鍥尯
+            tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
+            if(Constants.formatLongNum(c.getEndDistance()) <= 0){
+                //璇ュ鎴疯繑鍥炲洯鍖虹殑璺濈 ,濡傛灉涔嬪墠鏈幏鍙栬繃
+                isNew = true;
+                JkSketchCustomer start = new JkSketchCustomer();
+                start.setId(-1);
+                start.setLongitude(cLongitude);
+                start.setLatitude(cLatitude);
+
+                DistanceModel dm = DistanceCalculator.calculateDistanceGaode(url,c,start);
+                c.setEndDistance(dm.getDistance() );
+                tt.setDistance(dm.getDistance());
+                u.setEndDistance(dm.getDistance());
+                if(dm.getLocations().size()>0){
+                    //濡傛灉鏈夎矾寰勪俊鎭�
+                    u.setEndSteps(dm.getPolyline());
+                }
+            }
+            tmpList.add(tt);
+            if(isNew){//
+                u.setId(c.getCustomerId());
+                u.setDistance(JSONObject.toJSONString(tmpList));
+                updateCustomerList.add(u);
+            }
+            c.setDistanceMapParamList(tmpList);
+        }
+        if(updateCustomerList.size()>0){
+            for(JkCustomer c : updateCustomerList){
+                jkCustomerMapper.updateById(c);//鏇存柊瀹㈡埛涓庡叾浠栫偣涔嬮棿鐨勮窛绂�
+            }
+        }
+        if(navigationList.size()>0){
+            jkCustomerNavigationMapper.insert(navigationList);
+        }
+    }
+
+    private DistanceMapParam getParamByCustomerIds(  Integer id1, List<DistanceMapParam> distanceMapParamList) {
+        if(distanceMapParamList!=null){
+            for(DistanceMapParam p :distanceMapParamList){
+                if(Constants.equalsInteger(p.getId(),id1)){
+                    return p;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private List<DistanceMapParam> getListFromJsonStr(String distanceJson) {
+        try {
+            return  JSONObject.parseObject(distanceJson, new TypeReference<List<DistanceMapParam>>(){}.getType());
+        }catch (Exception e){
+        }
+        return new ArrayList<>();
     }
 
     private void dealSearchSolution(JkSketch model, TspSolver.DataModel dataModel) {
@@ -221,7 +353,7 @@
                 tModel.setCustomerList( new ArrayList<>());
                 //鏈夋晥璺緞
                 for (Integer cIndex : routes){
-                    if(cIndex ==0 || cIndex == routes.size()-1){
+                    if(cIndex ==0){
                         continue; //璧峰鐐逛笉澶勭悊
                     }
                     JkSketchCustomer customer = model.getCustomerList().get(cIndex-1);
@@ -239,9 +371,7 @@
                     cModel.setSketchId(model.getId());
                     cModel.setCustomerId(customer.getCustomerId());
                     tModel.getCustomerList().add(cModel);
-                    if(cIndex ==0 || cIndex == routes.size()-1){
-                        continue; //璧峰鐐逛笉澶勭悊
-                    }
+
                 }
             }
         }
@@ -287,13 +417,15 @@
     }
 
     private   List<JkSketchCustomer>  checkJketchCustomerLocation(JkSketch model) {
-
         MPJLambdaWrapper<JkSketchCustomer> queryWrapper = new MPJLambdaWrapper<>();
         queryWrapper.selectAll(JkSketchCustomer.class )
                 .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                 .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
+                .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                 .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                 .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
+                .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
+                .selectAs(JkCustomer::getEndDistance,JkSketchCustomer::getEndDistance)
                 .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId )
                 .eq(JkSketchCustomer::getSketchId, model.getId())
                 .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO)
@@ -311,7 +443,7 @@
         if(StringUtils.isNotBlank(errorMsg)){
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+errorMsg+"瀹氫綅淇℃伅涓嶅畬鏁达紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
         }
-        for(JkSketchCustomer c : customerList){
+       /* for(JkSketchCustomer c : customerList){
             List<Map<String,Object>> tmpList = new ArrayList<>();
             for(JkSketchCustomer cm : customerList){
                 Map<String,Object> t = new HashMap<>();
@@ -321,7 +453,7 @@
                 }else{
                     t.put("b", DistanceCalculator.calculateDistance(
                             Constants.formatBigdecimal(c.getLatitude()).doubleValue(),
-                            Constants.formatBigdecimal(c.getLatitude()).doubleValue(),
+                            Constants.formatBigdecimal(c.getLongitude()).doubleValue(),
                             Constants.formatBigdecimal(cm.getLatitude()).doubleValue(),
                             Constants.formatBigdecimal(cm.getLongitude()).doubleValue()));
                 }
@@ -329,8 +461,8 @@
             }
             c.setDistanceList(tmpList);
         }
-
-        if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){
+        */
+        /*if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){
             //濡傛灉鏄湭浼樺寲鐘舵�侊紝璁$畻鍘熷璺濈
             long totalDistance = 0;
             MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>();
@@ -359,7 +491,8 @@
                                         ,Constants.formatBigdecimal(c.getLatitude()).doubleValue()
                                         ,Constants.formatBigdecimal(c.getLongitude()).doubleValue());
                             }else{
-                                totalDistance += DistanceCalculator.calculateDistance(Constants.formatBigdecimal(c.getLatitude()).doubleValue()
+                                totalDistance += DistanceCalculator.calculateDistance(
+                                         Constants.formatBigdecimal(c.getLatitude()).doubleValue()
                                         ,Constants.formatBigdecimal(c.getLongitude()).doubleValue()
                                         ,Constants.formatBigdecimal(last.getLatitude()).doubleValue()
                                         ,Constants.formatBigdecimal(last.getLongitude()).doubleValue());
@@ -377,7 +510,7 @@
 
             }
             model.setOriginDistance(totalDistance);
-        }
+        }*/
 
         return customerList;
     }

--
Gitblit v1.9.3