diff --git a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/bo/app/OrderBO.java b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/bo/app/OrderBO.java index d27348821..86191e013 100644 --- a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/bo/app/OrderBO.java +++ b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/bo/app/OrderBO.java @@ -1,10 +1,7 @@ package com.youlai.mall.oms.pojo.bo.app; -import com.youlai.common.base.BaseVO; -import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery; import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.domain.OmsOrderItem; -import com.youlai.mall.oms.pojo.domain.OmsOrderLog; import lombok.Data; import java.util.List; @@ -22,8 +19,4 @@ public class OrderBO { private List orderItems; - private OmsOrderLog orderLog; - - private OmsOrderDelivery orderDelivery; - } diff --git a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrder.java b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrder.java index dc8d181b4..8f4eca145 100644 --- a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrder.java +++ b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrder.java @@ -1,13 +1,16 @@ package com.youlai.mall.oms.pojo.domain; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.youlai.common.base.BaseEntity; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import java.util.Date; +import java.util.List; /** * 订单详情表 @@ -94,5 +97,7 @@ public class OmsOrder extends BaseEntity { */ private Integer deleted; + @TableField(exist = false) + private List orderItems; } diff --git a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrderItem.java b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrderItem.java index 744f4e6df..4740e9d3d 100644 --- a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrderItem.java +++ b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/domain/OmsOrderItem.java @@ -3,8 +3,10 @@ package com.youlai.mall.oms.pojo.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.youlai.common.base.BaseEntity; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import lombok.experimental.Accessors; /** @@ -17,8 +19,9 @@ import lombok.experimental.Accessors; @Data @Accessors(chain = true) @Builder +@AllArgsConstructor +@NoArgsConstructor public class OmsOrderItem extends BaseEntity { - /** * id */ @@ -89,4 +92,6 @@ public class OmsOrderItem extends BaseEntity { */ private Integer deleted; + + } diff --git a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/vo/OrderListVO.java b/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/vo/OrderListVO.java deleted file mode 100644 index d7b737f96..000000000 --- a/mall-oms/oms-api/src/main/java/com/youlai/mall/oms/pojo/vo/OrderListVO.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.youlai.mall.oms.pojo.vo; - -import com.youlai.common.base.BaseVO; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Date; -import java.util.List; - -/** - * @author huawei - * @desc - * @email huawei_code@163.com - * @date 2021/2/13 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OrderListVO extends BaseVO { - - /** - * time : 2019-04-06 11:37 - * state : 9 - * goodsList : [{"title":"古黛妃 短袖t恤女 春夏装2019新款韩版宽松","price":179.5,"image":"https://img13.360buyimg.com/n8/jfs/t1/30343/20/1029/481370/5c449438Ecb46a15b/2b2adccb6dc742fd.jpg","number":1,"attr":"珊瑚粉 M"}] - */ - - private Long id; - private String orderSn; - private Long totalAmount; - private Long payAmount; - private Date gmtCreate; - - private Integer totalQuantity; - private String time; - private Integer status; - private String statusDesc; - private List orderItemLIst; - - @Data - public static class OrderItemBean extends BaseVO { - - /** - * title : 古黛妃 短袖t恤女 春夏装2019新款韩版宽松 - * price : 179.5 - * image : https://img13.360buyimg.com/n8/jfs/t1/30343/20/1029/481370/5c449438Ecb46a15b/2b2adccb6dc742fd.jpg - * number : 1 - * attr : 珊瑚粉 M - */ - private Long id; - private Long orderId; - private String skuId; - private String skuPic; - private Integer skuQuantity; - private Long skuTotalPrice; - private String title; - private Long price; - private String image; - private Integer number; - private String attr; - - - } -} diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/OrderController.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/OrderController.java index 926a92faf..20fa155bf 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/OrderController.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/OrderController.java @@ -1,10 +1,12 @@ package com.youlai.mall.oms.controller.app; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.youlai.common.result.Result; import com.youlai.mall.oms.enums.PayTypeEnum; +import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.dto.OrderConfirmDTO; import com.youlai.mall.oms.pojo.vo.OrderConfirmVO; -import com.youlai.mall.oms.pojo.vo.OrderListVO; import com.youlai.mall.oms.pojo.vo.OrderSubmitVO; import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO; import com.youlai.mall.oms.service.IOrderPayService; @@ -13,9 +15,7 @@ import io.swagger.annotations.*; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; - import javax.validation.Valid; -import java.util.List; /** @@ -33,24 +33,31 @@ public class OrderController { private IOrderService orderService; private IOrderPayService orderPayService; - @ApiOperation("订单列表") @GetMapping - @ApiImplicitParam(name = "status", value = "订单状态", required = true, defaultValue = "0") - public Result> list(Integer status) { - List orderList = orderService.list(status); - return Result.success(orderList); + @ApiImplicitParams({ + @ApiImplicitParam(name = "page",defaultValue = "1", value = "页码", paramType = "query", dataType = "Long"), + @ApiImplicitParam(name = "limit",defaultValue = "10", value = "每页数量", paramType = "query", dataType = "Long"), + @ApiImplicitParam(name = "status", value = "订单状态", paramType = "query", dataType = "Integer") + }) + public Result list( + Long page, + Long limit, + Integer status + ) { + IPage result = orderService.list(new Page<>(page, limit), new OmsOrder().setStatus(status)); + return Result.success(result.getRecords(), result.getTotal()); } - @ApiOperation( "订单确认") - @ApiImplicitParam(name = "orderConfirm",value = "确认订单信息",required = true, paramType = "body", dataType = "OrderConfirmDTO") + @ApiOperation("订单确认") + @ApiImplicitParam(name = "orderConfirm", value = "确认订单信息", required = true, paramType = "body", dataType = "OrderConfirmDTO") @PostMapping("/_confirm") public Result confirm(@RequestBody OrderConfirmDTO orderConfirm) { OrderConfirmVO result = orderService.confirm(orderConfirm); return Result.success(result); } - @ApiOperation( "订单提交") + @ApiOperation("订单提交") @ApiImplicitParam(name = "orderSubmitDTO", value = "提交订单信息", required = true, paramType = "body", dataType = "orderSubmitDTO") @PostMapping("/_submit") public Result submit(@Valid @RequestBody OrderSubmitDTO orderSubmitDTO) { diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderItemMapper.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderItemMapper.java index ac8d6182c..b87f75d2d 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderItemMapper.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderItemMapper.java @@ -2,7 +2,11 @@ package com.youlai.mall.oms.mapper; import com.youlai.mall.oms.pojo.domain.OmsOrderItem; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.youlai.mall.pms.pojo.domain.PmsSku; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * 订单商品信息表 @@ -14,4 +18,9 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface OrderItemMapper extends BaseMapper { + @Select("") + List listByOrderId(Long orderId); + } diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderMapper.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderMapper.java index e65cfa092..9cec836af 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderMapper.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/mapper/OrderMapper.java @@ -1,8 +1,10 @@ package com.youlai.mall.oms.mapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.*; +import java.util.List; /** * 订单详情表 @@ -14,4 +16,17 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface OrderMapper extends BaseMapper { + + @Select("") + @Results({ + @Result(id = true, column = "id", property = "id"), + @Result(property = "orderItems",column = "id",many = @Many(select="com.youlai.mall.oms.mapper.OrderItemMapper.listByOrderId")) + }) + List list(Page page, OmsOrder order); } diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/IOrderService.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/IOrderService.java index bb701499e..2d77e6969 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/IOrderService.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/IOrderService.java @@ -1,11 +1,12 @@ package com.youlai.mall.oms.service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.dto.OrderConfirmDTO; import com.youlai.mall.oms.pojo.vo.OrderConfirmVO; -import com.youlai.mall.oms.pojo.vo.OrderListVO; import com.youlai.mall.oms.pojo.vo.OrderSubmitVO; import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO; @@ -30,9 +31,6 @@ public interface IOrderService extends IService { */ OrderSubmitVO submit(OrderSubmitDTO orderSubmitDTO) ; - - - /** * 系统关闭订单 */ @@ -48,14 +46,7 @@ public interface IOrderService extends IService { */ boolean deleteOrder(Long id); - /** - * 订单列表查询 - */ - List list(Integer status); - /** - * 根据订单ID获取订单信息 - */ - OmsOrder getByOrderId(Long id); + IPage list(Page omsOrderPage, OmsOrder order); } diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderPayServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderPayServiceImpl.java index eb22c34db..c181e793e 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderPayServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderPayServiceImpl.java @@ -36,7 +36,7 @@ public class OrderPayServiceImpl extends ServiceImpl impleme */ @Override public OrderConfirmVO confirm(OrderConfirmDTO orderConfirmDTO) { - log.info("=======================订单确认======================="); + log.info("=======================订单确认=======================\n订单确认信息:{}",orderConfirmDTO); OrderConfirmVO orderConfirmVO = new OrderConfirmVO(); Long memberId = RequestUtils.getUserId(); // 获取购买商品信息 @@ -112,7 +115,7 @@ public class OrderServiceImpl extends ServiceImpl impleme }, threadPoolExecutor); CompletableFuture.allOf(orderItemsCompletableFuture, addressesCompletableFuture, orderTokenCompletableFuture).join(); - log.info("获取确认信息",orderConfirmVO.toString()); + log.info("订单确认响应:{}", orderConfirmVO.toString()); return orderConfirmVO; } @@ -122,7 +125,7 @@ public class OrderServiceImpl extends ServiceImpl impleme @Override @GlobalTransactional public OrderSubmitVO submit(OrderSubmitDTO submitDTO) { - log.info("=======================订单提交======================="); + log.info("=======================订单提交=======================\n订单提交信息:{}",submitDTO); // 订单重复提交校验 String orderToken = submitDTO.getOrderToken(); DefaultRedisScript redisScript = new DefaultRedisScript<>(RELEASE_LOCK_LUA_SCRIPT, Long.class); @@ -134,7 +137,7 @@ public class OrderServiceImpl extends ServiceImpl impleme List orderItems = submitDTO.getOrderItems(); if (CollectionUtil.isEmpty(orderItems)) { - throw new BizException("请选择商品再提交"); + throw new BizException("订单"); } // 订单验价 @@ -184,23 +187,24 @@ public class OrderServiceImpl extends ServiceImpl impleme .build()).collect(Collectors.toList()); orderItemService.saveBatch(orderItemList); - // 将订单放入延时队列,超时未支付系统自动关单 + // 将订单放入延时队列,超时未支付由交换机order.exchange切换到死信队列完成系统自动关单 rabbitTemplate.convertAndSend("order.exchange", "order.create", orderToken); OrderSubmitVO submitVO = new OrderSubmitVO(); submitVO.setOrderId(order.getId()); submitVO.setOrderSn(order.getOrderSn()); - log.info("订单提交返回结果:{}",submitVO.toString()); + log.info("订单提交响应:{}", submitVO.toString()); return submitVO; } @Override public boolean closeOrder(String orderToken) { + log.info("=======================订单关闭,订单SN:{}=======================", orderToken); OmsOrder order = this.getOne(new LambdaQueryWrapper() .eq(OmsOrder::getOrderSn, orderToken)); if (!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) { - return false; + return false; } order.setStatus(OrderStatusEnum.AUTO_CANCEL.getCode()); return this.updateById(order); @@ -208,67 +212,47 @@ public class OrderServiceImpl extends ServiceImpl impleme @Override public boolean cancelOrder(Long id) { - OmsOrder order = getByOrderId(id); - if (!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) { - throw new BizException("取消失败,订单状态不支持取消"); + log.info("=======================订单取消,订单ID:{}=======================", id); + OmsOrder order = this.getById(id); + + if ( order != null &&!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus()) ) { + throw new BizException("取消失败,订单状态不支持取消"); // 通过自定义异常,将异常信息抛出由异常处理器捕获显示给前端页面 } order.setStatus(OrderStatusEnum.USER_CANCEL.getCode()); - return this.updateById(order); + boolean result = this.updateById(order); + if(result){ + // 释放被锁定的库存 + Result unlockResult = skuFeignService.unlockStock(order.getOrderSn()); + if(!Result.isSuccess(unlockResult)){ + throw new BizException(unlockResult.getMsg()); + } + result=true; + } + return result; } @Override @Transactional(rollbackFor = Exception.class) public boolean deleteOrder(Long id) { - // 查询订单,校验订单状态 - OmsOrder order = this.getByOrderId(id); - if (!OrderStatusEnum.AUTO_CANCEL.getCode().equals(order.getStatus()) && - !OrderStatusEnum.USER_CANCEL.getCode().equals(order.getStatus())) { - throw new BizException("删除失败,订单状态不允许删除"); + log.info("=======================订单删除,订单ID:{}=======================", id); + OmsOrder order = this.getById(id); + if ( + order != null && + !OrderStatusEnum.AUTO_CANCEL.getCode().equals(order.getStatus()) && + !OrderStatusEnum.USER_CANCEL.getCode().equals(order.getStatus()) + ) { + throw new BizException("订单删除失败,订单不存在或订单状态不支持删除"); } return this.removeById(id); } - @Override - public List list(Integer status) { - log.info("订单列表查询,status={}", status); - QueryWrapper orderQuery = new QueryWrapper<>(); - if (status != 0) { - orderQuery.eq("status", status); - } - orderQuery.orderByDesc("id"); - List orderList = this.list(orderQuery); - if (orderList == null || orderList.size() <= 0) { - log.info("订单列表查询结果为空,status={}", status); - return null; - } - List orderIds = orderList.stream().map(order -> order.getId()).collect(Collectors.toList()); - Map> orderItemsMap = orderItemService.getByOrderIds(orderIds); - - List result = orderList.stream().map(order -> { - OrderListVO orderListVO = BeanMapperUtils.map(order, OrderListVO.class); - orderListVO.setStatusDesc(OrderStatusEnum.getValue(orderListVO.getStatus()).getText()); - List orderItems = orderItemsMap.get(orderListVO.getId()); - if (CollectionUtil.isNotEmpty(orderItems)) { - List orderItemBeans = orderItems.stream() - .map(orderItem -> BeanMapperUtils.map(orderItem, OrderListVO.OrderItemBean.class)) - .collect(Collectors.toList()); - orderListVO.setOrderItemLIst(orderItemBeans); - } - return orderListVO; - }).collect(Collectors.toList()); - return result; - } @Override - public OmsOrder getByOrderId(Long id) { - Long memberId = RequestUtils.getUserId(); - OmsOrder order = this.getOne(new LambdaQueryWrapper() - .eq(OmsOrder::getId, id) - .eq(OmsOrder::getMemberId, memberId)); - if (order == null) { - throw new BizException("订单不存在,订单ID非法"); - } - return order; + public IPage list(Page page, OmsOrder order) { + List list = this.baseMapper.list(page, order); + page.setRecords(list); + return page; } + } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSpuMapper.java similarity index 95% rename from mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java rename to mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSpuMapper.java index e410c332c..a06fe0fd2 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSpuMapper.java @@ -16,7 +16,7 @@ import java.util.List; * @date 2020-11-06 */ @Mapper -public interface PmsProductMapper extends BaseMapper { +public interface PmsSpuMapper extends BaseMapper { @Select("