From 86450ddc6c1e36e2160336778672bf20be1a0bd6 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期一, 13 十月 2025 15:49:26 +0800
Subject: [PATCH] 最新版本541200007

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

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
index cf6ef90..d4fddbd 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -1,12 +1,15 @@
 package com.doumee.service.business.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.annotation.excel.ExcelImporter;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
+import com.doumee.core.tsp.*;
 import com.doumee.core.utils.*;
-import com.doumee.core.utils.tsp.TspSolver;
-import com.doumee.core.utils.tsp.TspSolverSolutions;
+import com.doumee.core.wms.model.response.WmsBaseDataResponse;
+import com.doumee.core.wms.model.response.WmsBaseResponse;
 import com.doumee.dao.admin.request.JkOrdersImport;
 import com.doumee.dao.business.*;
 import com.doumee.dao.business.model.*;
@@ -19,8 +22,8 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import netscape.javascript.JSObject;
 import org.apache.commons.lang3.StringUtils;
-import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -139,6 +142,7 @@
     @Async
     public void startUpdateLineAsync(JkSketch model) {
         try {
+            initCustomerDistance(model);
             List<JkSketchCustomer> customerList = model.getCustomerList();
             List<JkLine> lineList = model.getLineList();
             TspSolver.DataModel dataModel = new TspSolver.DataModel();
@@ -188,6 +192,69 @@
                     .set(JkSketch::getPlanLineEndDate,new Date()));
         }
 
+    }
+
+    private void initCustomerDistance(JkSketch model) {
+        String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_LOCATION_GEOAPI_URL).getCode();
+        List<JkCustomer> updateCustomerList = new ArrayList<>();
+        List<JkSketchCustomer> customerList = model.getCustomerList();
+        for(JkSketchCustomer c : customerList){
+            List<DistanceMapParam> tmpList = new ArrayList<>();
+            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
+            for(JkSketchCustomer cm : customerList){
+                boolean isNew = false;
+                DistanceMapParam t = new DistanceMapParam();
+                t.setId(cm.getId());
+                DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList);
+                if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
+                    t = param;
+                }else{
+                    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){
+                            //濡傛灉鏈夎矾寰勪俊鎭�
+
+                        }
+                    }
+                }
+                tmpList.add(t);
+                if(isNew){//
+                    JkCustomer u =new JkCustomer();
+                    u.setId(c.getId());
+                    u.setDistance(JSONObject.toJSONString(tmpList));
+                }
+            }
+            c.setDistanceMapParamList(tmpList);
+        }
+        if(updateCustomerList.size()>0){
+            for(JkCustomer c : updateCustomerList){
+                jkCustomerMapper.updateById(c);//鏇存柊瀹㈡埛涓庡叾浠栫偣涔嬮棿鐨勮窛绂�
+            }
+        }
+    }
+
+    private DistanceMapParam getParamByCustomerIds(  Integer id1, List<DistanceMapParam> distanceMapParamList) {
+        if(distanceMapParamList!=null){
+            for(DistanceMapParam p :distanceMapParamList){
+                if(Constants.equalsInteger(p.getId(),id1)){
+                    return p;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private List<DistanceMapParam> getListFromJsonStr(String distanceJson) {
+        try {
+            return  JSONObject.parseObject(distanceJson, new TypeReference<List<DistanceMapParam>>(){}.getType());
+        }catch (Exception e){
+        }
+        return new ArrayList<>();
     }
 
     private void dealSearchSolution(JkSketch model, TspSolver.DataModel dataModel) {
@@ -287,11 +354,11 @@
     }
 
     private   List<JkSketchCustomer>  checkJketchCustomerLocation(JkSketch model) {
-
         MPJLambdaWrapper<JkSketchCustomer> queryWrapper = new MPJLambdaWrapper<>();
         queryWrapper.selectAll(JkSketchCustomer.class )
                 .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                 .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
+                .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                 .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                 .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                 .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId )
@@ -311,7 +378,7 @@
         if(StringUtils.isNotBlank(errorMsg)){
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+errorMsg+"瀹氫綅淇℃伅涓嶅畬鏁达紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
         }
-        for(JkSketchCustomer c : customerList){
+       /* for(JkSketchCustomer c : customerList){
             List<Map<String,Object>> tmpList = new ArrayList<>();
             for(JkSketchCustomer cm : customerList){
                 Map<String,Object> t = new HashMap<>();
@@ -321,7 +388,7 @@
                 }else{
                     t.put("b", DistanceCalculator.calculateDistance(
                             Constants.formatBigdecimal(c.getLatitude()).doubleValue(),
-                            Constants.formatBigdecimal(c.getLatitude()).doubleValue(),
+                            Constants.formatBigdecimal(c.getLongitude()).doubleValue(),
                             Constants.formatBigdecimal(cm.getLatitude()).doubleValue(),
                             Constants.formatBigdecimal(cm.getLongitude()).doubleValue()));
                 }
@@ -329,8 +396,8 @@
             }
             c.setDistanceList(tmpList);
         }
-
-        if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){
+        */
+        /*if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){
             //濡傛灉鏄湭浼樺寲鐘舵�侊紝璁$畻鍘熷璺濈
             long totalDistance = 0;
             MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>();
@@ -359,7 +426,8 @@
                                         ,Constants.formatBigdecimal(c.getLatitude()).doubleValue()
                                         ,Constants.formatBigdecimal(c.getLongitude()).doubleValue());
                             }else{
-                                totalDistance += DistanceCalculator.calculateDistance(Constants.formatBigdecimal(c.getLatitude()).doubleValue()
+                                totalDistance += DistanceCalculator.calculateDistance(
+                                         Constants.formatBigdecimal(c.getLatitude()).doubleValue()
                                         ,Constants.formatBigdecimal(c.getLongitude()).doubleValue()
                                         ,Constants.formatBigdecimal(last.getLatitude()).doubleValue()
                                         ,Constants.formatBigdecimal(last.getLongitude()).doubleValue());
@@ -377,7 +445,7 @@
 
             }
             model.setOriginDistance(totalDistance);
-        }
+        }*/
 
         return customerList;
     }

--
Gitblit v1.9.3