From f51c9e1bc0e82cbebd0e05130fb9a754317cbfa2 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期二, 21 十月 2025 15:37:44 +0800
Subject: [PATCH] 月台自动叫号处理问题

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

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
index f957eef..e61de7d 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,38 +1,50 @@
 package com.doumee.service.business.impl;
 
+import cn.hutool.core.bean.BeanUtil;
+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.utils.Constants;
-import com.doumee.core.utils.DateUtil;
-import com.doumee.dao.admin.request.JkCustomerImport;
+import com.doumee.core.tsp.*;
+import com.doumee.core.utils.*;
+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.dto.TelecomLineInfoDTO;
 import com.doumee.dao.business.model.*;
+import com.doumee.dao.business.vo.TelecomCategoryDataVO;
+import com.doumee.dao.business.vo.TelecomJkLineListVO;
+import com.doumee.dao.business.vo.TelecomLineCountVO;
+import com.doumee.dao.business.vo.TelecomLineDataVO;
 import com.doumee.service.business.third.model.LoginUserInfo;
 import com.doumee.service.business.third.model.PageData;
 import com.doumee.service.business.third.model.PageWrap;
-import com.doumee.core.utils.Utils;
 import com.doumee.service.business.JkSketchService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 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;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.PostConstruct;
 import java.math.BigDecimal;
-import java.util.ArrayList;
+import java.util.*;
 import java.util.Date;
-import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * 浜ゆ帶-绾胯矾浼樺寲璁板綍淇℃伅琛⊿ervice瀹炵幇
@@ -40,16 +52,21 @@
  * @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
     private JkSketchCustomerMapper jkSketchCustomerMapper;
     @Autowired
     private JkCustomerMapper jkCustomerMapper;
+    @Autowired
+    private JkCustomerNavigationMapper jkCustomerNavigationMapper;
     @Autowired
     private JkLineMapper jkLineMapper;
 
@@ -66,7 +83,6 @@
         jkSketchMapper.insert(jkSketch);
         return jkSketch.getId();
     }
-
     @Override
     public void deleteById(Integer id) {
         jkSketchMapper.deleteById(id);
@@ -79,16 +95,806 @@
     }
 
     @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
     public void deleteByIdInBatch(List<Integer> ids) {
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
         jkSketchMapper.deleteBatchIds(ids);
     }
+    //绾胯矾浼樺寲
+    @Override
+    public JkSketch updateById(JkSketch jkSketch ) {
+        JkSketch model = jkSketchMapper.selectById(jkSketch.getId());
+        if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if( model.getDateInfo() ==  null){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺棩鏈熶俊鎭笉姝g‘锛屼笉鏀寔浼樺寲锛�");
+        }
+        if(Constants.equalsInteger(Constants.ZERO,jkSketch.getForceUpdate()) && Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺瓨鍦ㄦ鍦ㄤ紭鍖栦腑锛岃鑰愬績绛夊緟浼樺寲瀹屾垚鎴栬�呴�夋嫨寮哄埗浼樺寲鎿嶄綔锛�");
+        }
+
+        if(  jkSketch.getLineIdList() ==null || jkSketch.getLineIdList().size()==0 ){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨鏈夋晥鍚堢悊鐨勭嚎璺繘琛屼紭鍖栨搷浣滐紒");
+        }
+        //褰撳墠鎵�鏈夌嚎璺�(绗﹀悎鏉′欢鐨勭嚎璺級
+        List<JkLine> lineList =  jkLineMapper.selectJoinList(JkLine.class,new MPJLambdaWrapper<JkLine>()
+                .selectAll(JkLine.class)
+                .eq(JkLine::getWeeks,DateUtil.getWeekZhouOfDate(model.getDateInfo()))//鍙兘閫夋嫨褰撳墠鐨勭嚎璺�
+                .eq(JkLine::getIsdeleted,Constants.ZERO)
+                .in(JkLine::getId,jkSketch.getLineIdList())
+        );
+        Integer totalCus = 0,totalNum =0;
+        for(JkLine line :lineList){
+            totalCus += Constants.formatIntegerNum(line.getMaxCustomer());//鎬诲鎴烽噺
+            totalNum += Constants.formatIntegerNum(line.getMaxOrder());//鎬婚�佽揣閲�
+        }
+        if( totalCus < Constants.formatIntegerNum(model.getOrderNum())  ){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇ョ嚎璺鍗曞鎴锋暟閲忚秴杩囦簡绾胯矾鎬诲鎴烽噺闄愬埗锛屾棤娉曡繘琛屼紭鍖栵紒");
+        }
+        if( totalNum < Constants.formatBigdecimal(model.getTotalNum()).doubleValue()){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇ョ嚎璺鍗曢�佽揣閲忚秴杩囦簡绾胯矾鎬婚�佽揣閲忛檺鍒讹紝鏃犳硶杩涜浼樺寲锛�");
+        }
+        model.setLineList(lineList);//绾胯矾闆嗗悎
+        model.setCustomerList(checkJketchCustomerLocation(model,false));//璁㈠崟闆嗗悎
+        model.setStatus(Constants.ONE);
+        model.setPlanLineNum(lineList.size());
+        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;
+    }
 
     @Override
