- 添加 userId 绑定 订单
- 添加后台订单分页
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
package cn.iocoder.mall.order.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderPageBO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderDO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderItemDO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderLogisticsDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@@ -24,39 +19,6 @@ public interface OrderConvert {
|
||||
|
||||
OrderConvert INSTANCE = Mappers.getMapper(OrderConvert.class);
|
||||
|
||||
/**
|
||||
* 转换 OrderLogisticsDO - OrderCreateDTO
|
||||
*
|
||||
* @param orderCreateDTO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
OrderLogisticsDO convert(OrderCreateDTO orderCreateDTO);
|
||||
|
||||
/**
|
||||
* 转换 OrderItemDO - orderCreateItemDTOList
|
||||
*
|
||||
* @param orderCreateItemDTOList
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
List<OrderItemDO> convert(List<OrderCreateItemDTO> orderCreateItemDTOList);
|
||||
|
||||
/**
|
||||
* 转换 OrderLogisticsDO - orderReceiverInformationDTO
|
||||
*
|
||||
* @param orderLogisticsDTO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
OrderLogisticsDO convert(OrderLogisticsDTO orderLogisticsDTO);
|
||||
|
||||
/**
|
||||
* 转换 OrderItemDO - orderReceiverInformationDTO
|
||||
*
|
||||
* @param orderItemUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
OrderItemDO convert(OrderItemUpdateDTO orderItemUpdateDTO);
|
||||
List<OrderPageBO> convertPageBO(List<OrderDO> orderDOList);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.order.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderItemDO;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单 item convert
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-03-23 14:34
|
||||
*/
|
||||
public interface OrderItemConvert {
|
||||
|
||||
OrderItemConvert INSTANCE = Mappers.getMapper(OrderItemConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
OrderItemDO convert(OrderItemUpdateDTO orderItemUpdateDTO);
|
||||
|
||||
@Mappings({})
|
||||
List<OrderItemDO> convert(List<OrderCreateItemDTO> orderCreateItemDTOList);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.order.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderLogisticsDTO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderLogisticsDO;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 订单物流 convert
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-03-23 14:39
|
||||
*/
|
||||
public interface OrderLogisticsConvert {
|
||||
|
||||
OrderLogisticsConvert INSTANCE = Mappers.getMapper(OrderLogisticsConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
OrderLogisticsDO convert(OrderCreateDTO orderCreateDTO);
|
||||
|
||||
@Mappings({})
|
||||
OrderLogisticsDO convert(OrderLogisticsDTO orderLogisticsDTO);
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package cn.iocoder.mall.order.dao;
|
||||
|
||||
import cn.iocoder.mall.order.api.dto.OrderQueryDTO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单 mapper
|
||||
*
|
||||
@@ -26,4 +30,30 @@ public interface OrderMapper {
|
||||
* @return
|
||||
*/
|
||||
int updateById(OrderDO orderDO);
|
||||
|
||||
/**
|
||||
* 查询 - 根据id 查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
OrderDO selectById(
|
||||
@Param("id") Integer id
|
||||
);
|
||||
|
||||
/**
|
||||
* 查询 - 后台分页page
|
||||
*
|
||||
* @param orderQueryDTO
|
||||
* @return
|
||||
*/
|
||||
int selectPageCount(OrderQueryDTO orderQueryDTO);
|
||||
|
||||
/**
|
||||
* 查询 - 后台分页page
|
||||
*
|
||||
* @param orderQueryDTO
|
||||
* @return
|
||||
*/
|
||||
List<OrderDO> selectPage(OrderQueryDTO orderQueryDTO, int offset, int pageSize);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ public class OrderDO extends DeletableDO {
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 物流id
|
||||
*/
|
||||
@@ -80,9 +84,10 @@ public class OrderDO extends DeletableDO {
|
||||
public String toString() {
|
||||
return "OrderDO{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", orderLogisticsId=" + orderLogisticsId +
|
||||
", orderNo='" + orderNo + '\'' +
|
||||
", price=" + money +
|
||||
", money=" + money +
|
||||
", paymentTime=" + paymentTime +
|
||||
", deliveryTime=" + deliveryTime +
|
||||
", receiverTime=" + receiverTime +
|
||||
@@ -102,6 +107,15 @@ public class OrderDO extends DeletableDO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public OrderDO setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getOrderLogisticsId() {
|
||||
return orderLogisticsId;
|
||||
}
|
||||
|
||||
@@ -11,21 +11,21 @@ import cn.iocoder.mall.order.api.constant.OrderHasReturnExchangeEnum;
|
||||
import cn.iocoder.mall.order.api.constant.OrderStatusEnum;
|
||||
import cn.iocoder.mall.order.api.dto.*;
|
||||
import cn.iocoder.mall.order.convert.OrderConvert;
|
||||
import cn.iocoder.mall.order.convert.OrderItemConvert;
|
||||
import cn.iocoder.mall.order.convert.OrderLogisticsConvert;
|
||||
import cn.iocoder.mall.order.dao.OrderItemMapper;
|
||||
import cn.iocoder.mall.order.dao.OrderLogisticsMapper;
|
||||
import cn.iocoder.mall.order.dao.OrderMapper;
|
||||
import cn.iocoder.mall.order.dataobject.OrderDO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderItemDO;
|
||||
import cn.iocoder.mall.order.dataobject.OrderLogisticsDO;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -47,12 +47,28 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Autowired
|
||||
private OrderCommon orderCommon;
|
||||
|
||||
@Override
|
||||
public CommonResult<List<OrderPageBO>> getOrderPage(OrderQueryDTO orderQueryDTO) {
|
||||
|
||||
int offset = orderQueryDTO.getPageNo() * orderQueryDTO.getPageSize();
|
||||
int pageSize = orderQueryDTO.getPageSize();
|
||||
|
||||
int totalCount = orderMapper.selectPageCount(orderQueryDTO);
|
||||
if (totalCount == 0) {
|
||||
return CommonResult.success(Collections.EMPTY_LIST);
|
||||
}
|
||||
|
||||
List<OrderDO> orderDOList = orderMapper.selectPage(orderQueryDTO, offset, pageSize);
|
||||
List<OrderPageBO> orderPageBOList = OrderConvert.INSTANCE.convertPageBO(orderDOList);
|
||||
return CommonResult.success(orderPageBOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommonResult<OrderBO> createOrder(OrderCreateDTO orderCreateDTO) {
|
||||
public CommonResult<OrderBO> createOrder(Integer userId, OrderCreateDTO orderCreateDTO) {
|
||||
List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems();
|
||||
OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderCreateDTO);
|
||||
List<OrderItemDO> orderItemDOList = OrderConvert.INSTANCE.convert(orderItemDTOList);
|
||||
OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderCreateDTO);
|
||||
List<OrderItemDO> orderItemDOList = OrderItemConvert.INSTANCE.convert(orderItemDTOList);
|
||||
|
||||
// 物流信息
|
||||
orderLogisticsDO
|
||||
@@ -62,21 +78,21 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderLogisticsMapper.insert(orderLogisticsDO);
|
||||
|
||||
// order
|
||||
OrderDO orderDO = new OrderDO();
|
||||
orderDO.setOrderLogisticsId(orderLogisticsDO.getId());
|
||||
orderDO.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
|
||||
orderDO.setMoney(-1); // 先设置一个默认值,金额在下面计算
|
||||
|
||||
orderDO.setClosingTime(null);
|
||||
orderDO.setDeliveryTime(null);
|
||||
orderDO.setPaymentTime(null);
|
||||
orderDO.setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue());
|
||||
orderDO.setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue());
|
||||
orderDO.setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse(""));
|
||||
OrderDO orderDO = new OrderDO()
|
||||
.setUserId(userId)
|
||||
.setOrderLogisticsId(orderLogisticsDO.getId())
|
||||
.setOrderNo(UUID.randomUUID().toString().replace("-", ""))
|
||||
.setMoney(-1) // 先设置一个默认值,金额在下面计算
|
||||
.setClosingTime(null)
|
||||
.setDeliveryTime(null)
|
||||
.setPaymentTime(null)
|
||||
.setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue())
|
||||
.setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue())
|
||||
.setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse(""));
|
||||
|
||||
orderDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
orderDO.setCreateTime(new Date());
|
||||
orderDO.setUpdateTime(null);
|
||||
orderDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
orderMapper.insert(orderDO);
|
||||
|
||||
// order item
|
||||
@@ -119,7 +135,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Override
|
||||
public CommonResult updateOrderItem(OrderItemUpdateDTO orderUpdateDTO) {
|
||||
OrderItemDO orderItemDO = OrderConvert.INSTANCE.convert(orderUpdateDTO);
|
||||
OrderItemDO orderItemDO = OrderItemConvert.INSTANCE.convert(orderUpdateDTO);
|
||||
orderItemMapper.updateById(orderItemDO);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
@@ -161,7 +177,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Override
|
||||
public CommonResult updateLogistics(OrderLogisticsDTO orderLogisticsDTO) {
|
||||
OrderLogisticsDO orderLogisticsDO = OrderConvert.INSTANCE.convert(orderLogisticsDTO);
|
||||
OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderLogisticsDTO);
|
||||
orderLogisticsMapper.updateById(orderLogisticsDO);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<mapper namespace="cn.iocoder.mall.order.dao.OrderMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, order_logistics_id, order_no, money, payment_time,
|
||||
id, user_id, order_logistics_id, order_no, money, payment_time,
|
||||
delivery_time, receiver_time, closing_time, has_return_exchange,
|
||||
status, remark, create_time, update_time, `delete`
|
||||
status, remark, create_time, update_time, `deleted`
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
@@ -13,12 +13,12 @@
|
||||
-->
|
||||
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO `order` (
|
||||
order_logistics_id, order_no, money, payment_time,
|
||||
user_id, order_logistics_id, order_no, money, payment_time,
|
||||
delivery_time, receiver_time, closing_time,
|
||||
has_return_exchange, status, remark,
|
||||
create_time, update_time, `deleted`
|
||||
) VALUES (
|
||||
#{orderLogisticsId}, #{orderNo}, #{money}, #{paymentTime},
|
||||
#{orderLogisticsId}, #{userId}, #{orderNo}, #{money}, #{paymentTime},
|
||||
#{deliveryTime}, #{receiverTime}, #{closingTime},
|
||||
#{hasReturnExchange}, #{status}, #{remark},
|
||||
#{createTime}, #{updateTime}, #{deleted}
|
||||
@@ -82,4 +82,63 @@
|
||||
<include refid="updateFieldSql" />
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!--
|
||||
查询 - 根据id 查询
|
||||
-->
|
||||
<select id="selectById" resultType="cn.iocoder.mall.order.dataobject.OrderDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM `order`
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!--
|
||||
查询条件
|
||||
-->
|
||||
<sql id="selectWhere">
|
||||
<if test="id">
|
||||
AND `id` = #{id}
|
||||
</if>
|
||||
<if test="userId">
|
||||
AND `user_id` = #{userId}
|
||||
</if>
|
||||
<if test="orderLogisticsId">
|
||||
AND `order_logistics_id` = #{orderLogisticsId}
|
||||
</if>
|
||||
<if test="orderNo">
|
||||
AND `order_no` = #{orderNo}
|
||||
</if>
|
||||
<if test="hasReturnExchange">
|
||||
AND `has_return_exchange` = #{hasReturnExchange}
|
||||
</if>
|
||||
<if test="status">
|
||||
AND `status` = #{status}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!--
|
||||
查询 - 后台分页page Count
|
||||
-->
|
||||
<select id="selectPageCount" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM `order`
|
||||
WHERE
|
||||
<include refid="selectWhere" />
|
||||
</select>
|
||||
|
||||
<!--
|
||||
查询 - 后台分页page
|
||||
-->
|
||||
<select id="selectPage" resultType="cn.iocoder.mall.order.dataobject.OrderDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM `order`
|
||||
WHERE
|
||||
<include refid="selectWhere" />
|
||||
LIMIT
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,14 +1,19 @@
|
||||
package cn.iocoder.mall.order.service;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.OrderApplicationTest;
|
||||
import cn.iocoder.mall.order.api.OrderService;
|
||||
import cn.iocoder.mall.order.api.bo.OrderBO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO;
|
||||
import cn.iocoder.mall.order.dao.OrderMapper;
|
||||
import cn.iocoder.mall.order.dataobject.OrderDO;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -22,22 +27,25 @@ import java.util.Arrays;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = OrderApplicationTest.class)
|
||||
//@Transactional
|
||||
@Transactional
|
||||
public class OrderServiceImplTest {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Test
|
||||
public void createOrderTest() {
|
||||
|
||||
Integer userId = 1;
|
||||
OrderCreateItemDTO orderCreateItemDTO
|
||||
= new OrderCreateItemDTO()
|
||||
.setSkuId(1)
|
||||
.setQuantity(1);
|
||||
|
||||
orderService.createOrder(
|
||||
CommonResult<OrderBO> result = orderService.createOrder(
|
||||
userId,
|
||||
new OrderCreateDTO()
|
||||
.setRemark("")
|
||||
.setName("张三")
|
||||
@@ -45,5 +53,8 @@ public class OrderServiceImplTest {
|
||||
.setAddress("深圳市福田区")
|
||||
.setAreaNo("1000100")
|
||||
.setOrderItems(Arrays.asList(orderCreateItemDTO)));
|
||||
|
||||
OrderDO orderDO = orderMapper.selectById(result.getData().getId());
|
||||
Assert.assertNotNull("创建的订单不存在!", orderDO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user