|  |  | 
 |  |  | 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 com.baomidou.mybatisplus.core.metadata.IPage; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import netscape.javascript.JSObject; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  | import org.springframework.web.multipart.MultipartFile; | 
 |  |  |  | 
 |  |  | import javax.annotation.PostConstruct; | 
 |  |  | import java.math.BigDecimal; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.concurrent.TimeUnit; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 交控-线路优化记录信息表Service实现 | 
 |  |  | 
 |  |  |  * @date 2025/09/28 09:01 | 
 |  |  |  */ | 
 |  |  | @Service | 
 |  |  | @Slf4j | 
 |  |  | public class JkSketchServiceImpl implements JkSketchService { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private JkSketchMapper jkSketchMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private CategoryMapper categoryMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private JkSketchLineMapper jkSketchLineMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private JkSketchCustomerMapper jkSketchCustomerMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private JkCustomerMapper jkCustomerMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private JkCustomerNavigationMapper jkCustomerNavigationMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private JkLineMapper jkLineMapper; | 
 |  |  |  | 
 |  |  | 
 |  |  |         jkSketchMapper.insert(jkSketch); | 
 |  |  |         return jkSketch.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteById(Integer id) { | 
 |  |  |         jkSketchMapper.deleteById(id); | 
 |  |  | 
 |  |  |     public void delete(JkSketch jkSketch) { | 
 |  |  |         UpdateWrapper<JkSketch> deleteWrapper = new UpdateWrapper<>(jkSketch); | 
 |  |  |         jkSketchMapper.delete(deleteWrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @PostConstruct | 
 |  |  |     public void initAyncsJob() { | 
 |  |  |         //重置交通规划和线路规划的异步任务状态 | 
 |  |  |         jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda() | 
 |  |  |                 .set(JkSketch::getStatus,Constants.THREE) | 
 |  |  |                 .eq(JkSketch::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(JkSketch::getStatus,Constants.ONE)); | 
 |  |  |         categoryMapper.update(null,new UpdateWrapper<Category>().lambda() | 
 |  |  |                 .set(Category::getStatus,Constants.ZERO) | 
 |  |  |                 .eq(Category::getType,Constants.FOUR) | 
 |  |  |                 .eq(Category::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(Category::getStatus,Constants.TWO)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |         if( model.getDateInfo() ==  null){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路日期信息不正确,不支持优化!"); | 
 |  |  |         } | 
 |  |  |        if(Constants.equalsInteger(Constants.ZERO,jkSketch.getForceUpdate()) && Constants.equalsInteger(model.getStatus(),Constants.ONE)){ | 
 |  |  |         if(Constants.equalsInteger(Constants.ZERO,jkSketch.getForceUpdate()) && Constants.equalsInteger(model.getStatus(),Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路存在正在优化中,请耐心等待优化完成或者选择强制优化操作!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |          if(  jkSketch.getLineIdList() ==null || jkSketch.getLineIdList().size()==0 ){ | 
 |  |  |         if(  jkSketch.getLineIdList() ==null || jkSketch.getLineIdList().size()==0 ){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择有效合理的线路进行优化操作!"); | 
 |  |  |         } | 
 |  |  |         //当前所有线路(符合条件的线路) | 
 |  |  | 
 |  |  |             totalCus += Constants.formatIntegerNum(line.getMaxCustomer());//总客户量 | 
 |  |  |             totalNum += Constants.formatIntegerNum(line.getMaxOrder());//总送货量 | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if( totalCus < Constants.formatIntegerNum(model.getOrderNum())  ){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该线路订单客户数量超过了线路总客户量限制,无法进行优化!"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该线路订单送货量超过了线路总送货量限制,无法进行优化!"); | 
 |  |  |         } | 
 |  |  |         model.setLineList(lineList);//线路集合 | 
 |  |  |         model.setCustomerList(checkJketchCustomerLocation(model));//订单集合 | 
 |  |  |         model.setCustomerList(checkJketchCustomerLocation(model,false));//订单集合 | 
 |  |  |         model.setStatus(Constants.ONE); | 
 |  |  |         model.setPlanLineNum(lineList.size()); | 
 |  |  |         model.setEditDate(new Date()); | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public  JkSketch updateSketchLine(JkSketch jkSketch) { | 
 |  |  |         JkSketch model = jkSketchMapper.selectById(jkSketch.getId()); | 
 |  |  |         if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(  jkSketch.getSketchLineList() ==null || jkSketch.getSketchLineList().size()==0 ){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请按要求调整优化方案!"); | 
 |  |  |         } | 
 |  |  |         if(Constants.equalsInteger(model.getStatus(),Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前线路正存在优化任务,请耐心等待优化完成再进行该调整操作!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //当前所有线路(符合条件的线路) | 
 |  |  |         List<JkSketchLine> lineList =  jkSketchLineMapper.selectJoinList(JkSketchLine.class,new MPJLambdaWrapper<JkSketchLine>() | 
 |  |  |                 .selectAll(JkSketchLine.class ) | 
 |  |  |                 .selectAs(JkLine::getName,JkSketchLine::getLineName) | 
 |  |  |                 .selectAs(JkLine::getMaxOrder,JkSketchLine::getMaxOrder) | 
 |  |  |                 .selectAs(JkLine::getMaxCustomer,JkSketchLine::getMaxCustomer) | 
 |  |  |                 .leftJoin(JkLine.class,JkLine::getId,JkOrders::getLineId ) | 
 |  |  |                 .eq(JkSketchLine::getSketchId,jkSketch.getId()) | 
 |  |  |                 .eq(JkSketchLine::getType, Constants.formatIntegerNum(model.getOptStatus())) | 
 |  |  |                 .eq(JkSketchLine::getIsdeleted,Constants.ZERO)); | 
 |  |  |         if(lineList ==null ||lineList.size() ==0){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前线路不满足优化方案调整条件!"); | 
 |  |  |         } | 
 |  |  |         for(JkSketchLine line :lineList){ | 
 |  |  |             JkSketchLine lineParam =getLineParamById(line.getId(),jkSketch.getSketchLineList()); | 
 |  |  |             if(lineParam == null){ | 
 |  |  |                 throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请基于现有线路进行方案调整,线路【"+line.getLineName()+"】线路配置不正确!"); | 
 |  |  |             } | 
 |  |  |             if(lineParam.getCustomerList() == null || lineParam.getCustomerList().size() == 0 ){ | 
 |  |  |                 throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请基于现有线路进行方案调整,线路【"+line.getLineName()+"】客户信息不能为空!"); | 
 |  |  |             } | 
 |  |  |             Integer totalCus = 0; | 
 |  |  |             BigDecimal totalNum =new BigDecimal(0); | 
 |  |  |             for(JkSketchCustomer customer :lineParam.getCustomerList()){ | 
 |  |  |                  totalCus += 1;//总客户量 | 
 |  |  |                  totalNum = totalNum.add(Constants.formatBigdecimal(customer.getTotalNum()));//总送货量 | 
 |  |  |                  customer.setSketchLineId(line.getId()); | 
 |  |  |             } | 
 |  |  |             if( totalCus > Constants.formatIntegerNum(line.getMaxCustomer()) ){ | 
 |  |  |                 throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"线路【"+line.getLineName()+"】线路订单客户数量超过了线路总客户量限制,无法进行调整!"); | 
 |  |  |             } | 
 |  |  |             if( totalNum.doubleValue() > Constants.formatIntegerNum(line.getMaxOrder())){ | 
 |  |  |                 throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"线路【"+line.getLineName()+"】订单送货量超过了线路总送货量限制,无法进行调整!"); | 
 |  |  |             } | 
 |  |  |             lineParam.setTotalNum(totalNum); | 
 |  |  |             lineParam.setOrderNum(totalCus); | 
 |  |  |         } | 
 |  |  |         model.setSketchLineList(jkSketch.getSketchLineList());//线路信息 | 
 |  |  |         model.setStatus(Constants.ONE); | 
 |  |  |         model.setEditDate(new Date()); | 
 |  |  |         model.setEditor(jkSketch.getLoginUserInfo().getId()); | 
 |  |  |         model.setPlanLineDate(model.getEditDate()); | 
 |  |  |         model.setPlanLineUserId(jkSketch.getLoginUserInfo().getId()); | 
 |  |  |         model.setJobId(UUID.randomUUID().toString()); | 
 |  |  |         redisTemplate.opsForValue().set(Constants.RedisKeys.JKLINE_JOB+model.getJobId(),true );//做异步处理 | 
 |  |  |         jkSketchMapper.updateById(model); | 
 |  |  |         return model; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private JkSketchLine getLineParamById(Integer id, List<JkSketchLine> sketchLineList) { | 
 |  |  |         for(JkSketchLine line: sketchLineList){ | 
 |  |  |             if(Constants.equalsInteger(line.getId(),id)){ | 
 |  |  |                 return line; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return  null; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public JkSketch initOriginDistance(JkSketch jkSketch ) { | 
 |  |  |         JkSketch model = jkSketchMapper.selectById(jkSketch.getId()); | 
 |  |  |         if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路已被优化,已无法计算原始路线路程数"); | 
 |  |  |         } | 
 |  |  |         checkJketchCustomerLocation(model,true); | 
 |  |  |         model.setEditDate(new Date()); | 
 |  |  |         model.setDistance(model.getOriginDistance()); | 
 |  |  |         jkSketchMapper.updateById(model); | 
 |  |  |         return model; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Async | 
 |  |  |     public  void distanceCustomer( Category cate) { | 
 |  |  |         try { | 
 |  |  |             List<JkCustomer> customerList = cate.getCustomerList(); | 
 |  |  |             String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_DISTANCE_GEOAPI_URL).getCode(); | 
 |  |  |             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(","); | 
 |  |  |                 cLongitude = new BigDecimal(ss[0]); | 
 |  |  |                 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){ | 
 |  |  |  | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         }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) { | 
 |  |  |         List<JkCustomer> updateCustomerList = new ArrayList<>(); | 
 |  |  |         List<JkCustomerNavigation> navigationList = new ArrayList<>(); | 
 |  |  |         List<DistanceMapParam> tmpList = new ArrayList<>(); | 
 |  |  |         List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistance()); | 
 |  |  |         boolean isNew = 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()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         tmpList.add(t0); | 
 |  |  |         for(JkCustomer cm : customerList){ | 
 |  |  |             //客户和客户之间的距离信息 | 
 |  |  |             DistanceMapParam t = new DistanceMapParam(); | 
 |  |  |             t.setId(cm.getId()); | 
 |  |  |             DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList); | 
 |  |  |             if(param!=null){//如果之前已经获取过 | 
 |  |  |                 t = param; | 
 |  |  |             }else{ | 
 |  |  |                 JkCustomerNavigation navigation = new JkCustomerNavigation(); | 
 |  |  |                 navigation.setStartId(c.getId()); | 
 |  |  |                 navigation.setEndId(cm.getId()); | 
 |  |  |                 navigation.setIsdeleted(Constants.ZERO); | 
 |  |  |                 navigation.setCreateDate(date); | 
 |  |  |                 navigation.setEditDate(date); | 
 |  |  |                 navigation.setEndLatitude(cm.getLatitude()); | 
 |  |  |                 navigation.setEndLogitude(cm.getLongitude()); | 
 |  |  |                 navigation.setStartLatitude(c.getLatitude()); | 
 |  |  |                 navigation.setStartLogitude(c.getLongitude()); | 
 |  |  |                 isNew = true; | 
 |  |  |                 if(Constants.equalsInteger(c.getId(),cm.getId())){ | 
 |  |  |                     t.setDistance(0l); | 
 |  |  |                 }else{ | 
 |  |  |                     DistanceCustomerModel dm = DistanceCalculator.calculateDistanceGaode(url,c,cm); | 
 |  |  |                     t.setDistance(dm.getDistance() ); | 
 |  |  |                     if(dm.getLocations().size()>0){ | 
 |  |  |                         //如果有路径信息 | 
 |  |  |                         navigation.setSteps(dm.getPolyline()); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 navigation.setIdIndex(c.getId()+"-"+cm.getId()); | 
 |  |  |                 navigation.setDistance(t.getDistance()); | 
 |  |  |                 navigationList.add(navigation); | 
 |  |  |             } | 
 |  |  |             tmpList.add(t); | 
 |  |  |         } | 
 |  |  |         DistanceMapParam tt = new DistanceMapParam(); | 
 |  |  |         tt.setId(-2);//表示返回园区 | 
 |  |  |         tt.setDistance(Constants.formatLongNum(c.getEndDistance())); | 
 |  |  |         if(Constants.formatLongNum(c.getEndDistance()) <= 0){ | 
 |  |  |             //该客户返回园区的距离 ,如果之前未获取过 | 
 |  |  |             isNew = true; | 
 |  |  |             JkCustomer start = new JkCustomer(); | 
 |  |  |             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()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         tmpList.add(tt); | 
 |  |  |         if(isNew){// | 
 |  |  |             u.setDistanceStatus(Constants.ONE); | 
 |  |  |             u.setId(c.getId()); | 
 |  |  |             u.setDistance(JSONObject.toJSONString(tmpList)); | 
 |  |  |             updateCustomerList.add(u); | 
 |  |  |         } | 
 |  |  |         if(updateCustomerList.size()>0){ | 
 |  |  |             for(JkCustomer c1 : updateCustomerList){ | 
 |  |  |                 jkCustomerMapper.updateById(c1);//更新客户与其他点之间的距离 | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if(navigationList.size()>0){ | 
 |  |  |             jkCustomerNavigationMapper.delete(new UpdateWrapper<JkCustomerNavigation>().lambda() | 
 |  |  |                     .eq(JkCustomerNavigation::getStartId,c.getId()));//删除历史数据 | 
 |  |  |             jkCustomerNavigationMapper.insert(navigationList);//插入最新数据 | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private  List<JkCustomer>  checkNeedDistanceDo( List<JkCustomer> customerList) { | 
 |  |  |         if(customerList==null || customerList.size()==0){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         boolean need = false; | 
 |  |  |         List<JkCustomer> list = new ArrayList<>(); | 
 |  |  |         for(JkCustomer jk : customerList){ | 
 |  |  |             if(Constants.equalsInteger(jk.getDistanceStatus(),Constants.ZERO)){ | 
 |  |  |                 need = true; | 
 |  |  |                 list.add(jk); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if(!need){//如果无需进行处理 | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         return  list; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public  Category checkDataValid(JkSketch model) { | 
 |  |  |         if(model.getCategoryId() == null){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>(); | 
 |  |  |         queryWrapper.selectAll(Category.class ) | 
 |  |  |                 .eq(Category::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(Category::getType,Constants.FOUR) | 
 |  |  |                 .eq(Category::getId,model.getCategoryId() ); | 
 |  |  |         Category c = categoryMapper.selectJoinOne(Category.class,queryWrapper); | 
 |  |  |         if(c==null){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(Constants.equalsInteger(c.getStatus(),Constants.TWO)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该主线正在进行客户距离计算任务,请耐心等待任务完成!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         MPJLambdaWrapper<JkCustomer> queryWrapper1 = new MPJLambdaWrapper<>(); | 
 |  |  |         queryWrapper1.selectAll(JkCustomer.class ) | 
 |  |  |                 .leftJoin(JkLine.class,JkLine::getId,JkCustomer::getLineId) | 
 |  |  |                 .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){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该主线下无需要进行距离计算的客户信息!"); | 
 |  |  |         } | 
 |  |  |         String errorMsg =""; | 
 |  |  |         for(JkCustomer c1 : customerList){ | 
 |  |  |             if(c1.getLatitude()==null || c1.getLongitude() ==null || Constants.equalsInteger(c1.getDistanceStatus(),Constants.TWO)){ | 
 |  |  |                 errorMsg += c.getName()+"-"+c.getName()+" | "; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if(StringUtils.isNotBlank(errorMsg)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:【"+errorMsg+"】定位信息不完整,不满足距离计算条件!"); | 
 |  |  |         } | 
 |  |  |         c.setStatus(Constants.TWO); | 
 |  |  |         categoryMapper.updateById(c);//更新任务执行状态 | 
 |  |  |         c.setCustomerList(customerList); | 
 |  |  |         return  c; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 开始异步执行线路优化任务 | 
 |  |  |      * @param model | 
 |  |  |      */ | 
 |  |  |     @Override | 
 |  |  |     @Async | 
 |  |  |     public void startUpdateLineAsync(JkSketch model) { | 
 |  |  |         try { | 
 |  |  |             initCustomerDistance(model); | 
 |  |  |             List<JkSketchCustomer> customerList = model.getCustomerList(); | 
 |  |  |             List<JkLine> lineList = model.getLineList(); | 
 |  |  |             TspSolver.DataModel dataModel = new TspSolver.DataModel(); | 
 |  |  | 
 |  |  |             long[] vehicleCapacities1=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; | 
 |  |  |             demands1[0] =0;//原点 | 
 |  |  |             double cLatitude =0; | 
 |  |  |             double cLongitude =0; | 
 |  |  |             String location = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.COMPANY_LOCATION).getCode(); | 
 |  |  |             try { | 
 |  |  |                 String[] ss = location.split(","); | 
 |  |  |                 cLongitude = Double.parseDouble(ss[0]); | 
 |  |  |                 cLatitude = Double.parseDouble(ss[1]); | 
 |  |  |             }catch (Exception e){ | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             for (int i = 0; i < customerList.size(); i++) { | 
 |  |  |                 distanceMatrix1[0][i] =  DistanceCalculator.calculateDistance(cLatitude,cLongitude,customerList.get(i).getLatitude().doubleValue(),customerList.get(i).getLongitude().doubleValue())/1000; | 
 |  |  |                 distanceMatrix1[i][0] = distanceMatrix1[0][i]; | 
 |  |  |                 List<DistanceMapParam>  disList =  customerList.get(i).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();  //各个点的订单量 | 
 |  |  |                 List<Map<String,Object>> disList = customerList.get(i).getDistanceList(); | 
 |  |  |                 for (int j = 0; j< disList.size(); j++) { | 
 |  |  |                     if(disList.size()>j){ | 
 |  |  |                         distanceMatrix1[i+1][j+1]  = (Long) disList.get(j).get("b")/1000;//构造距离矩阵 | 
 |  |  |                 for (int j = 0; j < customerList.size(); j++) { | 
 |  |  |                     distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ; | 
 |  |  |                 } | 
 |  |  |                /* for (int j = 0; j< disList.size()-2; j++) { | 
 |  |  |                     if(j+1 >=10){ | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                     if(disList.size()>j+1){ | 
 |  |  |                         distanceMatrix1[i+1][j+1]  = disList.get(j+1).getDistance()/1000;//构造距离矩阵 | 
 |  |  |                     }else{ | 
 |  |  |                         distanceMatrix1[i+1][j+1]  = 1l; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 }*/ | 
 |  |  |             } | 
 |  |  |             for (int i = 0; i < lineList.size(); i++) { | 
 |  |  |                 vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//每辆车的最大订单量限制 | 
 |  |  | 
 |  |  |                     .set(JkSketch::getStatus,Constants.THREE) | 
 |  |  |                     .set(JkSketch::getPlanLineEndDate,new Date())); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     @Async | 
 |  |  |     public  void startInitOriginDistanceBatch( JkSketch  model) { | 
 |  |  |                 initOriginDistance(model); | 
 |  |  |     } | 
 |  |  |     @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 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> customerListParam =  line.getCustomerList() ; | 
 |  |  |                 TspSolver.DataModel dataModel = new TspSolver.DataModel(); | 
 |  |  |                 int vehicleNumber1 = 1;//线路数量 | 
 |  |  |                 long[] vehicleCapacities1=new long[]{line.getMaxOrder()};//每辆车的最大订单量限制 | 
 |  |  |                 long[] demands1 = 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).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();  //各个点的订单量 | 
 |  |  |                     for (int j = 0; j < customerListParam.size(); j++) { | 
 |  |  |                         distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 //构造优化数据模型 | 
 |  |  |                 dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1); | 
 |  |  |                 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()+"】调整失败 ,未获得最优交通规划方案!"); | 
 |  |  |                 } | 
 |  |  |                 //有效路径 | 
 |  |  |                 for (Integer cIndex : routes){ | 
 |  |  |                     if(cIndex ==0){ | 
 |  |  |                         continue; //起始点不处理 | 
 |  |  |                     } | 
 |  |  |                     JkSketchCustomer customer = customerListParam.get(cIndex-1); | 
 |  |  |                     customer.setSortnum(cIndex-1); | 
 |  |  |                 } | 
 |  |  |                 line.setDistance(so.getDistance()); | 
 |  |  |             } | 
 |  |  |         }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())); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |     private List<JkSketchCustomer> initSketchCustomerListParam(List<JkSketchCustomer> customerList, List<JkSketchCustomer> customerList1) { | 
 |  |  |         for(JkSketchCustomer param : customerList){ | 
 |  |  |             for(JkSketchCustomer model : customerList1){ | 
 |  |  |               if(Constants.equalsInteger(model.getId(),param.getId())){ | 
 |  |  |                   param.setLatitude(model.getLatitude()); | 
 |  |  |                   param.setLongitude(model.getLongitude()); | 
 |  |  |                   param.setStartDistance(model.getStartDistance()); | 
 |  |  |                   param.setEndDistance(model.getEndDistance()); | 
 |  |  |                   param.setDistanceJson(model.getDistanceJson()); | 
 |  |  |               } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         for(JkSketchCustomer c : customerList){ | 
 |  |  |             List<DistanceMapParam> tmpList = new ArrayList<>(); | 
 |  |  |             List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson()); | 
 |  |  |             DistanceMapParam t0 = new DistanceMapParam(); | 
 |  |  |             t0.setId(-2);//表示返回园区 | 
 |  |  |             t0.setDistance(Constants.formatLongNum(c.getStartDistance()) ); | 
 |  |  |             tmpList.add(t0); | 
 |  |  |             for(JkSketchCustomer cm : customerList){ | 
 |  |  |                 //客户和客户之间的距离信息 | 
 |  |  |                 DistanceMapParam t = new DistanceMapParam(); | 
 |  |  |                 t.setId(cm.getCustomerId()); | 
 |  |  |                 t.setDistance(0); | 
 |  |  |                 DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList); | 
 |  |  |                 if(param!=null){//如果之前已经获取过 | 
 |  |  |                     t = param; | 
 |  |  |                 } | 
 |  |  |                 tmpList.add(t); | 
 |  |  |             } | 
 |  |  |             DistanceMapParam tt = new DistanceMapParam(); | 
 |  |  |             tt.setId(-2);//表示返回园区 | 
 |  |  |             tt.setDistance(Constants.formatLongNum(c.getEndDistance())); | 
 |  |  |             tmpList.add(tt); | 
 |  |  |             c.setDistanceMapParamList(tmpList); | 
 |  |  |         } | 
 |  |  |         return  customerList; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void initCustomerDistance(JkSketch model) { | 
 |  |  |         String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_LOCATION_GEOAPI_URL).getCode(); | 
 |  |  |         List<JkCustomer> updateCustomerList = new ArrayList<>(); | 
 |  |  |  | 
 |  |  |     private void initCustomerDistance( List<JkSketchLine> lineList,JkSketch model,boolean updateLineDistance) { | 
 |  |  |         List<JkSketchCustomer> customerList = model.getCustomerList(); | 
 |  |  |         for(JkSketchCustomer c : customerList){ | 
 |  |  |             List<DistanceMapParam> tmpList = new ArrayList<>(); | 
 |  |  |             List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson()); | 
 |  |  |             DistanceMapParam t0 = new DistanceMapParam(); | 
 |  |  |             t0.setId(-2);//表示返回园区 | 
 |  |  |             t0.setDistance(Constants.formatLongNum(c.getStartDistance()) ); | 
 |  |  |             if(Constants.formatLongNum(c.getStartDistance()) <= 0){ | 
 |  |  |                 //园区前往该客户的距离,如果之前未获取过 | 
 |  |  |                 throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足优化条件!"); | 
 |  |  |             } | 
 |  |  |             tmpList.add(t0); | 
 |  |  |             for(JkSketchCustomer cm : customerList){ | 
 |  |  |                 boolean isNew = false; | 
 |  |  |                 //客户和客户之间的距离信息 | 
 |  |  |                 DistanceMapParam t = new DistanceMapParam(); | 
 |  |  |                 t.setId(cm.getId()); | 
 |  |  |                 DistanceMapParam param = getParamByCustomerIds( cm.getId(),distanceMapParamList); | 
 |  |  |                 t.setId(cm.getCustomerId()); | 
 |  |  |                 DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList); | 
 |  |  |                 if(param!=null){//如果之前已经获取过 | 
 |  |  |                     t = param; | 
 |  |  |                 }else{ | 
 |  |  |                     isNew = true; | 
 |  |  |                     if(Constants.equalsInteger(c.getCustomerId(),cm.getCustomerId())){ | 
 |  |  |                         t.setDistance(0l); | 
 |  |  |                     }else{ | 
 |  |  |                         DistanceModel dm = DistanceCalculator.calculateDistanceGaode(url,c,cm); | 
 |  |  |                         t.setDistance(dm.getDistance() ); | 
 |  |  |                         if(dm.getLocations().size()>0){ | 
 |  |  |                             //如果有路径信息 | 
 |  |  |  | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足路程计算条件!"); | 
 |  |  |                 } | 
 |  |  |                 tmpList.add(t); | 
 |  |  |                 if(isNew){// | 
 |  |  |                     JkCustomer u =new JkCustomer(); | 
 |  |  |                     u.setId(c.getId()); | 
 |  |  |                     u.setDistance(JSONObject.toJSONString(tmpList)); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             DistanceMapParam tt = new DistanceMapParam(); | 
 |  |  |             tt.setId(-2);//表示返回园区 | 
 |  |  |             tt.setDistance(Constants.formatLongNum(c.getEndDistance())); | 
 |  |  |             if(Constants.formatLongNum(c.getEndDistance()) <= 0){ | 
 |  |  |                 //该客户返回园区的距离 ,如果之前未获取过 | 
 |  |  |                 throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足路程计算条件!"); | 
 |  |  |             } | 
 |  |  |             tmpList.add(tt); | 
 |  |  |             c.setDistanceMapParamList(tmpList); | 
 |  |  |         } | 
 |  |  |         if(updateCustomerList.size()>0){ | 
 |  |  |             for(JkCustomer c : updateCustomerList){ | 
 |  |  |                 jkCustomerMapper.updateById(c);//更新客户与其他点之间的距离 | 
 |  |  |         if(lineList!=null){ | 
 |  |  |             long totalDistance = 0; | 
 |  |  |             for (JkSketchLine line :lineList){ | 
 |  |  |                 long lineDistance = 0; | 
 |  |  |                 List<JkSketchCustomer> customers = getCustomerListByLineId(line.getId(),customerList); | 
 |  |  |                 int index =0; | 
 |  |  |                 for(JkSketchCustomer c : customers){ | 
 |  |  |                     if(index ==0){ | 
 |  |  |                         lineDistance+= Constants.formatLongNum(c.getStartDistance()); | 
 |  |  |                     } | 
 |  |  |                     if(index == customers.size()-1){ | 
 |  |  |                         lineDistance+= Constants.formatLongNum(c.getEndDistance()); | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                     DistanceMapParam param = getParamByCustomerIds( customers.get(index+1).getCustomerId(),getListFromJsonStr(c.getDistanceJson())); | 
 |  |  |                     lineDistance += param.getDistance(); | 
 |  |  |                     index++; | 
 |  |  |                   /*  for(JkSketchCustomer cm : customers){ | 
 |  |  |                         DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),getListFromJsonStr(c.getDistanceJson())); | 
 |  |  |                         lineDistance += param.getDistance(); | 
 |  |  |                     }*/ | 
 |  |  |                 } | 
 |  |  |                 if(updateLineDistance && Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){ | 
 |  |  |                     line.setDistance(lineDistance); | 
 |  |  |                     jkSketchLineMapper.updateById(line); | 
 |  |  |                 } | 
 |  |  |                 totalDistance += lineDistance; | 
 |  |  |             } | 
 |  |  |             if(Constants.equalsInteger(model.getStatus(),Constants.ZERO) ||Constants.formatLongNum(model.getOriginDistance()) <= 0l ){ | 
 |  |  |                 //如果首次优化或者之前没有计算过,设置优化前原始路径 | 
 |  |  |                 model.setOriginDistance(totalDistance); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private List<JkSketchCustomer> getCustomerListByLineId(Integer id, List<JkSketchCustomer> customerList) { | 
 |  |  |         List<JkSketchCustomer> list = new ArrayList<>(); | 
 |  |  |         for (JkSketchCustomer c :customerList){ | 
 |  |  |             if(Constants.equalsInteger(c.getSketchLineId(),id)){ | 
 |  |  |                 list.add(c); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return list; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private DistanceMapParam getParamByCustomerIds(  Integer id1, List<DistanceMapParam> distanceMapParamList) { | 
 |  |  | 
 |  |  |         if(solutions!=null && solutions.size()>0){ | 
 |  |  |             for(TspSolverSolutions so : solutions){ | 
 |  |  |                 List<Integer> routes = so.getRouteIndex(); | 
 |  |  |                 totalDistance+= so.getDistance(); | 
 |  |  |                 if(routes.size() <=2) { | 
 |  |  |                     continue;//无客户的非有效路线 | 
 |  |  |                 } | 
 |  |  |                 totalDistance+= so.getDistance(); | 
 |  |  | //                totalDistance+= so.getDistance(); | 
 |  |  |                 JkLine  line =model.getLineList().get(so.getLineIndex()); | 
 |  |  |                 JkSketchLine tModel =  new JkSketchLine(); | 
 |  |  |                 tModel.setSketchId(model.getId()); | 
 |  |  | 
 |  |  |                 tModel.setTotalNum(new BigDecimal(0)); | 
 |  |  |                 tModel.setOrderNum(routes.size()-2); | 
 |  |  |                 tModel.setDateInfo(model.getDateInfo()); | 
 |  |  |                 tModel.setType(Constants.ONE); | 
 |  |  |                 tModel.setSortnum(sketchLineList.size()+1); | 
 |  |  |                 tModel.setEditDate(tModel.getCreateDate()); | 
 |  |  |                 tModel.setEditor(tModel.getCreator()); | 
 |  |  | 
 |  |  |                 tModel.setCustomerList( new ArrayList<>()); | 
 |  |  |                 //有效路径 | 
 |  |  |                 for (Integer cIndex : routes){ | 
 |  |  |                     if(cIndex ==0 || cIndex == routes.size()-1){ | 
 |  |  |                     if(cIndex ==0){ | 
 |  |  |                         continue; //起始点不处理 | 
 |  |  |                     } | 
 |  |  |                     JkSketchCustomer customer = model.getCustomerList().get(cIndex-1); | 
 |  |  | 
 |  |  |                     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.setSketchId(model.getId()); | 
 |  |  |                     cModel.setCustomerId(customer.getCustomerId()); | 
 |  |  |                     tModel.getCustomerList().add(cModel); | 
 |  |  |                     if(cIndex ==0 || cIndex == routes.size()-1){ | 
 |  |  |                         continue; //起始点不处理 | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |             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); | 
 |  |  | 
 |  |  |                     .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) | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private   List<JkSketchCustomer>  checkJketchCustomerLocation(JkSketch model) { | 
 |  |  |     private   List<JkSketchCustomer>  checkJketchCustomerLocation(JkSketch model,boolean updateLineDistance) { | 
 |  |  |         MPJLambdaWrapper<JkSketchCustomer> queryWrapper = new MPJLambdaWrapper<>(); | 
 |  |  |         queryWrapper.selectAll(JkSketchCustomer.class ) | 
 |  |  |                 .selectAs(JkCustomer::getName,JkSketchCustomer::getName) | 
 |  |  |                 .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode) | 
 |  |  |                 .selectAs(JkCustomer::getDistanceStatus,JkSketchCustomer::getDistanceStatus) | 
 |  |  |                 .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.formatIntegerNum(model.getOptStatus())) | 
 |  |  |                 .eq(JkSketchCustomer::getSketchId, model.getId()) | 
 |  |  |                 .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .orderByAsc(JkSketchCustomer::getSortnum); | 
 |  |  | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户信息为空,不满足优化条件!"); | 
 |  |  |         } | 
 |  |  |         String errorMsg =""; | 
 |  |  |         String errorMsg1 =""; | 
 |  |  |         for(JkSketchCustomer c : customerList){ | 
 |  |  |             if(c.getLatitude()==null || c.getLongitude() ==null){ | 
 |  |  |                 errorMsg += c.getName()+"-"+c.getName()+";"; | 
 |  |  |                 errorMsg += c.getName()+"-"+c.getName()+" | "; | 
 |  |  |             } | 
 |  |  |             if(!Constants.equalsInteger(c.getDistanceStatus(),Constants.ONE)){ | 
 |  |  |                 errorMsg1 += c.getName()+"-"+c.getName()+" | "; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if(StringUtils.isNotBlank(errorMsg)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+errorMsg+"定位信息不完整,不满足优化条件!"); | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:【"+errorMsg+"】定位信息不完整,不满足优化条件!"); | 
 |  |  |         } | 
 |  |  |        /* for(JkSketchCustomer c : customerList){ | 
 |  |  |             List<Map<String,Object>> tmpList = new ArrayList<>(); | 
 |  |  |             for(JkSketchCustomer cm : customerList){ | 
 |  |  |                 Map<String,Object> t = new HashMap<>(); | 
 |  |  |                 t.put("a",cm.getId()); | 
 |  |  |                 if(Constants.equalsInteger(c.getCustomerId(),cm.getCustomerId())){ | 
 |  |  |                     t.put("b",0l); | 
 |  |  |                 }else{ | 
 |  |  |                     t.put("b", DistanceCalculator.calculateDistance( | 
 |  |  |                             Constants.formatBigdecimal(c.getLatitude()).doubleValue(), | 
 |  |  |                             Constants.formatBigdecimal(c.getLongitude()).doubleValue(), | 
 |  |  |                             Constants.formatBigdecimal(cm.getLatitude()).doubleValue(), | 
 |  |  |                             Constants.formatBigdecimal(cm.getLongitude()).doubleValue())); | 
 |  |  |                 } | 
 |  |  |                 tmpList.add(t); | 
 |  |  |             } | 
 |  |  |             c.setDistanceList(tmpList); | 
 |  |  |         if(StringUtils.isNotBlank(errorMsg1)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:【"+errorMsg1+"】交通规划尚未完成,不满足优化条件!"); | 
 |  |  |         } | 
 |  |  |         */ | 
 |  |  |         /*if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){ | 
 |  |  |             //如果是未优化状态,计算原始距离 | 
 |  |  |             long totalDistance = 0; | 
 |  |  |             MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>(); | 
 |  |  |             queryWrapper1.selectAll(JkSketchLine.class ) | 
 |  |  |                     .eq(JkSketchLine::getSketchId, model.getId()) | 
 |  |  |                     .eq(JkSketchLine::getIsdeleted,Constants.ZERO); | 
 |  |  |             List<JkSketchLine> lineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper1);// | 
 |  |  |             if(lineList!=null ||lineList.size()>0){ | 
 |  |  |                 double cLatitude =0; | 
 |  |  |                 double cLongitude =0; | 
 |  |  |                 String location = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.COMPANY_LOCATION).getCode(); | 
 |  |  |                 try { | 
 |  |  |                     String[] ss = location.split(","); | 
 |  |  |                     cLongitude = Double.parseDouble(ss[0]); | 
 |  |  |                     cLatitude = Double.parseDouble(ss[1]); | 
 |  |  |                 }catch (Exception e){ | 
 |  |  |  | 
 |  |  |                 } | 
 |  |  |                 for(JkSketchLine line : lineList){ | 
 |  |  |                     boolean isFirst =true; | 
 |  |  |                     JkSketchCustomer last = null; | 
 |  |  |                     for(JkSketchCustomer c : customerList){ | 
 |  |  |                         if(Constants.equalsInteger(c.getSketchLineId(),line.getId())){ | 
 |  |  |                             if(isFirst){ | 
 |  |  |                                 totalDistance += DistanceCalculator.calculateDistance(cLatitude,cLongitude | 
 |  |  |                                         ,Constants.formatBigdecimal(c.getLatitude()).doubleValue() | 
 |  |  |                                         ,Constants.formatBigdecimal(c.getLongitude()).doubleValue()); | 
 |  |  |                             }else{ | 
 |  |  |                                 totalDistance += DistanceCalculator.calculateDistance( | 
 |  |  |                                          Constants.formatBigdecimal(c.getLatitude()).doubleValue() | 
 |  |  |                                         ,Constants.formatBigdecimal(c.getLongitude()).doubleValue() | 
 |  |  |                                         ,Constants.formatBigdecimal(last.getLatitude()).doubleValue() | 
 |  |  |                                         ,Constants.formatBigdecimal(last.getLongitude()).doubleValue()); | 
 |  |  |                             } | 
 |  |  |                             last = c; | 
 |  |  |                             isFirst=false; | 
 |  |  |                         } | 
 |  |  |                         if(last!=null){ | 
 |  |  |                             totalDistance += DistanceCalculator.calculateDistance(cLatitude,cLongitude | 
 |  |  |                                     ,Constants.formatBigdecimal(last.getLatitude()).doubleValue() | 
 |  |  |                                     ,Constants.formatBigdecimal(last.getLongitude()).doubleValue()); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |             model.setOriginDistance(totalDistance); | 
 |  |  |         }*/ | 
 |  |  |  | 
 |  |  |         model.setCustomerList(customerList); | 
 |  |  |         MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>(); | 
 |  |  |         queryWrapper1.selectAll(JkSketchLine.class ) | 
 |  |  |                 .eq(JkSketchLine::getSketchId, model.getId()) | 
 |  |  |                 .eq(JkSketchLine::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(JkSketchLine::getType, Constants.formatIntegerNum(model.getOptStatus())) | 
 |  |  |                 .orderByAsc(JkSketchLine::getSortnum); | 
 |  |  |         List<JkSketchLine> lineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,queryWrapper1); | 
 |  |  |         initCustomerDistance(lineList,model,updateLineDistance); | 
 |  |  |         return customerList; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         QueryWrapper<JkSketch> wrapper = new QueryWrapper<>(jkSketch); | 
 |  |  |         return jkSketchMapper.selectCount(wrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public List<JkSketch> importBatch(MultipartFile file, String dateInfoStr, LoginUserInfo loginUser){ | 
 |  |  | 
 |  |  |             if(newOrderList.size()>0){ | 
 |  |  |                 jkOrdersMapper.insert(newOrderList); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             List<JkSketchLine> sketchLineList = initNewSketchLineList(newList,newOrderList,lineList); | 
 |  |  |             jkSketchLineMapper.update(null,new UpdateWrapper<JkSketchLine>().lambda() | 
 |  |  |                     .set(JkSketchLine::getIsdeleted,Constants.ONE) | 
 |  |  | 
 |  |  |             if(sketchLineList.size()>0){ | 
 |  |  |                 jkSketchLineMapper.insert(sketchLineList); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             List<JkSketchCustomer> sketchCuustomerList = initNewSketchCustomerList(sketchLineList,newOrderList);//按照主线路分组 | 
 |  |  |             jkSketchCustomerMapper.update(null,new UpdateWrapper<JkSketchCustomer>().lambda() | 
 |  |  |                     .set(JkSketchCustomer::getIsdeleted,Constants.ONE) | 
 |  |  | 
 |  |  |                 tModel.setTotalNum(orders.getNum()); | 
 |  |  |                 tModel.setDateInfo(orders.getDateInfo()); | 
 |  |  |                 tModel.setSortnum(list.size()+1); | 
 |  |  |                 tModel.setType(Constants.ZERO); | 
 |  |  |                 tModel.setEditDate(tModel.getCreateDate()); | 
 |  |  |                 tModel.setEditor(tModel.getCreator()); | 
 |  |  |                 tModel.setIsdeleted(Constants.ZERO); | 
 |  |  | 
 |  |  |             initOrderAndTotalNum(tModel,line.getId(),newOrderList); | 
 |  |  |             tModel.setDateInfo(newList.get(0).getDateInfo()); | 
 |  |  |             tModel.setSortnum(list.size()+1); | 
 |  |  |             tModel.setType(Constants.ZERO); | 
 |  |  |             tModel.setEditDate(tModel.getCreateDate()); | 
 |  |  |             tModel.setEditor(tModel.getCreator()); | 
 |  |  |             tModel.setIsdeleted(Constants.ZERO); | 
 |  |  | 
 |  |  |                 list.add(tModel); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         /*for(JkOrders orders : newOrderList){ | 
 |  |  |             JkSketchLine tModel = findModelFromListByLineId(orders.getLineId(),list); | 
 |  |  |             if(tModel!=null){ | 
 |  |  |                 tModel.setTotalNum(  tModel.getTotalNum().add(orders.getNum()));//订单量累计 | 
 |  |  |                 tModel.setOrderNum(tModel.getOrderNum()+1);//客户数加1 | 
 |  |  |             }else{ | 
 |  |  |                 tModel = new JkSketchLine(); | 
 |  |  |                 tModel.setSketchId(getSKetchIdByyCategoryId(orders.getCategoryId(),newList)); | 
 |  |  |                 tModel.setCreator(orders.getCreator()); | 
 |  |  |                 tModel.setCreateDate(orders.getCreateDate()); | 
 |  |  |                 tModel.setLineId(orders.getLineId()); | 
 |  |  |                 tModel.setTotalNum(orders.getNum()); | 
 |  |  |                 tModel.setOrderNum(1); | 
 |  |  |                 tModel.setDateInfo(orders.getDateInfo()); | 
 |  |  |                 tModel.setSortnum(list.size()+1); | 
 |  |  |                 tModel.setEditDate(tModel.getCreateDate()); | 
 |  |  |                 tModel.setEditor(tModel.getCreator()); | 
 |  |  |                 tModel.setIsdeleted(Constants.ZERO); | 
 |  |  |                 if(tModel.getSketchId()!=null){ | 
 |  |  |                     list.add(tModel); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         }*/ | 
 |  |  |  | 
 |  |  |         return list; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 tModel.setCreateDate(orders.getCreateDate()); | 
 |  |  |                 tModel.setCategoryId(orders.getCategoryId()); | 
 |  |  |                 tModel.setTotalNum(orders.getNum()); | 
 |  |  |                 tModel.setOptStatus(Constants.ZERO); | 
 |  |  |                 tModel.setOrderNum(1); | 
 |  |  |                 tModel.setDateInfo(orders.getDateInfo()); | 
 |  |  |                 tModel.setSortnum(list.size()+1); | 
 |  |  | 
 |  |  |         } | 
 |  |  |         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) | 
 |  |  |                 .and(StringUtils.isNotBlank(telecomLineInfoDTO.getSearchInfo()),i->i.like(Cars::getCode,telecomLineInfoDTO.getSearchInfo()).or().like(JkLine::getName,telecomLineInfoDTO.getSearchInfo())) | 
 |  |  |                 .eq(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::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(jkSketch.getCustomerNum()); | 
 |  |  |             List<JkSketchLine> childLineList = jkSketchLineList.stream().filter(i->Constants.equalsInteger(i.getSketchId(),jkSketch.getId())).collect(Collectors.toList()); | 
 |  |  |             //优化前数据 | 
 |  |  |             List<JkSketchLine> beforeList = childLineList.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) { | 
 |  |  | //                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); | 
 |  |  | //                } | 
 |  |  |                 TelecomLineDataVO telecomLineDataVO = new TelecomLineDataVO(); | 
 |  |  |                 telecomLineDataVO.setId(sketchLine.getId()); | 
 |  |  |                 telecomLineDataVO.setName(sketchLine.getLineName()); | 
 |  |  |                 telecomLineDataVOList.add(telecomLineDataVO); | 
 |  |  |                 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::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())&&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 ) ") | 
 |  |  |                 .eq(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; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |