From 275aa50b1de31ace0cb17fdf0b6f678a63267b3c Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期一, 20 十月 2025 10:14:01 +0800
Subject: [PATCH] 最新版本541200007

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java |  731 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 544 insertions(+), 187 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 c7669ef..b631c1d 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;
@@ -32,6 +33,7 @@
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.PostConstruct;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.Date;
@@ -43,10 +45,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
@@ -71,7 +76,6 @@
         jkSketchMapper.insert(jkSketch);
         return jkSketch.getId();
     }
-
     @Override
     public void deleteById(Integer id) {
         jkSketchMapper.deleteById(id);
@@ -81,6 +85,21 @@
     public void delete(JkSketch jkSketch) {
         UpdateWrapper<JkSketch> deleteWrapper = new UpdateWrapper<>(jkSketch);
         jkSketchMapper.delete(deleteWrapper);
+    }
+
+    @Override
+    @PostConstruct
+    public void initAyncsJob() {
+        //閲嶇疆浜ら�氳鍒掑拰绾胯矾瑙勫垝鐨勫紓姝ヤ换鍔$姸鎬�
+        jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+                .set(JkSketch::getStatus,Constants.THREE)
+                .eq(JkSketch::getIsdeleted,Constants.ZERO)
+                .eq(JkSketch::getStatus,Constants.ONE));
+        categoryMapper.update(null,new UpdateWrapper<Category>().lambda()
+                .set(Category::getStatus,Constants.ZERO)
+                .eq(Category::getType,Constants.FOUR)
+                .eq(Category::getIsdeleted,Constants.ZERO)
+                .eq(Category::getStatus,Constants.TWO));
     }
 
     @Override
@@ -126,7 +145,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());
@@ -140,10 +159,299 @@
     }
 
     @Override