-    public void updateById(JkSketch jkSketch) {
-        jkSketchMapper.updateById(jkSketch);
+    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.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 {
+            List<JkSketchCustomer> customerList = model.getCustomerList();
+            List<JkLine> lineList = model.getLineList();
+            TspSolver.DataModel dataModel = new TspSolver.DataModel();
+            int vehicleNumber1 = lineList.size();//绾胯矾鏁伴噺
+            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+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 < 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;
+                    }
+                    if(disList.size()>j+1){
+                        distanceMatrix1[i+1][j+1]  = disList.get(j+1).getDistance()/1000;//鏋勯�犺窛绂荤煩闃�
+                    }else{
+                        distanceMatrix1[i+1][j+1]  = 1l;
+                    }
+                }*/
+            }
+            for (int i = 0; i < lineList.size(); i++) {
+                vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
+            }
+            //鏋勯�犱紭鍖栨暟鎹ā鍨�
+            dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
+            TspSolver.startSearch(dataModel);
+            dealSearchSolution(model,dataModel);
+        }catch (Exception e){
+            e.printStackTrace();
+            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+                    .eq(JkSketch::getId,model.getId() )
+                    .eq(JkSketch::getJobId,model.getJobId() )
+                    .set(JkSketch::getPlanLineInfo,"鏈�杩戜竴娆$嚎璺紭鍖栧け璐ワ紒")
+                    .set(JkSketch::getStatus,Constants.THREE)
+                    .set(JkSketch::getPlanLineEndDate,new Date()));
+        }
+    }
+    @Override
+    @Async
+    public  void startInitOriginDistanceBatch( JkSketch  model) {
+                initOriginDistance(model);
+    }
+    @Override
+    @Async
+    public  void startEditSketchLineAsync(JkSketch model) {
+        boolean success = true;
+        int totalDistance = 0;
+        List<JkSketchLine> lineList = model.getSketchLineList();
+        try {
+            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());
+            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){
+                //鍥尯鍓嶅線璇ュ鎴风殑璺濈锛屽鏋滀箣鍓嶆湭鑾峰彇杩�
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
+            }
+            tmpList.add(t0);
+            for(JkSketchCustomer cm : customerList){
+                //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
+                DistanceMapParam t = new DistanceMapParam();
+                t.setId(cm.getCustomerId());
+                DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
+                if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
+                    t = param;
+                }else{
+                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒宠矾绋嬭绠楁潯浠讹紒");
+                }
+                tmpList.add(t);
+            }
+            DistanceMapParam tt = new DistanceMapParam();
+            tt.setId(-2);//琛ㄧず杩斿洖鍥尯
+            tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
+            if(Constants.formatLongNum(c.getEndDistance()) <= 0){
+                //璇ュ鎴疯繑鍥炲洯鍖虹殑璺濈 ,濡傛灉涔嬪墠鏈幏鍙栬繃
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:"+c.getName()+"浜ら�氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒宠矾绋嬭绠楁潯浠讹紒");
+            }
+            tmpList.add(tt);
+            c.setDistanceMapParamList(tmpList);
+        }
+        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);
+            }
+        }
+    }
+
+    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) {
+        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) {
+        Date date = new Date();
+        List<TspSolverSolutions> solutions = dataModel.getSolutions();
+        List<JkSketchLine> sketchLineList = new ArrayList<>();
+        List<JkSketchCustomer> sketchCustomerList  = new ArrayList<>();
+        long totalDistance = 0l;
+        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();
+                JkLine  line =model.getLineList().get(so.getLineIndex());
+                JkSketchLine tModel =  new JkSketchLine();
+                tModel.setSketchId(model.getId());
+                tModel.setCreator(model.getEditor());
+                tModel.setCreateDate(date);
+                tModel.setLineId(line.getId());
+                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());
+                tModel.setIsdeleted(Constants.ZERO);
+                tModel.setDistance(so.getDistance());//
+                sketchLineList.add(tModel);
+                tModel.setCustomerList( new ArrayList<>());
+                //鏈夋晥璺緞
+                for (Integer cIndex : routes){
+                    if(cIndex ==0){
+                        continue; //璧峰鐐逛笉澶勭悊
+                    }
+                    JkSketchCustomer customer = model.getCustomerList().get(cIndex-1);
+                    tModel.setTotalNum(tModel.getTotalNum().add(Constants.formatBigdecimal(customer.getTotalNum())));//閫佽揣閲�
+                    JkSketchCustomer cModel =  new JkSketchCustomer();
+                    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);
+                    cModel.setEditDate(tModel.getCreateDate());
+                    cModel.setEditor(tModel.getCreator());
+                    cModel.setIsdeleted(Constants.ZERO);
+                    cModel.setSketchId(model.getId());
+                    cModel.setCustomerId(customer.getCustomerId());
+                    tModel.getCustomerList().add(cModel);
+
+                }
+            }
+        }
+        if(sketchLineList!=null && sketchLineList.size()>0){
+            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);
+            }
+            for(JkSketchLine l : sketchLineList){
+                if(l.getCustomerList()!=null ){
+                    for(JkSketchCustomer c :l.getCustomerList()){
+                        c.setSketchLineId(l.getId());
+                    }
+                    sketchCustomerList.addAll(l.getCustomerList());
+                }
+            }
+            if(sketchCustomerList.size()>0){
+                jkSketchCustomerMapper.insert(sketchCustomerList);
+            }
+            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+                    .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)
+                    .set(JkSketch::getPlanLineEndDate,date));
+        }else{
+            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+                    .eq(JkSketch::getId,model.getId() )
+                    .eq(JkSketch::getJobId,model.getJobId() )
+                    .set(JkSketch::getPlanLineInfo,"鏈�杩戜竴娆$嚎璺紭鍖栧け璐�,鏈壘鍒版渶浼樿矾绾匡紒")
+                    .set(JkSketch::getStatus,Constants.THREE)
+                    .set(JkSketch::getPlanLineEndDate,date));
+        }
+    }
+
+    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);
+        List<JkSketchCustomer> customerList = jkSketchCustomerMapper.selectJoinList(JkSketchCustomer.class,queryWrapper);
+        if(customerList == null ||customerList.size() ==0){
+            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()+" | ";
+            }
+            if(!Constants.equalsInteger(c.getDistanceStatus(),Constants.ONE)){
+                errorMsg1 += c.getName()+"-"+c.getName()+" | ";
+            }
+        }
+        if(StringUtils.isNotBlank(errorMsg)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:銆�"+errorMsg+"銆戝畾浣嶄俊鎭笉瀹屾暣锛屼笉婊¤冻浼樺寲鏉′欢锛�");
+        }
+        if(StringUtils.isNotBlank(errorMsg1)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴�:銆�"+errorMsg1+"銆戜氦閫氳鍒掑皻鏈畬鎴愶紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
+        }
+        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;
     }
 
     @Override
