✅P278_商城业务-订单服务-构造订单数据
大约 1 分钟
订单创建To
cfmall-order/src/main/java/com/gyz/cfmall/order/to/OrderCreateTo.java
@Data
public class OrderCreateTo {
private OrderEntity order;
private List<OrderItemEntity> orderItems;
/**
* 订单计算的应付价格
*/
private BigDecimal payPrice;
/**
* 运费
*/
private BigDecimal fare;
}
订单创建方法
订单状态枚举类
cfmall-order/src/main/java/com/gyz/cfmall/order/enume/OrderStatusEnum.java
package com.gyz.cfmall.order.enume;
public enum OrderStatusEnum {
CREATE_NEW(0, "待付款"),
PAYED(1, "已付款"),
SENDED(2, "已发货"),
RECIEVED(3, "已完成"),
CANCLED(4, "已取消"),
SERVICING(5, "售后中"),
SERVICED(6, "售后完成");
private Integer code;
private String msg;
OrderStatusEnum(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
AddrAndFareVo
@Data
public class AddrAndFareVo {
private MemberAddressVo memberAddressVo;
private String fare;
}
远程查询收货地址和运费
cfmall-order/src/main/java/com/gyz/cfmall/order/feign/WmsFeignService.java
@FeignClient("cfmall-ware")
public interface WmsFeignService {
/**
* 查询运费和收货地址信息
*
* @param addrId
* @return
*/
@GetMapping(value = "/ware/wareinfo/fare")
R getFare(@RequestParam("addrId") Long addrId);
}
创建订单
cfmall-order/src/main/java/com/gyz/cfmall/order/service/impl/OrderServiceImpl.java
private ThreadLocal<OrderSubmitVo> submitVoThreadLocal = new ThreadLocal<>();
private OrderCreateTo createOrder() {
OrderCreateTo createTo = new OrderCreateTo();
OrderEntity orderEntity = this.builderOrder();
return createTo;
}
private OrderEntity builderOrder() {
OrderEntity orderEntity = new OrderEntity();
String orderSn = IdWorker.getTimeId();
orderEntity.setOrderSn(orderSn);
OrderSubmitVo orderSubmitVo = submitVoThreadLocal.get();
Long addrId = orderSubmitVo.getAddrId();
R r = wmsFeignService.getFare(addrId);
AddrAndFareVo addrAndFareVo = r.getData("data", new TypeReference<AddrAndFareVo>() {
});
//订单相关信息
orderEntity.setFreightAmount(new BigDecimal(addrAndFareVo.getFare()));
orderEntity.setReceiverName(addrAndFareVo.getMemberAddressVo().getName());
orderEntity.setReceiverProvince(addrAndFareVo.getMemberAddressVo().getProvince());
orderEntity.setReceiverCity(addrAndFareVo.getMemberAddressVo().getCity());
orderEntity.setReceiverDetailAddress(addrAndFareVo.getMemberAddressVo().getDetailAddress());
orderEntity.setReceiverPostCode(addrAndFareVo.getMemberAddressVo().getPostCode());
orderEntity.setReceiverPhone(addrAndFareVo.getMemberAddressVo().getPhone());
orderEntity.setReceiverRegion(addrAndFareVo.getMemberAddressVo().getRegion());
return orderEntity;
}