+    public  JkSketch updateSketchLine(JkSketch jkSketch) {
+        JkSketch model = jkSketchMapper.selectById(jkSketch.getId());
+        if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(  jkSketch.getSketchLineList() ==null || jkSketch.getSketchLineList().size()==0 ){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇锋寜瑕佹眰璋冩暣浼樺寲鏂规锛�");
+        }
+        if(Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠绾胯矾姝e瓨鍦ㄤ紭鍖栦换鍔★紝璇疯�愬績绛夊緟浼樺寲瀹屾垚鍐嶈繘琛岃璋冩暣鎿嶄綔锛�");
+        }
+
+        //褰撳墠鎵�鏈夌嚎璺�(绗﹀悎鏉′欢鐨勭嚎璺級
+        List<JkSketchLine> lineList =  jkSketchLineMapper.selectJoinList(JkSketchLine.class,new MPJLambdaWrapper<JkSketchLine>()
+                .selectAll(JkSketchLine.class )
+                .selectAs(JkLine::getName,JkSketchLine::getLineName)
+                .selectAs(JkLine::getMaxOrder,JkSketchLine::getMaxOrder)
+                .selectAs(JkLine::getMaxCustomer,JkSketchLine::getMaxCustomer)
+                .leftJoin(JkLine.class,JkLine::getId,JkOrders::getLineId )
+                .eq(JkSketchLine::getSketchId,jkSketch.getId())
+                .eq(JkSketchLine::getType, Constants.formatIntegerNum(model.getOptStatus()))
+                .eq(JkSketchLine::getIsdeleted,Constants.ZERO));
+        if(lineList ==null ||lineList.size() ==0){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠绾胯矾涓嶆弧瓒充紭鍖栨柟妗堣皟鏁存潯浠讹紒");
+        }
+        for(JkSketchLine line :lineList){
+            JkSketchLine lineParam =getLineParamById(line.getId(),jkSketch.getSketchLineList());
+            if(lineParam == null){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇峰熀浜庣幇鏈夌嚎璺繘琛屾柟妗堣皟鏁达紝绾胯矾銆�"+line.getLineName()+"銆戠嚎璺厤缃笉姝g‘锛�");
+            }
+            if(lineParam.getCustomerList() == null || lineParam.getCustomerList().size() == 0 ){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇峰熀浜庣幇鏈夌嚎璺繘琛屾柟妗堣皟鏁达紝绾胯矾銆�"+line.getLineName()+"銆戝鎴蜂俊鎭笉鑳戒负绌猴紒");
+            }
+            Integer totalCus = 0;
+            BigDecimal totalNum =new BigDecimal(0);
+            for(JkSketchCustomer customer :lineParam.getCustomerList()){
+                 totalCus += 1;//鎬诲鎴烽噺
+                 totalNum = totalNum.add(Constants.formatBigdecimal(customer.getTotalNum()));//鎬婚�佽揣閲�
+                 customer.setSketchLineId(line.getId());
+            }
+            if( totalCus > Constants.formatIntegerNum(line.getMaxCustomer()) ){
+                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戠嚎璺鍗曞鎴锋暟閲忚秴杩囦簡绾胯矾鎬诲鎴烽噺闄愬埗锛屾棤娉曡繘琛岃皟鏁达紒");
+            }
+            if( totalNum.doubleValue() > Constants.formatIntegerNum(line.getMaxOrder())){
+                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣鍗曢�佽揣閲忚秴杩囦簡绾胯矾鎬婚�佽揣閲忛檺鍒讹紝鏃犳硶杩涜璋冩暣锛�");
+            }
+            lineParam.setTotalNum(totalNum);
+            lineParam.setOrderNum(totalCus);
+        }
+        model.setSketchLineList(jkSketch.getSketchLineList());//绾胯矾淇℃伅
+        model.setStatus(Constants.ONE);
+        model.setEditDate(new Date());
+        model.setEditor(jkSketch.getLoginUserInfo().getId());
+        model.setPlanLineDate(model.getEditDate());
+        model.setPlanLineUserId(jkSketch.getLoginUserInfo().getId());
+        model.setJobId(UUID.randomUUID().toString());
+        redisTemplate.opsForValue().set(Constants.RedisKeys.JKLINE_JOB+model.getJobId(),true );//鍋氬紓姝ュ鐞�
+        jkSketchMapper.updateById(model);
+        return model;
+    }
+
+    private JkSketchLine getLineParamById(Integer id, List<JkSketchLine> sketchLineList) {
+        for(JkSketchLine line: sketchLineList){
+            if(Constants.equalsInteger(line.getId(),id)){
+                return line;
+            }
+        }
+        return  null;
+    }
+
+    @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 || Constants.equalsInteger(c1.getDistanceStatus(),Constants.TWO)){
+                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;
+    }
+
+    /**
+     * 寮�濮嬪紓姝ユ墽琛岀嚎璺紭鍖栦换鍔�
+     * @param model
+     */
+    @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();
@@ -151,13 +459,17 @@
             long[] vehicleCapacities1=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;
             demands1[0] =0;//鍘熺偣
             for (int i = 0; i < customerList.size(); i++) {
                 List<DistanceMapParam>  disList =  customerList.get(i).getDistanceMapParamList();
-                distanceMatrix1[0][i] =  disList.get(0).getDistance();
-                distanceMatrix1[i][0] = disList.get(disList.size() -1).getDistance();
+                distanceMatrix1[0][i+1] =  disList.get(0).getDistance();
+                distanceMatrix1[i+1][0] = disList.get(disList.size() -1).getDistance();
                 demands1[i+1] = Constants.formatBigdecimal( customerList.get(i).getTotalNum()).longValue();  //鍚勪釜鐐圭殑璁㈠崟閲�
-                for (int j = 0; j< disList.size()-2; j++) {
+                for (int j = 0; j < customerList.size(); j++) {
+                    distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ;
+                }
+               /* for (int j = 0; j< disList.size()-2; j++) {
                     if(j+1 >=10){
                         break;
                     }
@@ -166,7 +478,7 @@
                     }else{
                         distanceMatrix1[i+1][j+1]  = 1l;
                     }
-                }
+                }*/
             }
             for (int i = 0; i < lineList.size(); i++) {
                 vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
@@ -184,83 +496,179 @@
                     .set(JkSketch::getStatus,Constants.THREE)
                     .set(JkSketch::getPlanLineEndDate,new Date()));
         }
-
     }