@@ -184,7 +990,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){
@@ -216,9 +1021,11 @@
                     .selectAll(JkCustomer.class)
                     .eq(JkCustomer::getIsdeleted,Constants.ZERO)
             );
+            String week =  DateUtil.getWeekZhouOfDate(dateInfo);
             //褰撳墠鎵�鏈夌嚎璺�
             List<JkLine> lineList =  jkLineMapper.selectJoinList(JkLine.class,new MPJLambdaWrapper<JkLine>()
                     .selectAll(JkLine.class)
+                    .eq(JkLine::getWeeks,week)//鍙兘閫夋嫨褰撳墠鐨勭嚎璺�
                     .eq(JkLine::getIsdeleted,Constants.ZERO)
             );
             List<JkOrders> newOrderList = new ArrayList<>();
@@ -255,8 +1062,7 @@
             if(newOrderList.size()>0){
                 jkOrdersMapper.insert(newOrderList);
             }
-
-            List<JkSketchLine> sketchLineList = initNewSketchLineList(newList,newOrderList);
+            List<JkSketchLine> sketchLineList = initNewSketchLineList(newList,newOrderList,lineList);
             jkSketchLineMapper.update(null,new UpdateWrapper<JkSketchLine>().lambda()
                     .set(JkSketchLine::getIsdeleted,Constants.ONE)
                     .eq(JkSketchLine::getIsdeleted,Constants.ZERO)
@@ -264,7 +1070,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)
@@ -285,6 +1090,8 @@
 
     }
 
+
+
     private List<JkSketchCustomer> initNewSketchCustomerList(List<JkSketchLine> sketchLineList, List<JkOrders> newOrderList) {
         List<JkSketchCustomer> list =new ArrayList<>();
         for(JkOrders orders : newOrderList){
@@ -297,6 +1104,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);
@@ -308,32 +1116,36 @@
         }
         return list;
     }
-    private List<JkSketchLine> initNewSketchLineList(List<JkSketch> newList, List<JkOrders> newOrderList) {
+    private List<JkSketchLine> initNewSketchLineList(List<JkSketch> newList, List<JkOrders> newOrderList,List<JkLine> lineList) {
         List<JkSketchLine> list =new ArrayList<>();
-        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);
-                }
+        for (JkLine line : lineList){
+            JkSketchLine tModel =  new JkSketchLine();
+            tModel.setSketchId(getSKetchIdByyCategoryId(line.getCategoryId(),newList));
+            tModel.setCreator(newList.get(0).getCreator());
+            tModel.setCreateDate(newList.get(0).getCreateDate());
+            tModel.setLineId(line.getId());
+            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);
+            if(tModel.getSketchId()!=null && Constants.formatIntegerNum(tModel.getOrderNum()) >0){
+                list.add(tModel);
             }
         }
