From 70b0c325bfd26d2c231b70184175cc4b9dc22019 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期三, 19 十一月 2025 14:58:46 +0800
Subject: [PATCH] 最新版本541200007

---
 server/startsh/启动脚本和日志处理脚本说明.txt                                                                      |    8 ++
 server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java               |   20 +++++-
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java |  100 +++++++++++++++++++++++---------
 server/startsh/admin_start.sh                                                                         |    1 
 server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/TspSolver.java                        |   48 ++++++++++++---
 5 files changed, 132 insertions(+), 45 deletions(-)

diff --git a/server/startsh/admin_start.sh b/server/startsh/admin_start.sh
index d980965..7b11a6c 100644
--- a/server/startsh/admin_start.sh
+++ b/server/startsh/admin_start.sh
@@ -19,4 +19,3 @@
 cd /usr/local/ortools/java_or-tools
 
 
-tail -f /usr/local/jars/logs/visitsAdmin/info.2025-10-31.0.log
diff --git "a/server/startsh/\345\220\257\345\212\250\350\204\232\346\234\254\345\222\214\346\227\245\345\277\227\345\244\204\347\220\206\350\204\232\346\234\254\350\257\264\346\230\216.txt" "b/server/startsh/\345\220\257\345\212\250\350\204\232\346\234\254\345\222\214\346\227\245\345\277\227\345\244\204\347\220\206\350\204\232\346\234\254\350\257\264\346\230\216.txt"
index ecf18c1..c1fc2a6 100644
--- "a/server/startsh/\345\220\257\345\212\250\350\204\232\346\234\254\345\222\214\346\227\245\345\277\227\345\244\204\347\220\206\350\204\232\346\234\254\350\257\264\346\230\216.txt"
+++ "b/server/startsh/\345\220\257\345\212\250\350\204\232\346\234\254\345\222\214\346\227\245\345\277\227\345\244\204\347\220\206\350\204\232\346\234\254\350\257\264\346\230\216.txt"
@@ -17,3 +17,11 @@
 Linux绯荤粺瀹夎瀵瑰簲鐨勭増鏈湇鍔★細
 https://developers.google.cn/optimization/install/java/pkg_linux?hl=zh-cn#ubuntu
  https://modelers.csdn.net/68db8ec14b11580edfa299c6.html?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-5-134512600-blog-119785705.235%5Ev43%5Epc_blog_bottom_relevance_base5&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-5-134512600-blog-119785705.235%5Ev43%5Epc_blog_bottom_relevance_base5&utm_relevant_index=10
+
+
+#鏃犳硶鑱旂綉
+vim /etc/resolv.conf
+(nameserve 8.8.8.8)
+
+
+tail -f /usr/local/jars/logs/visitsAdmin/info.2025-10-31.0.log
\ No newline at end of file
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java b/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java
index 2c440ea..4dc03c7 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java
@@ -22,10 +22,22 @@
     public static void main(String[] args) {
         //118.363428,31.326485
         //118.363312,31.326638
-        System.out.println(calculateDistance(39.326638d,116.363312d,31.326606,118.363272));
+        JkCustomer start = new JkCustomer();
+        start.setId(-1);
+        start.setLongitude(new BigDecimal(118.39));
+        start.setLatitude(new BigDecimal(31.28));
+
+
+        JkCustomer c = new JkCustomer();
+        c.setId(-2);
+        c.setLongitude(new BigDecimal(118.328593));
+        c.setLatitude(new BigDecimal(30.914289));
+        String url="https://restapi.amap.com/v3/direction/driving?origin=${long1},${lat1}&destination=${long2},${lat2}&extensions=basel&key=248ee35dcdfe3f399ffaf12ac4299eca";
+        DistanceCustomerModel dm = DistanceCalculator.calculateDistanceGaode(url,start,c);
+        System.out.println(dm.getDistance());
     }
 
