From bcae55bc59cc812e98b98fa2c2009ea138d6daaa Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Sat, 23 Mar 2019 12:14:49 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=20item=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20-=20=E6=B7=BB=E5=8A=A0=20item=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20-=20=E6=B7=BB=E5=8A=A0=20=E9=94=99=E8=AF=AF=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=20-=20=E6=B7=BB=E5=8A=A0=20order=20common?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- order/order-service-api/pom.xml | 6 + .../iocoder/mall/order/api/OrderService.java | 35 +++-- .../cn/iocoder/mall/order/api/bo/OrderBO.java | 14 +- .../order/api/constant/ErrorCodeInterval.java | 17 +++ .../api/constant/OrderErrorCodeEnum.java | 32 +++++ .../order/api/dto/OrderCreateItemDTO.java | 6 +- .../order/api/dto/OrderItemDeletedDTO.java | 46 ++++++ .../order/api/dto/OrderItemUpdateDTO.java | 80 +++++++++++ .../mall/order/api/dto/OrderLogisticsDTO.java | 113 +++++++++++++++ .../api/dto/OrderReceiverInformationDTO.java | 99 ------------- .../mall/order/api/dto/OrderUpdateDTO.java | 16 --- .../cn/iocoder/mall/order/OrderCommon.java | 22 +++ .../iocoder/mall/order/OrderCommonImpl.java | 30 ++++ .../mall/order/convert/OrderConvert.java | 20 ++- .../mall/order/dao/OrderItemMapper.java | 33 +++++ .../mall/order/dao/OrderLogisticsMapper.java | 7 + .../mall/order/dataobject/OrderDO.java | 12 +- .../mall/order/dataobject/OrderItemDO.java | 6 +- .../mall/order/service/OrderServiceImpl.java | 133 ++++++++++++------ .../main/resources/mapper/OrderItemMapper.xml | 104 +++++++++++++- .../resources/mapper/OrderLogisticsMapper.xml | 35 ++++- .../src/main/resources/mapper/OrderMapper.xml | 32 +++-- .../order/service/OrderServiceImplTest.java | 5 +- 23 files changed, 681 insertions(+), 222 deletions(-) create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/ErrorCodeInterval.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemDeletedDTO.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemUpdateDTO.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderLogisticsDTO.java delete mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderReceiverInformationDTO.java delete mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderUpdateDTO.java create mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommon.java create mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommonImpl.java diff --git a/order/order-service-api/pom.xml b/order/order-service-api/pom.xml index 239cd3496..25a2d6266 100644 --- a/order/order-service-api/pom.xml +++ b/order/order-service-api/pom.xml @@ -16,5 +16,11 @@ javax.validation validation-api + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + compile + \ No newline at end of file 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 adb385add..bb390dc75 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 @@ -1,9 +1,11 @@ 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.OrderReceiverInformationDTO; -import cn.iocoder.mall.order.api.dto.OrderUpdateDTO; +import cn.iocoder.mall.order.api.dto.OrderItemDeletedDTO; +import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO; +import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; /** * 订单 service @@ -14,19 +16,28 @@ import cn.iocoder.mall.order.api.dto.OrderUpdateDTO; public interface OrderService { /** - * 订单创建 + * 订单 - 创建 * * @param orderCreateDTO * @return */ - OrderBO createOrder(OrderCreateDTO orderCreateDTO); + CommonResult createOrder(OrderCreateDTO orderCreateDTO); /** - * 订单更新 + * 订单item - 更新 + * + * @param orderItemUpdateDTO * - * @param orderUpdateDTO */ - void updateOrder(OrderUpdateDTO orderUpdateDTO); + CommonResult updateOrderItem(OrderItemUpdateDTO orderItemUpdateDTO); + + /** + * 订单item - 删除 + * + * @param orderItemDeletedDTO + * @return + */ + CommonResult deleteOrderItem(OrderItemDeletedDTO orderItemDeletedDTO); /** * 更新订单 - 收件这信息 @@ -37,33 +48,33 @@ public interface OrderService { * - 联系人电话 * - 联系人姓名 */ - void updateOrderReceiverInformation(OrderReceiverInformationDTO orderReceiverInfoDTO); + CommonResult updateLogistics(OrderLogisticsDTO orderLogisticsDTO); /** * 删除订单 * * @param id */ - void deleteOrder(Integer id); + CommonResult deleteOrder(Integer id); /** * 监听支付动作 * * mq 更新 payStatus */ - void listenerPayment(); + CommonResult listenerPayment(); /** * 监听确认收货 * * mq 更新 status */ - void listenerConfirmGoods(); + CommonResult listenerConfirmGoods(); /** * 监听换货 * * mq 更新 status */ - void listenerExchangeGoods(); + CommonResult listenerExchangeGoods(); } 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 75a8d97c9..15a2d6a2f 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 @@ -19,16 +19,16 @@ public class OrderBO implements Serializable { */ private String orderNo; /** - * 交易金额 + * 订单金额 */ - private Integer price; + private Integer money; @Override public String toString() { return "OrderBO{" + "id=" + id + ", orderNo='" + orderNo + '\'' + - ", price=" + price + + ", money=" + money + '}'; } @@ -50,12 +50,12 @@ public class OrderBO implements Serializable { return this; } - public Integer getPrice() { - return price; + public Integer getMoney() { + return money; } - public OrderBO setPrice(Integer price) { - this.price = price; + public OrderBO setMoney(Integer money) { + this.money = money; return this; } } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/ErrorCodeInterval.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/ErrorCodeInterval.java new file mode 100644 index 000000000..139ac7a02 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/ErrorCodeInterval.java @@ -0,0 +1,17 @@ +package cn.iocoder.mall.order.api.constant; + +import cn.iocoder.common.framework.constant.ModuleErrorCodeInterval; + +/** + * 错误码区间 + * + * 当前模块化区间:[1-000-001-000 ~ 1-000-002-000] + * + * @author Sin + * @time 2019-03-23 11:35 + */ +public class ErrorCodeInterval extends ModuleErrorCodeInterval { + + // OrderErrorCodeEnum 错误码区间 [1-000-001-000 ~ 1-000-001-100] + +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java new file mode 100644 index 000000000..36f60f6f0 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.order.api.constant; + +/** + * 订单错误码 + * + * 错误码区间 [1-000-001-000 ~ 1-000-002-000] + * + * @author Sin + * @time 2019-03-23 11:23 + */ +public enum OrderErrorCodeEnum { + + ORDER_ITEM_ONLY_ONE(1000001000, "订单Item只有一个"), + ; + + private final int code; + private final String message; + + OrderErrorCodeEnum(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } + +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java index da9323dbd..06f1be11f 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java @@ -13,7 +13,7 @@ public class OrderCreateItemDTO { * 商品编号 */ @NotNull - private String skuId; + private Integer skuId; /** * 数量 */ @@ -29,11 +29,11 @@ public class OrderCreateItemDTO { '}'; } - public String getSkuId() { + public Integer getSkuId() { return skuId; } - public OrderCreateItemDTO setSkuId(String skuId) { + public OrderCreateItemDTO setSkuId(Integer skuId) { this.skuId = skuId; return this; } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemDeletedDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemDeletedDTO.java new file mode 100644 index 000000000..b1409cebb --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemDeletedDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.order.api.dto; + +import java.io.Serializable; +import java.util.List; + +/** + * @author Sin + * @time 2019-03-23 10:22 + */ +public class OrderItemDeletedDTO implements Serializable { + + /** + * 订单id + */ + private Integer orderId; + /** + * 订单item id + */ + private List orderItemIds; + + @Override + public String toString() { + return "OrderItemDeletedDTO{" + + "orderId=" + orderId + + ", orderItemIds=" + orderItemIds + + '}'; + } + + public Integer getOrderId() { + return orderId; + } + + public OrderItemDeletedDTO setOrderId(Integer orderId) { + this.orderId = orderId; + return this; + } + + public List getOrderItemIds() { + return orderItemIds; + } + + public OrderItemDeletedDTO setOrderItemIds(List orderItemIds) { + this.orderItemIds = orderItemIds; + return this; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemUpdateDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemUpdateDTO.java new file mode 100644 index 000000000..40480207f --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderItemUpdateDTO.java @@ -0,0 +1,80 @@ +package cn.iocoder.mall.order.api.dto; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 订单更新 + * + * @author Sin + * @time 2019-03-16 14:46 + */ +public class OrderItemUpdateDTO implements Serializable { + + /** + * 编号 + */ + @NotNull + private Integer id; + /** + * 商品编号 + */ + @NotNull + private Integer skuId; + /** + * 数量 + */ + @NotNull + private Integer quantity; + /** + * 金额(分) + */ + @NotNull + private Integer price; + + @Override + public String toString() { + return "OrderItemUpdateDTO{" + + "id=" + id + + ", skuId=" + skuId + + ", quantity=" + quantity + + ", price=" + price + + '}'; + } + + public Integer getId() { + return id; + } + + public OrderItemUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getSkuId() { + return skuId; + } + + public OrderItemUpdateDTO setSkuId(Integer skuId) { + this.skuId = skuId; + return this; + } + + public Integer getQuantity() { + return quantity; + } + + public OrderItemUpdateDTO setQuantity(Integer quantity) { + this.quantity = quantity; + return this; + } + + public Integer getPrice() { + return price; + } + + public OrderItemUpdateDTO setPrice(Integer price) { + this.price = price; + return this; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderLogisticsDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderLogisticsDTO.java new file mode 100644 index 000000000..cdc5b28f5 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderLogisticsDTO.java @@ -0,0 +1,113 @@ +package cn.iocoder.mall.order.api.dto; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * 订单收件人信息 + * + * @author Sin + * @time 2019-03-17 20:22 + */ +public class OrderLogisticsDTO implements Serializable { + + /** + * 订单 id + */ + private Integer id; + /** + * 收件区域编号 + */ + @NotNull + private String areaNo; + /** + * 收件人名称 + */ + @NotNull + private String name; + /** + * 收件手机号 + */ + @NotNull + @Size(max = 11, min = 11) + // TODO: 2019-03-17 Sin 此处需要添加 手机号校验,需要添加新的注解 + private String mobile; + /** + * 收件详细地址 + */ + @NotNull + @Size(max = 250, min = 10, message = "收件地址应该在 10 ~ 250 个字符之间") + private String address; + /** + * 物流编号 + */ + @NotNull + private String logisticsNo; + + @Override + public String toString() { + return "OrderLogisticsDTO{" + + "id=" + id + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + ", logisticsNo='" + logisticsNo + '\'' + + '}'; + } + + public Integer getId() { + return id; + } + + public OrderLogisticsDTO setId(Integer id) { + this.id = id; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public OrderLogisticsDTO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public OrderLogisticsDTO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public OrderLogisticsDTO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public OrderLogisticsDTO setAddress(String address) { + this.address = address; + return this; + } + + public String getLogisticsNo() { + return logisticsNo; + } + + public OrderLogisticsDTO setLogisticsNo(String logisticsNo) { + this.logisticsNo = logisticsNo; + return this; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderReceiverInformationDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderReceiverInformationDTO.java deleted file mode 100644 index bcf5091a9..000000000 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderReceiverInformationDTO.java +++ /dev/null @@ -1,99 +0,0 @@ -package cn.iocoder.mall.order.api.dto; - -import javax.validation.constraints.Max; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.io.Serializable; - -/** - * 订单收件人信息 - * - * @author Sin - * @time 2019-03-17 20:22 - */ -public class OrderReceiverInformationDTO implements Serializable { - - /** - * 订单 id - */ - private Integer id; - /** - * 收件区域编号 - */ - @NotNull - private String receiverAreaNo; - /** - * 收件人名称 - */ - @NotNull - private String receiverName; - /** - * 收件手机号 - */ - @NotNull - @Size(max = 11, min = 11) - // TODO: 2019-03-17 Sin 此处需要添加 手机号校验,需要添加新的注解 - private String receiverMobile; - /** - * 收件详细地址 - */ - @NotNull - @Size(max = 250, min = 10, message = "收件地址应该在 10 ~ 250 个字符之间") - private String receiverAddress; - - @Override - public String toString() { - return "OrderReceiverInformationDTO{" + - "id=" + id + - ", receiverAreaNo='" + receiverAreaNo + '\'' + - ", receiverName='" + receiverName + '\'' + - ", receiverMobile='" + receiverMobile + '\'' + - ", receiverAddress='" + receiverAddress + '\'' + - '}'; - } - - public Integer getId() { - return id; - } - - public OrderReceiverInformationDTO setId(Integer id) { - this.id = id; - return this; - } - - public String getReceiverAreaNo() { - return receiverAreaNo; - } - - public OrderReceiverInformationDTO setReceiverAreaNo(String receiverAreaNo) { - this.receiverAreaNo = receiverAreaNo; - return this; - } - - public String getReceiverName() { - return receiverName; - } - - public OrderReceiverInformationDTO setReceiverName(String receiverName) { - this.receiverName = receiverName; - return this; - } - - public String getReceiverMobile() { - return receiverMobile; - } - - public OrderReceiverInformationDTO setReceiverMobile(String receiverMobile) { - this.receiverMobile = receiverMobile; - return this; - } - - public String getReceiverAddress() { - return receiverAddress; - } - - public OrderReceiverInformationDTO setReceiverAddress(String receiverAddress) { - this.receiverAddress = receiverAddress; - return this; - } -} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderUpdateDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderUpdateDTO.java deleted file mode 100644 index 9ccf7a7ba..000000000 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderUpdateDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.mall.order.api.dto; - -import java.io.Serializable; - -/** - * 订单更新 - * - * @author Sin - * @time 2019-03-16 14:46 - */ -public class OrderUpdateDTO implements Serializable { - - - - -} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommon.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommon.java new file mode 100644 index 000000000..9a732857f --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommon.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.order; + +import cn.iocoder.mall.order.dataobject.OrderItemDO; + +import java.util.List; + +/** + * 订单常用 + * + * @author Sin + * @time 2019-03-23 11:51 + */ +public interface OrderCommon { + + /** + * 计算订单金额 + * + * @param items + * @return + */ + Integer calculatedAmount(List items); +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommonImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommonImpl.java new file mode 100644 index 000000000..eeaac3c9d --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/OrderCommonImpl.java @@ -0,0 +1,30 @@ +package cn.iocoder.mall.order; + +import cn.iocoder.mall.order.dataobject.OrderItemDO; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 订单常用 + * + * @author Sin + * @time 2019-03-23 11:53 + */ +@Component +public class OrderCommonImpl implements OrderCommon { + + @Override + public Integer calculatedAmount(List items) { + if (CollectionUtils.isEmpty(items)) { + return 0; + } + AtomicInteger totalAmount = new AtomicInteger(0); + items.forEach(orderItemDO -> { + totalAmount.addAndGet(orderItemDO.getPrice() * orderItemDO.getQuantity()); + }); + return totalAmount.get(); + } +} 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 916a39dbc..d41c585a2 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 @@ -2,7 +2,8 @@ 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.OrderReceiverInformationDTO; +import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; +import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO; import cn.iocoder.mall.order.dataobject.OrderDO; import cn.iocoder.mall.order.dataobject.OrderItemDO; import cn.iocoder.mall.order.dataobject.OrderLogisticsDO; @@ -24,7 +25,7 @@ public interface OrderConvert { OrderConvert INSTANCE = Mappers.getMapper(OrderConvert.class); /** - * 转换 OrderDO - OrderCreateDTO + * 转换 OrderLogisticsDO - OrderCreateDTO * * @param orderCreateDTO * @return @@ -42,11 +43,20 @@ public interface OrderConvert { List convert(List orderCreateItemDTOList); /** - * 转换 OrderDO - orderReceiverInformationDTO + * 转换 OrderLogisticsDO - orderReceiverInformationDTO * - * @param orderReceiverInformationDTO + * @param orderLogisticsDTO * @return */ @Mappings({}) - OrderDO convert(OrderReceiverInformationDTO orderReceiverInformationDTO); + OrderLogisticsDO convert(OrderLogisticsDTO orderLogisticsDTO); + + /** + * 转换 OrderItemDO - orderReceiverInformationDTO + * + * @param orderItemUpdateDTO + * @return + */ + @Mappings({}) + OrderItemDO convert(OrderItemUpdateDTO orderItemUpdateDTO); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderItemMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderItemMapper.java index f53ac33b7..29bca50e3 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderItemMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderItemMapper.java @@ -1,8 +1,12 @@ package cn.iocoder.mall.order.dao; import cn.iocoder.mall.order.dataobject.OrderItemDO; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import javax.validation.constraints.NotNull; +import java.util.List; + /** * 订单 item mapper * @@ -18,4 +22,33 @@ public interface OrderItemMapper { * @param orderItemDO */ void insert(OrderItemDO orderItemDO); + + /** + * 更新 - 根据Id + * + * @param orderItemDO + */ + void updateById(OrderItemDO orderItemDO); + + /** + * 更新 - 根据Ids + * + * @param ids + * @param orderItemDO + */ + void updateByIds( + @Param("ids") List ids, + OrderItemDO orderItemDO + ); + + /** + * 查询 - 根据 orderId 下的 item + * + * @param orderId + * @return + */ + List selectByOrderIdAndDeleted( + @Param("orderId") Integer orderId, + @Param("deleted") @NotNull Integer deleted + ); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderLogisticsMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderLogisticsMapper.java index dd1737824..12237e161 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderLogisticsMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dao/OrderLogisticsMapper.java @@ -18,4 +18,11 @@ public interface OrderLogisticsMapper { * @param orderLogisticsDO */ void insert(OrderLogisticsDO orderLogisticsDO); + + /** + * 更新 - 根据id + * + * @param orderLogisticsDO + */ + void updateById(OrderLogisticsDO orderLogisticsDO); } 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 3928738dd..9bf4e173f 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 @@ -27,7 +27,7 @@ public class OrderDO extends DeletableDO { /** * 交易金额 */ - private Integer price; + private Integer money; /// /// 时间信息 @@ -82,7 +82,7 @@ public class OrderDO extends DeletableDO { "id=" + id + ", orderLogisticsId=" + orderLogisticsId + ", orderNo='" + orderNo + '\'' + - ", price=" + price + + ", price=" + money + ", paymentTime=" + paymentTime + ", deliveryTime=" + deliveryTime + ", receiverTime=" + receiverTime + @@ -120,12 +120,12 @@ public class OrderDO extends DeletableDO { return this; } - public Integer getPrice() { - return price; + public Integer getMoney() { + return money; } - public OrderDO setPrice(Integer price) { - this.price = price; + public OrderDO setMoney(Integer money) { + this.money = money; return this; } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java index d39a97651..38a5e374f 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java @@ -27,7 +27,7 @@ public class OrderItemDO extends DeletableDO { /** * 商品编号 */ - private String skuId; + private Integer skuId; /** * 数量 */ @@ -125,11 +125,11 @@ public class OrderItemDO extends DeletableDO { return this; } - public String getSkuId() { + public Integer getSkuId() { return skuId; } - public OrderItemDO setSkuId(String skuId) { + public OrderItemDO setSkuId(Integer skuId) { this.skuId = skuId; return this; } 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 0df86cf79..95c4a826b 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 @@ -1,14 +1,15 @@ package cn.iocoder.mall.order.service; -import cn.iocoder.common.framework.constant.DeleteStatusEnum; +import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.order.OrderCommon; import cn.iocoder.mall.order.api.OrderService; import cn.iocoder.mall.order.api.bo.OrderBO; +import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.constant.OrderHasReturnExchangeEnum; import cn.iocoder.mall.order.api.constant.OrderStatusEnum; -import cn.iocoder.mall.order.api.dto.OrderCreateDTO; -import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; -import cn.iocoder.mall.order.api.dto.OrderReceiverInformationDTO; -import cn.iocoder.mall.order.api.dto.OrderUpdateDTO; +import cn.iocoder.mall.order.api.dto.*; import cn.iocoder.mall.order.convert.OrderConvert; import cn.iocoder.mall.order.dao.OrderItemMapper; import cn.iocoder.mall.order.dao.OrderLogisticsMapper; @@ -19,12 +20,13 @@ import cn.iocoder.mall.order.dataobject.OrderLogisticsDO; 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.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; /** * 订单 service impl @@ -42,10 +44,12 @@ public class OrderServiceImpl implements OrderService { private OrderItemMapper orderItemMapper; @Autowired private OrderLogisticsMapper orderLogisticsMapper; + @Autowired + private OrderCommon orderCommon; @Override @Transactional - public OrderBO createOrder(OrderCreateDTO orderCreateDTO) { + public CommonResult createOrder(OrderCreateDTO orderCreateDTO) { List orderItemDTOList = orderCreateDTO.getOrderItems(); OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderCreateDTO); List orderItemDOList = OrderConvert.INSTANCE.convert(orderItemDTOList); @@ -61,10 +65,7 @@ public class OrderServiceImpl implements OrderService { OrderDO orderDO = new OrderDO(); orderDO.setOrderLogisticsId(orderLogisticsDO.getId()); orderDO.setOrderNo(UUID.randomUUID().toString().replace("-", "")); - orderDO.setPrice(-1); // 先设置一个默认值,金额在下面计算 - orderDO.setCreateTime(new Date()); - orderDO.setUpdateTime(null); - orderDO.setDeleted(DeleteStatusEnum.DELETE_NO.getValue()); + orderDO.setMoney(-1); // 先设置一个默认值,金额在下面计算 orderDO.setClosingTime(null); orderDO.setDeliveryTime(null); @@ -72,14 +73,15 @@ public class OrderServiceImpl implements OrderService { orderDO.setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue()); orderDO.setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue()); orderDO.setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse("")); + + orderDO.setCreateTime(new Date()); + orderDO.setUpdateTime(null); + orderDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); orderMapper.insert(orderDO); // order item - AtomicInteger totalPrice = new AtomicInteger(); orderItemDOList.forEach(orderItemDO -> { int goodsPrice = 1000; // 商品单价 - int price = orderItemDO.getQuantity() * goodsPrice; - totalPrice.addAndGet(price); orderItemDO .setOrderId(orderDO.getId()) .setOrderNo(orderDO.getOrderNo()) @@ -90,61 +92,102 @@ public class OrderServiceImpl implements OrderService { .setClosingTime(null) .setHasReturnExchange(OrderStatusEnum.WAITING_PAYMENT.getValue()) .setStatus(OrderStatusEnum.WAITING_PAYMENT.getValue()) - .setDeleted(DeleteStatusEnum.DELETE_NO.getValue()) + .setDeleted(DeletedStatusEnum.DELETED_NO.getValue()) .setCreateTime(new Date()) - .setUpdateTime(new Date()); + .setUpdateTime(null); orderItemMapper.insert(orderItemDO); }); // 更新订单金额 + Integer totalAmount = orderCommon.calculatedAmount(orderItemDOList); orderMapper.updateById( new OrderDO() .setId(orderDO.getId()) - .setPrice(totalPrice.get()) + .setMoney(totalAmount) ); // TODO: 2019-03-17 Sin 需要发送 创建成果 MQ 消息 - return new OrderBO() - .setId(orderDO.getId()) - .setOrderNo(orderDO.getOrderNo()) - .setPrice(orderDO.getPrice()); - } - - @Override - public void updateOrder(OrderUpdateDTO orderUpdateDTO) { - - } - - @Override - public void updateOrderReceiverInformation(OrderReceiverInformationDTO orderReceiverInfoDTO) { - // TODO: 2019-03-17 需要做校验 手机号 - OrderDO orderDO = OrderConvert.INSTANCE.convert(orderReceiverInfoDTO); - orderMapper.updateById(orderDO); - } - - @Override - public void deleteOrder(Integer id) { - // 删除订单操作,一般用于 用户端删除,是否存在检查可以过掉 - orderMapper.updateById((OrderDO) new OrderDO() - .setId(id) - .setDeleted(DeleteStatusEnum.DELETE_YES.getValue()) + return CommonResult.success( + new OrderBO() + .setId(orderDO.getId()) + .setOrderNo(orderDO.getOrderNo()) + .setMoney(orderDO.getMoney()) ); } @Override - public void listenerPayment() { - + public CommonResult updateOrderItem(OrderItemUpdateDTO orderUpdateDTO) { + OrderItemDO orderItemDO = OrderConvert.INSTANCE.convert(orderUpdateDTO); + orderItemMapper.updateById(orderItemDO); + return CommonResult.success(null); } @Override - public void listenerConfirmGoods() { + public CommonResult deleteOrderItem(OrderItemDeletedDTO orderItemDeletedDTO) { + Integer orderId = orderItemDeletedDTO.getOrderId(); + List orderItemIds = orderItemDeletedDTO.getOrderItemIds(); + // 获取当前有效的订单 item + List orderItemDOList = orderItemMapper + .selectByOrderIdAndDeleted(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + + List effectiveOrderItems = orderItemDOList.stream() + .filter(orderItemDO -> !orderItemIds.contains(orderItemDO.getId())) + .collect(Collectors.toList()); + + // 检查订单 item,必须要有一个 item + if (CollectionUtils.isEmpty(effectiveOrderItems)) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_ITEM_ONLY_ONE.getCode()); + } + + // 更新订单 item + orderItemMapper.updateByIds( + orderItemIds, + (OrderItemDO) new OrderItemDO() + .setDeleted(DeletedStatusEnum.DELETED_YES.getValue()) + ); + + // 更新订单 amount + Integer totalAmount = orderCommon.calculatedAmount(effectiveOrderItems); + orderMapper.updateById( + new OrderDO() + .setId(orderId) + .setMoney(totalAmount) + ); + return CommonResult.success(null); } @Override - public void listenerExchangeGoods() { + public CommonResult updateLogistics(OrderLogisticsDTO orderLogisticsDTO) { + OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderLogisticsDTO); + orderLogisticsMapper.updateById(orderLogisticsDO); + return CommonResult.success(null); + } + @Override + public CommonResult deleteOrder(Integer id) { + // 删除订单操作,一般用于 用户端删除,是否存在检查可以过掉 + orderMapper.updateById((OrderDO) new OrderDO() + .setId(id) + .setDeleted(DeletedStatusEnum.DELETED_YES.getValue()) + ); + return CommonResult.success(null); + } + + @Override + public CommonResult listenerPayment() { + return null; + } + + @Override + public CommonResult listenerConfirmGoods() { + return null; + } + + @Override + public CommonResult listenerExchangeGoods() { + return 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 4271d7fcb..861e2c32e 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml @@ -3,8 +3,9 @@ - id, order_id, commodity_id, quantity, price, - status, deliveryTime + id, order_id, order_no, sku_id, quantity, price, + payment_time, delivery_time, receiver_time, closing_time, + has_return_exchange, status, create_time, update_time, deleted INSERT INTO `order_item` ( - order_id, commodity_id, quantity, price, - status, deliveryTime + order_id, order_no, sku_id, quantity, price, + payment_time, delivery_time, receiver_time, closing_time, + has_return_exchange, status, create_time, update_time, deleted ) VALUES ( - #{orderId}, #{commodityId}, #{quantity}, #{price}, - #{status}, #{deliveryTime} + #{orderId}, #{orderNo}, #{skuId}, #{quantity}, #{price}, + #{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime}, + #{hasReturnExchange}, #{status}, + #{createTime}, #{updateTime}, #{deleted} ) - \ No newline at end of file + + + + + , order_id = #{orderId} + + + , order_no = #{orderNo} + + + , sku_id = #{skuId} + + + , quantity = #{quantity} + + + , price = #{price} + + -- time + + , payment_time = #{paymentTime} + + + , delivery_time = #{deliveryTime} + + + , receiver_time = #{receiverTime} + + + , closing_time = #{closingTime} + + -- other + + , has_return_exchange = #{hasReturnExchange} + + + , status = #{status} + + + , `deleted` = #{deleted} + + + , create_time = #{createTime} + + + , update_time = #{updateTime} + + + + + + + UPDATE `order_item` + + WHERE id = #{id} + + + + + UPDATE `order_item` + + WHERE id IN + + #{id} + + + + + + diff --git a/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml index ad3bedb80..97f758b4c 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderLogisticsMapper.xml @@ -11,11 +11,42 @@ --> INSERT INTO `order_logistics` ( - area_no, `name`, mobile, address, logistics_no + area_no, `name`, mobile, address, logistics_no, create_time, update_time ) VALUES ( #{areaNo}, #{name}, #{mobile}, #{address}, - #{logisticsNo} + #{logisticsNo}, #{createTime}, #{updateTime} ) + + + + + , area_no = #{areaNo} + + + , `name` = #{name} + + + , mobile = #{mobile} + + + , address = #{address} + + + , logistics_no = #{logisticsNo} + + + + + + + UPDATE `order_logistics` + + WHERE id = #{id} + \ No newline at end of file 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 254e7ec40..0a00bd9d1 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, price, payment_time, + id, order_logistics_id, order_no, money, payment_time, delivery_time, receiver_time, closing_time, has_return_exchange, - status, remark + status, remark, create_time, update_time, `delete` INSERT INTO `order` ( - order_logistics_id, order_no, price, payment_time, + order_logistics_id, order_no, money, payment_time, delivery_time, receiver_time, closing_time, - has_return_exchange, status, remark + has_return_exchange, status, remark, + create_time, update_time, `deleted` ) VALUES ( - #{orderLogisticsId}, ${orderNo}, #{price}, #{paymentTime}, + #{orderLogisticsId}, #{orderNo}, #{money}, #{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime}, - #{hasReturnExchange}, #{status}, #{remark} + #{hasReturnExchange}, #{status}, #{remark}, + #{createTime}, #{updateTime}, #{deleted} ) - + , order_logistics_id = #{orderLogisticsId} @@ -34,8 +36,8 @@ , order_no = #{orderNo} - - , price = #{price} + + , money = #{money} -- time @@ -57,8 +59,11 @@ , status = #{status} - - , `delete` = #{delete} + + , remark = #{remark} + + + , `deleted` = #{deleted} , create_time = #{createTime} @@ -66,9 +71,6 @@ , update_time = #{updateTime} - - , remark = #{remark} - @@ -77,7 +79,7 @@ --> UPDATE `order` - + WHERE id = #{id} \ 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 9c406b2b4..e97789c20 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 @@ -22,7 +22,7 @@ import java.util.Arrays; */ @RunWith(SpringRunner.class) @SpringBootTest(classes = OrderApplicationTest.class) -@Transactional +//@Transactional public class OrderServiceImplTest { @Autowired @@ -34,12 +34,13 @@ public class OrderServiceImplTest { public void createOrderTest() { OrderCreateItemDTO orderCreateItemDTO = new OrderCreateItemDTO() - .setSkuId("CID_001") + .setSkuId(1) .setQuantity(1); orderService.createOrder( new OrderCreateDTO() .setRemark("") + .setName("张三") .setMobile("13301926050") .setAddress("深圳市福田区") .setAreaNo("1000100")