From 9852b16ec51c85fd808dc68b75eadfebd117a27e Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期三, 15 十月 2025 18:27:06 +0800
Subject: [PATCH] 最新版本541200007

---
 admin/src/views/business/jkSketch.vue                                                                   |    4 
 server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java                 |   50 ++++
 server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/JkSketchCustomer.java         |    7 
 admin/src/views/business/categoryJkLine.vue                                                             |   28 ++
 server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java                 |    3 
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCustomerServiceImpl.java |    8 
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java   |   32 ++
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java   |  455 ++++++++++++++++++++++---------------
 admin/src/api/business/jkSketch.js                                                                      |    7 
 admin/src/api/business/jkLine.js                                                                        |    2 
 server/visits/dmvisit_admin/src/main/java/com/doumee/cloud/admin/JkSketchCloudController.java           |   21 +
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/JkSketchService.java            |    7 
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkLineServiceImpl.java     |   24 ++
 server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCustomerModel.java              |   21 +
 admin/src/views/business/jkLine.vue                                                                     |    4 
 15 files changed, 478 insertions(+), 195 deletions(-)

diff --git a/admin/src/api/business/jkLine.js b/admin/src/api/business/jkLine.js
index 33ba880..37e47e8 100644
--- a/admin/src/api/business/jkLine.js
+++ b/admin/src/api/business/jkLine.js
@@ -35,7 +35,7 @@
 
 // 鍒犻櫎
 export function deleteById (id) {
-  return request.get(`/business/jkLine/delete/${id}`)
+  return request.get(`/visitsAdmin/cloudService/business/jkLine/delete/${id}`)
 }
 
 // 鎵归噺鍒犻櫎
diff --git a/admin/src/api/business/jkSketch.js b/admin/src/api/business/jkSketch.js
index 04ef2ad..3d0f4ae 100644
--- a/admin/src/api/business/jkSketch.js
+++ b/admin/src/api/business/jkSketch.js
@@ -39,7 +39,12 @@
 export function updateById (data) {
   return request.post('/visitsAdmin/cloudService/business/jkSketch/updateById', data)
 }
-
+export function initOriginDistance (data) {
+  return request.post('/visitsAdmin/cloudService/business/jkSketch/initOriginDistance', data)
+}
+export function distanceCustomer (data) {
+  return request.post('/visitsAdmin/cloudService/business/jkSketch/distanceCustomer', data)
+}
 // 鍒犻櫎
 export function deleteById (id) {
   return request.get(`/business/jkSketch/delete/${id}`)
diff --git a/admin/src/views/business/categoryJkLine.vue b/admin/src/views/business/categoryJkLine.vue
index 46db5ee..2b860d2 100644
--- a/admin/src/views/business/categoryJkLine.vue
+++ b/admin/src/views/business/categoryJkLine.vue
@@ -25,16 +25,25 @@
       >
         <el-table-column type="selection" width="55"></el-table-column>
         <el-table-column prop="name" show-overflow-tooltip label="涓荤嚎璺�" min-width="120px"></el-table-column>
+        <el-table-column prop="lineNum" show-overflow-tooltip label="绾胯矾鏁�" min-width="120px"></el-table-column>
+        <el-table-column prop="customerNum" show-overflow-tooltip label="瀹㈡埛浜ら�氳鍒掞紙宸插畬鎴�/鍏ㄩ儴锛�" align="center" min-width="200px">
+          <template slot-scope="{row}">
+            <span class="green"> {{row.customerDoneNum || 0}}/</span>
+            <span  > {{row.customerNum || 0}}</span>
+            <span v-if="row.status == 2 " class="red" style="margin-left: 10px; ">(瑙勫垝涓�)</span>
+          </template>
+        </el-table-column>
         <el-table-column prop="sortnum" label="鎺掑簭鐮�"  min-width="70px"></el-table-column>
         <el-table-column prop="editDate" label="鎿嶄綔鏃堕棿" width="160px"></el-table-column>
         <el-table-column
             v-if="containPermissions(['business:category:update', 'business:category:delete' ])"
             label="鎿嶄綔"
-            min-width="140"
+            min-width="180"
             fixed="right"
         >
           <template slot-scope="{row}">
             <el-button type="text" icon="el-icon-edit" @click="$refs.OperaCategoryJkLineWindow.open('缂栬緫涓荤嚎璺�',row)" v-permissions="['business:category:update']">缂栬緫</el-button>
+            <el-button  type="text"  icon="el-icon-edit" @click="distanceDo(row)"  v-if="row.status !=2 && row.customerDoneNum < row.customerNum " v-permissions="['business:category:update']">浜ら�氳鍒�</el-button>
             <el-button  type="text"  icon="el-icon-delete" @click="deleteById(row)" style="color: red" v-permissions="['business:category:delete']">鍒犻櫎</el-button>
           </template>
         </el-table-column>
@@ -56,6 +65,7 @@
 import TableLayout from '@/layouts/TableLayout'
 import Pagination from '@/components/common/Pagination'
 import OperaCategoryJkLineWindow from '@/components/business/OperaCategoryJkLineWindow'
+import { distanceCustomer } from '@/api/business/jkSketch'
 export default {
   name: 'areaSet',
   extends: BaseTable,
@@ -79,6 +89,22 @@
     this.search()
   },
   methods: {
+    distanceDo (row) {
+      var that = this
+      this.$confirm('纭畾杩涜璇ヤ富绾胯矾涓嬪鎴疯窛绂昏绠楀悧?', '鎻愮ず', {
+        confirmButtonText: '纭畾',
+        cancelButtonText: '鍙栨秷',
+        type: 'warning'
+      }).then(() => {
+        distanceCustomer({ categoryId: row.id })
+          .then(res => {
+            this.$tip.apiSuccess('浜ら�氳鍒掍换鍔℃鍦ㄥ悗鍙版墽琛岋紝鍙兘闇�瑕佷竴娈垫椂闂达紝璇风瓑寰呬换鍔″畬鎴愬悗鏌ョ湅缁撴灉')
+            that.search()
+          })
+      }).catch(() => {
+        this.$tip.apiSuccess('鎿嶄綔澶辫触')
+      })
+    }
   }
 }
 </script>
