| | |
| | | @Autowired |
| | | private JkCustomerMapper jkCustomerMapper; |
| | | @Autowired |
| | | private JkCustomerNavigationMapper jkCustomerNavigationMapper; |
| | | @Autowired |
| | | private JkLineMapper jkLineMapper; |
| | | |
| | | @Autowired |
| | |
| | | totalCus += Constants.formatIntegerNum(line.getMaxCustomer());//总客户量 |
| | | totalNum += Constants.formatIntegerNum(line.getMaxOrder());//总送货量 |
| | | } |
| | | |
| | | if( totalCus < Constants.formatIntegerNum(model.getOrderNum()) ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该线路订单客户数量超过了线路总客户量限制,无法进行优化!"); |
| | | } |
| | |
| | | long[] demands1 = new long[customerList.size()+1]; //各个点的订单量 |
| | | long[][] distanceMatrix1 = new long[customerList.size()+1][customerList.size()+1]; |
| | | 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] = disList.get(0).getDistance(); |
| | | distanceMatrix1[i][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< 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; |
| | | } |
| | |
| | | } |
| | | |
| | | private void initCustomerDistance(JkSketch model) { |
| | | String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_LOCATION_GEOAPI_URL).getCode(); |
| | | String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_DISTANCE_GEOAPI_URL).getCode(); |
| | | List<JkCustomer> updateCustomerList = new ArrayList<>(); |
| | | List<JkCustomerNavigation> navigationList = new ArrayList<>(); |
| | | List<JkSketchCustomer> customerList = model.getCustomerList(); |
| | | |
| | | 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){ |
| | | } |
| | | for(JkSketchCustomer c : customerList){ |
| | | List<DistanceMapParam> tmpList = new ArrayList<>(); |
| | | List<DistanceMapParam> distanceMapParamList = getListFromJsonStr(c.getDistanceJson()); |
| | | for(JkSketchCustomer cm : customerList){ |
| | | 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; |
| | | JkSketchCustomer start = new JkSketchCustomer(); |
| | | start.setId(-1); |
| | | start.setLongitude(cLongitude); |
| | | start.setLatitude(cLatitude); |
| | | DistanceModel 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(JkSketchCustomer 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.getCustomerId(),cm.getCustomerId())){ |
| | | t.setDistance(0l); |
| | |
| | | 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); |
| | | 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){ |
| | | //该客户返回园区的距离 ,如果之前未获取过 |
| | | isNew = true; |
| | | JkSketchCustomer start = new JkSketchCustomer(); |
| | | start.setId(-1); |
| | | start.setLongitude(cLongitude); |
| | | start.setLatitude(cLatitude); |
| | | |
| | | DistanceModel 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.setId(c.getCustomerId()); |
| | | u.setDistance(JSONObject.toJSONString(tmpList)); |
| | | updateCustomerList.add(u); |
| | | } |
| | | c.setDistanceMapParamList(tmpList); |
| | | } |
| | |
| | | for(JkCustomer c : updateCustomerList){ |
| | | jkCustomerMapper.updateById(c);//更新客户与其他点之间的距离 |
| | | } |
| | | } |
| | | if(navigationList.size()>0){ |
| | | jkCustomerNavigationMapper.insert(navigationList); |
| | | } |
| | | } |
| | | |
| | |
| | | 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.setSketchId(model.getId()); |
| | | cModel.setCustomerId(customer.getCustomerId()); |
| | | tModel.getCustomerList().add(cModel); |
| | | if(cIndex ==0 || cIndex == routes.size()-1){ |
| | | continue; //起始点不处理 |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | .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::getSketchId, model.getId()) |
| | | .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO) |