From 4898564fb2510dcdbe10d01eaa94886512aebc77 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 20 十一月 2025 16:55:50 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/wuhuyancao' into wuhuyancao

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java |  163 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 118 insertions(+), 45 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 5455d33..2c34d74 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,49 +268,86 @@
                 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("浜ら�氳鍒�========"+cate.getId()+"/"+cate.getName()+"/"+customerList.get(j).getName()+"=======cirle/index:"+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<>();
         List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistance());
-        boolean isNew = false;
+        boolean isNew = false,hasError =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;
             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());
+                }
+            }else{
+                hasError=true;
             }
+
         }
         tmpList.add(t0);
         for(JkCustomer cm : customerList){
@@ -319,7 +355,7 @@
             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();
@@ -338,10 +374,15 @@
                 }else{
                     DistanceCustomerModel dm = DistanceCalculator.calculateDistanceGaode(url,c,cm);
                     t.setDistance(dm.getDistance() );
-                    if(dm.getLocations().size()>0){
-                        //濡傛灉鏈夎矾寰勪俊鎭�
-                        navigation.setSteps(dm.getPolyline());
+                    if(dm.getCode() == 1){
+                        if(dm.getLocations().size()>0){
+                            //濡傛灉鏈夎矾寰勪俊鎭�
+                            navigation.setSteps(dm.getPolyline());
+                        }
+                    }else{
+                        hasError=true;
                     }
+
                 }
                 navigation.setIdIndex(c.getId()+"-"+cm.getId());
                 navigation.setDistance(t.getDistance());
@@ -359,19 +400,25 @@
             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());
+                }
+            }else{
+                hasError=true;
             }
+
         }
         tmpList.add(tt);
         if(isNew){//
-            u.setDistanceStatus(Constants.ONE);
+            u.setDistanceStatus(hasError?Constants.ZERO:Constants.ONE);//鎵�鏈夐兘鎴愬姛鎵嶆爣娉ㄥ凡瑙勫垝
             u.setId(c.getId());
             u.setDistance(JSONObject.toJSONString(tmpList));
             updateCustomerList.add(u);
@@ -431,8 +478,8 @@
                 .eq(JkCustomer::getIsdeleted,Constants.ZERO)
                 .eq(JkLine::getCategoryId,model.getCategoryId() );
         List<JkCustomer> customerList = jkCustomerMapper.selectJoinList(JkCustomer.class,queryWrapper1);
-        List<JkCustomer> needList =checkNeedDistanceDo(customerList);
-        if(needList == null || needList.size() == 0){
+         List<JkCustomer> needList =checkNeedDistanceDo(customerList);
+        if(Constants.equalsInteger(model.getForceUpdate(),0)&& (needList == null || needList.size() == 0)){
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ヤ富绾夸笅鏃犻渶瑕佽繘琛岃窛绂昏绠楃殑瀹㈡埛淇℃伅锛�");
         }
         String errorMsg ="";
@@ -446,7 +493,7 @@
         }
         c.setStatus(Constants.TWO);
         categoryMapper.updateById(c);//鏇存柊浠诲姟鎵ц鐘舵��
-        c.setCustomerList(customerList);
+        c.setCustomerList(Constants.equalsInteger(model.getForceUpdate(),0)?needList:customerList);
         return  c;
     }
 
@@ -463,6 +510,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 +536,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 +602,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 +617,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()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");
@@ -1405,7 +1455,8 @@
                     .filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
             //浼樺寲鍚庢暟鎹�
             List<JkSketchLine> afterList = childLineList.stream()
-                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)
+                            && Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
 
             lineNum = lineNum + (Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)?beforeList.size():afterList.size());
             List<TelecomLineDataVO> telecomLineDataVOList = new ArrayList<>();
@@ -1461,7 +1512,9 @@
             telecomCategoryDataVO.setName(jkSketch.getCategoryName());
             //浼樺寲鍓嶆暟鎹�
             List<JkSketchLine> beforeList = jkSketchLineList.stream()
-                    .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())&&Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
+                    .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())
+                            && Objects.nonNull(i.getDistance())
+                            &&Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
             telecomCategoryDataVO.setDistance(
                     beforeList.stream().map(i->i.getDistance()).reduce(Long.valueOf(0),Long::sum)
             );
@@ -1470,16 +1523,36 @@
             }else{
                 //浼樺寲鍚庢暟鎹�
                 List<JkSketchLine> afterList = jkSketchLineList.stream()
-                        .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())&&Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+                        .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())
+                                && Objects.nonNull(i.getDistance())
+                                &&Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+        if(sketchList!=null){
+            for (JkSketch jkSketch:sketchList) {
+                TelecomCategoryDataVO telecomCategoryDataVO = new TelecomCategoryDataVO();
+                telecomCategoryDataVO.setId(jkSketch.getCategoryId());
+                telecomCategoryDataVO.setName(jkSketch.getCategoryName());
+                //浼樺寲鍓嶆暟鎹�
+                List<JkSketchLine> beforeList = jkSketchLineList.stream()
+                        .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())&&Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
+                telecomCategoryDataVO.setDistance(
+                        beforeList.stream().map(i->i.getDistance()).reduce(Long.valueOf(0),Long::sum)
+                );
+                if(Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)){
+                    telecomCategoryDataVO.setDistanceAfter(telecomCategoryDataVO.getDistance());
+                }else{
+                    //浼樺寲鍚庢暟鎹�
+                    List<JkSketchLine> afterList = jkSketchLineList.stream()
+                            .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())&&Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
 
-                Long distanceAfter = 0L;
-                for (JkSketchLine jkSketchLine:afterList) {
+                    Long distanceAfter = 0L;
+                    for (JkSketchLine jkSketchLine:afterList) {
                         distanceAfter = distanceAfter + jkSketchLine.getDistance();
-                }
-                telecomCategoryDataVO.setDistanceAfter(distanceAfter);
+                    }
+                    telecomCategoryDataVO.setDistanceAfter(distanceAfter);
 
+                }
+                telecomCategoryDataVOList.add(telecomCategoryDataVO);
             }
-            telecomCategoryDataVOList.add(telecomCategoryDataVO);
         }
         return telecomCategoryDataVOList;
     }

--
Gitblit v1.9.3