| | |
| | | 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.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 java.util.*; |
| | | import java.util.Date; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 交控-线路优化记录信息表Service实现 |
| | |
| | | } |
| | | checkJketchCustomerLocation(model,true); |
| | | model.setEditDate(new Date()); |
| | | model.setEditor(jkSketch.getLoginUserInfo().getId()); |
| | | model.setDistance(model.getOriginDistance()); |
| | | jkSketchMapper.updateById(model); |
| | | return model; |
| | |
| | | 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(","); |
| | |
| | | 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("交通规划========"+cate.getId()+"/"+cate.getName()+"/"+customerList.get(j).getName()+"=======cirle/index:"+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<>(); |
| | | List<DistanceMapParam> distanceMapParamList = getListFromJsonStr(c.getDistance()); |
| | | boolean isNew = false; |
| | | boolean isNew = false,hasError =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()); |
| | | 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()); |
| | | } |
| | | }else{ |
| | | hasError=true; |
| | | } |
| | | |
| | | } |
| | | tmpList.add(t0); |
| | | for(JkCustomer cm : customerList){ |
| | |
| | | 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(); |
| | |
| | | }else{ |
| | | DistanceCustomerModel dm = DistanceCalculator.calculateDistanceGaode(url,c,cm); |
| | | t.setDistance(dm.getDistance() ); |
| | | if(dm.getLocations().size()>0){ |
| | | //如果有路径信息 |
| | | navigation.setSteps(dm.getPolyline()); |
| | | if(dm.getCode() == 1){ |
| | | if(dm.getLocations().size()>0){ |
| | | //如果有路径信息 |
| | | navigation.setSteps(dm.getPolyline()); |
| | | } |
| | | }else{ |
| | | hasError=true; |
| | | } |
| | | |
| | | } |
| | | navigation.setIdIndex(c.getId()+"-"+cm.getId()); |
| | | navigation.setDistance(t.getDistance()); |
| | |
| | | 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()); |
| | | } |
| | | }else{ |
| | | hasError=true; |
| | | } |
| | | |
| | | } |
| | | tmpList.add(tt); |
| | | if(isNew){// |
| | | u.setDistanceStatus(Constants.ONE); |
| | | u.setDistanceStatus(hasError?Constants.ZERO:Constants.ONE);//所有都成功才标注已规划 |
| | | u.setId(c.getId()); |
| | | u.setDistance(JSONObject.toJSONString(tmpList)); |
| | | updateCustomerList.add(u); |
| | |
| | | .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){ |
| | | List<JkCustomer> needList =checkNeedDistanceDo(customerList); |
| | | if(Constants.equalsInteger(model.getForceUpdate(),0)&& (needList == null || needList.size() == 0)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该主线下无需要进行距离计算的客户信息!"); |
| | | } |
| | | String errorMsg =""; |
| | |
| | | } |
| | | c.setStatus(Constants.TWO); |
| | | categoryMapper.updateById(c);//更新任务执行状态 |
| | | c.setCustomerList(customerList); |
| | | c.setCustomerList(Constants.equalsInteger(model.getForceUpdate(),0)?needList:customerList); |
| | | return c; |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | } |
| | | 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){ |
| | |
| | | } |
| | | @Override |
| | | @Async |
| | | public void startInitOriginDistanceBatch(List<JkSketch> list) { |
| | | if(list!=null){ |
| | | for(JkSketch model :list){ |
| | | public void startInitOriginDistanceBatch( JkSketch model) { |
| | | initOriginDistance(model); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | @Async |
| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | //构造优化数据模型 |
| | | 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()+"】调整失败 ,未获得最优交通规划方案!"); |
| | |
| | | queryWrapper.eq(JkSketch::getSortnum, pageWrap.getModel().getSortnum()); |
| | | } |
| | | if (pageWrap.getModel().getDateInfo() != null) { |
| | | queryWrapper.eq(JkSketch::getDateInfo, pageWrap.getModel().getDateInfo()); |
| | | queryWrapper.like(JkSketch::getDateInfo, DateUtil.dateToString(pageWrap.getModel().getDateInfo(),"yyyy-MM-dd")); |
| | | } |
| | | if (pageWrap.getModel().getJobId() != null) { |
| | | queryWrapper.eq(JkSketch::getJobId, pageWrap.getModel().getJobId()); |
| | |
| | | } |
| | | 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) |
| | | .eq(JkSketch::getIsdeleted,Constants.ZERO) |
| | | .and(StringUtils.isNotBlank(telecomLineInfoDTO.getSearchInfo()),i->i.like(Cars::getCode,telecomLineInfoDTO.getSearchInfo()).or().like(JkLine::getName,telecomLineInfoDTO.getSearchInfo())) |
| | | .like(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::getIsdeleted,Constants.ZERO) |
| | | .like(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)); |
| | | Integer lineNum = Constants.ZERO; |
| | | List<TelecomCategoryDataVO> telecomCategoryDataVOList = new ArrayList<>(); |
| | | for (JkSketch jkSketch:sketchList) { |
| | | TelecomCategoryDataVO telecomCategoryDataVO = new TelecomCategoryDataVO(); |
| | | telecomCategoryDataVO.setId(jkSketch.getCategoryId()); |
| | | telecomCategoryDataVO.setName(jkSketch.getCategoryName()); |
| | | telecomCategoryDataVO.setCustomerNum(Constants.ZERO); |
| | | List<JkSketchLine> childLineList = jkSketchLineList.stream().filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())).collect(Collectors.toList()); |
| | | //优化前数据 |
| | | List<JkSketchLine> beforeList = jkSketchLineList.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()); |
| | | |
| | | lineNum = lineNum + (Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)?beforeList.size():afterList.size()); |
| | | List<TelecomLineDataVO> telecomLineDataVOList = new ArrayList<>(); |
| | | for (JkSketchLine sketchLine: Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)?beforeList:afterList) { |
| | | TelecomLineDataVO telecomLineDataVO = new TelecomLineDataVO(); |
| | | telecomLineDataVO.setId(sketchLine.getId()); |
| | | telecomLineDataVO.setName(sketchLine.getLineName()); |
| | | telecomLineDataVOList.add(telecomLineDataVO); |
| | | telecomCategoryDataVO.setCustomerNum(telecomCategoryDataVO.getCustomerNum() + sketchLine.getMaxCustomer()); |
| | | telecomLineCountVO.setCustomerNum( |
| | | telecomLineCountVO.getCustomerNum() + sketchLine.getMaxCustomer() |
| | | ); |
| | | } |
| | | telecomCategoryDataVO.setTelecomLineDataVOList(telecomLineDataVOList); |
| | | telecomCategoryDataVOList.add(telecomCategoryDataVO); |
| | | } |
| | | telecomLineCountVO.setLineNum(lineNum); |
| | | 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::getIsdeleted,Constants.ZERO) |
| | | .like(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()) |
| | | && 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) |
| | | ); |
| | | if(Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)){ |
| | | telecomCategoryDataVO.setDistanceAfter(telecomCategoryDataVO.getDistance()); |
| | | }else{ |
| | | //优化后数据 |
| | | List<JkSketchLine> afterList = jkSketchLineList.stream() |
| | | .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()); |
| | | if(sketchList!=null){ |
| | | 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) |
| | | ); |
| | | if(Constants.equalsInteger(jkSketch.getOptStatus(),Constants.ZERO)){ |
| | | telecomCategoryDataVO.setDistanceAfter(telecomCategoryDataVO.getDistance()); |
| | | }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()); |
| | | |
| | | Long distanceAfter = 0L; |
| | | for (JkSketchLine jkSketchLine:afterList) { |
| | | distanceAfter = distanceAfter + jkSketchLine.getDistance(); |
| | | } |
| | | telecomCategoryDataVO.setDistanceAfter(distanceAfter); |
| | | |
| | | } |
| | | 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()) |
| | | .apply(" ( t.TYPE = t1.OPT_STATUS ) ") |
| | | .like(JkSketch::getDateInfo, telecomLineInfoDTO.getDateInfo()); |
| | | List<JkSketchLine> returnLineList = 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; |
| | | |
| | | |
| | | } |
| | | |
| | | } |