-    public static DistanceCustomerModel calculateDistanceGaode(String urlStr, JkCustomer c1, JkCustomer c2) {
+    public static  DistanceCustomerModel calculateDistanceGaode(String urlStr, JkCustomer c1, JkCustomer c2) {
         DistanceCustomerModel r =new DistanceCustomerModel();
         r.setStart(c1);
         r.setEnd(c2);
@@ -67,10 +79,10 @@
                r.setCode(1);
                log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�==============");
             }else{
-                log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�=====澶辫触锛侊紒=========");
+                log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�=====澶辫触锛侊紒========="+c1.getName()+"==="+c2.getName()+result);
             }
         }catch (Exception e){
-            log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�=====澶辫触==========");
+            log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�=====澶辫触=========="+c1.getName()+"==="+c2.getName());
         }
 
         return r ;
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/TspSolver.java b/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/TspSolver.java
index 8d4ccdc..2aa6bef 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/TspSolver.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/TspSolver.java
@@ -4,6 +4,8 @@
 import com.doumee.core.exception.BusinessException;
 import com.google.ortools.Loader;
 import com.google.ortools.constraintsolver.*;
+import com.google.protobuf.Duration;
+import com.google.protobuf.DurationOrBuilder;
 import lombok.extern.slf4j.Slf4j;
 import com.google.ortools.constraintsolver.mainJNI;
 
@@ -85,7 +87,7 @@
         RoutingModel routing = new RoutingModel(manager);
 
         // 娉ㄥ唽鍥炶皟鍑芥暟
-        final int transitCallbackIndex =
+       /* final int transitCallbackIndex =
                 routing.registerTransitCallback((long fromIndex, long toIndex) -> {
                     int fromNode = manager.indexToNode(fromIndex);
                     int toNode = manager.indexToNode(toIndex);
@@ -94,25 +96,45 @@
 
         // 瀹氫箟鍥炶皟鍑芥暟鑷虫瘡鏉¤矾绾�
         routing.setArcCostEvaluatorOfAllVehicles(transitCallbackIndex);
-        // 澧炲姞璺濈缁村害绾︽潫
-        routing.addDimension(transitCallbackIndex, 0, 300000000,
+        routing.addDimension(transitCallbackIndex, 0, 30000000,
                 true,
                 "Distance");
         RoutingDimension distanceDimension = routing.getMutableDimension("Distance");
-        distanceDimension.setGlobalSpanCostCoefficient(100);
-//        // 娣诲姞瀹归噺闄愬埗
+        distanceDimension.setGlobalSpanCostCoefficient(100);*/
+        // 娉ㄥ唽鍥炶皟鍑芥暟
+        final int transitCallbackIndex1 =
+                routing.registerTransitCallback((long fromIndex, long toIndex) -> {
+                    return 1;
+                });
+        for (int d = 0; d < data.vehicleMaxNodes.length; d++) {
+            // 澧炲姞璺濈缁村害绾︽潫
+            routing.addDimension(transitCallbackIndex1, 0, data.vehicleMaxNodes[d],
+                    true,
+                    "customer_"+d);
+            RoutingDimension distanceDimension1 = routing.getMutableDimension("customer_"+d);
+            distanceDimension1.setGlobalSpanCostCoefficient(100);
+        }
+        // 娣诲姞瀹归噺闄愬埗
         final int demandCallbackIndex = routing.registerUnaryTransitCallback((long fromIndex) -> {
             int fromNode = manager.indexToNode(fromIndex);
             return data.demands[fromNode];
         });
         routing.addDimensionWithVehicleCapacity(demandCallbackIndex, 0, data.vehicleCapacities, true, "Capacity");
-//        routing.addDimensionWithVehicleTransits()
-        Solver solver = routing.solver();
 
-        //璁剧疆鎼滅储鏂规硶
+/*
+        // 娣诲姞瀹归噺闄愬埗
+        final int demandCallbackIndex1 = routing.registerUnaryTransitCallback((long fromIndex) -> {
+            return 1;
+        });
+        routing.addDimensionWithVehicleCapacity(demandCallbackIndex1, 0, data.vehicleMaxNodes, true, "Capacity");
+*/
+
+        Solver solver = routing.solver();
+        //璁剧疆鎼滅储鏂规硶(
         RoutingSearchParameters searchParameters =
                 main.defaultRoutingSearchParameters()
                         .toBuilder()
+                        .setTimeLimit(Duration.newBuilder().setSeconds(60*60).build())//鏈�涔�1灏忔椂
                         .setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC)
                         .build();
 