diff --git a/admin/src/views/business/jkLine.vue b/admin/src/views/business/jkLine.vue
index c71ffc3..256926e 100644
--- a/admin/src/views/business/jkLine.vue
+++ b/admin/src/views/business/jkLine.vue
@@ -28,7 +28,7 @@
       <ul class="toolbar" v-permissions="['business:jkline:create', 'business:jkline:delete']">
         <li><el-button type="primary" @click="$refs.operaJkLineWindow.open('鏂板缓浜ゆ帶-绾胯矾淇℃伅琛�')" icon="el-icon-plus" v-permissions="['business:jkline:create']">鏂板缓</el-button></li>
         <li><el-button icon="el-icon-upload"  type="primary" @click="$refs.OperaJkLineImportWindowRef.open('绾胯矾瀵煎叆')"  v-permissions="['business:jkline:create']">绾胯矾瀵煎叆</el-button></li>
-        <li><el-button type="danger" @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['business:jkline:delete']">鍒犻櫎</el-button></li>
+        <li><el-button type="danger"  @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['business:jkline:delete']">鍒犻櫎</el-button></li>
       </ul>
       <el-table
 
@@ -55,7 +55,7 @@
         >
           <template slot-scope="{row}">
             <el-button type="text" @click="$refs.operaJkLineWindow.open('缂栬緫浜ゆ帶-绾胯矾淇℃伅琛�', row)" icon="el-icon-edit" v-permissions="['business:jkline:update']">缂栬緫</el-button>
-            <el-button type="text" @click="deleteById(row)" icon="el-icon-delete" v-permissions="['business:jkline:delete']">鍒犻櫎</el-button>
+            <el-button type="text" class="red" @click="deleteById(row)" icon="el-icon-delete" v-permissions="['business:jkline:delete']">鍒犻櫎</el-button>
           </template>
         </el-table-column>
       </el-table>
diff --git a/admin/src/views/business/jkSketch.vue b/admin/src/views/business/jkSketch.vue
index 59b2a53..fc55295 100644
--- a/admin/src/views/business/jkSketch.vue
+++ b/admin/src/views/business/jkSketch.vue
@@ -58,13 +58,13 @@
         <el-table-column
           v-if="containPermissions(['business:jksketch:update', 'business:jksketch:delete'])"
           label="鎿嶄綔"
-          min-width="120"
+          min-width="140"
           align="left"
           fixed="right"
         >
           <template slot-scope="{row}">
             <el-button type="text" @click="$refs.operaJkSketchWindow.open('绾胯矾浼樺寲', row)" icon="el-icon-edit" v-permissions="['business:jksketch:update']">绾胯矾浼樺寲</el-button>
-            <el-button type="text" @click="$refs.OperaJkSketchResultWindow.open('浼樺寲缁撴灉寰皟-', row)" icon="el-icon-edit" v-if="row.status ==2" >浼樺寲缁撴灉寰皟</el-button>
+            <el-button type="text" class="red" @click="$refs.OperaJkSketchResultWindow.open('浼樺寲缁撴灉寰皟-', row)" icon="el-icon-edit" v-if="row.status ==2" >浼樺寲缁撴灉寰皟</el-button>
           </template>
         </el-table-column>
       </el-table>
diff --git a/server/visits/dmvisit_admin/src/main/java/com/doumee/cloud/admin/JkSketchCloudController.java b/server/visits/dmvisit_admin/src/main/java/com/doumee/cloud/admin/JkSketchCloudController.java
index 34df5fa..34800e7 100644
--- a/server/visits/dmvisit_admin/src/main/java/com/doumee/cloud/admin/JkSketchCloudController.java
+++ b/server/visits/dmvisit_admin/src/main/java/com/doumee/cloud/admin/JkSketchCloudController.java
@@ -4,7 +4,10 @@
 import com.doumee.config.annotation.CloudRequiredPermission;
 import com.doumee.core.annotation.excel.ExcelExporter;
 import com.doumee.core.annotation.pr.PreventRepeat;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
 import com.doumee.core.utils.Constants;
+import com.doumee.dao.business.model.Category;
 import com.doumee.dao.business.model.JkCustomer;
 import com.doumee.dao.business.model.JkSketch;
 import com.doumee.service.business.JkSketchService;
@@ -72,6 +75,24 @@
         return ApiResponse.success(null);
     }
 
+    @ApiOperation("鏍规嵁ID閲嶆柊璁$畻褰撳墠绾胯矾鐨勮窛绂�")
+    @PostMapping("/initOriginDistance")
+    @CloudRequiredPermission("business:jksketch:update")
+    public ApiResponse<JkSketch> initOriginDistance(@RequestBody JkSketch jkSketch, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
+        jkSketch.setLoginUserInfo(this.getLoginUser(token));
+        JkSketch model = jkSketchService.initOriginDistance(jkSketch);
+        return ApiResponse.success(model);
+    }
+    @ApiOperation("涓荤嚎璺鎴疯窛绂昏绠�")
+    @PostMapping("/distanceCustomer")
+    @CloudRequiredPermission("business:jksketch:update")
+    public ApiResponse distanceCustomer(@RequestBody JkSketch model, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
+        model.setLoginUserInfo(this.getLoginUser(token));
+        Category category =  jkSketchService.checkDataValid(model);//寮傛璁$畻
+        jkSketchService.distanceCustomer(category);//寮傛璁$畻
+        return ApiResponse.success(null);
+    }
+
     @ApiOperation("鍒嗛〉鏌ヨ")
     @PostMapping("/page")
     @CloudRequiredPermission("business:jksketch:query")
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 239e1dc..2c440ea 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
@@ -25,6 +25,56 @@
         System.out.println(calculateDistance(39.326638d,116.363312d,31.326606,118.363272));
     }
 
