doum
12 小时以前 9b849587816ec31c960d066302d580fb8eb0adcc
最新版本541200007
已修改4个文件
81 ■■■■ 文件已修改
server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchCustomerServiceImpl.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/DistanceCalculator.java
@@ -157,4 +157,16 @@
        return  (long) (EARTH_RADIUS * c * 1000);
    }
    public static long calculateDistanceDecinal (BigDecimal lat1, BigDecimal lon1, BigDecimal lat2, BigDecimal lon2) {
        double dLat = Math.toRadians(Constants.formatBigdecimal(lat2).doubleValue() - Constants.formatBigdecimal(lat1).doubleValue());
        double dLon = Math.toRadians(Constants.formatBigdecimal(lon2).doubleValue()  - Constants.formatBigdecimal(lon1).doubleValue() );
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                Math.cos(Math.toRadians(Constants.formatBigdecimal(lat1).doubleValue()))
                        * Math.cos(Math.toRadians(Constants.formatBigdecimal(lat2).doubleValue())) *
                        Math.sin(dLon / 2) * Math.sin(dLon / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        return  (long) (EARTH_RADIUS * c * 1000);
    }
}
server/visits/dmvisit_service/src/main/java/com/doumee/dao/business/model/Category.java
@@ -110,6 +110,9 @@
    private List<Category> childCategoryList;
    @ApiModelProperty(value = "客户集合")
    @TableField(exist = false)
    private List<JkCustomer> needList;
    @ApiModelProperty(value = "客户集合")
    @TableField(exist = false)
    private List<JkCustomer> customerList;
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchCustomerServiceImpl.java
@@ -2,6 +2,8 @@
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.tsp.DistanceCalculator;
import com.doumee.core.tsp.DistanceMapParam;
import com.doumee.core.utils.Constants;
import com.doumee.dao.business.JkCustomerNavigationMapper;
import com.doumee.dao.business.JkSketchMapper;
@@ -140,6 +142,8 @@
            startmodel.setDistance(allList.get(0).getStartDistance());
            startmodel.setSteps(allList.get(0).getStartSteps());
            if(StringUtils.isBlank(startmodel.getSteps())){
                // (BigDecimal lat1, BigDecimal lon1, BigDecimal lat2, BigDecimal lon2)
                startmodel.setDistance(DistanceCalculator.calculateDistanceDecinal(startmodel.getStartLatitude(),startmodel.getStartLogitude(),startmodel.getEndLatitude(),startmodel.getEndLatitude()));
                startmodel.setSteps(comLocation +";"+allList.get(0).getLongitude()+","+allList.get(0).getLatitude());
            }
            list.add(startmodel);
@@ -177,6 +181,13 @@
                    tt.setStartLogitude(start.getLongitude());
                    tt.setEndLatitude(end.getLatitude());
                    tt.setEndLogitude(end.getLongitude());
                    List<DistanceMapParam> distanceMapParamList  =JkSketchServiceImpl.getListFromJsonStr(start.getDistanceJson());
                    DistanceMapParam param = JkSketchServiceImpl.getParamByCustomerIds( end.getId(),distanceMapParamList);
                    if(param!=null && param.getDistance()!=0){//如果之前已经获取过
                        tt.setDistance(param.getDistance());
                    }else{
                        tt.setDistance(DistanceCalculator.calculateDistanceDecinal(tt.getStartLatitude(),tt.getStartLogitude(),tt.getEndLatitude(),tt.getEndLatitude()));
                    }
                }
                tt.setLocation(allList.get(i).getLocation());
                tt.setName(allList.get(i).getName());
@@ -188,11 +199,6 @@
        }
        return list;
    }
    @Override
    public List<JkSketchCustomer> findList(JkSketchCustomer jkSketchCustomer) {
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -129,8 +129,7 @@
        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(),"请选择有效合理的线路进行优化操作!");
        }
        //当前所有线路(符合条件的线路)
@@ -256,7 +255,8 @@
    @Async
    public  void distanceCustomer( Category cate) {
        try {
            List<JkCustomer> customerList = cate.getCustomerList();
            List<JkCustomer> allList = cate.getCustomerList();
            List<JkCustomer> customerList = cate.getNeedList();
            String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GAODE_DISTANCE_GEOAPI_URL).getCode();
            Date date = new Date();
            BigDecimal cLatitude =new BigDecimal(0);
@@ -288,7 +288,7 @@
                        for (int j = start; j < end; j++) {
                            try {
                                log.error("交通规划========"+cate.getId()+"/"+cate.getName()+"/"+customerList.get(j).getName()+"=======cirle/index:"+finalI+"/"+index++);
                                dealDistancePerCustomer(customerList.get(j),url,date, finalCLatitude, finalCLongitude,customerList);
                                dealDistancePerCustomer(customerList.get(j),url,date, finalCLatitude, finalCLongitude,allList);
                            }catch (Exception e){
                            }
@@ -429,8 +429,10 @@
            }
        }
        if(navigationList.size()>0){
            jkCustomerNavigationMapper.delete(new UpdateWrapper<JkCustomerNavigation>().lambda()
                    .eq(JkCustomerNavigation::getStartId,c.getId()));//删除历史数据
            for (JkCustomerNavigation navigation:navigationList) {
                jkCustomerNavigationMapper.delete(new UpdateWrapper<JkCustomerNavigation>().lambda()
                        .eq(JkCustomerNavigation::getIdIndex,navigation.getIdIndex()));//删除历史数据
            }
            jkCustomerNavigationMapper.insert(navigationList);//插入最新数据
        }
    }
