| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.annotation.excel.ExcelImporter; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.tsp.*; |
| | | import com.doumee.core.utils.*; |
| | | import com.doumee.core.utils.tsp.TspSolver; |
| | | import com.doumee.core.utils.tsp.TspSolverSolutions; |
| | | import com.doumee.core.wms.model.response.WmsBaseDataResponse; |
| | | import com.doumee.core.wms.model.response.WmsBaseResponse; |
| | | import com.doumee.dao.admin.request.JkOrdersImport; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.model.*; |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import netscape.javascript.JSObject; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.checkerframework.checker.units.qual.C; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.scheduling.annotation.Async; |
| | |
| | | @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(); |
| | |
| | | .set(JkSketch::getPlanLineEndDate,new Date())); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void initCustomerDistance(JkSketch model) { |
| | | String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_LOCATION_GEOAPI_URL).getCode(); |
| | | List<JkCustomer> updateCustomerList = new ArrayList<>(); |
| | | List<JkSketchCustomer> customerList = model.getCustomerList(); |
| | | for(JkSketchCustomer c : customerList){ |
| | | List<DistanceMapParam> tmpList = new ArrayList<>(); |
| | | List<DistanceMapParam> distanceMapParamList = getListFromJsonStr(c.getDistanceJson()); |
| | | for(JkSketchCustomer cm : customerList){ |
| | | boolean isNew = false; |
| | | DistanceMapParam t = new DistanceMapParam(); |
| | | t.setId(cm.getId()); |
| | | DistanceMapParam param = getParamByCustomerIds( cm.getId(),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){ |
| | | //如果有路径信息 |
| | | |
| | | } |
| | | } |
| | | } |
| | | tmpList.add(t); |
| | | if(isNew){// |
| | | JkCustomer u =new JkCustomer(); |
| | | u.setId(c.getId()); |
| | | u.setDistance(JSONObject.toJSONString(tmpList)); |
| | | } |
| | | } |
| | | c.setDistanceMapParamList(tmpList); |
| | | } |
| | | if(updateCustomerList.size()>0){ |
| | | for(JkCustomer c : updateCustomerList){ |
| | | jkCustomerMapper.updateById(c);//更新客户与其他点之间的距离 |
| | | } |
| | | } |
| | | } |
| | | |
| | | private DistanceMapParam getParamByCustomerIds( Integer id1, List<DistanceMapParam> distanceMapParamList) { |
| | | if(distanceMapParamList!=null){ |
| | | for(DistanceMapParam p :distanceMapParamList){ |
| | | if(Constants.equalsInteger(p.getId(),id1)){ |
| | | return p; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private List<DistanceMapParam> getListFromJsonStr(String distanceJson) { |
| | | try { |
| | | return JSONObject.parseObject(distanceJson, new TypeReference<List<DistanceMapParam>>(){}.getType()); |
| | | }catch (Exception e){ |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | private void dealSearchSolution(JkSketch model, TspSolver.DataModel dataModel) { |
| | |
| | | } |
| | | |
| | | private List<JkSketchCustomer> checkJketchCustomerLocation(JkSketch model) { |
| | | |
| | | 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) |
| | | .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId ) |
| | |
| | | if(StringUtils.isNotBlank(errorMsg)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+errorMsg+"定位信息不完整,不满足优化条件!"); |
| | | } |
| | | for(JkSketchCustomer c : customerList){ |
| | | /* for(JkSketchCustomer c : customerList){ |
| | | List<Map<String,Object>> tmpList = new ArrayList<>(); |
| | | for(JkSketchCustomer cm : customerList){ |
| | | Map<String,Object> t = new HashMap<>(); |
| | |
| | | }else{ |
| | | t.put("b", DistanceCalculator.calculateDistance( |
| | | Constants.formatBigdecimal(c.getLatitude()).doubleValue(), |
| | | Constants.formatBigdecimal(c.getLatitude()).doubleValue(), |
| | | Constants.formatBigdecimal(c.getLongitude()).doubleValue(), |
| | | Constants.formatBigdecimal(cm.getLatitude()).doubleValue(), |
| | | Constants.formatBigdecimal(cm.getLongitude()).doubleValue())); |
| | | } |
| | |
| | | } |
| | | c.setDistanceList(tmpList); |
| | | } |
| | | |
| | | if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){ |
| | | */ |
| | | /*if(Constants.equalsInteger(Constants.ZERO,model.getStatus())){ |
| | | //如果是未优化状态,计算原始距离 |
| | | long totalDistance = 0; |
| | | MPJLambdaWrapper<JkSketchLine> queryWrapper1 = new MPJLambdaWrapper<>(); |
| | |
| | | ,Constants.formatBigdecimal(c.getLatitude()).doubleValue() |
| | | ,Constants.formatBigdecimal(c.getLongitude()).doubleValue()); |
| | | }else{ |
| | | totalDistance += DistanceCalculator.calculateDistance(Constants.formatBigdecimal(c.getLatitude()).doubleValue() |
| | | totalDistance += DistanceCalculator.calculateDistance( |
| | | Constants.formatBigdecimal(c.getLatitude()).doubleValue() |
| | | ,Constants.formatBigdecimal(c.getLongitude()).doubleValue() |
| | | ,Constants.formatBigdecimal(last.getLatitude()).doubleValue() |
| | | ,Constants.formatBigdecimal(last.getLongitude()).doubleValue()); |
| | |
| | | |
| | | } |
| | | model.setOriginDistance(totalDistance); |
| | | } |
| | | }*/ |
| | | |
| | | return customerList; |
| | | } |