+    public static DistanceCustomerModel calculateDistanceGaode(String urlStr, JkCustomer c1, JkCustomer c2) {
+        DistanceCustomerModel r =new DistanceCustomerModel();
+        r.setStart(c1);
+        r.setEnd(c2);
+        r.setDistance(0);
+        r.setCode(0);
+        r.setLocations( new ArrayList<>());
+        try {
+            String url  =urlStr.replace("${lat1}", Constants.formatBigdecimalScale(c1.getLatitude(),6)+"")
+                    .replace("${lat2}",Constants.formatBigdecimalScale(c2.getLatitude(),6)+"")
+                    .replace("${long1}",Constants.formatBigdecimalScale(c1.getLongitude(),6)+"")
+                    .replace("${long2}",Constants.formatBigdecimalScale(c2.getLongitude(),6)+"");
+            String result = HttpsUtil.get(url ,true);
+            JSONObject json = JSONObject.parseObject(result);
+            if(json!=null
+                    && json.getInteger("status")!=null
+                    && json.getInteger("status") ==1
+                    && json.getJSONObject("route")!=null
+                    && json.getJSONObject("route").getJSONArray("paths") !=null
+                    && json.getJSONObject("route").getJSONArray("paths") .size()>0 ){
+                JSONArray array = json.getJSONObject("route").getJSONArray("paths");
+                JSONObject model = array.getJSONObject(0);//鍙栫涓�涓�
+               Long distance = Long.parseLong(model.getString("distance"));
+               r.setDistance(distance);
+               JSONArray steps = model.getJSONArray("steps");
+               String tl = "";
+               if(steps!=null && steps.size()>0){
+                   for (int i = 0; i < steps.size(); i++) {
+                       if(StringUtils.isBlank(steps.getJSONObject(i).getString("polyline" ))){
+                           continue;
+                       }
+                       if(!tl.equals("") &&!tl.endsWith(";")){
+                           tl += ";";
+                       }
+                       tl+= steps.getJSONObject(i).getString("polyline" );
+                   }
+               }
+               r.setPolyline(tl);
+               r.setLocations(Arrays.asList(tl.split(";")));
+               r.setCode(1);
+               log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�==============");
+            }else{
+                log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�=====澶辫触锛侊紒=========");
+            }
+        }catch (Exception e){
+            log.error("鑾峰彇浜ら�氳鍒掔嚎璺俊鎭垚鍔�=====澶辫触==========");
+        }
+
+        return r ;
+    }
     public static DistanceModel calculateDistanceGaode(String urlStr, JkSketchCustomer c1, JkSketchCustomer c2) {
         DistanceModel r =new DistanceModel();
         r.setStart(c1);
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCustomerModel.java b/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCustomerModel.java
new file mode 100644
index 0000000..5e5164b
--- /dev/null
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCustomerModel.java
@@ -0,0 +1,21 @@
+package com.doumee.core.tsp;
+
+import com.doumee.dao.business.model.JkCustomer;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+
+@Slf4j
+@Data
+public class DistanceCustomerModel {
+     private long distance;
+     private List<String> locations;
+     private String polyline;
+     private JkCustomer start;
+     private JkCustomer end;
+     private int code;//0澶辫触 1鎴愬姛
+
+
+
+}
\ No newline at end of file
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java b/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java
index 38fbbec..3c1dbea 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java
@@ -108,6 +108,9 @@
     @ApiModelProperty(value = "瀛愰泦鍒嗙被")
     @TableField(exist = false)
     private List<Category> childCategoryList;
+    @ApiModelProperty(value = "瀹㈡埛闆嗗悎")
+    @TableField(exist = false)
+    private List<JkCustomer> customerList;
 
 
 }
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/JkSketchCustomer.java b/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/JkSketchCustomer.java
index 6f81fd5..26240d5 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/JkSketchCustomer.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/JkSketchCustomer.java
@@ -127,6 +127,10 @@
     //@ExcelColumn(name="鐘舵�� 0姝e父 绂佺敤")
     @TableField(exist = false)
     private Long  startDistance;
+    @ApiModelProperty(value = "瀹㈡埛鏄惁瀹屾垚浜ら�氳鍒�", example = "1")
+    //@ExcelColumn(name="鐘舵�� 0姝e父 绂佺敤")
+    @TableField(exist = false)
+    private Integer  distanceStatus;
     @ApiModelProperty(value = "璇ュ鎴疯繑鍥炲洯鍖虹殑璺濈锛堢背锛�", example = "1")
     @TableField(exist = false)
     //@ExcelColumn(name="鐘舵�� 0姝e父 绂佺敤")
@@ -139,9 +143,6 @@
     //@ExcelColumn(name="鐘舵�� 0姝e父 绂佺敤")
     @TableField(exist = false)
     private String  endSteps;
