From 13c89a34b2b57bfcf7aad32c940a12a2cfab76e5 Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Sat, 23 Mar 2019 14:53:08 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=20userId=20=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=20=E8=AE=A2=E5=8D=95=20-=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E8=AE=A2=E5=8D=95=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iocoder/mall/order/api/OrderService.java | 18 +- .../mall/order/api/dto/OrderCreateDTO.java | 16 +- .../mall/order/api/dto/OrderPageBO.java | 248 ++++++++++++++++++ .../mall/order/api/dto/OrderQueryDTO.java | 152 +++++++++++ order/order-service-impl/pom.xml | 6 + .../mall/order/convert/OrderConvert.java | 42 +-- .../mall/order/convert/OrderItemConvert.java | 26 ++ .../order/convert/OrderLogisticsConvert.java | 24 ++ .../iocoder/mall/order/dao/OrderMapper.java | 30 +++ .../mall/order/dataobject/OrderDO.java | 16 +- .../mall/order/service/OrderServiceImpl.java | 58 ++-- .../src/main/resources/mapper/OrderMapper.xml | 67 ++++- .../order/service/OrderServiceImplTest.java | 19 +- 13 files changed, 646 insertions(+), 76 deletions(-) create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderPageBO.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderQueryDTO.java create mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderItemConvert.java create mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderLogisticsConvert.java 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 bb390dc75..6a6d0d541 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 @@ -2,10 +2,9 @@ package cn.iocoder.mall.order.api; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.bo.OrderBO; -import cn.iocoder.mall.order.api.dto.OrderCreateDTO; -import cn.iocoder.mall.order.api.dto.OrderItemDeletedDTO; -import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO; -import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; +import cn.iocoder.mall.order.api.dto.*; + +import java.util.List; /** * 订单 service @@ -15,13 +14,22 @@ import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; */ public interface OrderService { + /** + * 订单 page + * + * @param orderQueryDTO + * @return + */ + CommonResult> getOrderPage(OrderQueryDTO orderQueryDTO); + /** * 订单 - 创建 * + * @param userId * @param orderCreateDTO * @return */ - CommonResult createOrder(OrderCreateDTO orderCreateDTO); + CommonResult createOrder(Integer userId, OrderCreateDTO orderCreateDTO); /** * 订单item - 更新 diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java index 60916a31b..42a175f2f 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java @@ -13,6 +13,10 @@ import java.util.List; */ public class OrderCreateDTO implements Serializable { + /** + * 用户id + */ + private Integer userId; /** * 收件区域编号 */ @@ -48,7 +52,8 @@ public class OrderCreateDTO implements Serializable { @Override public String toString() { return "OrderCreateDTO{" + - "areaNo='" + areaNo + '\'' + + "userId=" + userId + + ", areaNo='" + areaNo + '\'' + ", name='" + name + '\'' + ", mobile='" + mobile + '\'' + ", address='" + address + '\'' + @@ -57,6 +62,15 @@ public class OrderCreateDTO implements Serializable { '}'; } + public Integer getUserId() { + return userId; + } + + public OrderCreateDTO setUserId(Integer userId) { + this.userId = userId; + return this; + } + public String getAreaNo() { return areaNo; } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderPageBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderPageBO.java new file mode 100644 index 000000000..e28ad4938 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderPageBO.java @@ -0,0 +1,248 @@ +package cn.iocoder.mall.order.api.dto; + +import java.io.Serializable; +import java.util.Date; + +/** + * 订单 page + * + * @author Sin + * @time 2019-03-23 14:30 + */ +public class OrderPageBO implements Serializable { + /** + * id + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 物流id + */ + private Integer orderLogisticsId; + /** + * 订单编号 + */ + private String orderNo; + /** + * 交易金额 + */ + private Integer money; + + /// + /// 时间信息 + + /** + * 付款时间(待发货) + */ + private Date paymentTime; + /** + * 发货时间(待收货) + */ + private Date deliveryTime; + /** + * 收货时间(已签收) + */ + private Date receiverTime; + /** + * 成交时间(用户确认收货 -> status = 已完成) + */ + private Date closingTime; + + /// + /// 其他 + + /** + * 是否退货 + * + * - 0、没有 + * - 1、换货 + * - 2、退货 + * - 3、换货 + 退货 + */ + private Integer hasReturnExchange; + /** + * 状态(如果有多个商品分开发货需要全部商品发完才会改变状态) + * + * - 0、待付款 + * - 1、待发货 + * - 2、待收获 + * - 3、已完成 + * - 4、已关闭 + */ + private Integer status; + /** + * 备注 + */ + private String remark; + /** + * 创建时间 + */ + private Date createTime; + /** + * 更新时间 + */ + private Date updateTime; + /** + * 删除 + */ + private Integer deleted; + + @Override + public String toString() { + return "OrderPageBO{" + + "id=" + id + + ", userId=" + userId + + ", orderLogisticsId=" + orderLogisticsId + + ", orderNo='" + orderNo + '\'' + + ", money=" + money + + ", paymentTime=" + paymentTime + + ", deliveryTime=" + deliveryTime + + ", receiverTime=" + receiverTime + + ", closingTime=" + closingTime + + ", hasReturnExchange=" + hasReturnExchange + + ", status=" + status + + ", remark='" + remark + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", deleted=" + deleted + + '}'; + } + + public Integer getId() { + return id; + } + + public OrderPageBO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getUserId() { + return userId; + } + + public OrderPageBO setUserId(Integer userId) { + this.userId = userId; + return this; + } + + public Integer getOrderLogisticsId() { + return orderLogisticsId; + } + + public OrderPageBO setOrderLogisticsId(Integer orderLogisticsId) { + this.orderLogisticsId = orderLogisticsId; + return this; + } + + public String getOrderNo() { + return orderNo; + } + + public OrderPageBO setOrderNo(String orderNo) { + this.orderNo = orderNo; + return this; + } + + public Integer getMoney() { + return money; + } + + public OrderPageBO setMoney(Integer money) { + this.money = money; + return this; + } + + public Date getPaymentTime() { + return paymentTime; + } + + public OrderPageBO setPaymentTime(Date paymentTime) { + this.paymentTime = paymentTime; + return this; + } + + public Date getDeliveryTime() { + return deliveryTime; + } + + public OrderPageBO setDeliveryTime(Date deliveryTime) { + this.deliveryTime = deliveryTime; + return this; + } + + public Date getReceiverTime() { + return receiverTime; + } + + public OrderPageBO setReceiverTime(Date receiverTime) { + this.receiverTime = receiverTime; + return this; + } + + public Date getClosingTime() { + return closingTime; + } + + public OrderPageBO setClosingTime(Date closingTime) { + this.closingTime = closingTime; + return this; + } + + public Integer getHasReturnExchange() { + return hasReturnExchange; + } + + public OrderPageBO setHasReturnExchange(Integer hasReturnExchange) { + this.hasReturnExchange = hasReturnExchange; + return this; + } + + public Integer getStatus() { + return status; + } + + public OrderPageBO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getRemark() { + return remark; + } + + public OrderPageBO setRemark(String remark) { + this.remark = remark; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public OrderPageBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + + public Date getUpdateTime() { + return updateTime; + } + + public OrderPageBO setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + return this; + } + + public Integer getDeleted() { + return deleted; + } + + public OrderPageBO setDeleted(Integer deleted) { + this.deleted = deleted; + return this; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderQueryDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderQueryDTO.java new file mode 100644 index 000000000..79a723545 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderQueryDTO.java @@ -0,0 +1,152 @@ +package cn.iocoder.mall.order.api.dto; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +/** + * 订单 query + * + * @author Sin + * @time 2019-03-23 14:15 + */ +public class OrderQueryDTO implements Serializable { + + /** + * id + */ + private Integer id; + /** + * 订单号 + */ + private String orderNo; + /** + * 用户 id + */ + private Integer userId; + /** + * 付款时间(待发货) + */ + private Date startPaymentTime; + private Date endPaymentTime; + /** + * 创建时间 + */ + private Date startCreateTime; + private Date endCreateTime; + /** + * 删除状态 + */ + private Integer deleted; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + + @Override + public String toString() { + return "OrderQueryDTO{" + + "id=" + id + + ", orderNo='" + orderNo + '\'' + + ", userId=" + userId + + ", startPaymentTime=" + startPaymentTime + + ", endPaymentTime=" + endPaymentTime + + ", startCreateTime=" + startCreateTime + + ", endCreateTime=" + endCreateTime + + ", deleted=" + deleted + + ", pageNo=" + pageNo + + ", pageSize=" + pageSize + + '}'; + } + + public Integer getId() { + return id; + } + + public OrderQueryDTO setId(Integer id) { + this.id = id; + return this; + } + + public String getOrderNo() { + return orderNo; + } + + public OrderQueryDTO setOrderNo(String orderNo) { + this.orderNo = orderNo; + return this; + } + + public Integer getUserId() { + return userId; + } + + public OrderQueryDTO setUserId(Integer userId) { + this.userId = userId; + return this; + } + + public Date getStartPaymentTime() { + return startPaymentTime; + } + + public OrderQueryDTO setStartPaymentTime(Date startPaymentTime) { + this.startPaymentTime = startPaymentTime; + return this; + } + + public Date getEndPaymentTime() { + return endPaymentTime; + } + + public OrderQueryDTO setEndPaymentTime(Date endPaymentTime) { + this.endPaymentTime = endPaymentTime; + return this; + } + + public Date getStartCreateTime() { + return startCreateTime; + } + + public OrderQueryDTO setStartCreateTime(Date startCreateTime) { + this.startCreateTime = startCreateTime; + return this; + } + + public Date getEndCreateTime() { + return endCreateTime; + } + + public OrderQueryDTO setEndCreateTime(Date endCreateTime) { + this.endCreateTime = endCreateTime; + return this; + } + + public Integer getDeleted() { + return deleted; + } + + public OrderQueryDTO setDeleted(Integer deleted) { + this.deleted = deleted; + return this; + } + + public Integer getPageNo() { + return pageNo; + } + + public OrderQueryDTO setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public OrderQueryDTO setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } +} diff --git a/order/order-service-impl/pom.xml b/order/order-service-impl/pom.xml index 371573cb7..e7c08a32e 100644 --- a/order/order-service-impl/pom.xml +++ b/order/order-service-impl/pom.xml @@ -84,6 +84,12 @@ spring-boot-starter-test test + + cn.iocoder.mall + user-sdk + 1.0-SNAPSHOT + compile + diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java index d41c585a2..de3de2b33 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java @@ -1,12 +1,7 @@ package cn.iocoder.mall.order.convert; -import cn.iocoder.mall.order.api.dto.OrderCreateDTO; -import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; -import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; -import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO; +import cn.iocoder.mall.order.api.dto.OrderPageBO; import cn.iocoder.mall.order.dataobject.OrderDO; -import cn.iocoder.mall.order.dataobject.OrderItemDO; -import cn.iocoder.mall.order.dataobject.OrderLogisticsDO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -24,39 +19,6 @@ public interface OrderConvert { OrderConvert INSTANCE = Mappers.getMapper(OrderConvert.class); - /** - * 转换 OrderLogisticsDO - OrderCreateDTO - * - * @param orderCreateDTO - * @return - */ @Mappings({}) - OrderLogisticsDO convert(OrderCreateDTO orderCreateDTO); - - /** - * 转换 OrderItemDO - orderCreateItemDTOList - * - * @param orderCreateItemDTOList - * @return - */ - @Mappings({}) - List convert(List orderCreateItemDTOList); - - /** - * 转换 OrderLogisticsDO - orderReceiverInformationDTO - * - * @param orderLogisticsDTO - * @return - */ - @Mappings({}) - OrderLogisticsDO convert(OrderLogisticsDTO orderLogisticsDTO); - - /** - * 转换 OrderItemDO - orderReceiverInformationDTO - * - * @param orderItemUpdateDTO - * @return - */ - @Mappings({}) - OrderItemDO convert(OrderItemUpdateDTO orderItemUpdateDTO); + List convertPageBO(List orderDOList); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderItemConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderItemConvert.java new file mode 100644 index 000000000..493873651 --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderItemConvert.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.order.convert; + +import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; +import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; +import cn.iocoder.mall.order.dataobject.OrderItemDO; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 订单 item convert + * + * @author Sin + * @time 2019-03-23 14:34 + */ +public interface OrderItemConvert { + + OrderItemConvert INSTANCE = Mappers.getMapper(OrderItemConvert.class); + + @Mappings({}) + OrderItemDO convert(OrderItemUpdateDTO orderItemUpdateDTO); + + @Mappings({}) + List convert(List orderCreateItemDTOList); +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderLogisticsConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderLogisticsConvert.java new file mode 100644 index 000000000..52c61afed --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderLogisticsConvert.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.order.convert; + +import cn.iocoder.mall.order.api.dto.OrderCreateDTO; +import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO; +import cn.iocoder.mall.order.dataobject.OrderLogisticsDO; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * 订单物流 convert + * + * @author Sin + * @time 2019-03-23 14:39 + */ +public interface OrderLogisticsConvert { + + OrderLogisticsConvert INSTANCE = Mappers.getMapper(OrderLogisticsConvert.class); + + @Mappings({}) + OrderLogisticsDO convert(OrderCreateDTO orderCreateDTO); + + @Mappings({}) + OrderLogisticsDO convert(OrderLogisticsDTO orderLogisticsDTO); +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderMapper.java index 207e76627..d98d28875 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderMapper.java @@ -1,8 +1,12 @@ package cn.iocoder.mall.order.dao; +import cn.iocoder.mall.order.api.dto.OrderQueryDTO; import cn.iocoder.mall.order.dataobject.OrderDO; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.List; + /** * 订单 mapper * @@ -26,4 +30,30 @@ public interface OrderMapper { * @return */ int updateById(OrderDO orderDO); + + /** + * 查询 - 根据id 查询 + * + * @param id + * @return + */ + OrderDO selectById( + @Param("id") Integer id + ); + + /** + * 查询 - 后台分页page + * + * @param orderQueryDTO + * @return + */ + int selectPageCount(OrderQueryDTO orderQueryDTO); + + /** + * 查询 - 后台分页page + * + * @param orderQueryDTO + * @return + */ + List selectPage(OrderQueryDTO orderQueryDTO, int offset, int pageSize); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java index 9bf4e173f..4b5bf3a6f 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java @@ -16,6 +16,10 @@ public class OrderDO extends DeletableDO { * id */ private Integer id; + /** + * 用户编号 + */ + private Integer userId; /** * 物流id */ @@ -80,9 +84,10 @@ public class OrderDO extends DeletableDO { public String toString() { return "OrderDO{" + "id=" + id + + ", userId=" + userId + ", orderLogisticsId=" + orderLogisticsId + ", orderNo='" + orderNo + '\'' + - ", price=" + money + + ", money=" + money + ", paymentTime=" + paymentTime + ", deliveryTime=" + deliveryTime + ", receiverTime=" + receiverTime + @@ -102,6 +107,15 @@ public class OrderDO extends DeletableDO { return this; } + public Integer getUserId() { + return userId; + } + + public OrderDO setUserId(Integer userId) { + this.userId = userId; + return this; + } + public Integer getOrderLogisticsId() { return orderLogisticsId; } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java index 95c4a826b..8ed2db5f8 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java @@ -11,21 +11,21 @@ import cn.iocoder.mall.order.api.constant.OrderHasReturnExchangeEnum; import cn.iocoder.mall.order.api.constant.OrderStatusEnum; import cn.iocoder.mall.order.api.dto.*; import cn.iocoder.mall.order.convert.OrderConvert; +import cn.iocoder.mall.order.convert.OrderItemConvert; +import cn.iocoder.mall.order.convert.OrderLogisticsConvert; import cn.iocoder.mall.order.dao.OrderItemMapper; import cn.iocoder.mall.order.dao.OrderLogisticsMapper; import cn.iocoder.mall.order.dao.OrderMapper; import cn.iocoder.mall.order.dataobject.OrderDO; import cn.iocoder.mall.order.dataobject.OrderItemDO; import cn.iocoder.mall.order.dataobject.OrderLogisticsDO; +import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.util.Date; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; /** @@ -47,12 +47,28 @@ public class OrderServiceImpl implements OrderService { @Autowired private OrderCommon orderCommon; + @Override + public CommonResult> getOrderPage(OrderQueryDTO orderQueryDTO) { + + int offset = orderQueryDTO.getPageNo() * orderQueryDTO.getPageSize(); + int pageSize = orderQueryDTO.getPageSize(); + + int totalCount = orderMapper.selectPageCount(orderQueryDTO); + if (totalCount == 0) { + return CommonResult.success(Collections.EMPTY_LIST); + } + + List orderDOList = orderMapper.selectPage(orderQueryDTO, offset, pageSize); + List orderPageBOList = OrderConvert.INSTANCE.convertPageBO(orderDOList); + return CommonResult.success(orderPageBOList); + } + @Override @Transactional - public CommonResult createOrder(OrderCreateDTO orderCreateDTO) { + public CommonResult createOrder(Integer userId, OrderCreateDTO orderCreateDTO) { List orderItemDTOList = orderCreateDTO.getOrderItems(); - OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderCreateDTO); - List orderItemDOList = OrderConvert.INSTANCE.convert(orderItemDTOList); + OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderCreateDTO); + List orderItemDOList = OrderItemConvert.INSTANCE.convert(orderItemDTOList); // 物流信息 orderLogisticsDO @@ -62,21 +78,21 @@ public class OrderServiceImpl implements OrderService { orderLogisticsMapper.insert(orderLogisticsDO); // order - OrderDO orderDO = new OrderDO(); - orderDO.setOrderLogisticsId(orderLogisticsDO.getId()); - orderDO.setOrderNo(UUID.randomUUID().toString().replace("-", "")); - orderDO.setMoney(-1); // 先设置一个默认值,金额在下面计算 - - orderDO.setClosingTime(null); - orderDO.setDeliveryTime(null); - orderDO.setPaymentTime(null); - orderDO.setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue()); - orderDO.setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue()); - orderDO.setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse("")); + OrderDO orderDO = new OrderDO() + .setUserId(userId) + .setOrderLogisticsId(orderLogisticsDO.getId()) + .setOrderNo(UUID.randomUUID().toString().replace("-", "")) + .setMoney(-1) // 先设置一个默认值,金额在下面计算 + .setClosingTime(null) + .setDeliveryTime(null) + .setPaymentTime(null) + .setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue()) + .setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue()) + .setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse("")); + orderDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); orderDO.setCreateTime(new Date()); orderDO.setUpdateTime(null); - orderDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); orderMapper.insert(orderDO); // order item @@ -119,7 +135,7 @@ public class OrderServiceImpl implements OrderService { @Override public CommonResult updateOrderItem(OrderItemUpdateDTO orderUpdateDTO) { - OrderItemDO orderItemDO = OrderConvert.INSTANCE.convert(orderUpdateDTO); + OrderItemDO orderItemDO = OrderItemConvert.INSTANCE.convert(orderUpdateDTO); orderItemMapper.updateById(orderItemDO); return CommonResult.success(null); } @@ -161,7 +177,7 @@ public class OrderServiceImpl implements OrderService { @Override public CommonResult updateLogistics(OrderLogisticsDTO orderLogisticsDTO) { - OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderLogisticsDTO); + OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderLogisticsDTO); orderLogisticsMapper.updateById(orderLogisticsDO); return CommonResult.success(null); } 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 0a00bd9d1..2f6655162 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml @@ -3,9 +3,9 @@ - id, order_logistics_id, order_no, money, payment_time, + id, user_id, order_logistics_id, order_no, money, payment_time, delivery_time, receiver_time, closing_time, has_return_exchange, - status, remark, create_time, update_time, `delete` + status, remark, create_time, update_time, `deleted` INSERT INTO `order` ( - order_logistics_id, order_no, money, payment_time, + user_id, order_logistics_id, order_no, money, payment_time, delivery_time, receiver_time, closing_time, has_return_exchange, status, remark, create_time, update_time, `deleted` ) VALUES ( - #{orderLogisticsId}, #{orderNo}, #{money}, #{paymentTime}, + #{orderLogisticsId}, #{userId}, #{orderNo}, #{money}, #{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime}, #{hasReturnExchange}, #{status}, #{remark}, #{createTime}, #{updateTime}, #{deleted} @@ -82,4 +82,63 @@ WHERE id = #{id} + + + + + + + + AND `id` = #{id} + + + AND `user_id` = #{userId} + + + AND `order_logistics_id` = #{orderLogisticsId} + + + AND `order_no` = #{orderNo} + + + AND `has_return_exchange` = #{hasReturnExchange} + + + AND `status` = #{status} + + + + + + + + + + \ No newline at end of file diff --git a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java index e97789c20..09db66885 100644 --- a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java +++ b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java @@ -1,14 +1,19 @@ package cn.iocoder.mall.order.service; +import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.OrderApplicationTest; import cn.iocoder.mall.order.api.OrderService; +import cn.iocoder.mall.order.api.bo.OrderBO; import cn.iocoder.mall.order.api.dto.OrderCreateDTO; import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; +import cn.iocoder.mall.order.dao.OrderMapper; +import cn.iocoder.mall.order.dataobject.OrderDO; +import org.checkerframework.checker.units.qual.A; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; @@ -22,22 +27,25 @@ import java.util.Arrays; */ @RunWith(SpringRunner.class) @SpringBootTest(classes = OrderApplicationTest.class) -//@Transactional +@Transactional public class OrderServiceImplTest { @Autowired private OrderService orderService; @Autowired - private Environment environment; + private OrderMapper orderMapper; @Test public void createOrderTest() { + + Integer userId = 1; OrderCreateItemDTO orderCreateItemDTO = new OrderCreateItemDTO() .setSkuId(1) .setQuantity(1); - orderService.createOrder( + CommonResult result = orderService.createOrder( + userId, new OrderCreateDTO() .setRemark("") .setName("张三") @@ -45,5 +53,8 @@ public class OrderServiceImplTest { .setAddress("深圳市福田区") .setAreaNo("1000100") .setOrderItems(Arrays.asList(orderCreateItemDTO))); + + OrderDO orderDO = orderMapper.selectById(result.getData().getId()); + Assert.assertNotNull("创建的订单不存在!", orderDO); } }