From 10807b0c6f92196bb9c9502616106180e05842a1 Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Fri, 5 Apr 2019 17:51:37 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E5=8F=91=E8=B4=A7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/AdminsOrderController.java | 21 +++-- .../application/convert/OrderConvertAPP.java | 12 +-- .../convert/OrderDeliveryConvert.java | 20 +++++ .../order/application/po/OrderDeliverPO.java | 89 +++++++++++++++++++ .../mall/order/api/dto/OrderDeliveryDTO.java | 58 ++---------- .../biz/convert/OrderLogisticsConvert.java | 4 + .../mall/order/biz/dao/OrderItemMapper.java | 6 +- .../order/biz/service/OrderServiceImpl.java | 42 ++++++++- .../main/resources/mapper/OrderItemMapper.xml | 77 ++++++++-------- .../resources/mapper/OrderLogisticsMapper.xml | 7 +- .../src/main/resources/mapper/OrderMapper.xml | 10 +-- 11 files changed, 229 insertions(+), 117 deletions(-) create mode 100644 order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderDeliveryConvert.java create mode 100644 order/order-application/src/main/java/cn/iocoder/mall/order/application/po/OrderDeliverPO.java diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminsOrderController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminsOrderController.java index c59199a1e..b5651d3a6 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminsOrderController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminsOrderController.java @@ -7,12 +7,13 @@ import cn.iocoder.mall.order.api.bo.OrderPageBO; import cn.iocoder.mall.order.api.bo.OrderRecipientBO; import cn.iocoder.mall.order.api.dto.*; import cn.iocoder.mall.order.application.convert.OrderConvertAPP; -import cn.iocoder.mall.order.application.vo.OrderItemUpdateVO; -import cn.iocoder.mall.order.application.vo.OrderLogisticsVO; -import cn.iocoder.mall.order.application.vo.OrderPageQueryVO; +import cn.iocoder.mall.order.application.convert.OrderDeliveryConvert; +import cn.iocoder.mall.order.application.po.OrderDeliverPO; +import cn.iocoder.mall.order.application.po.OrderItemUpdatePO; +import cn.iocoder.mall.order.application.po.OrderLogisticsPO; +import cn.iocoder.mall.order.application.po.OrderPageQueryPO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -35,7 +36,7 @@ public class AdminsOrderController { @GetMapping("page") @ApiOperation("订单列表") - public CommonResult getOrderPage(@Validated OrderPageQueryVO orderPageQueryVO) { + public CommonResult getOrderPage(@Validated OrderPageQueryPO orderPageQueryVO) { OrderQueryDTO orderQueryDTO = OrderConvertAPP.INSTANCE.convertPageBO(orderPageQueryVO); return orderService.getOrderPage(orderQueryDTO); } @@ -52,6 +53,12 @@ public class AdminsOrderController { return orderService.getOrderRecipientBO(orderId); } + @PostMapping("order_deliver") + @ApiOperation("订单发货") + public CommonResult orderDeliver(@RequestBody @Validated OrderDeliverPO orderDeliverPO) { + return orderService.orderDelivery(OrderDeliveryConvert.INSTANCE.convert(orderDeliverPO)); + } + @PutMapping("update_remark") @ApiOperation("更新-更新订单备注") public CommonResult updateRemark(@RequestParam("orderId") Integer orderId, @@ -78,14 +85,14 @@ public class AdminsOrderController { @PutMapping("order_item/update") @ApiOperation("更新-订单item") - public CommonResult updateOrderItem(@RequestBody @Validated OrderItemUpdateVO orderItemUpdateVO) { + public CommonResult updateOrderItem(@RequestBody @Validated OrderItemUpdatePO orderItemUpdateVO) { OrderItemUpdateDTO dto = OrderConvertAPP.INSTANCE.convertPageBO(orderItemUpdateVO); return orderService.updateOrderItem(dto); } @PutMapping("logistics/update") @ApiOperation("更新-订单物流") - public CommonResult updateLogistics(@RequestBody @Validated OrderLogisticsVO orderLogisticsVO) { + public CommonResult updateLogistics(@RequestBody @Validated OrderLogisticsPO orderLogisticsVO) { OrderLogisticsUpdateDTO dto = OrderConvertAPP.INSTANCE.convertPageBO(orderLogisticsVO); return orderService.updateLogistics(dto); } diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderConvertAPP.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderConvertAPP.java index e089fdd1e..99d1f1a9f 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderConvertAPP.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderConvertAPP.java @@ -3,9 +3,9 @@ package cn.iocoder.mall.order.application.convert; import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; import cn.iocoder.mall.order.api.dto.OrderLogisticsUpdateDTO; import cn.iocoder.mall.order.api.dto.OrderQueryDTO; -import cn.iocoder.mall.order.application.vo.OrderItemUpdateVO; -import cn.iocoder.mall.order.application.vo.OrderLogisticsVO; -import cn.iocoder.mall.order.application.vo.OrderPageQueryVO; +import cn.iocoder.mall.order.application.po.OrderItemUpdatePO; +import cn.iocoder.mall.order.application.po.OrderPageQueryPO; +import cn.iocoder.mall.order.application.po.OrderLogisticsPO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -24,11 +24,11 @@ public interface OrderConvertAPP { OrderConvertAPP INSTANCE = Mappers.getMapper(OrderConvertAPP.class); @Mappings({}) - OrderQueryDTO convertPageBO(OrderPageQueryVO orderPageQueryVO); + OrderQueryDTO convertPageBO(OrderPageQueryPO orderPageQueryVO); @Mappings({}) - OrderLogisticsUpdateDTO convertPageBO(OrderLogisticsVO orderLogisticsVO); + OrderLogisticsUpdateDTO convertPageBO(OrderLogisticsPO orderLogisticsVO); @Mappings({}) - OrderItemUpdateDTO convertPageBO(OrderItemUpdateVO orderItemUpdateVO); + OrderItemUpdateDTO convertPageBO(OrderItemUpdatePO orderItemUpdateVO); } diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderDeliveryConvert.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderDeliveryConvert.java new file mode 100644 index 000000000..4e16cfeda --- /dev/null +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderDeliveryConvert.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.order.application.convert; + +import cn.iocoder.mall.order.api.dto.OrderDeliveryDTO; +import cn.iocoder.mall.order.application.po.OrderDeliverPO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Sin + * @time 2019-04-05 17:00 + */ +@Mapper +public interface OrderDeliveryConvert { + + OrderDeliveryConvert INSTANCE = Mappers.getMapper(OrderDeliveryConvert.class); + + @Mappings({}) + OrderDeliveryDTO convert(OrderDeliverPO orderDeliverPO); +} diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/OrderDeliverPO.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/OrderDeliverPO.java new file mode 100644 index 000000000..0faa04fb6 --- /dev/null +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/OrderDeliverPO.java @@ -0,0 +1,89 @@ +package cn.iocoder.mall.order.application.po; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * 订单发货 + * + * @author Sin + * @time 2019-04-05 16:55 + */ +@ApiModel(description = "订单发货PO") +public class OrderDeliverPO implements Serializable { + + /** + * 订单编号 + */ + @ApiModelProperty("订单id") + @NotNull(message = "orderId不能为空") + private Integer orderId; + /** + * 物流 (字典) + */ + @ApiModelProperty("物流商家") + @NotNull(message = "必须选择商家") + private Integer logistics; + /** + * 物流编号 + */ + @ApiModelProperty("物流单号") + @NotNull(message = "没有物流单号") + private String logisticsNo; + /** + * 订单 items + */ + @ApiModelProperty("订单items") + @NotNull(message = "没有选择发货的商品") + private List orderItemIds; + + @Override + public String toString() { + return "OrderDeliverPO{" + + "orderId=" + orderId + + ", logistics=" + logistics + + ", logisticsNo='" + logisticsNo + '\'' + + ", orderItemIds=" + orderItemIds + + '}'; + } + + public Integer getOrderId() { + return orderId; + } + + public OrderDeliverPO setOrderId(Integer orderId) { + this.orderId = orderId; + return this; + } + + public Integer getLogistics() { + return logistics; + } + + public OrderDeliverPO setLogistics(Integer logistics) { + this.logistics = logistics; + return this; + } + + public String getLogisticsNo() { + return logisticsNo; + } + + public OrderDeliverPO setLogisticsNo(String logisticsNo) { + this.logisticsNo = logisticsNo; + return this; + } + + public List getOrderItemIds() { + return orderItemIds; + } + + public OrderDeliverPO setOrderItemIds(List orderItemIds) { + this.orderItemIds = orderItemIds; + return this; + } +} 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 index 7b1b59cf3..f5dea8eeb 100644 --- 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 @@ -12,21 +12,9 @@ import java.util.List; public class OrderDeliveryDTO implements Serializable { /** - * 收件区域编号 + * 订单id */ - private String areaNo; - /** - * 收件人名称 - */ - private String name; - /** - * 收件手机号 - */ - private String mobile; - /** - * 收件详细地址 - */ - private String address; + private Integer orderId; /** * 物流 (字典) */ @@ -46,50 +34,20 @@ public class OrderDeliveryDTO implements Serializable { @Override public String toString() { - return "OrderDeliverGoodsDTO{" + - "areaNo='" + areaNo + '\'' + - ", name='" + name + '\'' + - ", mobile='" + mobile + '\'' + - ", address='" + address + '\'' + + return "OrderDeliveryDTO{" + + "orderId=" + orderId + ", logistics=" + logistics + ", logisticsNo='" + logisticsNo + '\'' + ", orderItemIds=" + orderItemIds + '}'; } - public String getAreaNo() { - return areaNo; + public Integer getOrderId() { + return orderId; } - 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; + public OrderDeliveryDTO setOrderId(Integer orderId) { + this.orderId = orderId; return this; } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsConvert.java index a06a5af59..6eddea2e8 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsConvert.java @@ -5,6 +5,7 @@ import cn.iocoder.mall.order.api.dto.OrderCreateDTO; import cn.iocoder.mall.order.api.dto.OrderDeliveryDTO; import cn.iocoder.mall.order.api.dto.OrderLogisticsUpdateDTO; import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDO; +import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -28,6 +29,9 @@ public interface OrderLogisticsConvert { @Mappings({}) OrderLogisticsDO convert(OrderLogisticsUpdateDTO orderLogisticsDTO); + @Mappings({}) + OrderLogisticsDO convert(OrderRecipientDO orderRecipientDO); + @Mappings({}) List convertOrderLogisticsBO(List orderLogisticsDOList); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java index e5b3321d4..6a44b1840 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java @@ -29,7 +29,7 @@ public interface OrderItemMapper { * * @param orderItemDO */ - void updateById(OrderItemDO orderItemDO); + void updateById(@Param("orderItemDO") OrderItemDO orderItemDO); /** * 更新 - 根据 orderId @@ -45,7 +45,7 @@ public interface OrderItemMapper { */ void updateByIds( @Param("ids") List ids, - OrderItemDO orderItemDO + @Param("orderItemDO") OrderItemDO orderItemDO ); /** @@ -54,7 +54,7 @@ public interface OrderItemMapper { * @param ids * @return */ - List selectByIds(Collection ids); + List selectByIds(@Param("ids") Collection ids); /** * 查询 - 根据 orderIds 和 status 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 5d320185f..26bfbaed3 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 @@ -295,21 +295,55 @@ public class OrderServiceImpl implements OrderService { @Transactional public CommonResult orderDelivery(OrderDeliveryDTO orderDelivery) { List orderItemIds = orderDelivery.getOrderItemIds(); - List orderItemDOList = orderItemMapper.selectByIds(orderItemIds); - if (orderItemDOList.size() != orderItemIds.size()) { + + // 获取所有订单 items + List allOrderItems = orderItemMapper + .selectByOrderIdAndDeleted(orderDelivery.getOrderId(), DeletedStatusEnum.DELETED_NO.getValue()); + + // 当前需要发货订单,检查 id 和 status + List needDeliveryOrderItems = allOrderItems.stream() + .filter(orderItemDO -> orderItemIds.contains(orderItemDO.getId()) + && OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus()) + .collect(Collectors.toList()); + + List deliveredOrderItems = allOrderItems.stream() + .filter(orderItemDO -> OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus()) + .collect(Collectors.toList()); + + // 发货订单,检查 + if (needDeliveryOrderItems.size() != orderItemIds.size()) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_DELIVERY_INCORRECT_DATA.getCode()); } + OrderRecipientDO orderRecipientDO = orderRecipientMapper.selectByOrderId(orderDelivery.getOrderId()); + OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderRecipientDO); + // 保存物流信息 - OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderDelivery); orderLogisticsDO + .setLogisticsNo(orderDelivery.getLogisticsNo()) + .setLogistics(orderDelivery.getLogistics()) .setCreateTime(new Date()) .setUpdateTime(null); orderLogisticsMapper.insert(orderLogisticsDO); // 关联订单item 和 物流信息 - orderItemMapper.updateByIds(orderItemIds, new OrderItemDO().setOrderLogisticsId(orderLogisticsDO.getId())); + orderItemMapper.updateByIds( + orderItemIds, + new OrderItemDO() + .setOrderLogisticsId(orderLogisticsDO.getId()) + .setStatus(OrderStatusEnum.ALREADY_SHIPMENT.getValue()) + ); + + // 子订单是否全部发货,如果发完,就更新 order + if (deliveredOrderItems.size() <= 0) { + orderMapper.updateById( + new OrderDO() + .setId(orderDelivery.getOrderId()) + .setStatus(OrderStatusEnum.ALREADY_SHIPMENT.getValue()) + ); + } + return CommonResult.success(null); } diff --git a/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml index fe369cfb1..d6ada983d 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml @@ -29,61 +29,64 @@ --> - - , order_id = #{orderId} + + , order_id = #{orderItemDO.orderId} - - , order_no = #{orderNo} + + , order_no = #{orderItemDO.orderNo} - - , sku_id = #{skuId} + + , order_logistics_id = #{orderItemDO.orderLogisticsId} - - , sku_name = #{skuName} + + , sku_id = #{orderItemDO.skuId} - - , sku_image = #{skuImage} + + , sku_name = #{orderItemDO.skuName} - - , quantity = #{quantity} + + , sku_image = #{orderItemDO.skuImage} - - , price = #{price} + + , quantity = #{orderItemDO.quantity} - - , pay_amount = #{payAmount} + + , price = #{orderItemDO.price} + + + , pay_amount = #{orderItemDO.payAmount} - - , payment_time = #{paymentTime} + + , payment_time = #{orderItemDO.paymentTime} - - , delivery_time = #{deliveryTime} + + , delivery_time = #{orderItemDO.deliveryTime} - - , receiver_time = #{receiverTime} + + , receiver_time = #{orderItemDO.receiverTime} - - , closing_time = #{closingTime} + + , closing_time = #{orderItemDO.closingTime} - - , has_return_exchange = #{hasReturnExchange} + + , has_return_exchange = #{orderItemDO.hasReturnExchange} - - , status = #{status} + + , status = #{orderItemDO.status} - - , delivery_type = #{deliveryType} + + , delivery_type = #{orderItemDO.deliveryType} - - , `deleted` = #{deleted} + + , `deleted` = #{orderItemDO.deleted} - - , create_time = #{createTime} + + , create_time = #{orderItemDO.createTime} - - , update_time = #{updateTime} + + , update_time = #{orderItemDO.updateTime} @@ -94,7 +97,7 @@ UPDATE `order_item` - WHERE id = #{id} + WHERE id = #{orderItemDO.id} INSERT INTO `order_logistics` ( - area_no, `name`, mobile, address, logistics_no, create_time, update_time + area_no, `name`, mobile, address, logistics, logistics_no, create_time, update_time ) VALUES ( #{areaNo}, #{name}, #{mobile}, #{address}, - #{logisticsNo}, #{createTime}, #{updateTime} + #{logistics}, #{logisticsNo}, #{createTime}, #{updateTime} ) @@ -35,6 +35,9 @@ , address = #{address} + + , logistics = #{logistics} + , logistics_no = #{logisticsNo} diff --git a/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml index 03eb79168..ee68a4915 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml @@ -14,12 +14,12 @@ --> INSERT INTO `order` ( - user_id, order_logistics_id, order_no, price, payment_time, + user_id, order_no, price, payment_time, delivery_time, receiver_time, closing_time, has_return_exchange, status, remark, create_time, update_time, `deleted` ) VALUES ( - #{orderLogisticsId}, #{userId}, #{orderNo}, #{price}, #{paymentTime}, + #{userId}, #{orderNo}, #{price}, #{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime}, #{hasReturnExchange}, #{status}, #{remark}, #{createTime}, #{updateTime}, #{deleted} @@ -31,9 +31,6 @@ --> - - , order_logistics_id = #{orderLogisticsId} - , order_no = #{orderNo} @@ -110,9 +107,6 @@ AND `order_no` = #{orderNo} - - AND `order_logistics_id` = #{orderLogisticsId} - AND `has_return_exchange` = #{hasReturnExchange}