diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java index 046d84c77..e3075366f 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java @@ -56,6 +56,14 @@ public interface OrderService { */ CommonResult cancelOrder(Integer orderId, Integer reasons, String otherReasons); + /** + * 订单发货 + * + * @param orderDelivery + * @return + */ + CommonResult orderDelivery(OrderDeliveryDTO orderDelivery); + /** * 更新订单 - 备注 * diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderBO.java index 4b2d3a8d6..b483ab3b5 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderBO.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderBO.java @@ -90,7 +90,7 @@ public class OrderBO implements Serializable { /** * 订单物流信息 */ - private OrderLogisticsBO orderLogistics; + private OrderRecipientBO orderRecipient; @Override public String toString() { @@ -108,7 +108,7 @@ public class OrderBO implements Serializable { ", status=" + status + ", remark='" + remark + '\'' + ", orderItems=" + orderItems + - ", orderLogistics=" + orderLogistics + + ", orderRecipient=" + orderRecipient + '}'; } @@ -229,12 +229,12 @@ public class OrderBO implements Serializable { return this; } - public OrderLogisticsBO getOrderLogistics() { - return orderLogistics; + public OrderRecipientBO getOrderRecipient() { + return orderRecipient; } - public OrderBO setOrderLogistics(OrderLogisticsBO orderLogistics) { - this.orderLogistics = orderLogistics; + public OrderBO setOrderRecipient(OrderRecipientBO orderRecipient) { + this.orderRecipient = orderRecipient; return this; } } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderRecipientBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderRecipientBO.java new file mode 100644 index 000000000..eb0a6ba4c --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderRecipientBO.java @@ -0,0 +1,103 @@ +package cn.iocoder.mall.order.api.bo; + +import cn.iocoder.common.framework.dataobject.BaseDO; + +/** + * 订单收件人信息 order_recipient + * + * @author Sin + * @time 2019-03-31 11:37 + */ +public class OrderRecipientBO extends BaseDO { + + /** + * 编号 + */ + private Integer id; + /** + * 订单id + */ + private Integer orderId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + + @Override + public String toString() { + return "OrderRecipientBO{" + + "id=" + id + + ", orderId=" + orderId + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public Integer getId() { + return id; + } + + public OrderRecipientBO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getOrderId() { + return orderId; + } + + public OrderRecipientBO setOrderId(Integer orderId) { + this.orderId = orderId; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public OrderRecipientBO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public OrderRecipientBO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public OrderRecipientBO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public OrderRecipientBO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/LogisticsEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/LogisticsEnum.java new file mode 100644 index 000000000..d9b7332aa --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/LogisticsEnum.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.order.api.constant; + +/** + * 物流信息 + * + * @author Sin + * @time 2019-03-30 22:33 + */ +public enum LogisticsEnum { + + LOGISTICS_1(1, "顺丰快递"), + LOGISTICS_2(2, "圆通快递"), + LOGISTICS_3(3, "申通快递"), + LOGISTICS_4(4, "韵答快递"), + LOGISTICS_5(5, "天天快递"), + LOGISTICS_6(6, "EMS中国邮政"), + + ; + + /** + * 状态值 + */ + private Integer value; + /** + * 状态名 + */ + private String name; + + LogisticsEnum(int value, String name) { + this.value = value; + this.name = name; + } + + public int getValue() { + return value; + } + + public String getName() { + return name; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderDeliveryDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderDeliveryDTO.java new file mode 100644 index 000000000..7b1b59cf3 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderDeliveryDTO.java @@ -0,0 +1,122 @@ +package cn.iocoder.mall.order.api.dto; + +import java.io.Serializable; +import java.util.List; + +/** + * 订单发货 + * + * @author Sin + * @time 2019-03-30 22:31 + */ +public class OrderDeliveryDTO implements Serializable { + + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 物流 (字典) + */ + private Integer logistics; + /** + * 物流编号 + */ + private String logisticsNo; + + /// + /// 物理信息是跟 orderItem 走 + + /** + * 订单 orderItemId + */ + private List orderItemIds; + + @Override + public String toString() { + return "OrderDeliverGoodsDTO{" + + "areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + ", logistics=" + logistics + + ", logisticsNo='" + logisticsNo + '\'' + + ", orderItemIds=" + orderItemIds + + '}'; + } + + public String getAreaNo() { + return areaNo; + } + + public OrderDeliveryDTO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public OrderDeliveryDTO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public OrderDeliveryDTO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public OrderDeliveryDTO setAddress(String address) { + this.address = address; + return this; + } + + public Integer getLogistics() { + return logistics; + } + + public OrderDeliveryDTO setLogistics(Integer logistics) { + this.logistics = logistics; + return this; + } + + public String getLogisticsNo() { + return logisticsNo; + } + + public OrderDeliveryDTO setLogisticsNo(String logisticsNo) { + this.logisticsNo = logisticsNo; + return this; + } + + public List getOrderItemIds() { + return orderItemIds; + } + + public OrderDeliveryDTO setOrderItemIds(List orderItemIds) { + this.orderItemIds = orderItemIds; + return this; + } +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java new file mode 100644 index 000000000..8a40c914a --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.order.biz.convert; + +import cn.iocoder.mall.order.api.bo.OrderRecipientBO; +import cn.iocoder.mall.order.api.dto.OrderCreateDTO; +import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 订单收件人信息 + * + * @author Sin + * @time 2019-03-31 12:50 + */ +@Mapper +public interface OrderRecipientConvert { + + OrderRecipientConvert INSTANCE = Mappers.getMapper(OrderRecipientConvert.class); + + @Mappings({}) + OrderRecipientDO convert(OrderCreateDTO orderCreateDTO); + + @Mappings({}) + List convert(List orderRecipientDOList); +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderRecipientMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderRecipientMapper.java new file mode 100644 index 000000000..a529013ce --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderRecipientMapper.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.order.biz.dao; + +import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.List; + +/** + * 订单收件人 信息 + * + * @author Sin + * @time 2019-03-31 12:16 + */ +@Repository +public interface OrderRecipientMapper { + + /** + * 插入 - 订单收件人 + * + * @param orderRecipient + * @return + */ + int insert(OrderRecipientDO orderRecipient); + + /** + * 查询 - 根据 orderIds + * + * @param orderIds + * @return + */ + List selectByOrderIds( + @Param("orderIds")Collection orderIds + ); +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderRecipientDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderRecipientDO.java new file mode 100644 index 000000000..27d27ada2 --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderRecipientDO.java @@ -0,0 +1,103 @@ +package cn.iocoder.mall.order.biz.dataobject; + +import cn.iocoder.common.framework.dataobject.BaseDO; + +/** + * 订单收件人信息 order_recipient + * + * @author Sin + * @time 2019-03-31 11:37 + */ +public class OrderRecipientDO extends BaseDO { + + /** + * 编号 + */ + private Integer id; + /** + * 订单id + */ + private Integer orderId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + + @Override + public String toString() { + return "OrderRecipientDO{" + + "id=" + id + + ", orderId=" + orderId + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public Integer getId() { + return id; + } + + public OrderRecipientDO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getOrderId() { + return orderId; + } + + public OrderRecipientDO setOrderId(Integer orderId) { + this.orderId = orderId; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public OrderRecipientDO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public OrderRecipientDO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public OrderRecipientDO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public OrderRecipientDO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java index d7e6f3ed9..909b3471e 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java @@ -13,14 +13,9 @@ import cn.iocoder.mall.order.biz.OrderCommon; import cn.iocoder.mall.order.biz.convert.OrderConvert; import cn.iocoder.mall.order.biz.convert.OrderItemConvert; import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert; -import cn.iocoder.mall.order.biz.dao.OrderCancelMapper; -import cn.iocoder.mall.order.biz.dao.OrderItemMapper; -import cn.iocoder.mall.order.biz.dao.OrderLogisticsMapper; -import cn.iocoder.mall.order.biz.dao.OrderMapper; -import cn.iocoder.mall.order.biz.dataobject.OrderCancelDO; -import cn.iocoder.mall.order.biz.dataobject.OrderDO; -import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; -import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDO; +import cn.iocoder.mall.order.biz.convert.OrderRecipientConvert; +import cn.iocoder.mall.order.biz.dao.*; +import cn.iocoder.mall.order.biz.dataobject.*; import com.google.common.collect.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -47,6 +42,8 @@ public class OrderServiceImpl implements OrderService { @Autowired private OrderLogisticsMapper orderLogisticsMapper; @Autowired + private OrderRecipientMapper orderRecipientMapper; + @Autowired private OrderCancelMapper orderCancelMapper; @Autowired private OrderCommon orderCommon; @@ -67,16 +64,11 @@ public class OrderServiceImpl implements OrderService { .map(orderDO -> orderDO.getId()) .collect(Collectors.toSet()); - Set orderLogisticsIds = orderDOList.stream() - .map(orderDO -> orderDO.getOrderLogisticsId()) - .collect(Collectors.toSet()); - // 获取物流信息 - List orderLogisticsDOList = orderLogisticsMapper.selectByIds(orderLogisticsIds); - List orderLogisticsBOList - = OrderLogisticsConvert.INSTANCE.convertOrderLogisticsBO(orderLogisticsDOList); - Map orderLogisticsDOMap - = orderLogisticsBOList.stream().collect(Collectors.toMap(OrderLogisticsBO::getId, obj -> obj)); + List orderRecipientDOList = orderRecipientMapper.selectByOrderIds(orderIds); + List orderRecipientBOList = OrderRecipientConvert.INSTANCE.convert(orderRecipientDOList); + Map orderRecipientBOMap + = orderRecipientBOList.stream().collect(Collectors.toMap(OrderRecipientBO::getOrderId, obj -> obj)); // 获取 订单的 items List orderItemDOList = orderItemMapper @@ -100,8 +92,8 @@ public class OrderServiceImpl implements OrderService { if (orderItemBOMultimap.containsKey(orderBO.getId())) { orderBO.setOrderItems(orderItemBOMultimap.get(orderBO.getId())); } - if (orderLogisticsDOMap.containsKey(orderBO.getOrderLogisticsId())) { - orderBO.setOrderLogistics(orderLogisticsDOMap.get(orderBO.getOrderLogisticsId())); + if (orderRecipientBOMap.containsKey(orderBO.getId())) { + orderBO.setOrderRecipient(orderRecipientBOMap.get(orderBO.getId())); } return orderBO; }).collect(Collectors.toList()); @@ -117,7 +109,7 @@ public class OrderServiceImpl implements OrderService { @Transactional public CommonResult createOrder(Integer userId, OrderCreateDTO orderCreateDTO) { List orderItemDTOList = orderCreateDTO.getOrderItems(); - OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderCreateDTO); + OrderRecipientDO orderRecipientDO = OrderRecipientConvert.INSTANCE.convert(orderCreateDTO); List orderItemDOList = OrderItemConvert.INSTANCE.convert(orderItemDTOList); // TODO: 2019-03-24 sin 校验商品是否存在 @@ -137,17 +129,10 @@ public class OrderServiceImpl implements OrderService { // orderItemDO.setPrice(1000); // } - // 物流信息 - orderLogisticsDO - .setLogisticsNo("") - .setCreateTime(new Date()) - .setUpdateTime(null); - orderLogisticsMapper.insert(orderLogisticsDO); - // order OrderDO orderDO = new OrderDO() .setUserId(userId) - .setOrderLogisticsId(orderLogisticsDO.getId()) + .setOrderLogisticsId(null) .setOrderNo(UUID.randomUUID().toString().replace("-", "")) .setPayAmount(-1) // 先设置一个默认值,金额在下面计算 .setClosingTime(null) @@ -162,6 +147,14 @@ public class OrderServiceImpl implements OrderService { orderDO.setUpdateTime(null); orderMapper.insert(orderDO); + // 收件人信息 + orderRecipientDO + .setOrderId(orderDO.getId()) + .setCreateTime(new Date()) + .setUpdateTime(null); + + orderRecipientMapper.insert(orderRecipientDO); + // order item orderItemDOList.forEach(orderItemDO -> { int goodsPrice = 1000; // 商品单价 @@ -271,6 +264,11 @@ public class OrderServiceImpl implements OrderService { return CommonResult.success(null); } + @Override + public CommonResult orderDelivery(OrderDeliveryDTO orderDelivery) { + return null; + } + @Override public CommonResult updateOrderRemake(Integer orderId, String remake) { // 此处不做订单校验,直接设置备注即可 diff --git a/order/order-service-impl/src/main/resources/mapper/OrderRecipientMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderRecipientMapper.xml new file mode 100644 index 000000000..b2d9f675b --- /dev/null +++ b/order/order-service-impl/src/main/resources/mapper/OrderRecipientMapper.xml @@ -0,0 +1,35 @@ + + + + + + id, order_id, `area_no`, `name`, mobile, address, + create_time, update_time + + + + + INSERT INTO `order_recipient` ( + order_id, `area_no`, `name`, mobile, address, + create_time, update_time + ) VALUES ( + #{orderId}, #{areaNo}, #{name}, #{mobile}, #{address}, + #{createTime}, #{updateTime} + ) + + + + +