doum
2026-06-11 d9c657aa78cf0ebe31933a87e63ca92edd8a8da3
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -33,6 +33,7 @@
import netscape.javascript.JSObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -44,6 +45,7 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.Date;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -56,6 +58,9 @@
@Slf4j
public class JkSketchServiceImpl implements JkSketchService {
    @Autowired
    @Qualifier("asyncExecutor")
    private Executor asyncExecutor;
    @Autowired
    private JkSketchMapper jkSketchMapper;
    @Autowired
@@ -246,10 +251,13 @@
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路已被优化,已无法计算原始路线路程数");
        }
        checkJketchCustomerLocation(model,true);
        model.setEditDate(new Date());
        model.setDistance(model.getOriginDistance());
        jkSketchMapper.updateById(model);
        return model;
        JkSketch update = new JkSketch();
        update.setId(model.getId());
        update.setEditDate(new Date());
        update.setDistance(model.getOriginDistance());
        update.setOriginDistance(model.getOriginDistance());
        jkSketchMapper.updateById(update);
        return update;
    }
    @Override
@@ -283,7 +291,7 @@
                BigDecimal finalCLongitude = cLongitude;
                log.error("交通规划====线程circle:"+i+"====start:"+start+"===========end:"+end);
                int finalI = i;
                Thread t1=new Thread(() -> {
                asyncExecutor.execute(() -> {
                    try {
                        int index =0;
                        for (int j = start; j < end; j++) {
@@ -308,10 +316,9 @@
                    }
                });
                t1.start();
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("distanceCustomer异常", e);
        }finally {
        }
@@ -547,7 +554,7 @@
            dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
            TspSolver.startSearch(dataModel);
            JkSketch nowModel = jkSketchMapper.selectById(model.getId());
            if(StringUtils.equals(model.getJobId(), nowModel.getJobId())){
            if(!StringUtils.equals(model.getJobId(), nowModel.getJobId())){
               log.error( "优化结果已失效,非最近一次操作!");
               return;
            }
@@ -641,7 +648,7 @@
            queryWrapper.selectAll(JkSketchCustomer.class )
                    .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                    .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
//                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                    .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                    .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                    .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
@@ -705,7 +712,7 @@
                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+line.getLineName()+"】调整失败 ,未获得最优交通规划方案!");
                }
                JkSketch nowModel = jkSketchMapper.selectById(model.getId());
                if(StringUtils.equals(model.getJobId(), nowModel.getJobId())){
                if(!StringUtils.equals(model.getJobId(), nowModel.getJobId())){
                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+line.getLineName()+"】调整失败 ,非最近一次操作!");
                }
@@ -766,7 +773,7 @@
            queryWrapper.selectAll(JkSketchCustomer.class )
                    .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                    .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
//                    .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                    .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                    .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                    .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
@@ -873,7 +880,7 @@
        }
        for(JkSketchCustomer c : customerList){
            List<DistanceMapParam> tmpList = new ArrayList<>();
            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
//            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
            DistanceMapParam t0 = new DistanceMapParam();
            t0.setId(-2);//表示返回园区
            t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
@@ -883,10 +890,11 @@
                DistanceMapParam t = new DistanceMapParam();
                t.setId(cm.getCustomerId());
                t.setDistance(0);
                DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
               /* DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                if(param!=null){//如果之前已经获取过
                    t = param;
                }
                }*/
                tmpList.add(t);
            }
            DistanceMapParam tt = new DistanceMapParam();
@@ -912,38 +920,44 @@
        }
        for(JkSketchCustomer c : customerList){
            List<DistanceMapParam> tmpList = new ArrayList<>();
            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
            //====标记==忽略交通规划距离=====
//            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
            DistanceMapParam t0 = new DistanceMapParam();
            t0.setId(-2);//表示返回园区
            t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
            t0.setId(-2);//
            t0.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
            //====标记==忽略交通规划距离=====
          /*  t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
            if(Constants.formatLongNum(c.getStartDistance()) <= 0){
                //园区前往该客户的距离,如果之前未获取过
                t0.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足优化条件!");
            }
            }*/
            tmpList.add(t0);
            for(JkSketchCustomer cm : customerList){
                //客户和客户之间的距离信息
                DistanceMapParam t = new DistanceMapParam();
                t.setId(cm.getCustomerId());
                 DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
                //====标记==忽略交通规划距离=====
              /*  DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                if(param!=null && t.getDistance()>0){//如果之前已经获取过
                    t = param;
                }else{
                    //如果未规划,按照直线距离
                    t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
//                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"与客户:"+cm.getName()+"简交通规划尚未完成,不满足路程计算条件!");
                }
                }*/
                tmpList.add(t);
            }
            DistanceMapParam tt = new DistanceMapParam();
            tt.setId(-2);//表示返回园区
            tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
            tt.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
            //====标记==忽略交通规划距离=====
           /* tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
            if(Constants.formatLongNum(c.getEndDistance()) <= 0){
                //该客户返回园区的距离 ,如果之前未获取过
                tt.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"与起点交通规划尚未完成,不满足路程计算条件!");
            }
            }*/
            tmpList.add(tt);
            c.setDistanceMapParamList(tmpList);
        }
@@ -955,32 +969,35 @@
                int index =0;
                for(JkSketchCustomer c : customers){
                    if(index ==0){
                        if(Constants.formatLongNum(c.getStartDistance()) >0){
                        lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
                        //====标记==忽略交通规划距离=====
                      /*  if(Constants.formatLongNum(c.getStartDistance()) >0){
                            lineDistance+= Constants.formatLongNum(c.getStartDistance());
                        }else{
                            lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
                        }
                        }*/
                    }
                    if(index == customers.size()-1){
                        if(Constants.formatLongNum(c.getEndDistance())>0){
                        lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
                        //====标记==忽略交通规划距离=====
                     /*   if(Constants.formatLongNum(c.getEndDistance())>0){
                            lineDistance+= Constants.formatLongNum(c.getEndDistance());
                        }else{
                            lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude);
                        }
                        }*/
                        break;
                    }
                    JkSketchCustomer end = customers.get(index+1);
                    DistanceMapParam param1 = getParamByCustomerIds(end.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
                    lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),end.getLatitude(),end.getLongitude());
                    //====标记==忽略交通规划距离=====
                 /*   DistanceMapParam param1 = getParamByCustomerIds(end.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
                    if(param1 !=null && param1.getDistance()>0){
                        lineDistance += param1.getDistance();
                    }else{
                        lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),end.getLatitude(),end.getLongitude());
                    }
                    index++;
                  /*  for(JkSketchCustomer cm : customers){
                        DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
                        lineDistance += param.getDistance();
                    }*/
                    index++;
                }
                if(updateLineDistance && Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){
                    line.setDistance(lineDistance);
@@ -1242,7 +1259,7 @@
                .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
                .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
                .selectAs(JkCustomer::getDistanceStatus,JkSketchCustomer::getDistanceStatus)
                .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
//                .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
                .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
                .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
                .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)