-    @ApiModelProperty(value = "鍚岀彮缁勯棿瀹㈡埛浣嶇疆璺濈鏁扮粍锛孾{a:12,b:100},{a:13,b:200},...],a锛氬鎴风紪鐮侊紝b锛氫笌瀹㈡埛a涔嬮棿鐨勮窛绂�")
-    @TableField(exist = false)
-    private List<Map<String,Object>> distanceList;
     @ApiModelProperty(value = "鍚岀彮缁勯棿瀹㈡埛浣嶇疆璺濈鏁扮粍锛孾{a:12,b:100},{a:13,b:200},...],a锛氬鎴风紪鐮侊紝b锛氫笌瀹㈡埛a涔嬮棿鐨勮窛绂�")
     @TableField(exist = false)
     private List<DistanceMapParam> distanceMapParamList;
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/JkSketchService.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/JkSketchService.java
index 5f7fe5d..45c1a3c 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/JkSketchService.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/JkSketchService.java
@@ -1,5 +1,7 @@
 package com.doumee.service.business;
 
+import com.doumee.dao.business.model.Category;
+import com.doumee.dao.business.model.JkCustomer;
 import com.doumee.service.business.third.model.LoginUserInfo;
 import com.doumee.service.business.third.model.PageData;
 import com.doumee.service.business.third.model.PageWrap;
@@ -50,6 +52,7 @@
      * @param jkSketch 瀹炰綋瀵硅薄
      */
     JkSketch updateById(JkSketch jkSketch );
