接口的新特性

2018-08-02  本文已影响0人  YNZXGWZM
image.png
package com.ymdd.galaxy.waybill.core.inter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import com.ymdd.galaxy.base.api.vo.DepartmentVo;
import com.ymdd.galaxy.base.api.vo.DistrictVo;
import com.ymdd.galaxy.waybill.api.vo.WaybillApiDTO;
import com.ymdd.galaxy.waybill.entity.rec.waybill.model.ReceiveAddress;
import com.ymdd.galaxy.waybill.entity.rec.waybill.model.WaybillServiceFeeVo;

import jersey.repackaged.com.google.common.collect.Maps;


/***
 * 
 * @author lzm
 *
 *运单装饰接口,用来费用计算、网点转义
 *
 */
public interface CascadeWaybillInterface {

    
    /**
     * 组装fee进入waybill
     * */
    default void cascadeWaybillFee(WaybillApiDTO dto, WaybillServiceFeeVo fee){
        
        BeanUtils.copyProperties(fee, dto);
        
        //BeanCopier copier = BeanCopierUtils.getBeanCopier(WaybillApiDTO.class, WaybillServiceFeeVo.class);
        
        //copier.copy(fee, dto, null);
        
    }
    
    
    /**
     * 组装address进入waybill
     * */
    default void cascadeWaybillAddress(WaybillApiDTO dto, ReceiveAddress address){
        
        BeanUtils.copyProperties(address, dto);
        if (StringUtils.isNotBlank(address.getConsigneeAddressCode())) {
            dto.setConsigneeAddressCode(address.getConsigneeAddressCode());
        }
        
        if (StringUtils.isNotBlank(address.getSendAddressCode())) {
            dto.setSendAddressCode(address.getSendAddressCode());
        }
        
    }
    
    
    /**
     * 批量组装fee进入waybill
     * */
    default void batchCascadeWaybillFee(List<WaybillApiDTO> dtoList, List<WaybillServiceFeeVo> feeList){
        
        Map<Long, WaybillServiceFeeVo> map =   feeList.stream()
                .collect(Collectors.toMap(WaybillServiceFeeVo::getWaybillNo, p -> p));
        
        if(!map.isEmpty()){
            
            for(WaybillApiDTO dto : dtoList){
                
                WaybillServiceFeeVo fee = map.get(dto.getWaybillNo());
                
                if(null != fee){
                    
                    cascadeWaybillFee(dto, fee);
                }
                
            }
            
        }
        
    }
    
     
    
    /**
     * 批量组装address进入waybill
     * */
//此接口将来会在实现类中调用
    default void batchCascadeWaybillAddress(List<WaybillApiDTO> dtoList, List<ReceiveAddress> addressList){
        
        Map<Long, ReceiveAddress> map = addressList.stream()
                .collect(Collectors.toMap(ReceiveAddress::getWaybillNo, p -> p, (key1, key2) -> key1));
        
        if(!map.isEmpty()){
            
            for(WaybillApiDTO dto : dtoList){
                
                ReceiveAddress address = map.get(dto.getWaybillNo());
                
                if(null != address){
                    
                    cascadeWaybillAddress(dto, address);
                }
                
            }
            
        }
        
    }
    
    default String[] getSortDirection(String sortDirection) {
        if (StringUtils.isNotBlank(sortDirection)) {
            return sortDirection.split(",");
        }
        return null;
    }
    
    default String[] getSortName(String sortName) {
        if (StringUtils.isNotBlank(sortName)) {
            return sortName.split(",");
        }
        return null;
    }
    
    
    /**
     * 
     * @author lzm
     * 封装查询行政区域
     * */
    default HashMap<Integer,String> createDistrict(DistrictVo[] arr){
        
        HashMap<Integer,String> map = Maps.newHashMap();
        
        if(null != arr){
            
             for(DistrictVo v : arr){
                 
                 map.put(v.getCode(), v.getName());
                 
             }
             
        }
        
        return map;
        
    }
    
    
    /**
     * 
     * @author lzm
     * 封装查询网点名称
     * */
    default HashMap<String,String> createDept(DepartmentVo[] arr){
        
        HashMap<String,String> map = Maps.newHashMap();
        
        if(null != arr){
             
             for(DepartmentVo v : arr){
                 
                 map.put(v.getDeptCode(), v.getOutDeptName());
                 
             }
             
        }
        
        return map;
        
    }
    
}
image.png image.png
上一篇 下一篇

猜你喜欢

热点阅读