+
         return list;
+    }
+
+    private void initOrderAndTotalNum(JkSketchLine tModel, Integer id, List<JkOrders> newOrderList) {
+        for(JkOrders orders : newOrderList){
+            if(Constants.equalsInteger(orders.getLineId(),id)){
+                tModel.setOrderNum(Constants.formatIntegerNum(tModel.getOrderNum())+1);
+                tModel.setTotalNum(Constants.formatBigdecimal(tModel.getTotalNum()).add(Constants.formatBigdecimal(orders.getNum())));
+            }
+        }
     }
 
     private Integer getSKetchIdByyCategoryId(Integer categoryId, List<JkSketch> newList) {
@@ -366,10 +1178,12 @@
             }else{
                 tModel = new JkSketch();
                 tModel.setLineNum(getLineNumByOrders(orders.getCategoryId(),newOrderList));
+                tModel.setPlanLineNum(tModel.getLineNum());
                 tModel.setCreator(orders.getCreator());
                 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);
@@ -429,7 +1243,7 @@
         }
         JkLine line = findLineFromListByName(model.getLineName(),lineList);
         if(line == null){
-            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝绗�" + (index + 3) + "琛岀嚎璺��" + model.getLineName() + "銆戜笉瀛樺湪锛岃妫�鏌ヨ〃鏍煎唴瀹癸紒");
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝绗�" + (index + 3) + "琛岀嚎璺��" + model.getLineName() + "銆戜笉瀛樺湪鎴栬�呴厤閫佸懆鏈熶笉绗﹀悎锛岃妫�鏌ヨ〃鏍煎唴瀹癸紒");
         }
 
         JkOrders tModel =   new JkOrders();
@@ -440,6 +1254,8 @@
         tModel.setNum(getDecimalByVal(model.getNum()));
         tModel.setCustomerId(customer.getId());
         tModel.setDateInfo(dateInfo);
+        tModel.setLatitude(customer.getLatitude());
+        tModel.setLongitude(customer.getLongitude());
         tModel.setSortnum(model.getSortnum());
         tModel.setLineId(line.getId());
         tModel.setCategoryId(line.getCategoryId());
@@ -489,4 +1305,330 @@
         }
         return null;
     }
