- 增加 OrderLogisticsMapper

- 修改 OrderServiceImpl 订单创建和删除
- 修改 订单的表结构
This commit is contained in:
sin 2019-03-22 21:51:55 +08:00
parent c5f8abd6de
commit f4c7f65cb8
10 changed files with 307 additions and 139 deletions

View File

@ -0,0 +1,22 @@
package cn.iocoder.mall.order.dao;
import cn.iocoder.mall.order.dataobject.OrderDO;
import cn.iocoder.mall.order.dataobject.OrderLogisticsDO;
import org.springframework.stereotype.Repository;
/**
* 订单 item mapper
*
* @author Sin
* @time 2019-03-16 15:09
*/
@Repository
public interface OrderLogisticsMapper {
/**
* 插入数据
*
* @param orderLogisticsDO
*/
void insert(OrderLogisticsDO orderLogisticsDO);
}

View File

@ -2,7 +2,6 @@ package cn.iocoder.mall.order.dataobject;
import cn.iocoder.common.framework.dataobject.BaseDO;
import java.io.Serializable;
import java.util.Date;
/**
@ -34,19 +33,19 @@ public class OrderDO extends BaseDO {
/// 时间信息
/**
* 付款时间
* 付款时间待发货
*/
private Date paymentTime;
/**
* 发货时间
* 发货时间待收货
*/
private Date deliveryTime;
/**
* 收货时间
* 收货时间已签收
*/
private Date receiverTime;
/**
* 成交时间
* 成交时间用户确认收货 -> status = 已完成
*/
private Date closingTime;
@ -72,13 +71,6 @@ public class OrderDO extends BaseDO {
* - 4已关闭
*/
private Integer status;
/**
* 删除状态
*
* - 0 未删除
* - 1 已删除
*/
private Integer deleteStatus;
/**
* 备注
*/
@ -97,7 +89,6 @@ public class OrderDO extends BaseDO {
", closingTime=" + closingTime +
", hasReturnExchange=" + hasReturnExchange +
", status=" + status +
", deleteStatus=" + deleteStatus +
", remark='" + remark + '\'' +
'}';
}
@ -192,15 +183,6 @@ public class OrderDO extends BaseDO {
return this;
}
public Integer getDeleteStatus() {
return deleteStatus;
}
public OrderDO setDeleteStatus(Integer deleteStatus) {
this.deleteStatus = deleteStatus;
return this;
}
public String getRemark() {
return remark;
}

View File

@ -24,6 +24,10 @@ public class OrderExchangeDO extends BaseDO {
* 订单编号
*/
private String orderNo;
/**
* 订单 item 编号
*/
private Integer orderItemId;
/**
* 商品id保存一个冗余如果一个订单下存在多个商品会有很大的作用
*/
@ -62,8 +66,9 @@ public class OrderExchangeDO extends BaseDO {
/**
* 创建时间
* supper baseDO
*/
private Date createTime;
// private Date createTime;
/**
* 付款时间
*/
@ -84,6 +89,13 @@ public class OrderExchangeDO extends BaseDO {
///
/// 其他
/**
* 订单类型
*
* - 0 Order 订单 对整个订单退货
* - 1 OrderItem 订单 对订单某一个商品退货
*/
private Integer orderType;
/**
* 状态
*
@ -101,17 +113,18 @@ public class OrderExchangeDO extends BaseDO {
"id=" + id +
", orderId=" + orderId +
", orderNo='" + orderNo + '\'' +
", orderItemId=" + orderItemId +
", skuId='" + skuId + '\'' +
", exchangeSkuId='" + exchangeSkuId + '\'' +
", exchangeOrderLogisticsId=" + exchangeOrderLogisticsId +
", receiverOrderLogisticsId=" + receiverOrderLogisticsId +
", orderReasonId=" + orderReasonId +
", reason='" + reason + '\'' +
", createTime=" + createTime +
", paymentTime=" + paymentTime +
", deliveryTime=" + deliveryTime +
", receiverTime=" + receiverTime +
", closingTime=" + closingTime +
", orderType=" + orderType +
", status=" + status +
'}';
}
@ -143,6 +156,15 @@ public class OrderExchangeDO extends BaseDO {
return this;
}
public Integer getOrderItemId() {
return orderItemId;
}
public OrderExchangeDO setOrderItemId(Integer orderItemId) {
this.orderItemId = orderItemId;
return this;
}
public String getSkuId() {
return skuId;
}
@ -197,17 +219,6 @@ public class OrderExchangeDO extends BaseDO {
return this;
}
@Override
public Date getCreateTime() {
return createTime;
}
@Override
public OrderExchangeDO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Date getPaymentTime() {
return paymentTime;
}
@ -244,6 +255,15 @@ public class OrderExchangeDO extends BaseDO {
return this;
}
public Integer getOrderType() {
return orderType;
}
public OrderExchangeDO setOrderType(Integer orderType) {
this.orderType = orderType;
return this;
}
public Integer getStatus() {
return status;
}

View File

@ -40,10 +40,6 @@ public class OrderItemDO extends BaseDO {
///
/// 时间信息
/**
* 创建时间
*/
private Date createTime;
/**
* 付款时间
*/
@ -67,25 +63,20 @@ public class OrderItemDO extends BaseDO {
/**
* 是否退货
*
* - 0no
* - 1yes
* - 1没有
* - 2换货
* - 3退货
* - 4换货 + 退货
*/
private Integer hasReturn;
/**
* 是否换货
*
* - 0no
* - 1yes
*/
private Integer hasExchange;
private Integer hasReturnExchange;
/**
* 状态
*
* - 0待付款
* - 1待发货
* - 2待收获
* - 3已完成
* - 4已关闭
* - 1待付款
* - 2待发货
* - 3已发货
* - 4已完成
* - 5已关闭
*/
private Integer status;
@ -98,13 +89,11 @@ public class OrderItemDO extends BaseDO {
", skuId='" + skuId + '\'' +
", quantity=" + quantity +
", price=" + price +
", createTime=" + createTime +
", paymentTime=" + paymentTime +
", deliveryTime=" + deliveryTime +
", receiverTime=" + receiverTime +
", closingTime=" + closingTime +
", hasReturn=" + hasReturn +
", hasExchange=" + hasExchange +
", hasReturnExchange=" + hasReturnExchange +
", status=" + status +
'}';
}
@ -163,17 +152,6 @@ public class OrderItemDO extends BaseDO {
return this;
}
@Override
public Date getCreateTime() {
return createTime;
}
@Override
public OrderItemDO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Date getPaymentTime() {
return paymentTime;
}
@ -210,21 +188,12 @@ public class OrderItemDO extends BaseDO {
return this;
}
public Integer getHasReturn() {
return hasReturn;
public Integer getHasReturnExchange() {
return hasReturnExchange;
}
public OrderItemDO setHasReturn(Integer hasReturn) {
this.hasReturn = hasReturn;
return this;
}
public Integer getHasExchange() {
return hasExchange;
}
public OrderItemDO setHasExchange(Integer hasExchange) {
this.hasExchange = hasExchange;
public OrderItemDO setHasReturnExchange(Integer hasReturnExchange) {
this.hasReturnExchange = hasReturnExchange;
return this;
}

View File

@ -30,10 +30,6 @@ public class OrderLogisticsDetailDO extends BaseDO {
* 物流信息
*/
private String logisticsInformation;
/**
* 创建时间同步时间
*/
private Date createTime;
@Override
public String toString() {
@ -42,7 +38,6 @@ public class OrderLogisticsDetailDO extends BaseDO {
", orderLogisticsId=" + orderLogisticsId +
", logisticsTime=" + logisticsTime +
", logisticsInformation='" + logisticsInformation + '\'' +
", createTime=" + createTime +
'}';
}
@ -81,13 +76,4 @@ public class OrderLogisticsDetailDO extends BaseDO {
this.logisticsInformation = logisticsInformation;
return this;
}
public Date getCreateTime() {
return createTime;
}
public OrderLogisticsDetailDO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
}

View File

@ -32,6 +32,10 @@ public class OrderReturnDO extends BaseDO {
* 商品编号保存一个冗余如果一个订单下存在多个商品会有很大的作用
*/
private String skuId;
/**
* 物流id
*/
private Integer orderLogisticsId;
///
/// 退货原因
@ -102,6 +106,7 @@ public class OrderReturnDO extends BaseDO {
", orderNo='" + orderNo + '\'' +
", orderItemId=" + orderItemId +
", skuId='" + skuId + '\'' +
", orderLogisticsId=" + orderLogisticsId +
", orderReasonId=" + orderReasonId +
", reason='" + reason + '\'' +
", createTime=" + createTime +
@ -159,6 +164,15 @@ public class OrderReturnDO extends BaseDO {
return this;
}
public Integer getOrderLogisticsId() {
return orderLogisticsId;
}
public OrderReturnDO setOrderLogisticsId(Integer orderLogisticsId) {
this.orderLogisticsId = orderLogisticsId;
return this;
}
public Integer getOrderReasonId() {
return orderReasonId;
}

View File

@ -1,27 +1,30 @@
package cn.iocoder.mall.order.service;
import cn.iocoder.common.framework.constant.DeleteStatusEnum;
import cn.iocoder.mall.order.api.OrderService;
import cn.iocoder.mall.order.api.bo.OrderBO;
import cn.iocoder.mall.order.api.constants.OrderDeleteStatusEnum;
import cn.iocoder.mall.order.api.constants.OrderPayStatusEnum;
import cn.iocoder.mall.order.api.constants.OrderStatusEnum;
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.convert.OrderConvert;
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 org.checkerframework.checker.units.qual.A;
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 java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 订单 service impl
@ -37,39 +40,67 @@ public class OrderServiceImpl implements OrderService {
private OrderMapper orderMapper;
@Autowired
private OrderItemMapper orderItemMapper;
@Autowired
private OrderLogisticsMapper orderLogisticsMapper;
@Override
@Transactional
public OrderBO createOrder(OrderCreateDTO orderCreateDTO) {
List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems();
OrderDO orderDO = OrderConvert.INSTANCE.convert(orderCreateDTO);
OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderCreateDTO);
List<OrderItemDO> orderItemDOList = OrderConvert.INSTANCE.convert(orderItemDTOList);
// 物流信息
orderLogisticsDO.setLogisticsNo("");
orderLogisticsMapper.insert(orderLogisticsDO);
// order
OrderDO orderDO = new OrderDO();
orderDO.setOrderLogisticsId(orderLogisticsDO.getId());
orderDO.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
orderDO.setPrice(1000);
orderDO.setPrice(-1); // 先设置一个默认值金额在下面计算
orderDO.setCreateTime(new Date());
orderDO.setUpdateTime(null);
orderDO.setDeleted(DeleteStatusEnum.DELETE_NO.getValue());
orderDO.setClosingTime(null);
orderDO.setDeliveryTime(null);
orderDO.setPaymentTime(null);
orderDO.setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue());
orderDO.setPayStatus(OrderPayStatusEnum.WAITING_PAYMENT.getValue());
orderDO.setDeleteStatus(OrderDeleteStatusEnum.DELETE_NO.getValue());
orderDO.setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue());
orderDO.setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse(""));
orderMapper.insert(orderDO);
// order item
int goodsPrice = 1000;
AtomicInteger totalPrice = new AtomicInteger();
orderItemDOList.forEach(orderItemDO -> {
int goodsPrice = 1000; // 商品单价
int price = orderItemDO.getQuantity() * goodsPrice;
totalPrice.addAndGet(price);
orderItemDO
.setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue())
.setOrderId(orderDO.getId())
.setPrice(price)
.setDeliveryTime(null);
.setOrderNo(orderDO.getOrderNo())
.setPrice(goodsPrice)
.setPaymentTime(null)
.setDeliveryTime(null)
.setReceiverTime(null)
.setClosingTime(null)
.setHasReturnExchange(OrderStatusEnum.WAITING_PAYMENT.getValue())
.setStatus(OrderStatusEnum.WAITING_PAYMENT.getValue())
.setCreateTime(new Date())
.setUpdateTime(new Date())
.setDeleted(DeleteStatusEnum.DELETE_NO.getValue());
orderItemMapper.insert(orderItemDO);
});
// 更新订单金额
orderMapper.updateById(
new OrderDO()
.setId(orderDO.getId())
.setPrice(totalPrice.get())
);
// TODO: 2019-03-17 Sin 需要发送 创建成果 MQ 消息
return new OrderBO()
@ -93,9 +124,9 @@ public class OrderServiceImpl implements OrderService {
@Override
public void deleteOrder(Integer id) {
// 删除订单操作一般用于 用户端删除是否存在检查可以过掉
orderMapper.updateById(new OrderDO()
orderMapper.updateById((OrderDO) new OrderDO()
.setId(id)
.setDeleteStatus(OrderDeleteStatusEnum.DELETE_YES.getValue())
.setDeleted(DeleteStatusEnum.DELETE_YES.getValue())
);
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.order.dao.OrderLogisticsMapper">
<sql id="FIELDS">
id, area_no, `name`, mobile, address, logistics_no
</sql>
<!--
插入数据
-->
<insert id="insert" parameterType="OrderLogisticsDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO `order_logistics` (
area_no, `name`, mobile, address, logistics_no
) VALUES (
#{areaNo}, #{name}, #{mobile}, #{address},
#{logisticsNo}
)
</insert>
</mapper>

View File

@ -3,9 +3,9 @@
<mapper namespace="cn.iocoder.mall.order.dao.OrderMapper">
<sql id="FIELDS">
order_no, price, receiver_area_no, receiver_mobile,
receiver_address, `status`, pay_status, create_time,
payment_time, delivery_time, closing_time, remark
id, order_logistics_id, order_no, price, payment_time,
delivery_time, receiver_time, closing_time, has_return_exchange,
status, remark
</sql>
<!--
@ -13,13 +13,13 @@
-->
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO `order` (
order_no, price, receiver_area_no, receiver_mobile,
receiver_address, `status`, pay_status, create_time,
payment_time, delivery_time, closing_time, remark
order_logistics_id, order_no, price, payment_time,
delivery_time, receiver_time, closing_time,
has_return_exchange, status, remark
) VALUES (
#{orderNo}, ${price}, #{receiverAreaNo}, #{receiverMobile},
#{receiverAddress}, #{status}, #{payStatus}, #{createTime},
#{paymentTime}, #{deliveryTime}, #{closingTime}, #{remark}
#{orderLogisticsId}, ${orderNo}, #{price}, #{paymentTime},
#{deliveryTime}, #{receiverTime}, #{closingTime},
#{hasReturnExchange}, #{status}, #{remark}
)
</insert>
@ -28,42 +28,44 @@
-->
<sql id="updateSql" >
<set>
<if test="orderLogisticsId != null">
, order_logistics_id = #{orderLogisticsId}
</if>
<if test="orderNo != null">
, order_no = #{orderNo}
</if>
<if test="price != null">
, price = #{price}
</if>
<if test="receiverAreaNo != null">
, receiver_area_no = #{receiverAreaNo}
</if>
<if test="receiverMobile != null">
, receiver_mobile = #{receiverMobile}
</if>
<if test="receiverAddress != null">
, receiver_address = #{receiverAddress}
</if>
<if test="status != null">
, status = #{status}
</if>
<if test="payStatus != null">
, pay_status = #{payStatus}
</if>
<if test="deleteStatus != null">
, delete_status = #{deleteStatus}
</if>
<if test="createTime != null">
, create_time = #{createTime}
</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>
<if test="hasReturnExchange != null">
, has_return_exchange = #{hasReturnExchange}
</if>
-- other
<if test="status != null">
, status = #{status}
</if>
<if test="delete != null">
, `delete` = #{delete}
</if>
<if test="createTime != null">
, create_time = #{createTime}
</if>
<if test="updateTime != null">
, update_time = #{updateTime}
</if>
<if test="remark != null">
, remark = #{remark}
</if>

View File

@ -0,0 +1,121 @@
DROP TABLE `order`;
DROP TABLE `order_item`;
DROP TABLE `order_exchange`;
DROP TABLE `order_return`;
DROP TABLE `order_logistics`;
DROP TABLE `order_logistics_detail`;
CREATE TABLE `order` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Id自增长',
`order_logistics_id` int NOT NULL COMMENT '物流id',
`order_no` varchar(50) NOT NULL COMMENT '订单单号',
`price` int(10) NULL COMMENT '金额(分)',
`payment_time` datetime NULL COMMENT '付款时间',
`delivery_time` datetime NULL COMMENT '发货时间',
`receiver_time` datetime NULL COMMENT '收货时间',
`closing_time` datetime NULL COMMENT '成交时间',
`has_return_exchange` smallint NULL COMMENT '是否退换货',
`remark` varchar(255) NULL COMMENT '备注',
`status` smallint(2) NULL COMMENT '状态(如果有多个商品分开发货需要全部商品发完才会改变状态) 0、待付款 1、待发货 2、待收货 3、已完成 4、已关闭',
`create_time` datetime NULL COMMENT '订单创建时间',
`update_time` datetime NULL COMMENT '更新时间',
`deleted` smallint NULL COMMENT '删除状态',
PRIMARY KEY (`id`)
);
CREATE TABLE `order_item` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'id自增长',
`order_id` int NOT NULL COMMENT '订单编号',
`order_no` varchar(50) NOT NULL COMMENT '订单号',
`sku_id` int NOT NULL COMMENT '商品编号',
`quantity` int(3) NOT NULL COMMENT '商品数量',
`price` int(255) NOT NULL COMMENT '金额',
`payment_time` datetime NULL COMMENT '付款时间',
`delivery_time` datetime NULL COMMENT '发货时间',
`receiver_time` datetime NULL COMMENT '收货时间',
`closing_time` datetime NULL,
`has_return_exchange` int NULL COMMENT '是否退换货',
`create_time` datetime NULL COMMENT '创建时间',
`update_time` datetime NULL COMMENT '更新时间',
`status` smallint(2) NOT NULL COMMENT '状态0、代发货 1、已发货 2、已收货 20、换货中 21、换货成功 40、退货中 41、已退货',
`delete` smallint(2) NOT NULL COMMENT '删除状态',
PRIMARY KEY (`id`)
);
CREATE TABLE `order_exchange` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`order_no` varchar(50) NOT NULL,
`sku_id` int(11) NOT NULL,
`exchange_sku_id` int(11) NOT NULL COMMENT '换货商品id',
`exchange_order_logistics_id` int(11) NOT NULL COMMENT '换货物流id',
`receiver_order_logistics_id` int(11) NOT NULL COMMENT '收件地址',
`order_reason_id` int(11) NULL COMMENT '换货原因',
`reason` varchar(255) NULL COMMENT '换货原因 (其他的时候)',
`payment_time` datetime NULL COMMENT '付款时间',
`delivery_time` datetime NULL COMMENT '发货时间',
`receiver_time` datetime NULL COMMENT '收货时间',
`closing_time` datetime NULL COMMENT '成交时间',
`create_time` datetime NULL COMMENT '创建时间',
`update_time` datetime NULL COMMENT '更新时间',
`delete` smallint(2) NULL COMMENT '删除状态',
`order_type` int(2) NULL COMMENT '订单类型 0、为 Order 订单 1、为 OrderItem 订单',
`status` int(2) NULL COMMENT '状态 申请换货、申请成功、申请失败、换货中、换货成功',
PRIMARY KEY (`id`)
);
CREATE TABLE `order_return` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'id自增长',
`order_id` int NOT NULL COMMENT '订单编号',
`order_no` varchar(50) NOT NULL COMMENT '订单号',
`sku_id` int NOT NULL COMMENT '商品编号',
`order_item_id` int(11) NOT NULL COMMENT '订单item id',
`order_logistics_id` int(11) NOT NULL COMMENT '物流 id',
`order_reason_id` int(11) NULL COMMENT '退货原因',
`reason` varchar(255) NULL COMMENT '换货原因 (其他的时候)',
`create_time` datetime NULL COMMENT '创建时间',
`approval_time` datetime NULL COMMENT '同意时间',
`logistics_time` datetime NULL COMMENT '物流时间(填写物流单号时间)',
`receiver_time` datetime NULL COMMENT '收货时间',
`closing_time` datetime NULL COMMENT '成交时间',
`order_type` int(2) NULL COMMENT '订单类型 0、为 Order 订单 1、为 OrderItem 订单',
`update_time` datetime NULL COMMENT '更新时间',
`delete` smallint(2) NULL COMMENT '删除状态',
`status` int(2) NULL COMMENT '状态 申请换货、申请成功、申请失败、退货中、退货成功',
PRIMARY KEY (`id`)
);
CREATE TABLE `order_logistics` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'id自增长',
`area_no` int NOT NULL COMMENT '订单编号',
`name` VARCHAR(20) NOT NULL COMMENT '名称',
`mobile` VARCHAR(20) NOT NULL COMMENT '手机号',
`address` VARCHAR(255) NOT NULL COMMENT '详细地址',
`logistics_no` VARCHAR(20) NOT NULL COMMENT '物流单号',
PRIMARY KEY (`id`)
);
CREATE TABLE `order_logistics_detail` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'id自增长',
`order_logistics_id` int NOT NULL COMMENT '物流编号',
`logistics_time` datetime NOT NULL COMMENT '物流时间',
`logistics_information` VARCHAR(20) NOT NULL COMMENT '物流信息',
PRIMARY KEY (`id`)
);