parent
4fd506895c
commit
bcae55bc59
|
@ -16,5 +16,11 @@
|
|||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>common-framework</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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<OrderBO> 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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<Integer> 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<Integer> getOrderItemIds() {
|
||||
return orderItemIds;
|
||||
}
|
||||
|
||||
public OrderItemDeletedDTO setOrderItemIds(List<Integer> orderItemIds) {
|
||||
this.orderItemIds = orderItemIds;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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<OrderItemDO> items);
|
||||
}
|
|
@ -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<OrderItemDO> items) {
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
return 0;
|
||||
}
|
||||
AtomicInteger totalAmount = new AtomicInteger(0);
|
||||
items.forEach(orderItemDO -> {
|
||||
totalAmount.addAndGet(orderItemDO.getPrice() * orderItemDO.getQuantity());
|
||||
});
|
||||
return totalAmount.get();
|
||||
}
|
||||
}
|
|
@ -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<OrderItemDO> convert(List<OrderCreateItemDTO> 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);
|
||||
}
|
||||
|
|
|
@ -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<Integer> ids,
|
||||
OrderItemDO orderItemDO
|
||||
);
|
||||
|
||||
/**
|
||||
* 查询 - 根据 orderId 下的 item
|
||||
*
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
List<OrderItemDO> selectByOrderIdAndDeleted(
|
||||
@Param("orderId") Integer orderId,
|
||||
@Param("deleted") @NotNull Integer deleted
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,4 +18,11 @@ public interface OrderLogisticsMapper {
|
|||
* @param orderLogisticsDO
|
||||
*/
|
||||
void insert(OrderLogisticsDO orderLogisticsDO);
|
||||
|
||||
/**
|
||||
* 更新 - 根据id
|
||||
*
|
||||
* @param orderLogisticsDO
|
||||
*/
|
||||
void updateById(OrderLogisticsDO orderLogisticsDO);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<OrderBO> createOrder(OrderCreateDTO orderCreateDTO) {
|
||||
List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems();
|
||||
OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderCreateDTO);
|
||||
List<OrderItemDO> 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<Integer> orderItemIds = orderItemDeletedDTO.getOrderItemIds();
|
||||
|
||||
// 获取当前有效的订单 item
|
||||
List<OrderItemDO> orderItemDOList = orderItemMapper
|
||||
.selectByOrderIdAndDeleted(orderId, DeletedStatusEnum.DELETED_NO.getValue());
|
||||
|
||||
List<OrderItemDO> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
<mapper namespace="cn.iocoder.mall.order.dao.OrderItemMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
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
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
|
@ -12,12 +13,101 @@
|
|||
-->
|
||||
<insert id="insert" parameterType="OrderItemDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
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}
|
||||
)
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
<!--
|
||||
更新 - 可更新的字段
|
||||
-->
|
||||
<sql id="updateFieldSql" >
|
||||
<set>
|
||||
<if test="orderId != null">
|
||||
, order_id = #{orderId}
|
||||
</if>
|
||||
<if test="orderNo != null">
|
||||
, order_no = #{orderNo}
|
||||
</if>
|
||||
<if test="skuId != null">
|
||||
, sku_id = #{skuId}
|
||||
</if>
|
||||
<if test="quantity != null">
|
||||
, quantity = #{quantity}
|
||||
</if>
|
||||
<if test="price != null">
|
||||
, price = #{price}
|
||||
</if>
|
||||
-- time
|
||||
<if test="paymentTime != null">
|
||||
, payment_time = #{paymentTime}
|
||||
</if>
|
||||
<if test="deliveryTime != null">
|
||||
, delivery_time = #{deliveryTime}
|
||||
</if>
|
||||
<if test="receiverTime != null">
|
||||
, receiver_time = #{receiverTime}
|
||||
</if>
|
||||
<if test="closingTime != null">
|
||||
, closing_time = #{closingTime}
|
||||
</if>
|
||||
-- other
|
||||
<if test="hasReturnExchange != null">
|
||||
, has_return_exchange = #{hasReturnExchange}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
, status = #{status}
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
, `deleted` = #{deleted}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
, create_time = #{createTime}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
, update_time = #{updateTime}
|
||||
</if>
|
||||
</set>
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
更新 - 根据 id 更新
|
||||
-->
|
||||
<update id="updateById" parameterType="OrderDO">
|
||||
UPDATE `order_item`
|
||||
<include refid="updateFieldSql" />
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!--
|
||||
更新 - 根据 ids 更新
|
||||
-->
|
||||
<update id="updateByIds">
|
||||
UPDATE `order_item`
|
||||
<include refid="updateFieldSql" />
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!--
|
||||
查询 - 根据 orderId 下的 item
|
||||
-->
|
||||
<select id="selectByOrderIdAndDeleted" resultType="cn.iocoder.mall.order.dataobject.OrderItemDO">
|
||||
SELECT * FROM `order_item`
|
||||
WHERE 1=1
|
||||
<if test="deleted">
|
||||
AND deleted = #{deleted}
|
||||
</if>
|
||||
<if test="orderId">
|
||||
AND order_id = #{orderId}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -11,11 +11,42 @@
|
|||
-->
|
||||
<insert id="insert" parameterType="OrderLogisticsDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
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}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!--
|
||||
可更新字段
|
||||
-->
|
||||
<sql id="updateFieldSql" >
|
||||
<set>
|
||||
<if test="areaNo != null">
|
||||
, area_no = #{areaNo}
|
||||
</if>
|
||||
<if test="name != null">
|
||||
, `name` = #{name}
|
||||
</if>
|
||||
<if test="mobile != null">
|
||||
, mobile = #{mobile}
|
||||
</if>
|
||||
<if test="address != null">
|
||||
, address = #{address}
|
||||
</if>
|
||||
<if test="logisticsNo != null">
|
||||
, logistics_no = #{logisticsNo}
|
||||
</if>
|
||||
</set>
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
更新 - 根据id
|
||||
-->
|
||||
<update id="updateById">
|
||||
UPDATE `order_logistics`
|
||||
<include refid="updateFieldSql" />
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
</mapper>
|
|
@ -3,9 +3,9 @@
|
|||
<mapper namespace="cn.iocoder.mall.order.dao.OrderMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
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`
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
|
@ -13,20 +13,22 @@
|
|||
-->
|
||||
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
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}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!--
|
||||
更新 - 可更新的字段
|
||||
-->
|
||||
<sql id="updateSql" >
|
||||
<sql id="updateFieldSql" >
|
||||
<set>
|
||||
<if test="orderLogisticsId != null">
|
||||
, order_logistics_id = #{orderLogisticsId}
|
||||
|
@ -34,8 +36,8 @@
|
|||
<if test="orderNo != null">
|
||||
, order_no = #{orderNo}
|
||||
</if>
|
||||
<if test="price != null">
|
||||
, price = #{price}
|
||||
<if test="money != null">
|
||||
, money = #{money}
|
||||
</if>
|
||||
-- time
|
||||
<if test="paymentTime != null">
|
||||
|
@ -57,8 +59,11 @@
|
|||
<if test="status != null">
|
||||
, status = #{status}
|
||||
</if>
|
||||
<if test="delete != null">
|
||||
, `delete` = #{delete}
|
||||
<if test="remark != null">
|
||||
, remark = #{remark}
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
, `deleted` = #{deleted}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
, create_time = #{createTime}
|
||||
|
@ -66,9 +71,6 @@
|
|||
<if test="updateTime != null">
|
||||
, update_time = #{updateTime}
|
||||
</if>
|
||||
<if test="remark != null">
|
||||
, remark = #{remark}
|
||||
</if>
|
||||
</set>
|
||||
</sql>
|
||||
|
||||
|
@ -77,7 +79,7 @@
|
|||
-->
|
||||
<update id="updateById" parameterType="OrderDO">
|
||||
UPDATE `order`
|
||||
<include refid="updateSql" />
|
||||
<include refid="updateFieldSql" />
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
</mapper>
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue