【客户下单】基于CRM完全匹配地址库实现自动分单
作者:互联网
【客户下单】基于CRM完全匹配地址库实现自动分单
将寄件人的下单地址,以webservice的方式,发送给CRM地址库,获取到对应的客户关联的定区,匹配与定区关联的快递员,实现自动分单。
在crm_management的CustomerService接口中,添加根据地址获取定区编码方法。
public interface CustomerService {
@Path("/customer/findFixedAreaIdByAddress")
@GET
@Consumes({"application/xml","application/json"})
public String findFixedAreaIdByAddress(@QuertParam("address")String address);
}
crm_management的CustomerService接口实现类CustomerServiceImpl:
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService{
//注入dao
@Autowired
private CustomerRepository customerRepository;
@Override
public String findFixedAreaIdByAddress(String address){
return customerRepository.findFixedAreaIdByAddress(address);
}
}
dao:CustomerRepository
public interface CustomerRepository extends JpaRepository<Customer,Integer>{
@Query("select fixedAreaId from Customer where address=?")
public String findFixedAreaIdByAddress(String address);
}
在bos_management中,编写OrderService和OrderServiceImpl:
OrderService:
public interface OrderService {
@Path("/order")
@POST
@Consumes({ "application/xml", "application/json" })
public void saveOrder(Order order);
public Order findByOrderNum(String orderNum);
}
OrderServiceImpl:
@Service
@Transactional
public class OrderServiceImpl implements OrderService{
@Autowired
private FixedAreaRepository fixedAreaRepository;
@Autowired
private OrderRepository orderRepository;
@Override
public void saveOrder(Order order){
//自动分单逻辑,基于CRM地址库完全匹配,获取定区,匹配快递员
String fixedAreaId = WebClient.create(Constants.CRM_MANAGEMENT_URL+"/services/customerService/findFixedAreaIdByAddress?address="+order.getSendAddress()).accept(MediaType.APPLICATION_JSON).get(String.class);
if(fixedAreaId!=null){
FixedArea fixedArea = fixedAreaRepository.findOne(fixedAreaId);//获取定区
Courier courier = fixedArea.getCouriers().iterator().next();
if(courier!=null){
//自动分单成功
System.out.println("自动分单成功...");
order.setCourier(courier);//将快递员关联到订单上
//保存订单
orderRepository.save(order);
return;
}
}
}
}
标签:String,order,findFixedAreaIdByAddress,下单,address,CRM,public,分单 来源: https://blog.51cto.com/u_7692005/2967061