-
-    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<>();
-        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();
+    @Override
+    @Async
+    public  void startInitOriginDistanceBatch(List<JkSketch> list) {
+        if(list!=null){
+            for(JkSketch model :list){
+                initOriginDistance(model);
+            }
+        }
+    }
+    @Override
+    @Async
+    public  void startEditSketchLineAsync(JkSketch model) {
+        boolean success = true;
+        int totalDistance = 0;
+        List<JkSketchLine> lineList = model.getSketchLineList();
         try {
-            String[] ss = location.split(",");
-            cLongitude = new BigDecimal(ss[0]);
-            cLatitude =  new BigDecimal(ss[1]);
+            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)
+                    .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
+                    .selectAs(JkCustomer::getEndDistance,JkSketchCustomer::getEndDistance)
+                    .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId )
+                    .eq(JkSketchCustomer::getType, Constants.equalsInteger(model.getOptStatus(),Constants.ONE)?1:0)
+                    .eq(JkSketchCustomer::getSketchId, model.getId())
+                    .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO)
+                    .orderByAsc(JkSketchCustomer::getSortnum);
+            List<JkSketchCustomer> customerList = jkSketchCustomerMapper.selectJoinList(JkSketchCustomer.class,queryWrapper);
+            if(customerList == null ||customerList.size() ==0){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴蜂俊鎭负绌猴紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
+            }
+
+            int totalNum = 0;
+            for(JkSketchLine line : lineList){
+                //瀹屽杽绾胯矾瀹㈡埛浼樺寲鍙傛暟
+                List<JkSketchCustomer> customerListParam =  line.getCustomerList() ;
+                if(customerListParam ==null || customerListParam.size()==0){
+                    throw  new BusinessException(ResponseStatus.BAD_REQUEST);
+                }
+                initSketchCustomerListParam(line.getCustomerList(),customerList) ;
+                totalNum += customerListParam.size();
+            }
+            if(totalNum != Constants.formatIntegerNum(model.getOrderNum())){
+                throw  new BusinessException(ResponseStatus.BAD_REQUEST);
+            }
+            for(JkSketchLine line : lineList){
+                //閫愪釜璺嚎浼樺寲
+                List<JkSketchCustomer> customerListParam =  line.getCustomerList() ;
+                TspSolver.DataModel dataModel = new TspSolver.DataModel();
+                int vehicleNumber1 = 1;//绾胯矾鏁伴噺
+                long[] vehicleCapacities1=new long[]{line.getMaxOrder()};//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
+                long[] demands1 = new long[customerListParam.size()+1]; //鍚勪釜鐐圭殑璁㈠崟閲�
+                long[][] distanceMatrix1 = new long[customerListParam.size()+1][customerListParam.size()+1];
+                distanceMatrix1[0][0] = 0;
+                demands1[0] =0;//鍘熺偣
+                for (int i = 0; i < customerListParam.size(); i++) {
+                    List<DistanceMapParam>  disList =  customerListParam.get(i).getDistanceMapParamList();
+                    distanceMatrix1[0][i+1] =  disList.get(0).getDistance();
+                    distanceMatrix1[i+1][0] = disList.get(disList.size() -1).getDistance();
+                    demands1[i+1] = Constants.formatBigdecimal( customerListParam.get(i).getTotalNum()).longValue();  //鍚勪釜鐐圭殑璁㈠崟閲�
+                    for (int j = 0; j < customerListParam.size(); j++) {
+                        distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ;
+                    }
+                }
+                //鏋勯�犱紭鍖栨暟鎹ā鍨�
+                dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
+                TspSolver.startSearch(dataModel);
+                if(dataModel.getSolutions()==null || dataModel.getSolutions().size()==0){
+                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");
+                }
+                TspSolverSolutions so = dataModel.getSolutions().get(0);
+                List<Integer> routes = so.getRouteIndex();
+                totalDistance += so.getDistance();
+                if(routes.size() <=2) {
+                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");
+                }
+                //鏈夋晥璺緞
+                for (Integer cIndex : routes){
+                    if(cIndex ==0){
+                        continue; //璧峰鐐逛笉澶勭悊
+                    }
+                    JkSketchCustomer customer = customerListParam.get(cIndex-1);
+                    customer.setSortnum(cIndex-1);
+                }
+                line.setDistance(so.getDistance());
+            }
         }catch (Exception e){
+            e.printStackTrace();
+            success =false;
+        }finally {
+            if(success){
+                List<JkSketchCustomer> allList = new ArrayList<>();
+                for(JkSketchLine line : lineList){
+                    allList.addAll(line.getCustomerList());
+                }
+                jkSketchLineMapper.updateById(lineList);
+                jkSketchCustomerMapper.updateById(allList);
+            }
+            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+                    .eq(JkSketch::getId,model.getId() )
+                    .eq(JkSketch::getJobId,model.getJobId() )
+                    .set(success,JkSketch::getDistance,totalDistance)
+                    .set(JkSketch::getPlanLineInfo,success?"鏈�杩戜竴娆$嚎璺皟鏁存垚鍔�":"鏈�杩戜竴娆$嚎璺皟鏁村け璐ワ紒")
+                    .set(JkSketch::getStatus,success?Constants.TWO:Constants.THREE)
+                    .set(JkSketch::getPlanLineEndDate,new Date()));
+        }
+    }
+    private List<JkSketchCustomer> initSketchCustomerListParam(List<JkSketchCustomer> customerList, List<JkSketchCustomer> customerList1) {
+        for(JkSketchCustomer param : customerList){
+            for(JkSketchCustomer model : customerList1){
+              if(Constants.equalsInteger(model.getId(),param.getId())){
+                  param.setLatitude(model.getLatitude());
+                  param.setLongitude(model.getLongitude());
+                  param.setStartDistance(model.getStartDistance());
+                  param.setEndDistance(model.getEndDistance());
+                  param.setDistanceJson(model.getDistanceJson());
+              }
+            }
         }
         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()) );