+    JkSketch initOriginDistance(JkSketch jkSketch );
 
     /**
      * 鎵归噺涓婚敭鏇存柊
@@ -101,4 +104,8 @@
     List<JkSketch> importBatch(MultipartFile file, String dateInfo, LoginUserInfo loginUser);
 
     void startUpdateLineAsync(JkSketch model);
+
+    void distanceCustomer(Category model );
+
+    Category   checkDataValid(JkSketch model);
 }
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
index 5bb5632..b89b1b5 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -3,6 +3,8 @@
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
+import com.doumee.dao.business.JkLineMapper;
+import com.doumee.dao.business.model.JkLine;
 import com.doumee.service.business.third.model.LoginUserInfo;
 import com.doumee.service.business.third.model.PageData;
 import com.doumee.service.business.third.model.PageWrap;
@@ -44,6 +46,8 @@
     private SystemDictDataBiz systemDictDataBiz;
     @Autowired
     private CategoryMapper categoryMapper;
+    @Autowired
+    private JkLineMapper jkLineMapper;
 
     @Override
     @Transactional(rollbackFor = {Exception.class, BindException.class})
@@ -81,6 +85,17 @@
 
     @Override
     public void deleteById(Integer id) {
+        Category c = categoryMapper.selectById(id);
+        if(c == null||Constants.equalsInteger(c.getIsdeleted(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(Constants.equalsInteger(c.getType(),Constants.FOUR)){
+            //濡傛灉鏄柊绾胯矾锛屾鏌ユ槸鍚︽湁瀛愮嚎璺紝鏈夊垯涓嶅厑璁稿垹闄�
+            if(jkLineMapper.selectCount(new MPJLambdaWrapper<JkLine>().eq(JkLine::getIsdeleted,Constants.ZERO)
+                    .eq(JkLine::getCategoryId,id)) >0){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"涓荤嚎璺��"+c.getName()+"銆戜笅宸插瓨鍦ㄥ瓙绾胯矾锛屼笉鍏佽鍒犻櫎锛�");
+            }
+        }
         categoryMapper.update(null,new UpdateWrapper<Category>().lambda().set(Category::getIsdeleted,Constants.ONE)
                 .eq(Category::getId,id)
         );
@@ -97,7 +112,20 @@
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        categoryMapper.update(null,new UpdateWrapper<Category>().lambda().set(Category::getIsdeleted,Constants.ONE)
+        for(Integer id :ids){
+            Category c = categoryMapper.selectById(id);
+            if(c == null ||Constants.equalsInteger(c.getIsdeleted(),Constants.ONE)){
+                continue;
+            }
+            if(Constants.equalsInteger(c.getType(),Constants.FOUR)){
+                //濡傛灉鏄柊绾胯矾锛屾鏌ユ槸鍚︽湁瀛愮嚎璺紝鏈夊垯涓嶅厑璁稿垹闄�
+                if(jkLineMapper.selectCount(new MPJLambdaWrapper<JkLine>().eq(JkLine::getIsdeleted,Constants.ZERO)
+                        .eq(JkLine::getCategoryId,id)) >0){
+                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"涓荤嚎璺��"+c.getName()+"銆戜笅宸插瓨鍦ㄥ瓙绾胯矾锛屼笉鍏佽鍒犻櫎锛�");
+                }
+            }
+        }
+       categoryMapper.update(null,new UpdateWrapper<Category>().lambda().set(Category::getIsdeleted,Constants.ONE)
                 .in(Category::getId,ids)
         );
     }
@@ -167,7 +195,7 @@
             //濡傛灉鏄富绾胯矾锛屾煡璇㈢嚎璺暟鍜屽鎴锋暟
             queryWrapper.select( "(select count(1) from jk_line b where b.isdeleted=0 and b.CATEGORY_ID = t.id)",Category::getLineNum);
             queryWrapper.select( "(select count(1) from jk_customer b left join jk_line c on b.line_id=c.id where c.isdeleted=0 and b.isdeleted=0 and c.CATEGORY_ID = t.id)",Category::getCustomerNum);
-            queryWrapper.select( "(select count(1) from jk_customer b left join jk_line c on b.line_id=c.id where c.isdeleted=0 and b.isdeleted=0 and c.CATEGORY_ID = t.id b.DISTANCE_STATUS = 1)",Category::getCustomerDoneNum);
+            queryWrapper.select( "(select count(1) from jk_customer b left join jk_line c on b.line_id=c.id where c.isdeleted=0 and b.isdeleted=0 and c.CATEGORY_ID = t.id and b.DISTANCE_STATUS = 1)",Category::getCustomerDoneNum);
         }
         queryWrapper.eq(Category::getIsdeleted,Constants.ZERO)
                 .eq(Objects.nonNull(pageWrap.getModel().getType()),Category::getType,pageWrap.getModel().getType())
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCustomerServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCustomerServiceImpl.java
index 85cf953..acd94f9 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCustomerServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCustomerServiceImpl.java
@@ -156,6 +156,7 @@
                 .selectAs(Category::getName,JkCustomer::getCategoryName)
                 .leftJoin(JkLine.class,JkLine::getId,JkCustomer::getLineId )
                 .leftJoin(Category.class,Category::getId,JkLine::getCategoryId );
+        queryWrapper.eq( pageWrap.getModel().getDistanceStatus()!=null,JkCustomer::getDistanceStatus, pageWrap.getModel().getDistanceStatus());
         queryWrapper.eq( pageWrap.getModel().getCategoryId()!=null,JkLine::getCategoryId, pageWrap.getModel().getCategoryId());
         queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getLineWeeks()),JkLine::getWeeks, pageWrap.getModel().getLineWeeks());
         queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCategoryName()),Category::getName, pageWrap.getModel().getCategoryName());
@@ -236,6 +237,7 @@
         try {
             LambdaQueryWrapper<JkCustomer> queryWrapper = new LambdaQueryWrapper<>();
             queryWrapper.isNotNull(JkCustomer::getLocation);
+            queryWrapper.isNotNull(JkCustomer::getLocation);
             queryWrapper.and(wrapper ->{
                 wrapper.isNull(JkCustomer::getLatitude)
                         .or().isNull(JkCustomer::getLongitude); });
@@ -247,7 +249,9 @@
             String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_LOCATION_GEOAPI_URL).getCode();
             for(JkCustomer c : list){
                 try {
-                    String result = HttpsUtil.get(url.replace("${param}",c.getLocation()),true);
+                    String urlStr =url.replace("${param}"
+                            ,c.getLocation().replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", ""));
+                    String result = HttpsUtil.get(urlStr,true);
                     JSONObject json = JSONObject.parseObject(result);
                     if(json!=null
                             && json.getInteger("status")!=null
@@ -271,7 +275,7 @@
                         }
                     }else{
                         log.error("鏇存柊浜ゆ帶涓績瀹㈡埛缁忕含搴︿俊鎭�=====鑾峰彇json=========="+json);
-                        log.error("鏇存柊浜ゆ帶涓績瀹㈡埛缁忕含搴︿俊鎭�=====鑾峰彇澶辫触=========="+c.getName()+"-"+c.getLocation());
+                        log.error("鏇存柊浜ゆ帶涓績瀹㈡埛缁忕含搴︿俊鎭�=====鑾峰彇澶辫触=========="+urlStr+c.getName()+"-"+c.getLocation());
                     }
                 }catch (Exception e){
                     log.error("鏇存柊浜ゆ帶涓績瀹㈡埛缁忕含搴︿俊鎭�=====澶辫触=========="+c.getName()+"-"+c.getLocation());
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkLineServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkLineServiceImpl.java
index 1b1f6cb..3d347eb 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkLineServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkLineServiceImpl.java
@@ -10,6 +10,7 @@
 import com.doumee.dao.admin.request.JkLineImport;
 import com.doumee.dao.business.CarsMapper;
 import com.doumee.dao.business.CategoryMapper;
+import com.doumee.dao.business.JkCustomerMapper;
 import com.doumee.dao.business.model.*;
 import com.doumee.service.business.third.model.LoginUserInfo;
 import com.doumee.service.business.third.model.PageData;
@@ -22,6 +23,7 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import io.swagger.models.auth.In;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -51,6 +53,8 @@
     @Autowired
     private CategoryMapper categoryMapper;
     @Autowired
+    private JkCustomerMapper jkCustomerMapper;
+    @Autowired
     private CarsMapper carsMapper;
 
     @Override
@@ -78,6 +82,15 @@
 
     @Override
     public void deleteById(Integer id, LoginUserInfo user) {
+        JkLine c = jkLineMapper.selectById(id);
+        if(c == null||Constants.equalsInteger(c.getIsdeleted(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        //濡傛灉鏄柊绾胯矾锛屾鏌ユ槸鍚︽湁瀛愮嚎璺紝鏈夊垯涓嶅厑璁稿垹闄�
+        if(jkCustomerMapper.selectCount(new MPJLambdaWrapper<JkCustomer>().eq(JkCustomer::getIsdeleted,Constants.ZERO)
+                .eq(JkCustomer::getLineId,id)) >0){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+c.getName()+"銆戜笅宸插瓨鍦ㄥ鎴蜂俊鎭紝涓嶅厑璁稿垹闄わ紒");
+        }
         jkLineMapper.update(null,new UpdateWrapper<JkLine>().lambda()
                 .set(JkLine::getIsdeleted,Constants.ONE)
                 .set(JkLine::getEditor,user.getId())
@@ -97,6 +110,17 @@
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
+        for(Integer id :ids){
+            JkLine c = jkLineMapper.selectById(id);
+            if(c == null||Constants.equalsInteger(c.getIsdeleted(),Constants.ONE)){
+               continue;
+            }
+            //濡傛灉鏄柊绾胯矾锛屾鏌ユ槸鍚︽湁瀛愮嚎璺紝鏈夊垯涓嶅厑璁稿垹闄�
+            if(jkCustomerMapper.selectCount(new MPJLambdaWrapper<JkCustomer>().eq(JkCustomer::getIsdeleted,Constants.ZERO)
+                    .eq(JkCustomer::getLineId,id)) >0){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+c.getName()+"銆戜笅宸插瓨鍦ㄥ鎴蜂俊鎭紝涓嶅厑璁稿垹闄わ紒");
+            }
+        }
         jkLineMapper.update(null,new UpdateWrapper<JkLine>().lambda()
                 .set(JkLine::getIsdeleted,Constants.ONE)
                 .set(JkLine::getEditor,user.getId())
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 c7669ef..c7ef282 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
@@ -22,6 +22,7 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import lombok.extern.slf4j.Slf4j;
 import netscape.javascript.JSObject;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,10 +44,13 @@
  * @date 2025/09/28 09:01
  */
 @Service