@@ -203,6 +225,7 @@
         public   long[] demands;
         //杞﹁締鏈�澶у杞�
         public   long[] vehicleCapacities ;
+        public   long[] vehicleMaxNodes ;
         public   long[][] distanceMatrix ;
 
        public List<TspSolverSolutions> getSolutions() {
@@ -213,22 +236,25 @@
            this.solutions = solutions;
        }
 
-       public  void initDataInfo(int vehicleNumber1, long[] demands1, long[] vehicleCapacities1, long[][] distanceMatrix1){
+       public  void initDataInfo(int vehicleNumber1, long[] demands1, long[] vehicleCapacities1, long[][] distanceMatrix1,long[] vehicleMaxNodes){
             this.demands = demands1;
             this.vehicleNumber = vehicleNumber1;
             this.vehicleCapacities=vehicleCapacities1;
             this.distanceMatrix=distanceMatrix1;
+            this.vehicleMaxNodes =vehicleMaxNodes;
         }
         public   void initDataList(){
-            lenght = 100;
-            vehicleNumber = 7;
+            lenght = 20;
+            vehicleNumber = 5;
             demands = new long[lenght];
             vehicleCapacities =new long[vehicleNumber];
+            vehicleMaxNodes =new long[vehicleNumber];
             distanceMatrix =  new long[lenght][lenght];
             int total0 =0;
             for (int i = 0; i <vehicleNumber ; i++) {
                 long tem = (long) (Math.random() * 1000 + 20000);
                 vehicleCapacities[i] = tem;
+                vehicleMaxNodes[i] =5;
                 total0+=tem;
                 System.out.print(tem+" ,");
             }
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 5455d33..f5dbf90 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
@@ -261,7 +261,6 @@
             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(",");
@@ -269,25 +268,55 @@
                 cLatitude =  new BigDecimal(ss[1]);
             }catch (Exception e){
             }
-            int index =0;
-            for(JkCustomer c : customerList){
-                try {
-                    log.info("浜ら�氳鍒�========"+c.getName()+"==========="+index++);
-                    dealDistancePerCustomer(c,url,date,cLatitude,cLongitude,customerList);
-                }catch (Exception e){
-
-                }
+            int circle = customerList.size()/100;//
+            if(customerList.size()%100>0){
+                circle +=1;
             }
 
+            boolean[] results = new boolean[circle] ;
+            for (int i = 0; i < circle; i++) {
+                final  int start =i*100;
+                final int end = (i+1)*100 > customerList.size()? customerList.size(): (i+1)*100;
+                results[i] =false;
+                BigDecimal finalCLatitude = cLatitude;
+                BigDecimal finalCLongitude = cLongitude;
+                log.error("浜ら�氳鍒�====绾跨▼circle锛�"+i+"====start:"+start+"===========end:"+end);
+                int finalI = i;
+                Thread t1=new Thread(() -> {
+                    try {
+                        int index =0;
+                        for (int j = start; j < end; j++) {
+                            try {
+                                log.error("浜ら�氳鍒�========"+customerList.get(j).getName()+"========cirle:"+finalI+"==="+index++);
+                                dealDistancePerCustomer(customerList.get(j),url,date, finalCLatitude, finalCLongitude,customerList);
+                            }catch (Exception e){
+
+                            }
+                        }
+                    }catch (Exception e){
+                    }finally {
+                        results[finalI] =true;
+                        boolean isDone = false;
+                        for(boolean t : results){
+                            isDone = isDone&&t;
+                        }
+                        if(isDone){
+                            cate.setStatus(Constants.ZERO);
+                            categoryMapper.updateById(cate);//鏇存柊浠诲姟鎵ц鐘舵��
+                        }
+                    }
+
+                });
+                t1.start();
+            }
         }catch (Exception e){
             e.printStackTrace();
         }finally {
-            cate.setStatus(Constants.ZERO);
-            categoryMapper.updateById(cate);//鏇存柊浠诲姟鎵ц鐘舵��
+
         }
     }
 