+            tmpList.add(t0);
+            for(JkSketchCustomer cm : customerList){
+                //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
+                DistanceMapParam t = new DistanceMapParam();
+                t.setId(cm.getCustomerId());
+                t.setDistance(0);
+                DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
+                if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
+                    t = param;
+                }
+                tmpList.add(t);
+            }
+            DistanceMapParam tt = new DistanceMapParam();
+            tt.setId(-2);//琛ㄧず杩斿洖鍥尯
+            tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
+            tmpList.add(tt);
+            c.setDistanceMapParamList(tmpList);
+        }
+        return  customerList;
+    }
+
+
+    private void initCustomerDistance( List<JkSketchLine> lineList,JkSketch model,boolean updateLineDistance) {
+        List<JkSketchCustomer> customerList = model.getCustomerList();
+        for(JkSketchCustomer c : customerList){
+            List<DistanceMapParam> tmpList = new ArrayList<>();
+            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
             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 +677,54 @@
             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);
+                int index =0;
+                for(JkSketchCustomer c : customers){
+                    if(index ==0){
+                        lineDistance+= Constants.formatLongNum(c.getStartDistance());
+                    }
+                    if(index == customers.size()-1){
+                        lineDistance+= Constants.formatLongNum(c.getEndDistance());
+                        break;
+                    }
+                    DistanceMapParam param = getParamByCustomerIds( customers.get(index+1).getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
+                    lineDistance += param.getDistance();
+                    index++;
+                  /*  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) {
@@ -331,10 +756,11 @@
         if(solutions!=null && solutions.size()>0){
             for(TspSolverSolutions so : solutions){
                 List<Integer> routes = so.getRouteIndex();
+                totalDistance+= so.getDistance();
                 if(routes.size() <=2) {
                     continue;//鏃犲鎴风殑闈炴湁鏁堣矾绾�
                 }
-                totalDistance+= so.getDistance();
+//                totalDistance+= so.getDistance();
                 JkLine  line =model.getLineList().get(so.getLineIndex());
                 JkSketchLine tModel =  new JkSketchLine();
                 tModel.setSketchId(model.getId());
@@ -344,6 +770,7 @@
                 tModel.setTotalNum(new BigDecimal(0));
                 tModel.setOrderNum(routes.size()-2);
                 tModel.setDateInfo(model.getDateInfo());
+                tModel.setType(Constants.ONE);
                 tModel.setSortnum(sketchLineList.size()+1);
                 tModel.setEditDate(tModel.getCreateDate());
                 tModel.setEditor(tModel.getCreator());
@@ -362,6 +789,7 @@
                     cModel.setCreator(tModel.getCreator());
                     cModel.setOrderId(customer.getOrderId());
                     cModel.setCreateDate(tModel.getCreateDate());
+                    cModel.setType(Constants.ONE);
                     cModel.setTotalNum(customer.getTotalNum());
                     cModel.setDateInfo(model.getDateInfo());
                     cModel.setSortnum(tModel.getCustomerList().size()+1);
@@ -379,10 +807,12 @@
             jkSketchLineMapper.update(null,new UpdateWrapper<JkSketchLine>().lambda()
                     .set(JkSketchLine::getIsdeleted,Constants.ONE)
                     .eq(JkSketchLine::getIsdeleted,Constants.ZERO)
+                    .eq(JkSketchLine::getType,Constants.ONE)
                     .eq(JkSketchLine::getDateInfo,model.getDateInfo()));
             jkSketchCustomerMapper.update(null,new UpdateWrapper<JkSketchCustomer>().lambda()
                     .set(JkSketchCustomer::getIsdeleted,Constants.ONE)
                     .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO)
+                    .eq(JkSketchCustomer::getType,Constants.ONE)
                     .eq(JkSketchCustomer::getDateInfo,model.getDateInfo()));
             if(sketchLineList.size()>0){
                 jkSketchLineMapper.insert(sketchLineList);
@@ -402,6 +832,7 @@
                     .eq(JkSketch::getId,model.getId() )
                     .eq(JkSketch::getJobId,model.getJobId() )
                     .set(JkSketch::getLineNum,sketchLineList.size() )
+                    .set(JkSketch::getOptStatus,Constants.ONE)//宸茬敓鎴愪紭鍖栫嚎璺�
                     .set(JkSketch::getDistance,totalDistance)
                     .set(JkSketch::getPlanLineInfo,"鏈�杩戜竴娆$嚎璺紭鍖栨垚鍔燂紝浼樺寲鍚庢�昏窛绂伙細"+(totalDistance/1000)+"鍏噷锛�")
                     .set(JkSketch::getStatus,Constants.TWO)
@@ -416,17 +847,19 @@
         }
     }
 
-    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)
                 .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
                 .selectAs(JkCustomer::getEndDistance,JkSketchCustomer::getEndDistance)
                 .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId )
+                .eq(JkSketchCustomer::getType, Constants.formatIntegerNum(model.getOptStatus()))
                 .eq(JkSketchCustomer::getSketchId, model.getId())
                 .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO)
                 .orderByAsc(JkSketchCustomer::getSortnum);
@@ -435,83 +868,30 @@
             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)
+                .eq(JkSketchLine::getType, Constants.formatIntegerNum(model.getOptStatus()))
+                .orderByAsc(JkSketchLine::getSortnum);
+        List<JkSketchLine> lineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper1);
+        initCustomerDistance(lineList,model,updateLineDistance);
         return customerList;
     }
 
@@ -608,8 +988,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 +1060,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 +1068,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)
@@ -726,6 +1102,7 @@
                 tModel.setTotalNum(orders.getNum());
                 tModel.setDateInfo(orders.getDateInfo());
                 tModel.setSortnum(list.size()+1);
+                tModel.setType(Constants.ZERO);
                 tModel.setEditDate(tModel.getCreateDate());
                 tModel.setEditor(tModel.getCreator());
                 tModel.setIsdeleted(Constants.ZERO);
@@ -748,6 +1125,7 @@
             initOrderAndTotalNum(tModel,line.getId(),newOrderList);
             tModel.setDateInfo(newList.get(0).getDateInfo());
             tModel.setSortnum(list.size()+1);
+            tModel.setType(Constants.ZERO);
             tModel.setEditDate(tModel.getCreateDate());
             tModel.setEditor(tModel.getCreator());
             tModel.setIsdeleted(Constants.ZERO);
@@ -755,29 +1133,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;
     }
 
@@ -825,6 +1181,7 @@
                 tModel.setCreateDate(orders.getCreateDate());
                 tModel.setCategoryId(orders.getCategoryId());
                 tModel.setTotalNum(orders.getNum());
+                tModel.setOptStatus(Constants.ZERO);
                 tModel.setOrderNum(1);
                 tModel.setDateInfo(orders.getDateInfo());
                 tModel.setSortnum(list.size()+1);

--
Gitblit v1.9.3