| | |
| | | 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.admin.request.SketchCateModel; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.dto.TelecomLineInfoDTO; |
| | | import com.doumee.dao.business.model.*; |
| | |
| | | @Async |
| | | public void startUpdateLineAsync(JkSketch model) { |
| | | try { |
| | | int maxnum =100; |
| | | try { |
| | | maxnum = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_MAX_CLUSTER).getCode()); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | List<JkSketchCustomer> allCustomerList = model.getCustomerList(); |
| | | //两公里内数据客户合并 |
| | | // List<SketchCateModel> customerList =Clustering.clusterPoints(allCustomerList,1000); |
| | | List<SketchCateModel> customerList = new ClusterCustomKMeans().clusterPoints(allCustomerList,maxnum,500); |
| | | List<JkLine> lineList = model.getLineList(); |
| | | 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[] demands2 = new long[customerList.size()+1]; //各个点的客戶量 |
| | | long[][] distanceMatrix1 = new long[customerList.size()+1][customerList.size()+1]; |
| | | distanceMatrix1[0][0] = 0; |
| | | demands1[0] =0;//原点 |
| | | demands2[0] =0;//原点 |
| | | for (int i = 0; i < customerList.size(); i++) { |
| | | List<DistanceMapParam> disList = customerList.get(i).getStartPoint().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(); //各个点的订单量 |
| | | demands2[i+1] = customerList.get(i).getTotalCustomer(); //各个点的订单量 |
| | | for (int j = 0; j < customerList.size(); j++) { |
| | | distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ; |
| | | } |
| | | } |
| | | for (int i = 0; i < lineList.size(); i++) { |
| | | vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//每辆车的最大订单量限制 |
| | | vehicleMaxNodes[i] =lineList.get(i).getMaxCustomer();//最大客户数 |
| | | } |
| | | //构造优化数据模型 |
| | | dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes); |
| | | TspSolver.startSearch(dataModel); |
| | | 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::getStatus,Constants.THREE) |
| | | .set(JkSketch::getPlanLineEndDate,new Date())); |
| | | } |
| | | } |
| | | |
| | | private List<JkSketchCustomer> getCustomerCateList(List<JkSketchCustomer> allCustomerList) { |
| | | List<JkSketchCustomer> list = new ArrayList<>(); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 开始异步执行线路优化任务 |
| | | * @param model |
| | | */ |
| | | @Override |
| | | @Async |
| | | public void startUpdateLineAsyncOld(JkSketch model) { |
| | | try { |
| | | List<JkSketchCustomer> customerList = model.getCustomerList(); |
| | | List<JkLine> lineList = model.getLineList(); |
| | | TspSolver.DataModel dataModel = new TspSolver.DataModel(); |
| | |
| | | long[] vehicleCapacities1=new long[lineList.size()];//每辆车的最大订单量限制 |
| | | long[] vehicleMaxNodes=new long[lineList.size()];//每辆车的最大订单量限制 |
| | | long[] demands1 = new long[customerList.size()+1]; //各个点的订单量 |
| | | long[] demands2 = new long[customerList.size()+1]; //各个点的客户量 |
| | | long[][] distanceMatrix1 = new long[customerList.size()+1][customerList.size()+1]; |
| | | distanceMatrix1[0][0] = 0; |
| | | demands1[0] =0;//原点 |
| | |
| | | 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(); //各个点的订单量 |
| | | demands2[i+1] =1; //各个点的订单量 |
| | | for (int j = 0; j < customerList.size(); j++) { |
| | | distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ; |
| | | } |
| | |
| | | vehicleMaxNodes[i] =lineList.get(i).getMaxCustomer();//最大客户数 |
| | | } |
| | | //构造优化数据模型 |
| | | dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes); |
| | | dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes); |
| | | TspSolver.startSearch(dataModel); |
| | | dealSearchSolution(model,dataModel); |
| | | dealSearchSolutionOld(model,dataModel); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda() |
| | |
| | | @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 maxnum =100; |
| | | try { |
| | | maxnum = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.JK_PLAN_MAX_CLUSTER).getCode()); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | 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> allCustomerListParam = line.getCustomerList() ; |
| | | // List<SketchCateModel> customerListParam = Clustering.clusterPoints(allCustomerListParam,1000); |
| | | List<SketchCateModel> customerListParam = new ClusterCustomKMeans().clusterPoints(allCustomerListParam,maxnum,500); |
| | | 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[] demands2 = 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).getStartPoint().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(); //各个点的订单量 |
| | | demands2[i+1] = customerListParam.get(i).getTotalCustomer() ; //各个点的订单量 |
| | | for (int j = 0; j < customerListParam.size(); j++) { |
| | | distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ; |
| | | } |
| | | } |
| | | //构造优化数据模型 |
| | | dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes); |
| | | 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()+"】调整失败 ,未获得最优交通规划方案!"); |
| | | } |
| | | int index = 0; |
| | | line.setDistance(so.getDistance()); |
| | | //有效路径 |
| | | for (Integer cIndex : routes){ |
| | | if(cIndex ==0){ |
| | | continue; //起始点不处理 |
| | | } |
| | | SketchCateModel cateModel = customerListParam.get(cIndex-1); |
| | | for(int t=0;t<cateModel.getCustomerList().size();t++){ |
| | | JkSketchCustomer customer = cateModel.getCustomerList().get(t); |
| | | customer.setSortnum(index++); |
| | | if(t < cateModel.getCustomerList().size()-1){ |
| | | long tdistance = (long)Clustering.distanceTo(customer, cateModel.getCustomerList().get(t+1)); |
| | | line.setDistance(Constants.formatLongNum(line.getDistance()) +tdistance); |
| | | totalDistance += tdistance; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }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())); |
| | | } |
| | | } |
| | | @Override |
| | | @Async |
| | | public void startEditSketchLineAsyncOld(JkSketch model) { |
| | | boolean success = true; |
| | | int totalDistance = 0; |
| | | List<JkSketchLine> lineList = model.getSketchLineList(); |
| | |
| | | long[] vehicleCapacities1=new long[]{line.getMaxOrder()};//每辆车的最大订单量限制 |
| | | long[] vehicleMaxNodes=new long[]{line.getMaxCustomer()};//每辆车的最大订单量限制 |
| | | long[] demands1 = new long[customerListParam.size()+1]; //各个点的订单量 |
| | | long[] demands2 = new long[customerListParam.size()+1]; //各个点的订单量 |
| | | long[][] distanceMatrix1 = new long[customerListParam.size()+1][customerListParam.size()+1]; |
| | | distanceMatrix1[0][0] = 0; |
| | | demands1[0] =0;//原点 |
| | |
| | | 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(); //各个点的订单量 |
| | | demands2[i+1] = 1; //各个点的订单量 |
| | | for (int j = 0; j < customerListParam.size(); j++) { |
| | | distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ; |
| | | } |
| | | } |
| | | //构造优化数据模型 |
| | | dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes); |
| | | dataModel.initDataInfo(vehicleNumber1,demands1,demands2,vehicleCapacities1,distanceMatrix1,vehicleMaxNodes); |
| | | TspSolver.startSearch(dataModel); |
| | | if(dataModel.getSolutions()==null || dataModel.getSolutions().size()==0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+line.getLineName()+"】调整失败 ,未获得最优交通规划方案!"); |
| | |
| | | DistanceMapParam t = new DistanceMapParam(); |
| | | t.setId(cm.getCustomerId()); |
| | | DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList); |
| | | if(param!=null){//如果之前已经获取过 |
| | | if(param!=null && t.getDistance()>0){//如果之前已经获取过 |
| | | t = param; |
| | | }else{ |
| | | //如果未规划,按照直线距离 |
| | |
| | | int index =0; |
| | | for(JkSketchCustomer c : customers){ |
| | | if(index ==0){ |
| | | lineDistance+= Constants.formatLongNum(c.getStartDistance()); |
| | | if(c.getStartDistance() >0){ |
| | | lineDistance+= Constants.formatLongNum(c.getStartDistance()); |
| | | }else{ |
| | | lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude); |
| | | } |
| | | } |
| | | if(index == customers.size()-1){ |
| | | lineDistance+= Constants.formatLongNum(c.getEndDistance()); |
| | | if(c.getEndDistance() >0){ |
| | | lineDistance+= Constants.formatLongNum(c.getEndDistance()); |
| | | }else{ |
| | | lineDistance += DistanceCalculator.calculateDistanceDecinal(c.getLatitude(),c.getLongitude(),cLatitude,cLongitude); |
| | | } |
| | | break; |
| | | } |
| | | DistanceMapParam param = getParamByCustomerIds( customers.get(index+1).getCustomerId(),getListFromJsonStr(c.getDistanceJson())); |
| | | lineDistance += param.getDistance(); |
| | | JkSketchCustomer end = customers.get(index+1); |
| | | 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())); |
| | |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | private void dealSearchSolution(JkSketch model, TspSolver.DataModel dataModel) { |
| | | private void dealSearchSolution(JkSketch model, List<SketchCateModel> customerList,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;//无客户的非有效路线 |
| | | } |
| | | 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.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())));//送货量 |
| | | SketchCateModel cateModel = customerList.get(cIndex-1); |
| | | tModel.setTotalNum(tModel.getTotalNum().add(Constants.formatBigdecimal(cateModel.getTotalNum())));//送货量 |
| | | for(int t=0;t<cateModel.getCustomerList().size();t++){ |
| | | JkSketchCustomer customer = cateModel.getCustomerList().get(t); |
| | | 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()); |
| | | if(t < cateModel.getCustomerList().size()-1){ |
| | | long tdistance = (long)Clustering.distanceTo(customer, cateModel.getCustomerList().get(t+1)); |
| | | tModel.setDistance(Constants.formatLongNum(tModel.getDistance()) +tdistance); |
| | | totalDistance += tdistance; |
| | | } |
| | | tModel.getCustomerList().add(cModel); |
| | | } |
| | | tModel.setOrderNum( tModel.getCustomerList().size()); |
| | | } |
| | | } |
| | | } |
| | | 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 void dealSearchSolutionOld(JkSketch model, TspSolver.DataModel dataModel) { |
| | | Date date = new Date(); |
| | | List<TspSolverSolutions> solutions = dataModel.getSolutions(); |
| | | List<JkSketchLine> sketchLineList = new ArrayList<>(); |
| | |
| | | .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<>(); |
| | |
| | | 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) |
| | | ); |
| | |
| | | }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) { |