-    private void dealDistancePerCustomer(JkCustomer c, String url, Date date, BigDecimal cLatitude, BigDecimal cLongitude, List<JkCustomer> customerList) {
+    private void dealDistancePerCustomer(JkCustomer c, String url, Date date, BigDecimal cLatitude, BigDecimal cLongitude, List<JkCustomer> customerList) throws InterruptedException {
         List<JkCustomer> updateCustomerList = new ArrayList<>();
         List<JkCustomerNavigation> navigationList = new ArrayList<>();
         List<DistanceMapParam> tmpList = new ArrayList<>();
@@ -298,28 +327,34 @@
         t0.setId(-2);//琛ㄧず杩斿洖鍥尯
         t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
         if(Constants.formatLongNum(c.getStartDistance()) <= 0){
-            //鍥尯鍓嶅線璇ュ鎴风殑璺濈锛屽鏋滀箣鍓嶆湭鑾峰彇杩�
+            //鍥尯鍓嶅線璇ュ鎴风殑璺濈锛屽鏋滀箣鍓嶆湭鑾峰彇
             isNew = true;
             JkCustomer start = new JkCustomer();
             start.setId(-1);
             start.setLongitude(cLongitude);
             start.setLatitude(cLatitude);
             DistanceCustomerModel 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());
+            if(dm.getCode() == 1){
+                //瑙勫垝澶辫触
+                log.error("==============瀹㈡埛浜ら�氳鍒掓垚鍔熻捣鐐�:"+c.getName());
+                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(JkCustomer cm : customerList){
             //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
+            Thread.sleep(500);
             DistanceMapParam t = new DistanceMapParam();
             t.setId(cm.getId());
             DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList);
-            if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
+            if(param!=null && param.getDistance()!=0){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
                 t = param;
             }else{
                 JkCustomerNavigation navigation = new JkCustomerNavigation();
@@ -359,15 +394,19 @@
             start.setId(-1);
             start.setLongitude(cLongitude);
             start.setLatitude(cLatitude);
-
             DistanceCustomerModel 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());
+            if(dm.getCode()== 1){
+                //瑙勫垝澶辫触
+                log.error("==============瀹㈡埛浜ら�氳鍒掓垚鍔�2:"+c.getName());
+                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){//
@@ -463,6 +502,7 @@
             TspSolver.DataModel dataModel = new TspSolver.DataModel();
             int vehicleNumber1 = lineList.size();//绾胯矾鏁伴噺
             long[] vehicleCapacities1=new long[lineList.size()];//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
+            long[] vehicleMaxNodes=new long[lineList.size()];//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
             long[] demands1 = new long[customerList.size()+1]; //鍚勪釜鐐圭殑璁㈠崟閲�
             long[][] distanceMatrix1 = new long[customerList.size()+1][customerList.size()+1];
             distanceMatrix1[0][0] = 0;
@@ -488,9 +528,10 @@
             }
             for (int i = 0; i < lineList.size(); i++) {
                 vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
+                vehicleMaxNodes[i] =lineList.get(i).getMaxCustomer();//鏈�澶у鎴锋暟
             }
             //鏋勯�犱紭鍖栨暟鎹ā鍨�
-            dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
+            dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
             TspSolver.startSearch(dataModel);
             dealSearchSolution(model,dataModel);
         }catch (Exception e){
@@ -553,6 +594,7 @@
                 TspSolver.DataModel dataModel = new TspSolver.DataModel();
                 int vehicleNumber1 = 1;//绾胯矾鏁伴噺
                 long[] vehicleCapacities1=new long[]{line.getMaxOrder()};//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
+                long[] vehicleMaxNodes=new long[]{line.getMaxCustomer()};//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
                 long[] demands1 = new long[customerListParam.size()+1]; //鍚勪釜鐐圭殑璁㈠崟閲�
                 long[][] distanceMatrix1 = new long[customerListParam.size()+1][customerListParam.size()+1];
                 distanceMatrix1[0][0] = 0;
@@ -567,7 +609,7 @@
                     }
                 }
                 //鏋勯�犱紭鍖栨暟鎹ā鍨�
-                dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
+                dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
                 TspSolver.startSearch(dataModel);
                 if(dataModel.getSolutions()==null || dataModel.getSolutions().size()==0){
                     throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");

--
Gitblit v1.9.3