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 97a337e0c..98703be0e 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 @@ -38,7 +38,7 @@ public interface OrderConvertAPP { OrderCreateDTO convert(OrderCreatePO orderCreatePO); @Mappings({}) - List convert(List cartItems); + List convert(List cartItems); default OrderCreateDTO createOrderCreateDTO(Integer userId, Integer userAddressId, String remark, String ip, List cartItems, Integer couponCardId) { diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/user/OrderCreatePO.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/user/OrderCreatePO.java index f88ddf24d..4c193fbc3 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/user/OrderCreatePO.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/po/user/OrderCreatePO.java @@ -1,9 +1,9 @@ package cn.iocoder.mall.order.application.po.user; -import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.Max; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.io.Serializable; @@ -38,6 +38,22 @@ public class OrderCreatePO implements Serializable { @NotNull() @Size(max = 1000, min = 1, message = "用户订单中没有商品!") - private List orderItems; + private List orderItems; + @Data + @Accessors(chain = true) + public static class OrderItem { + + /** + * 商品编号 + */ + @NotNull + private Integer skuId; + /** + * 数量 + */ + @NotNull + @Max(value = 1000) + private Integer quantity; + } } 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 77cf6d4f2..101b39451 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 @@ -3,6 +3,8 @@ package cn.iocoder.mall.order.api.dto; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.Max; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; @@ -40,6 +42,23 @@ public class OrderCreateDTO implements Serializable { /// /// order item - private List orderItems; - + private List orderItems; + + + @Data + @Accessors(chain = true) + public static class OrderItem { + + /** + * 商品编号 + */ + @NotNull + private Integer skuId; + /** + * 数量 + */ + @NotNull + @Max(value = 1000) + private Integer quantity; + } } 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 deleted file mode 100644 index 69ea79808..000000000 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.mall.order.api.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.Max; -import javax.validation.constraints.NotNull; - -/** - * @author Sin - * @time 2019-03-17 09:37 - */ -@Data -@Accessors(chain = true) -public class OrderCreateItemDTO { - - /** - * 商品编号 - */ - @NotNull - private Integer skuId; - /** - * 数量 - */ - @NotNull - @Max(value = 1000) - private Integer quantity; - -} diff --git a/order/order-service-impl/pom.xml b/order/order-service-impl/pom.xml index 5588a6cfd..a4e22371a 100644 --- a/order/order-service-impl/pom.xml +++ b/order/order-service-impl/pom.xml @@ -35,6 +35,11 @@ 1.0-SNAPSHOT compile + + cn.iocoder.mall + promotion-service-api + 1.0-SNAPSHOT + com.alibaba diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderItemConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderItemConvert.java index 1a8591d69..1b3831775 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderItemConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderItemConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.order.biz.convert; -import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; import cn.iocoder.mall.order.api.bo.OrderItemBO; +import cn.iocoder.mall.order.api.dto.OrderCreateDTO; import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO; import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; import org.mapstruct.Mapper; @@ -28,7 +28,7 @@ public interface OrderItemConvert { List convertOrderItemBO(List orderItemDOList); @Mappings({}) - List convert(List orderCreateItemDTOList); + List convert(List orderCreateItemDTOList); @Mappings({}) List convertOrderItemDO(List orderItemDOList); 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 bd0a8e9dc..702508dd7 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 @@ -194,7 +194,7 @@ public class OrderServiceImpl implements OrderService { @Transactional // TODO 芋艿,先不考虑分布式事务的问题 public CommonResult createOrder(OrderCreateDTO orderCreateDTO) { Integer userId = orderCreateDTO.getUserId(); - List orderItemDTOList = orderCreateDTO.getOrderItems(); + List orderItemDTOList = orderCreateDTO.getOrderItems(); List orderItemDOList = OrderItemConvert.INSTANCE.convert(orderItemDTOList); // 获取商品信息 @@ -337,7 +337,7 @@ public class OrderServiceImpl implements OrderService { .setUserId(orderCreateDTO.getUserId()) .setItems(new ArrayList<>(skus.size())) .setCouponCardId(orderCreateDTO.getCouponCardId()); - for (OrderCreateItemDTO item : orderCreateDTO.getOrderItems()) { + for (OrderCreateDTO.OrderItem item : orderCreateDTO.getOrderItems()) { calcOrderPriceDTO.getItems().add(new CalcOrderPriceDTO.Item(item.getSkuId(), item.getQuantity(), true)); } // 执行计算 diff --git a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderServiceImplTest.java b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderServiceImplTest.java index 4baed21ba..0f9bc56ca 100644 --- a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderServiceImplTest.java +++ b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderServiceImplTest.java @@ -5,7 +5,6 @@ import cn.iocoder.mall.order.OrderApplicationTest; import cn.iocoder.mall.order.api.OrderService; import cn.iocoder.mall.order.api.bo.OrderCreateBO; import cn.iocoder.mall.order.api.dto.OrderCreateDTO; -import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO; import cn.iocoder.mall.order.biz.dao.OrderMapper; import cn.iocoder.mall.order.biz.dataobject.OrderDO; import org.junit.Assert;