From c467370d8741bc05ca7c22d4253c58ac0a979ef5 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期二, 09 六月 2026 09:46:25 +0800
Subject: [PATCH] 功能优化

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java |   89 ++++++++++++++++++++++++++------------------
 1 files changed, 53 insertions(+), 36 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 95f0717..8a477f2 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
@@ -33,6 +33,7 @@
 import netscape.javascript.JSObject;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -44,6 +45,7 @@
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.Date;
+import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -56,6 +58,9 @@
 @Slf4j
 public class JkSketchServiceImpl implements JkSketchService {
 
+    @Autowired
+    @Qualifier("asyncExecutor")
+    private Executor asyncExecutor;
     @Autowired
     private JkSketchMapper jkSketchMapper;
     @Autowired
@@ -246,10 +251,13 @@
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺凡琚紭鍖栵紝宸叉棤娉曡绠楀師濮嬭矾绾胯矾绋嬫暟");
         }
         checkJketchCustomerLocation(model,true);
-        model.setEditDate(new Date());
-        model.setDistance(model.getOriginDistance());
-        jkSketchMapper.updateById(model);
-        return model;
+        JkSketch update = new JkSketch();
+        update.setId(model.getId());
+        update.setEditDate(new Date());
+        update.setDistance(model.getOriginDistance());
+        update.setOriginDistance(model.getOriginDistance());
+        jkSketchMapper.updateById(update);
+        return update;
     }
 
     @Override
@@ -283,7 +291,7 @@
                 BigDecimal finalCLongitude = cLongitude;
                 log.error("浜ら�氳鍒�====绾跨▼circle锛�"+i+"====start:"+start+"===========end:"+end);
                 int finalI = i;
-                Thread t1=new Thread(() -> {
+                asyncExecutor.execute(() -> {
                     try {
                         int index =0;
                         for (int j = start; j < end; j++) {
@@ -308,10 +316,9 @@
                     }
 
                 });
-                t1.start();
             }
         }catch (Exception e){
-            e.printStackTrace();
+            log.error("distanceCustomer寮傚父", e);
         }finally {
 
         }
@@ -547,7 +554,7 @@
             dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
             TspSolver.startSearch(dataModel);
             JkSketch nowModel = jkSketchMapper.selectById(model.getId());
-            if(StringUtils.equals(model.getJobId(), nowModel.getJobId())){
+            if(!StringUtils.equals(model.getJobId(), nowModel.getJobId())){
                log.error( "浼樺寲缁撴灉宸插け鏁堬紝闈炴渶杩戜竴娆℃搷浣滐紒");
                return;
             }
@@ -641,7 +648,7 @@
             queryWrapper.selectAll(JkSketchCustomer.class )
                     .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                     .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
-                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
+//                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                     .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                     .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                     .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
@@ -705,7 +712,7 @@
                     throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");
                 }
                 JkSketch nowModel = jkSketchMapper.selectById(model.getId());
-                if(StringUtils.equals(model.getJobId(), nowModel.getJobId())){
+                if(!StringUtils.equals(model.getJobId(), nowModel.getJobId())){
                     throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛岄潪鏈�杩戜竴娆℃搷浣滐紒");
                 }
 
@@ -766,7 +773,7 @@
             queryWrapper.selectAll(JkSketchCustomer.class )
                     .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                     .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
-                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
+//                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                     .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                     .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                     .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
@@ -873,7 +880,7 @@
         }
         for(JkSketchCustomer c : customerList){
             List<DistanceMapParam> tmpList = new ArrayList<>();
-            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
+//            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
             DistanceMapParam t0 = new DistanceMapParam();
             t0.setId(-2);//琛ㄧず杩斿洖鍥尯
             t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
@@ -883,10 +890,11 @@
                 DistanceMapParam t = new DistanceMapParam();
                 t.setId(cm.getCustomerId());
                 t.setDistance(0);
-                DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
+                t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
+               /* DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                 if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
                     t = param;
-                }
+                }*/
                 tmpList.add(t);
             }
             DistanceMapParam tt = new DistanceMapParam();
@@ -912,38 +920,44 @@
         }
         for(JkSketchCustomer c : customerList){
             List<DistanceMapParam> tmpList = new ArrayList<>();
-            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
+            //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+//            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
             DistanceMapParam t0 = new DistanceMapParam();
-            t0.setId(-2);//琛ㄧず杩斿洖鍥尯
-            t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
+            t0.setId(-2);//
+            t0.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
+
+            //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+          /*  t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
             if(Constants.formatLongNum(c.getStartDistance()) <= 0){
                 //鍥尯鍓嶅線璇ュ鎴风殑璺濈锛屽鏋滀箣鍓嶆湭鑾峰彇杩�
                 t0.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
-//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
-            }
+            }*/
             tmpList.add(t0);
             for(JkSketchCustomer cm : customerList){
                 //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
                 DistanceMapParam t = new DistanceMapParam();
                 t.setId(cm.getCustomerId());
-                 DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
+                t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
+                //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+              /*  DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                 if(param!=null && t.getDistance()>0){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
                     t = param;
                 }else{
                     //濡傛灉鏈鍒掞紝鎸夌収鐩寸嚎璺濈
                     t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
-//                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"涓庡鎴�:"+cm.getName()+"绠�浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒宠矾绋嬭绠楁潯浠讹紒");
-                }
+                }*/
                 tmpList.add(t);
             }
             DistanceMapParam tt = new DistanceMapParam();
             tt.setId(-2);//琛ㄧず杩斿洖鍥尯