+@Slf4j
 public class JkSketchServiceImpl implements JkSketchService {
 
     @Autowired
     private JkSketchMapper jkSketchMapper;
+    @Autowired
+    private CategoryMapper categoryMapper;
     @Autowired
     private JkSketchLineMapper jkSketchLineMapper;
     @Autowired
@@ -126,7 +130,7 @@
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇ョ嚎璺鍗曢�佽揣閲忚秴杩囦簡绾胯矾鎬婚�佽揣閲忛檺鍒讹紝鏃犳硶杩涜浼樺寲锛�");
         }
         model.setLineList(lineList);//绾胯矾闆嗗悎
-        model.setCustomerList(checkJketchCustomerLocation(model));//璁㈠崟闆嗗悎
+        model.setCustomerList(checkJketchCustomerLocation(model,false));//璁㈠崟闆嗗悎
         model.setStatus(Constants.ONE);
         model.setPlanLineNum(lineList.size());
         model.setEditDate(new Date());
@@ -138,12 +142,224 @@
         jkSketchMapper.updateById(model);
         return model;
     }
+    @Override
+    public JkSketch initOriginDistance(JkSketch jkSketch ) {
+        JkSketch model = jkSketchMapper.selectById(jkSketch.getId());
+        if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(!Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺凡琚紭鍖栵紝宸叉棤娉曡绠楀師濮嬭矾绾胯矾绋嬫暟");
+        }
+        checkJketchCustomerLocation(model,true);
+        model.setEditDate(new Date());
+        model.setEditor(jkSketch.getLoginUserInfo().getId());
+        model.setDistance(model.getOriginDistance());
+        jkSketchMapper.updateById(model);
+        return model;
+    }
 
+    @Override
+    @Async
+    public  void distanceCustomer( Category cate) {
+        try {
+            List<JkCustomer> customerList = cate.getCustomerList();
+            String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_DISTANCE_GEOAPI_URL).getCode();
+            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){
+            }
+            int index =0;
+            for(JkCustomer c : customerList){
+                try {
+                    log.info("浜ら�氳鍒�========"+c.getName()+"==========="+index++);
+                    dealDistancePerCustomer(c,url,date,cLatitude,cLongitude,customerList);
+                }catch (Exception e){
+
+                }
+            }
+
+        }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) {
+        List<JkCustomer> updateCustomerList = new ArrayList<>();
+        List<JkCustomerNavigation> navigationList = new ArrayList<>();
+        List<DistanceMapParam> tmpList = new ArrayList<>();
+        List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistance());
+        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;
+            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());
+            }
+        }
+        tmpList.add(t0);
+        for(JkCustomer 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.getId(),cm.getId())){
+                    t.setDistance(0l);
+                }else{
+                    DistanceCustomerModel 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;
+            JkCustomer start = new JkCustomer();
+            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());
+            }
+        }
+        tmpList.add(tt);
+        if(isNew){//
+            u.setDistanceStatus(Constants.ONE);
+            u.setId(c.getId());
+            u.setDistance(JSONObject.toJSONString(tmpList));
+            updateCustomerList.add(u);
+        }
+        if(updateCustomerList.size()>0){
+            for(JkCustomer c1 : updateCustomerList){
+                jkCustomerMapper.updateById(c1);//鏇存柊瀹㈡埛涓庡叾浠栫偣涔嬮棿鐨勮窛绂�
+            }
+        }
+        if(navigationList.size()>0){
+            jkCustomerNavigationMapper.delete(new UpdateWrapper<JkCustomerNavigation>().lambda()
+                    .eq(JkCustomerNavigation::getStartId,c.getId()));//鍒犻櫎鍘嗗彶鏁版嵁
+            jkCustomerNavigationMapper.insert(navigationList);//鎻掑叆鏈�鏂版暟鎹�
+        }
+    }
+
+    private  List<JkCustomer>  checkNeedDistanceDo( List<JkCustomer> customerList) {
+        if(customerList==null || customerList.size()==0){
+            return null;
+        }
+        boolean need = false;
+        List<JkCustomer> list = new ArrayList<>();
+        for(JkCustomer jk : customerList){
+            if(Constants.equalsInteger(jk.getDistanceStatus(),Constants.ZERO)){
+                need = true;
+                list.add(jk);
+            }
+        }
+        if(!need){//濡傛灉鏃犻渶杩涜澶勭悊
+            return null;
+        }
+        return  list;
+
+    }
+
+    @Override
+    public  Category checkDataValid(JkSketch model) {
+        if(model.getCategoryId() == null){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>();
+        queryWrapper.selectAll(Category.class )
+                .eq(Category::getIsdeleted,Constants.ZERO)
+                .eq(Category::getType,Constants.FOUR)
+                .eq(Category::getId,model.getCategoryId() );
+        Category c = categoryMapper.selectJoinOne(Category.class,queryWrapper);
+        if(c==null){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(Constants.equalsInteger(c.getStatus(),Constants.TWO)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ヤ富绾挎鍦ㄨ繘琛屽鎴疯窛绂昏绠椾换鍔★紝璇疯�愬績绛夊緟浠诲姟瀹屾垚锛�");
+        }
+
+        MPJLambdaWrapper<JkCustomer> queryWrapper1 = new MPJLambdaWrapper<>();
+        queryWrapper1.selectAll(JkCustomer.class )
+                .leftJoin(JkLine.class,JkLine::getId,JkCustomer::getLineId)
+                .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){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ヤ富绾夸笅鏃犻渶瑕佽繘琛岃窛绂昏绠楃殑瀹㈡埛淇℃伅锛�");
+        }
+        String errorMsg ="";
+        for(JkCustomer c1 : customerList){
+            if(c1.getLatitude()==null || c1.getLongitude() ==null){
+                errorMsg += c.getName()+"-"+c.getName()+" | ";
+            }
+        }
+        if(StringUtils.isNotBlank(errorMsg)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:銆�"+errorMsg+"銆戝畾浣嶄俊鎭笉瀹屾暣锛屼笉婊¤冻璺濈璁$畻鏉′欢锛�");
+        }
+        c.setStatus(Constants.TWO);
+        categoryMapper.updateById(c);//鏇存柊浠诲姟鎵ц鐘舵��
+        c.setCustomerList(customerList);
+        return  c;
+    }
     @Override
     @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();
@@ -187,80 +403,28 @@
 
     }
 