@@ -493,7 +495,8 @@
        }
        c.setStatus(Constants.TWO);
        categoryMapper.updateById(c);//更新任务执行状态
        c.setCustomerList(Constants.equalsInteger(model.getForceUpdate(),0)?needList:customerList);
        c.setCustomerList(customerList);
        c.setNeedList(Constants.equalsInteger(model.getForceUpdate(),0)?needList:customerList);
        return  c;
    }
@@ -701,6 +704,15 @@
    private void initCustomerDistance( List<JkSketchLine> lineList,JkSketch model,boolean updateLineDistance) {
        List<JkSketchCustomer> customerList = model.getCustomerList();
        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(JkSketchCustomer c : customerList){
            List<DistanceMapParam> tmpList = new ArrayList<>();
            List<DistanceMapParam> distanceMapParamList  = getListFromJsonStr(c.getDistanceJson());
@@ -709,18 +721,21 @@
            t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
            if(Constants.formatLongNum(c.getStartDistance()) <= 0){
                //园区前往该客户的距离,如果之前未获取过
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足优化条件!");
                t0.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足优化条件!");
            }
            tmpList.add(t0);
            for(JkSketchCustomer cm : customerList){
                //客户和客户之间的距离信息
                DistanceMapParam t = new DistanceMapParam();
                t.setId(cm.getCustomerId());
                DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                 DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
                if(param!=null){//如果之前已经获取过
                    t = param;
                }else{
                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足路程计算条件!");
                    //如果未规划,按照直线距离
                    t.setDistance(DistanceCalculator.calculateDistanceDecinal(cm.getLatitude(),cm.getLongitude(),c.getLatitude(),c.getLongitude()));
//                    throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"与客户:"+cm.getName()+"简交通规划尚未完成,不满足路程计算条件!");
                }
                tmpList.add(t);
            }
@@ -729,7 +744,8 @@
            tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
            if(Constants.formatLongNum(c.getEndDistance()) <= 0){
                //该客户返回园区的距离 ,如果之前未获取过
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"交通规划尚未完成,不满足路程计算条件!");
                tt.setDistance(DistanceCalculator.calculateDistanceDecinal(cLatitude,cLongitude,c.getLatitude(),c.getLongitude()));
//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:"+c.getName()+"与起点交通规划尚未完成,不满足路程计算条件!");
            }
            tmpList.add(tt);
            c.setDistanceMapParamList(tmpList);
@@ -779,7 +795,7 @@
        return list;
    }
    private DistanceMapParam getParamByCustomerIds(  Integer id1, List<DistanceMapParam> distanceMapParamList) {
    public static DistanceMapParam getParamByCustomerIds(  Integer id1, List<DistanceMapParam> distanceMapParamList) {
        if(distanceMapParamList!=null){
            for(DistanceMapParam p :distanceMapParamList){
                if(Constants.equalsInteger(p.getId(),id1)){
@@ -791,7 +807,7 @@
        return null;
    }
    private List<DistanceMapParam> getListFromJsonStr(String distanceJson) {
    public static List<DistanceMapParam> getListFromJsonStr(String distanceJson) {
        try {
            return  JSONObject.parseObject(distanceJson, new TypeReference<List<DistanceMapParam>>(){}.getType());
        }catch (Exception e){
@@ -923,11 +939,11 @@
        String errorMsg1 ="";
        for(JkSketchCustomer c : customerList){
            if(c.getLatitude()==null || c.getLongitude() ==null){
                errorMsg += c.getName()+"-"+c.getName()+" | ";
                errorMsg +=  c.getName()+" | ";
            }
            if(!Constants.equalsInteger(c.getDistanceStatus(),Constants.ONE)){
                errorMsg1 += c.getName()+"-"+c.getName()+" | ";
            }
        /*    if(!Constants.equalsInteger(c.getDistanceStatus(),Constants.ONE)){
                errorMsg1 +=  c.getName()+" | ";
            }*/
        }
        if(StringUtils.isNotBlank(errorMsg)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该线路客户:【"+errorMsg+"】定位信息不完整,不满足优化条件!");