rk
12 小时以前 6a2149633eca11ada6b3c5dc6012d6a1c21d0bc4
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -261,7 +261,6 @@
            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(",");
@@ -269,25 +268,55 @@
                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){
                }
            int circle = customerList.size()/100;//
            if(customerList.size()%100>0){
                circle +=1;
            }
            boolean[] results = new boolean[circle] ;
            for (int i = 0; i < circle; i++) {
                final  int start =i*100;
                final int end = (i+1)*100 > customerList.size()? customerList.size(): (i+1)*100;
                results[i] =false;
                BigDecimal finalCLatitude = cLatitude;
                BigDecimal finalCLongitude = cLongitude;
                log.error("交通规划====线程circle:"+i+"====start:"+start+"===========end:"+end);
                int finalI = i;
                Thread t1=new Thread(() -> {
                    try {
                        int index =0;
                        for (int j = start; j < end; j++) {
                            try {
                                log.error("交通规划========"+customerList.get(j).getName()+"========cirle:"+finalI+"==="+index++);
                                dealDistancePerCustomer(customerList.get(j),url,date, finalCLatitude, finalCLongitude,customerList);
                            }catch (Exception e){
                            }
                        }
                    }catch (Exception e){
                    }finally {
                        results[finalI] =true;
                        boolean isDone = false;
                        for(boolean t : results){
                            isDone = isDone&&t;
                        }
                        if(isDone){
                            cate.setStatus(Constants.ZERO);
                            categoryMapper.updateById(cate);//更新任务执行状态
                        }
                    }
                });
                t1.start();
            }
        }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) {
    private void dealDistancePerCustomer(JkCustomer c, String url, Date date, BigDecimal cLatitude, BigDecimal cLongitude, List<JkCustomer> customerList) throws InterruptedException {
        List<JkCustomer> updateCustomerList = new ArrayList<>();
        List<JkCustomerNavigation> navigationList = new ArrayList<>();
        List<DistanceMapParam> tmpList = new ArrayList<>();
@@ -298,28 +327,34 @@
        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());
            if(dm.getCode() == 1){
                //规划失败
                log.error("==============客户交通规划成功起点:"+c.getName());
                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){
            //客户和客户之间的距离信息
            Thread.sleep(500);
            DistanceMapParam t = new DistanceMapParam();
            t.setId(cm.getId());
            DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList);
            if(param!=null){//如果之前已经获取过
            if(param!=null && param.getDistance()!=0){//如果之前已经获取过
                t = param;
            }else{
                JkCustomerNavigation navigation = new JkCustomerNavigation();
@@ -359,15 +394,19 @@
            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());
            if(dm.getCode()== 1){
                //规划失败
                log.error("==============客户交通规划成功2:"+c.getName());
                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){//
@@ -463,6 +502,7 @@
            TspSolver.DataModel dataModel = new TspSolver.DataModel();
            int vehicleNumber1 = lineList.size();//线路数量
            long[] vehicleCapacities1=new long[lineList.size()];//每辆车的最大订单量限制
            long[] vehicleMaxNodes=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;
@@ -488,9 +528,10 @@
            }
            for (int i = 0; i < lineList.size(); i++) {
                vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//每辆车的最大订单量限制
                vehicleMaxNodes[i] =lineList.get(i).getMaxCustomer();//最大客户数
            }
            //构造优化数据模型
            dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
            dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
            TspSolver.startSearch(dataModel);
            dealSearchSolution(model,dataModel);
        }catch (Exception e){
@@ -553,6 +594,7 @@
                TspSolver.DataModel dataModel = new TspSolver.DataModel();
                int vehicleNumber1 = 1;//线路数量
                long[] vehicleCapacities1=new long[]{line.getMaxOrder()};//每辆车的最大订单量限制
                long[] vehicleMaxNodes=new long[]{line.getMaxCustomer()};//每辆车的最大订单量限制
                long[] demands1 = new long[customerListParam.size()+1]; //各个点的订单量
                long[][] distanceMatrix1 = new long[customerListParam.size()+1][customerListParam.size()+1];
                distanceMatrix1[0][0] = 0;
@@ -567,7 +609,7 @@
                    }
                }
                //构造优化数据模型
                dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
                dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes);
                TspSolver.startSearch(dataModel);
                if(dataModel.getSolutions()==null || dataModel.getSolutions().size()==0){
                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+line.getLineName()+"】调整失败 ,未获得最优交通规划方案!");
@@ -1405,7 +1447,8 @@
                    .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());
                    .filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)
                            && Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
            lineNum = lineNum + (Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)?beforeList.size():afterList.size());
            List<TelecomLineDataVO> telecomLineDataVOList = new ArrayList<>();
@@ -1461,7 +1504,9 @@
            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());
                    .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())
                            && Objects.nonNull(i.getDistance())
                            &&Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList());
            telecomCategoryDataVO.setDistance(
                    beforeList.stream().map(i->i.getDistance()).reduce(Long.valueOf(0),Long::sum)
            );
@@ -1470,7 +1515,9 @@
            }else{
                //优化后数据
                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());
                        .filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())
                                && Objects.nonNull(i.getDistance())
                                &&Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getIsdeleted(),Constants.ZERO)).collect(Collectors.toList());
                Long distanceAfter = 0L;
                for (JkSketchLine jkSketchLine:afterList) {