+
+
+
+    @Override
+    public List<TelecomJkLineListVO>  getLineForTelecom(TelecomLineInfoDTO telecomLineInfoDTO){
+        if(StringUtils.isBlank(telecomLineInfoDTO.getDateInfo())){
+            telecomLineInfoDTO.setDateInfo(DateUtil.getDate(new Date(),"yyyy-MM-dd"));
+        }
+        MPJLambdaWrapper<JkSketchLine> queryWrapper = new MPJLambdaWrapper<JkSketchLine>().selectAll(JkSketchLine.class )
+                .selectAs(Cars::getCode,JkSketchLine::getCarCode)
+                .selectAs(Category::getName,JkSketchLine::getCategoryName)
+                .selectAs(JkLine::getName,JkSketchLine::getLineName)
+                .select(" ifnull((select count(1) from jk_sketch_customer jc where jc.ISDELETED= 0  and jc.SKETCH_LINE_ID = t.id),0)" ,JkSketchLine::getMaxCustomer)
+                .leftJoin(JkSketch.class,JkSketch::getId,JkSketchLine::getSketchId)
+                .leftJoin(JkLine.class,JkLine::getId,JkSketchLine::getLineId)
+                .leftJoin(Category.class,Category::getId,JkLine::getCategoryId )
+                .leftJoin(Cars.class,Cars::getId,JkLine::getCarId)
+                .and(StringUtils.isNotBlank(telecomLineInfoDTO.getSearchInfo()),i->i.like(Cars::getCode,telecomLineInfoDTO.getSearchInfo()).or().like(JkLine::getName,telecomLineInfoDTO.getSearchInfo()))
+                .eq(StringUtils.isNotBlank(telecomLineInfoDTO.getDateInfo()),JkSketch::getDateInfo, telecomLineInfoDTO.getDateInfo())
+                .eq(Objects.nonNull(telecomLineInfoDTO.getCategoryId()),JkLine::getCategoryId, telecomLineInfoDTO.getCategoryId())
+                .eq(Objects.nonNull(telecomLineInfoDTO.getLineId()),JkLine::getId, telecomLineInfoDTO.getLineId());
+
+        List<JkSketchLine> jkSketchLineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper);
+        List<TelecomJkLineListVO> telecomJkLineListVOList = new ArrayList<>();
+
+        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(jkSketchLineList)){
+            //浼樺寲鍓嶆暟鎹�
+            List<JkSketchLine> beforeList = jkSketchLineList.stream()
+                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
+            //浼樺寲鍚庢暟鎹�
+            List<JkSketchLine> afterList = jkSketchLineList.stream()
+                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+            
+            for (JkSketchLine sketchLine:beforeList) {
+                JkSketchLine finalSketchLine = sketchLine;
+                List<JkSketchLine> afterSelectList = afterList.stream().filter(i->Constants.equalsInteger(i.getLineId(), finalSketchLine.getLineId())).collect(Collectors.toList());
+                if(afterSelectList.size()>Constants.ZERO){
+                    sketchLine = afterSelectList.get(Constants.ZERO);
+                }
+                TelecomJkLineListVO telecomJkLineListVO = new TelecomJkLineListVO();
+                telecomJkLineListVO.setCategoryName(sketchLine.getCategoryName());
+                telecomJkLineListVO.setName(sketchLine.getLineName());
+                telecomJkLineListVO.setCarCode(sketchLine.getCarCode());
+                telecomJkLineListVO.setCustomerNum(sketchLine.getMaxCustomer());
+                telecomJkLineListVOList.add(telecomJkLineListVO);
+            }
+
+        }
+        return telecomJkLineListVOList;
+    }
+
+    @Override
+    public TelecomLineCountVO getTelecomLineCount(TelecomLineInfoDTO telecomLineInfoDTO){
+        if(StringUtils.isBlank(telecomLineInfoDTO.getDateInfo())){
+            telecomLineInfoDTO.setDateInfo(DateUtil.getDate(new Date(),"yyyy-MM-dd"));
+        }
+        TelecomLineCountVO telecomLineCountVO = new TelecomLineCountVO();
+        telecomLineCountVO.setLineNum(Constants.ZERO);
+        telecomLineCountVO.setCategoryNum(Constants.ZERO);
+        telecomLineCountVO.setCustomerNum(Constants.ZERO);
+        MPJLambdaWrapper<JkSketch> sketchMPJLambdaWrapper = new MPJLambdaWrapper<JkSketch>().selectAll(JkSketch.class )
+                .selectAs(Category::getName,JkSketch::getCategoryName)
+                .select(" ifnull((select count(1) from jk_sketch_customer jc where jc.ISDELETED= 0 and  jc.SKETCH_ID = t.id),0)" ,JkSketch::getCustomerNum)
+                .select(" ifnull((select count(1) from jk_sketch_line jc where   jc.TYPE = 0  and  jc.SKETCH_ID = t.id),0)" ,JkSketch::getBeforeLineNum)
+                .leftJoin(Category.class,Category::getId,JkSketch::getCategoryId )
+                .eq(JkSketch::getDateInfo, telecomLineInfoDTO.getDateInfo());
+        List<JkSketch> sketchList = jkSketchMapper.selectJoinList(JkSketch.class,sketchMPJLambdaWrapper);
+        if(CollectionUtils.isEmpty(sketchList)){
+            return telecomLineCountVO;
+        }
+        MPJLambdaWrapper<JkSketchLine> queryWrapper = new MPJLambdaWrapper<JkSketchLine>().selectAll(JkSketchLine.class )
+                .selectAs(Cars::getCode,JkSketchLine::getCarCode)
+                .selectAs(Category::getName,JkSketchLine::getCategoryName)
+                .selectAs(JkLine::getName,JkSketchLine::getLineName)
+                .select(" ifnull((select count(1) from jk_sketch_customer jc where jc.ISDELETED= 0 and jc.SKETCH_LINE_ID = t.id),0)" ,JkSketchLine::getMaxCustomer)
+                .leftJoin(JkSketch.class,JkSketch::getId,JkSketchLine::getSketchId)
+                .leftJoin(JkLine.class,JkLine::getId,JkSketchLine::getLineId)
+                .leftJoin(Category.class,Category::getId,JkLine::getCategoryId )
+                .leftJoin(Cars.class,Cars::getId,JkLine::getCarId)
+                .in(JkSketchLine::getSketchId,sketchList.stream().map(i->i.getId()).collect(Collectors.toList()));
+        List<JkSketchLine> jkSketchLineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper);
+
+        telecomLineCountVO.setCategoryNum(sketchList.size());
+        telecomLineCountVO.setLineNum(sketchList.stream().map(i->i.getBeforeLineNum()).reduce(Constants.ZERO,Integer::sum));
+
+        List<TelecomCategoryDataVO> telecomCategoryDataVOList = new ArrayList<>();
+        for (JkSketch jkSketch:sketchList) {
+            TelecomCategoryDataVO telecomCategoryDataVO = new TelecomCategoryDataVO();
+            telecomCategoryDataVO.setId(jkSketch.getCategoryId());
+            telecomCategoryDataVO.setName(jkSketch.getCategoryName());
+            telecomCategoryDataVO.setCustomerNum(jkSketch.getCustomerNum());
+            List<JkSketchLine> childLineList = jkSketchLineList.stream().filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())).collect(Collectors.toList());
+            //浼樺寲鍓嶆暟鎹�
+            List<JkSketchLine> beforeList = childLineList.stream()
+                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
+            //浼樺寲鍚庢暟鎹�
+            List<JkSketchLine> afterList = childLineList.stream()
+                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+            List<TelecomLineDataVO> telecomLineDataVOList = new ArrayList<>();
+            for (JkSketchLine sketchLine:beforeList) {
+                JkSketchLine finalSketchLine = sketchLine;
+                List<JkSketchLine> afterSelectList = afterList.stream().filter(i->Constants.equalsInteger(i.getLineId(), finalSketchLine.getLineId())).collect(Collectors.toList());
+                if(afterSelectList.size()>Constants.ZERO){
+                    sketchLine = afterSelectList.get(Constants.ZERO);
+                }
+                TelecomLineDataVO telecomLineDataVO = new TelecomLineDataVO();
+                telecomLineDataVO.setId(sketchLine.getId());
+                telecomLineDataVO.setName(sketchLine.getLineName());
+                telecomLineDataVOList.add(telecomLineDataVO);
+                telecomLineCountVO.setCustomerNum(
+                        telecomLineCountVO.getCustomerNum() + sketchLine.getMaxCustomer()
+                );
+            }
+            telecomCategoryDataVO.setTelecomLineDataVOList(telecomLineDataVOList);
+            telecomCategoryDataVOList.add(telecomCategoryDataVO);
+        }
+        telecomLineCountVO.setTelecomCategoryDataVOList(telecomCategoryDataVOList);
+        return telecomLineCountVO;
+    }
+
+
+
+    @Override
+    public List<TelecomCategoryDataVO> getTelecomLineDistance(TelecomLineInfoDTO telecomLineInfoDTO){
+        if(StringUtils.isBlank(telecomLineInfoDTO.getDateInfo())){
+            telecomLineInfoDTO.setDateInfo(DateUtil.getDate(new Date(),"yyyy-MM-dd"));
+        }
+        MPJLambdaWrapper<JkSketch> sketchMPJLambdaWrapper = new MPJLambdaWrapper<JkSketch>().selectAll(JkSketch.class )
+                .selectAs(Category::getName,JkSketch::getCategoryName)
+                .leftJoin(Category.class,Category::getId,JkSketch::getCategoryId )
+                .eq(JkSketch::getDateInfo, telecomLineInfoDTO.getDateInfo());
+        List<JkSketch> sketchList = jkSketchMapper.selectJoinList(JkSketch.class,sketchMPJLambdaWrapper);
+        if(CollectionUtils.isEmpty(sketchList)){
+            return new ArrayList<TelecomCategoryDataVO>();
+        }
+        MPJLambdaWrapper<JkSketchLine> queryWrapper = new MPJLambdaWrapper<JkSketchLine>().selectAll(JkSketchLine.class )
+                .selectAs(Cars::getCode,JkSketchLine::getCarCode)
+                .selectAs(Category::getName,JkSketchLine::getCategoryName)
+                .selectAs(JkLine::getName,JkSketchLine::getLineName)
+                .leftJoin(JkSketch.class,JkSketch::getId,JkSketchLine::getSketchId)
+                .leftJoin(JkLine.class,JkLine::getId,JkSketchLine::getLineId)
+                .leftJoin(Category.class,Category::getId,JkLine::getCategoryId )
+                .leftJoin(Cars.class,Cars::getId,JkLine::getCarId)
+                .in(JkSketchLine::getSketchId,sketchList.stream().map(i->i.getId()).collect(Collectors.toList()));
+        List<JkSketchLine> jkSketchLineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper);
+
+        List<TelecomCategoryDataVO> telecomCategoryDataVOList = new ArrayList<>();
+        for (JkSketch jkSketch:sketchList) {
+            TelecomCategoryDataVO telecomCategoryDataVO = new TelecomCategoryDataVO();
+            telecomCategoryDataVO.setId(jkSketch.getCategoryId());
+            telecomCategoryDataVO.setName(jkSketch.getCategoryName());
+            //浼樺寲鍓嶆暟鎹�
+            List<JkSketchLine> beforeList = jkSketchLineList.stream()
+                    .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())&&Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
+            telecomCategoryDataVO.setDistance(
+                    beforeList.stream().map(i->i.getDistance()).reduce(Long.valueOf(0),Long::sum)
+            );
+            //浼樺寲鍚庢暟鎹�
+            List<JkSketchLine> afterList = jkSketchLineList.stream()
+                    .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())&&Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+            if(org.apache.commons.collections.CollectionUtils.isEmpty(afterList)){
+                telecomCategoryDataVO.setDistanceAfter(telecomCategoryDataVO.getDistance());
+            }else if(beforeList.size()>afterList.size()){
+                Long distanceAfter = 0L;
+                for (JkSketchLine jkSketchLine:beforeList) {
+                    List<JkSketchLine> afterSelectList = afterList.stream().filter(i->Constants.equalsInteger(i.getLineId(),jkSketchLine.getLineId())).collect(Collectors.toList());
+                    if(afterSelectList.size()>Constants.ZERO){
+                        distanceAfter = distanceAfter + afterSelectList.get(Constants.ZERO).getDistance();
+                    }else{
+                        distanceAfter = distanceAfter + jkSketchLine.getDistance();
+                    }
+                }
+                telecomCategoryDataVO.setDistanceAfter(distanceAfter);
+            }else{
+                telecomCategoryDataVO.setDistanceAfter(
+                        afterList.stream().map(i->i.getDistance()).reduce(Long.valueOf(0),Long::sum)
+                );
+            }
+            telecomCategoryDataVOList.add(telecomCategoryDataVO);
+        }
+        return telecomCategoryDataVOList;
+    }
+
+
+    @Override
+    public List<TelecomLineDataVO> getTelecomLineInfo(TelecomLineInfoDTO telecomLineInfoDTO){
+        if(StringUtils.isBlank(telecomLineInfoDTO.getDateInfo())){
+            telecomLineInfoDTO.setDateInfo(DateUtil.getDate(new Date(),"yyyy-MM-dd"));
+        }
+        MPJLambdaWrapper<JkSketchLine> queryWrapper = new MPJLambdaWrapper<JkSketchLine>().selectAll(JkSketchLine.class )
+                .selectAs(Cars::getCode,JkSketchLine::getCarCode)
+                .selectAs(Category::getName,JkSketchLine::getCategoryName)
+                .selectAs(JkLine::getName,JkSketchLine::getLineName)
+                .leftJoin(JkSketch.class,JkSketch::getId,JkSketchLine::getSketchId)
+                .leftJoin(JkLine.class,JkLine::getId,JkSketchLine::getLineId)
+                .leftJoin(Category.class,Category::getId,JkLine::getCategoryId )
+                .leftJoin(Cars.class,Cars::getId,JkLine::getCarId)
+                .eq(JkSketchLine::getIsdeleted,Constants.ZERO)
+                .eq(Objects.nonNull(telecomLineInfoDTO.getCategoryId()),JkSketchLine::getCategoryId,telecomLineInfoDTO.getCategoryId())
+                .eq(Objects.nonNull(telecomLineInfoDTO.getLineId()),JkSketchLine::getLineId,telecomLineInfoDTO.getLineId())
+                .eq(JkSketch::getDateInfo, telecomLineInfoDTO.getDateInfo());
+        List<JkSketchLine> jkSketchLineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper);
+
+        //浼樺寲鍓嶆暟鎹�
+        List<JkSketchLine> beforeList = jkSketchLineList.stream()
+                .filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
+
+        //浼樺寲鍚庢暟鎹�
+        List<JkSketchLine> afterList = jkSketchLineList.stream()
+                .filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
+
+        List<JkSketchLine> returnLineList = new ArrayList<>();
+        for (JkSketchLine jkSketchLine:beforeList) {
+            List<JkSketchLine> afterSelectList = afterList.stream().filter(i->Constants.equalsInteger(i.getLineId(),jkSketchLine.getLineId())).collect(Collectors.toList());
+            if(afterSelectList.size()>Constants.ZERO){
+                returnLineList.add(afterList.get(Constants.ZERO));
+            }else{
+                returnLineList.add(jkSketchLine);
+            }
+        }
+        List<TelecomLineDataVO> dataVOList = new ArrayList<>();
+        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(returnLineList)){
+            //鑾峰彇鎵�鏈夊湴鍥剧粡绾害鏁版嵁
+            MPJLambdaWrapper<JkSketchCustomer> jkSketchCustomerMPJLambdaWrapper = new MPJLambdaWrapper<>();
+            jkSketchCustomerMPJLambdaWrapper.selectAll(JkSketchCustomer.class )
+                    .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
+                    .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
+                    .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
+                    .selectAs(JkCustomer::getEndDistance,JkSketchCustomer::getEndDistance)
+                    .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
+                    .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
+                    .selectAs(JkCustomer::getStartSteps,JkSketchCustomer::getStartSteps)
+                    .selectAs(JkCustomer::getEndSteps,JkSketchCustomer::getEndSteps)
+                    .selectAs(JkCustomer::getLocation,JkSketchCustomer::getLocation)
+                    .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId )
+                    .eq( JkSketchCustomer::getIsdeleted,Constants.ZERO)
+                    .in( JkSketchCustomer::getSketchLineId,returnLineList.stream().map(i->i.getId()).collect(Collectors.toList()));
+
+            List<JkSketchCustomer> allList =  jkSketchCustomerMapper.selectJoinList(JkSketchCustomer.class,jkSketchCustomerMPJLambdaWrapper);
+            BigDecimal cLatitude =new BigDecimal(0);
+            BigDecimal cLongitude =new BigDecimal(0);
+            String comLocation = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.COMPANY_LOCATION).getCode();
+            try {
+                String[] ss = comLocation.split(",");
+                cLongitude = new BigDecimal(ss[0]);
+                cLatitude =  new BigDecimal(ss[1]);
+            }catch (Exception e){
+            }
+            for (JkSketchLine line:returnLineList) {
+                TelecomLineDataVO telecomLineDataVO = new TelecomLineDataVO();
+                telecomLineDataVO.setId(line.getLineId());
+                telecomLineDataVO.setName(line.getLineName());
+                List<JkSketchCustomer> sketchCustomerList = allList.stream().filter(i->Constants.equalsInteger(i.getSketchLineId(),line.getId())).collect(Collectors.toList());
+                if(org.apache.commons.collections.CollectionUtils.isNotEmpty(sketchCustomerList)){
+                    telecomLineDataVO.setNavigationList(this.dealLineCustomerInfo(cLatitude,cLongitude,comLocation,sketchCustomerList));
+                }
+                dataVOList.add(telecomLineDataVO);
+            }
+        }
+        return dataVOList;
+    }
+    
+    
+    
+    public List<JkCustomerNavigation> dealLineCustomerInfo(BigDecimal cLatitude,BigDecimal cLongitude,String comLocation,List<JkSketchCustomer> allList){
+        List<JkCustomerNavigation> list = new ArrayList<>();
+        JkCustomerNavigation startmodel = new JkCustomerNavigation();
+        startmodel.setStartId(-1);
+        startmodel.setName("鍥尯");
+        startmodel.setStartLatitude(cLatitude);
+        startmodel.setStartLogitude(cLongitude);
+        startmodel.setEndLatitude(allList.get(0).getLatitude());
+        startmodel.setEndLogitude(allList.get(0).getLongitude());
+        startmodel.setDistance(allList.get(0).getStartDistance());
+        startmodel.setSteps(allList.get(0).getStartSteps());
+        if(StringUtils.isBlank(startmodel.getSteps())){
+            startmodel.setSteps(comLocation +";"+allList.get(0).getLongitude()+","+allList.get(0).getLatitude());
+        }
+        list.add(startmodel);
+
+        for (int i = 0; i < allList.size(); i++) {
+            if(allList.size() == i+1){
+                JkCustomerNavigation endmodel = new JkCustomerNavigation();
+                endmodel.setStartId(-1);
+                endmodel.setLocation(allList.get(i).getLocation());
+                endmodel.setName(allList.get(i).getName());
+                endmodel.setSteps(allList.get(i).getEndSteps());
+                endmodel.setStartLatitude(allList.get(i).getLatitude());
+                endmodel.setStartLogitude(allList.get(i).getLongitude());
+                endmodel.setDistance(allList.get(0).getEndDistance());
+                endmodel.setEndLatitude(cLatitude);
+                endmodel.setEndLogitude(cLongitude);
+                if(StringUtils.isBlank(startmodel.getSteps())){
+                    startmodel.setSteps(allList.get(i).getLongitude()+","+allList.get(i).getLatitude()+";"+comLocation);
+                }
+                list.add(endmodel);
+                break;
+            }
+            JkSketchCustomer start = allList.get(i);
+            JkSketchCustomer end = allList.get(i+1);
+            JkCustomerNavigation tt = jkCustomerNavigationMapper.selectOne(new QueryWrapper<JkCustomerNavigation>().lambda()
+                    .eq(JkCustomerNavigation::getIsdeleted,Constants.ZERO)
+                    .eq(JkCustomerNavigation::getIdIndex, allList.get(i).getCustomerId()+"-"+ allList.get(i+1).getCustomerId())
+                    .orderByDesc(JkCustomerNavigation::getId)
+                    .last("limit 1")
+            );
+            if(tt==null){
+                //鍙湁璧锋鐐�
+                tt = new JkCustomerNavigation();
+                tt.setStartLatitude(start.getLatitude());
+                tt.setStartLogitude(start.getLongitude());
+                tt.setEndLatitude(end.getLatitude());
+                tt.setEndLogitude(end.getLongitude());
+            }
+            tt.setLocation(allList.get(i).getLocation());
+            tt.setName(allList.get(i).getName());
+            if(StringUtils.isBlank(tt.getSteps())){
+                tt.setSteps(start.getLongitude()+","+end.getLatitude()+";"+end.getLongitude()+","+end.getLatitude());
+            }
+            list.add(tt);
+        }
+        return list;
+
+
+    }
+
 }

--
Gitblit v1.9.3