-    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<>();
+    private void initCustomerDistance( List<JkSketchLine> lineList,JkSketch model,boolean updateLineDistance) {
         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());
-                }
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
             }
             tmpList.add(t0);
             for(JkSketchCustomer cm : customerList){
                 //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
                 DistanceMapParam t = new DistanceMapParam();
-                t.setId(cm.getId());
-                DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList);
+                t.setId(cm.getCustomerId());
+                DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),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);
+                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒宠矾绋嬭绠楁潯浠讹紒");
                 }
                 tmpList.add(t);
             }
@@ -269,37 +433,45 @@
             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());
-                }
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒宠矾绋嬭绠楁潯浠讹紒");
             }
             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(lineList!=null){
+            long totalDistance = 0;
+            for (JkSketchLine line :lineList){
+                long lineDistance = 0;
+                List<JkSketchCustomer> customers = getCustomerListByLineId(line.getId(),customerList);
+                for(JkSketchCustomer c : customers){
+                    lineDistance+= Constants.formatLongNum(c.getStartDistance());
+                    lineDistance+= Constants.formatLongNum(c.getEndDistance());
+                    for(JkSketchCustomer cm : customers){
+                        DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
+                        lineDistance += param.getDistance();
+                    }
+                }
+                if(updateLineDistance && Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){
+                    line.setDistance(lineDistance);
+                    jkSketchLineMapper.updateById(line);
+                }
+                totalDistance += lineDistance;
+            }
+            if(Constants.equalsInteger(model.getStatus(),Constants.ZERO) ||Constants.formatLongNum(model.getOriginDistance()) <= 0l ){
+                //濡傛灉棣栨浼樺寲鎴栬�呬箣鍓嶆病鏈夎绠楄繃锛岃缃紭鍖栧墠鍘熷璺緞
+                model.setOriginDistance(totalDistance);
             }
         }
-        if(navigationList.size()>0){
-            jkCustomerNavigationMapper.insert(navigationList);
+    }
+
+    private List<JkSketchCustomer> getCustomerListByLineId(Integer id, List<JkSketchCustomer> customerList) {
+        List<JkSketchCustomer> list = new ArrayList<>();
+        for (JkSketchCustomer c :customerList){
+            if(Constants.equalsInteger(c.getSketchLineId(),id)){
+                list.add(c);
+            }
         }
+        return list;
     }
 
     private DistanceMapParam getParamByCustomerIds(  Integer id1, List<DistanceMapParam> distanceMapParamList) {
@@ -416,11 +588,12 @@
         }
     }
 
-    private   List<JkSketchCustomer>  checkJketchCustomerLocation(JkSketch model) {
+    private   List<JkSketchCustomer>  checkJketchCustomerLocation(JkSketch model,boolean updateLineDistance) {
         MPJLambdaWrapper<JkSketchCustomer> queryWrapper = new MPJLambdaWrapper<>();
         queryWrapper.selectAll(JkSketchCustomer.class )
                 .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                 .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
+                .selectAs(JkCustomer::getDistanceStatus,JkSketchCustomer::getDistanceStatus)
                 .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                 .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                 .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
@@ -435,83 +608,29 @@
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴蜂俊鎭负绌猴紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
         }
         String errorMsg ="";
+        String errorMsg1 ="";
         for(JkSketchCustomer c : customerList){
             if(c.getLatitude()==null || c.getLongitude() ==null){
-                errorMsg += c.getName()+"-"+c.getName()+"锛�";
+                errorMsg += c.getName()+"-"+c.getName()+" | ";
+            }
+            if(!Constants.equalsInteger(c.getDistanceStatus(),Constants.ONE)){
+                errorMsg1 += c.getName()+"-"+c.getName()+" | ";
             }
         }
         if(StringUtils.isNotBlank(errorMsg)){
-            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+errorMsg+"瀹氫綅淇℃伅涓嶅畬鏁达紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:銆�"+errorMsg+"銆戝畾浣嶄俊鎭笉瀹屾暣锛屼笉婊¤冻浼樺寲鏉′欢锛�");
         }