-            tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
+            tt.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
+
+            //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+           /* tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
             if(Constants.formatLongNum(c.getEndDistance()) <= 0){
                 //璇ュ鎴疯繑鍥炲洯鍖虹殑璺濈 ,濡傛灉涔嬪墠鏈幏鍙栬繃
                 tt.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
-//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"涓庤捣鐐逛氦閫氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒宠矾绋嬭绠楁潯浠讹紒");
-            }
+            }*/
             tmpList.add(tt);
             c.setDistanceMapParamList(tmpList);
         }
@@ -955,32 +969,35 @@
                 int index =0;
                 for(JkSketchCustomer c : customers){
                     if(index ==0){
-                        if(Constants.formatLongNum(c.getStartDistance()) >0){
+
+                        lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
+                        //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+                      /*  if(Constants.formatLongNum(c.getStartDistance()) >0){
                             lineDistance+= Constants.formatLongNum(c.getStartDistance());
                         }else{
                             lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
-                        }
+                        }*/
                     }
                     if(index == customers.size()-1){
-                        if(Constants.formatLongNum(c.getEndDistance())>0){
+                        lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
+                        //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+                     /*   if(Constants.formatLongNum(c.getEndDistance())>0){
                             lineDistance+= Constants.formatLongNum(c.getEndDistance());
                         }else{
                             lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
-                        }
+                        }*/
                         break;
                     }
                     JkSketchCustomer end = customers.get(index+1);
-                    DistanceMapParam param1 = getParamByCustomerIds(end.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
+                    lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),end.getLatitude(),end.getLongitude());
+                    //====鏍囪==蹇界暐浜ら�氳鍒掕窛绂�=====
+                 /*   DistanceMapParam param1 = getParamByCustomerIds(end.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
                     if(param1 !=null && param1.getDistance()>0){
                         lineDistance += param1.getDistance();
                     }else{
                         lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),end.getLatitude(),end.getLongitude());
-                    }
-                    index++;
-                  /*  for(JkSketchCustomer cm : customers){
-                        DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
-                        lineDistance += param.getDistance();
                     }*/
+                    index++;
                 }
                 if(updateLineDistance && Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){
                     line.setDistance(lineDistance);
@@ -1242,7 +1259,7 @@
                 .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                 .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
                 .selectAs(JkCustomer::getDistanceStatus,JkSketchCustomer::getDistanceStatus)
-                .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
+//                .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                 .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                 .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                 .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)

--
Gitblit v1.9.3