doum
2 天以前 4558adddaef81753e04d74a865abb318afb71e9b
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -246,10 +246,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
@@ -500,7 +503,6 @@
        c.setNeedList(Constants.equalsInteger(model.getForceUpdate(),0)?needList:customerList);
        return  c;
    }
    /**
     * 开始异步执行线路优化任务
     * @param model
@@ -512,7 +514,7 @@
            int maxnum =100,distance = 500;
            try {
                maxnum = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_MAX_CLUSTER).getCode());
                distance = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_DISTANCECLUSTER).getCode());
                distance = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_DISTANCE_CLUSTER).getCode());
            }catch (Exception e){
            }
            List<JkSketchCustomer> allCustomerList = model.getCustomerList();
@@ -547,13 +549,18 @@
            //构造优化数据模型
            dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
            TspSolver.startSearch(dataModel);
            JkSketch nowModel = jkSketchMapper.selectById(model.getId());
            if(StringUtils.equals(model.getJobId(), nowModel.getJobId())){
               log.error( "优化结果已失效,非最近一次操作!");
               return;
            }
            dealSearchSolution(model,  customerList,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::getPlanLineInfo,"最近一次线路优化失败!"+e.getMessage())
                    .set(JkSketch::getStatus,Constants.THREE)
                    .set(JkSketch::getPlanLineEndDate,new Date()));
        }
@@ -637,7 +644,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)
@@ -654,7 +661,7 @@
            int maxnum =100,distance = 500;
            try {
                maxnum = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_MAX_CLUSTER).getCode());
                distance = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_DISTANCECLUSTER).getCode());
                distance = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_DISTANCE_CLUSTER).getCode());
            }catch (Exception e){
            }
            int totalNum = 0;
@@ -700,6 +707,11 @@
                if(dataModel.getSolutions()==null || dataModel.getSolutions().size()==0){
                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+line.getLineName()+"】调整失败 ,未获得最优交通规划方案!");
                }
                JkSketch nowModel = jkSketchMapper.selectById(model.getId());
                if(StringUtils.equals(model.getJobId(), nowModel.getJobId())){
                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+line.getLineName()+"】调整失败 ,非最近一次操作!");
                }
                TspSolverSolutions so = dataModel.getSolutions().get(0);
                List<Integer> routes = so.getRouteIndex();
                totalDistance += so.getDistance();
@@ -738,7 +750,7 @@
                jkSketchCustomerMapper.updateById(allList);
            }
            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
//                    .eq(JkSketch::getId,model.getId() )
                    .eq(JkSketch::getId,model.getId() )
                    .eq(JkSketch::getJobId,model.getJobId() )
                    .set(success,JkSketch::getDistance,totalDistance)
                    .set(JkSketch::getPlanLineInfo,success?"最近一次线路调整成功":"最近一次线路调整失败!")
@@ -757,7 +769,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)
@@ -864,7 +876,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()) );
@@ -874,10 +886,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();
@@ -903,38 +916,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);
        }
@@ -946,32 +965,35 @@
                int index =0;
                for(JkSketchCustomer c : customers){
                    if(index ==0){
                        if(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(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);
@@ -1085,11 +1107,13 @@
                    .set(JkSketchLine::getIsdeleted,Constants.ONE)
                    .eq(JkSketchLine::getIsdeleted,Constants.ZERO)
                    .eq(JkSketchLine::getType,Constants.ONE)
                    .eq(JkSketchLine::getSketchId,model.getId())
                    .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::getSketchId,model.getId())
                    .eq(JkSketchCustomer::getDateInfo,model.getDateInfo()));
            if(sketchLineList.size()>0){
                jkSketchLineMapper.insert(sketchLineList);
@@ -1107,7 +1131,7 @@
            }
            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
                    .eq(JkSketch::getId,model.getId() )
                    .eq(JkSketch::getJobId,model.getJobId() )
//                    .eq(JkSketch::getJobId,model.getJobId() )
                    .set(JkSketch::getLineNum,sketchLineList.size() )
                    .set(JkSketch::getOptStatus,Constants.ONE)//已生成优化线路
                    .set(JkSketch::getDistance,totalDistance)
@@ -1117,7 +1141,7 @@
        }else{
            jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
                    .eq(JkSketch::getId,model.getId() )
                    .eq(JkSketch::getJobId,model.getJobId() )
//                    .eq(JkSketch::getJobId,model.getJobId() )
                    .set(JkSketch::getPlanLineInfo,"最近一次线路优化失败,未找到最优路线!")
                    .set(JkSketch::getStatus,Constants.THREE)
                    .set(JkSketch::getPlanLineEndDate,date));
@@ -1184,11 +1208,13 @@
                    .set(JkSketchLine::getIsdeleted,Constants.ONE)
                    .eq(JkSketchLine::getIsdeleted,Constants.ZERO)
                    .eq(JkSketchLine::getType,Constants.ONE)
                    .eq(JkSketchLine::getSketchId,model.getId())
                    .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::getSketchId,model.getId())
                    .eq(JkSketchCustomer::getDateInfo,model.getDateInfo()));
            if(sketchLineList.size()>0){
                jkSketchLineMapper.insert(sketchLineList);
@@ -1229,7 +1255,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)