-       /* for(JkSketchCustomer c : customerList){
-            List<Map<String,Object>> tmpList = new ArrayList<>();
-            for(JkSketchCustomer cm : customerList){
-                Map<String,Object> t = new HashMap<>();
-                t.put("a",cm.getId());
-                if(Constants.equalsInteger(c.getCustomerId(),cm.getCustomerId())){
-                    t.put("b",0l);
-                }else{
-                    t.put("b", DistanceCalculator.calculateDistance(
-                            Constants.formatBigdecimal(c.getLatitude()).doubleValue(),
-                            Constants.formatBigdecimal(c.getLongitude()).doubleValue(),
-                            Constants.formatBigdecimal(cm.getLatitude()).doubleValue(),
-                            Constants.formatBigdecimal(cm.getLongitude()).doubleValue()));
-                }
-                tmpList.add(t);
-            }
-            c.setDistanceList(tmpList);
+        if(StringUtils.isNotBlank(errorMsg1)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:銆�"+errorMsg1+"銆戜氦閫氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
         }
-        */
-        /*if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){
-            //濡傛灉鏄湭浼樺寲鐘舵�侊紝璁$畻鍘熷璺濈
-            long totalDistance = 0;
-            MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>();
-            queryWrapper1.selectAll(JkSketchLine.class )
-                    .eq(JkSketchLine::getSketchId, model.getId())
-                    .eq(JkSketchLine::getIsdeleted,Constants.ZERO);
-            List<JkSketchLine> lineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper1);//
-            if(lineList!=null ||lineList.size()>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(JkSketchLine line : lineList){
-                    boolean isFirst =true;
-                    JkSketchCustomer last = null;
-                    for(JkSketchCustomer c : customerList){
-                        if(Constants.equalsInteger(c.getSketchLineId(),line.getId())){
-                            if(isFirst){
-                                totalDistance += DistanceCalculator.calculateDistance(cLatitude,cLongitude
-                                        ,Constants.formatBigdecimal(c.getLatitude()).doubleValue()
-                                        ,Constants.formatBigdecimal(c.getLongitude()).doubleValue());
-                            }else{
-                                totalDistance += DistanceCalculator.calculateDistance(
-                                         Constants.formatBigdecimal(c.getLatitude()).doubleValue()
-                                        ,Constants.formatBigdecimal(c.getLongitude()).doubleValue()
-                                        ,Constants.formatBigdecimal(last.getLatitude()).doubleValue()
-                                        ,Constants.formatBigdecimal(last.getLongitude()).doubleValue());
-                            }
-                            last = c;
-                            isFirst=false;
-                        }
-                        if(last!=null){
-                            totalDistance += DistanceCalculator.calculateDistance(cLatitude,cLongitude
-                                    ,Constants.formatBigdecimal(last.getLatitude()).doubleValue()
-                                    ,Constants.formatBigdecimal(last.getLongitude()).doubleValue());
-                        }
-                    }
-                }
-
-            }
-            model.setOriginDistance(totalDistance);
-        }*/
-
+        model.setCustomerList(customerList);
+        MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>();
+        queryWrapper1.selectAll(JkSketchLine.class )
+                .eq(JkSketchLine::getSketchId, model.getId())
+                .eq(JkSketchLine::getIsdeleted,Constants.ZERO)
+                .orderByAsc(JkSketchLine::getSortnum);
+        List<JkSketchLine> lineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper1);
+        initCustomerDistance(lineList,model,updateLineDistance);
         return customerList;
     }
 
@@ -608,8 +727,6 @@
         QueryWrapper<JkSketch> wrapper = new QueryWrapper<>(jkSketch);
         return jkSketchMapper.selectCount(wrapper);
     }
-
-
     @Override
     @Transactional(rollbackFor = {Exception.class,BusinessException.class})
     public List<JkSketch> importBatch(MultipartFile file, String dateInfoStr, LoginUserInfo loginUser){
@@ -682,7 +799,6 @@
             if(newOrderList.size()>0){
                 jkOrdersMapper.insert(newOrderList);
             }
-
             List<JkSketchLine> sketchLineList = initNewSketchLineList(newList,newOrderList,lineList);
             jkSketchLineMapper.update(null,new UpdateWrapper<JkSketchLine>().lambda()
                     .set(JkSketchLine::getIsdeleted,Constants.ONE)
@@ -691,7 +807,6 @@
             if(sketchLineList.size()>0){
                 jkSketchLineMapper.insert(sketchLineList);
             }
-
             List<JkSketchCustomer> sketchCuustomerList = initNewSketchCustomerList(sketchLineList,newOrderList);//鎸夌収涓荤嚎璺垎缁�
             jkSketchCustomerMapper.update(null,new UpdateWrapper<JkSketchCustomer>().lambda()
                     .set(JkSketchCustomer::getIsdeleted,Constants.ONE)
@@ -755,29 +870,7 @@
                 list.add(tModel);
             }
         }
-        /*for(JkOrders orders : newOrderList){
-            JkSketchLine tModel = findModelFromListByLineId(orders.getLineId(),list);
-            if(tModel!=null){
-                tModel.setTotalNum(  tModel.getTotalNum().add(orders.getNum()));//璁㈠崟閲忕疮璁�
-                tModel.setOrderNum(tModel.getOrderNum()+1);//瀹㈡埛鏁板姞1
-            }else{
-                tModel = new JkSketchLine();
-                tModel.setSketchId(getSKetchIdByyCategoryId(orders.getCategoryId(),newList));
-                tModel.setCreator(orders.getCreator());
-                tModel.setCreateDate(orders.getCreateDate());
-                tModel.setLineId(orders.getLineId());
-                tModel.setTotalNum(orders.getNum());
-                tModel.setOrderNum(1);
-                tModel.setDateInfo(orders.getDateInfo());
-                tModel.setSortnum(list.size()+1);
-                tModel.setEditDate(tModel.getCreateDate());
-                tModel.setEditor(tModel.getCreator());
-                tModel.setIsdeleted(Constants.ZERO);
-                if(tModel.getSketchId()!=null){
-                    list.add(tModel);
-                }
-            }
-        }*/
+
         return list;
     }
 

--
Gitblit v1.9.3