From 6a728ff4105c78bfeb48dc5c97b3f837945c418b Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Thu, 11 Apr 2019 23:07:55 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E5=8F=91=E8=B4=A7=20bug?= =?UTF-8?q?=EF=BC=8C=E5=A4=9A=E5=8F=91=E8=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/constant/OrderErrorCodeEnum.java | 6 +- .../order/biz/service/OrderServiceImpl.java | 85 +++++++++---------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java index 00bb00fe8..b9ca8ffe1 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java @@ -21,11 +21,11 @@ public enum OrderErrorCodeEnum { ORDER_GOODS_AMOUNT_INCORRECT(1008000007, "商品金额非法!"), ORDER_GET_GOODS_INFO_INCORRECT(1008000008, "获取额商品信息不正确!"), ORDER_GET_USER_ADDRESS_FAIL(1008000009, "获取用户地址失败!"), - ORDER_GET_PAY_FAIL(1008000009, "调用pay失败!"), + ORDER_GET_PAY_FAIL(1008000010, "调用pay失败!"), // order item - ORDER_ITEM_ONLY_ONE(1008000004, "订单Item只有一个!"), - ORDER_ITEM_SOME_NOT_EXISTS(-1, "有不存在的商品"), // TODO 芋艿 后面改下错误码 + ORDER_ITEM_ONLY_ONE(1008000200, "订单Item只有一个!"), + ORDER_ITEM_SOME_NOT_EXISTS(1008000201, "有不存在的商品!"), // ========== 购物车 ========== 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 5c283945f..8d1e3780d 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 @@ -1,7 +1,6 @@ package cn.iocoder.mall.order.biz.service; import cn.iocoder.common.framework.constant.DeletedStatusEnum; -import cn.iocoder.common.framework.util.DateUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.OrderService; @@ -9,7 +8,6 @@ import cn.iocoder.mall.order.api.bo.*; 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.constant.PayAppId; import cn.iocoder.mall.order.api.dto.*; import cn.iocoder.mall.order.biz.OrderCommon; import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum; @@ -21,9 +19,8 @@ import cn.iocoder.mall.order.biz.convert.OrderRecipientConvert; import cn.iocoder.mall.order.biz.dao.*; import cn.iocoder.mall.order.biz.dataobject.*; import cn.iocoder.mall.pay.api.PayTransactionService; -import cn.iocoder.mall.pay.api.dto.PayTransactionCreateDTO; import cn.iocoder.mall.product.api.ProductSpuService; -import cn.iocoder.mall.product.api.bo.ProductSpuBO; +import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; import cn.iocoder.mall.user.api.UserAddressService; import cn.iocoder.mall.user.api.bo.UserAddressBO; import com.alibaba.dubbo.config.annotation.Reference; @@ -31,7 +28,6 @@ import com.google.common.collect.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.util.CollectionUtils; import java.util.*; @@ -92,7 +88,7 @@ public class OrderServiceImpl implements OrderService { .map(orderDO -> orderDO.getId()) .collect(Collectors.toSet()); - // 获取物流信息 + // 获取配送信息 List orderRecipientDOList = orderRecipientMapper.selectByOrderIds(orderIds); List orderRecipientBOList = OrderRecipientConvert.INSTANCE.convert(orderRecipientDOList); Map orderRecipientBOMap @@ -125,8 +121,7 @@ public class OrderServiceImpl implements OrderService { } return orderBO; }).collect(Collectors.toList()); - - return CommonResult.success( + return CommonResult.success( new OrderPageBO() .setTotal(totalCount) .setOrders(result) @@ -168,54 +163,57 @@ public class OrderServiceImpl implements OrderService { Set skuIds = orderItemDOList.stream() .map(orderItemDO -> orderItemDO.getSkuId()).collect(Collectors.toSet()); - CommonResult> result = productSpuService.getProductSpuList(skuIds); + CommonResult> productResult = productSpuService.getProductSkuDetailList(skuIds); // 校验商品信息 - if (result.isError()) { + if (productResult.isError()) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_SKU_FAIL.getCode()); } - if (result.getData() == null) { + if (productResult.getData() == null) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_SKU_NOT_EXISTENT.getCode()); } - if (orderItemDTOList.size() != result.getData().size()) { + if (orderItemDTOList.size() != productResult.getData().size()) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_GOODS_INFO_INCORRECT.getCode()); } // 设置 orderItem - Map productSpuBOMap = result.getData() + Map productSpuBOMap = productResult.getData() .stream().collect(Collectors.toMap(o -> o.getId(), o -> o)); for (OrderItemDO orderItemDO : orderItemDOList) { - ProductSpuBO productSpuBO = productSpuBOMap.get(orderItemDO.getSkuId()); - if (productSpuBO.getQuantity() <= 0) { + ProductSkuDetailBO productSkuDetailBO = productSpuBOMap.get(orderItemDO.getSkuId()); + if (productSkuDetailBO.getQuantity() <= 0) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_INSUFFICIENT_INVENTORY.getCode()); } - if (productSpuBO.getPrice() <= 0) { + if (productSkuDetailBO.getPrice() <= 0) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GOODS_AMOUNT_INCORRECT.getCode()); } - orderItemDO.setSkuImage(Optional.ofNullable(productSpuBO.getPicUrls().get(0)).get()); - orderItemDO.setSkuName(productSpuBO.getName()); - orderItemDO.setPrice(productSpuBO.getPrice()); + orderItemDO.setSkuImage(Optional.ofNullable(productSkuDetailBO.getSpu().getPicUrls().get(0)).get()); + orderItemDO.setSkuName(productSkuDetailBO.getSpu().getName()); + orderItemDO.setPrice(productSkuDetailBO.getPrice()); int payAmount = orderItemDO.getQuantity() * orderItemDO.getPrice(); orderItemDO.setPayAmount(payAmount); } // order + + // TODO: 2019-04-11 Sin 订单号需要生成规则 + String orderNo = UUID.randomUUID().toString().replace("-", "").substring(0, 16); Integer totalAmount = orderCommon.calculatedAmount(orderItemDOList); OrderDO orderDO = new OrderDO() .setUserId(userId) - .setOrderNo(UUID.randomUUID().toString().replace("-", "")) + .setOrderNo(orderNo) .setPayAmount(totalAmount) .setClosingTime(null) .setDeliveryTime(null) .setPaymentTime(null) - .setStatus(OrderStatusEnum.WAIT_SHIPMENT.getValue()) + .setStatus(OrderStatusEnum.WAITING_PAYMENT.getValue()) .setHasReturnExchange(OrderHasReturnExchangeEnum.NO.getValue()) .setRemark(Optional.ofNullable(orderCreateDTO.getRemark()).orElse("")); @@ -259,24 +257,24 @@ public class OrderServiceImpl implements OrderService { // 创建预订单 // TODO sin 支付订单 orderSubject 暂时取第一个子订单商品信息 - String orderSubject = orderItemDOList.get(0).getSkuName(); - Date expireTime = DateUtil.addDate(Calendar.MINUTE, PAY_EXPIRE_TIME); - CommonResult commonResult = payTransactionService.createTransaction( - new PayTransactionCreateDTO() - .setCreateIp(orderCreateDTO.getIp()) - .setAppId(PayAppId.APP_ID_1024) - .setExpireTime(expireTime) - .setPrice(orderDO.getPayAmount()) - .setOrderSubject(orderSubject) - .setOrderMemo(orderDO.getRemark()) - .setOrderDescription("") - ); +// String orderSubject = orderItemDOList.get(0).getSkuName(); +// Date expireTime = DateUtil.addDate(Calendar.MINUTE, PAY_EXPIRE_TIME); +// CommonResult commonResult = payTransactionService.createTransaction( +// new PayTransactionCreateDTO() +// .setCreateIp(orderCreateDTO.getIp()) +// .setAppId(PayAppId.APP_ID_1024) +// .setExpireTime(expireTime) +// .setPrice(orderDO.getPayAmount()) +// .setOrderSubject(orderSubject) +// .setOrderMemo(orderDO.getRemark()) +// .setOrderDescription("") +// ); - if (commonResult.isError()) { - //手动开启事务回滚 - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_PAY_FAIL.getCode()); - } +// if (commonResult.isError()) { +// //手动开启事务回滚 +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_PAY_FAIL.getCode()); +// } // TODO: 2019-03-17 Sin 需要发送 创建成果 MQ 消息,业务扩展和统计 return CommonResult.success( @@ -370,10 +368,6 @@ public class OrderServiceImpl implements OrderService { && OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus()) .collect(Collectors.toList()); - List deliveredOrderItems = allOrderItems.stream() - .filter(orderItemDO -> OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus()) - .collect(Collectors.toList()); - // 发货订单,检查 if (needDeliveryOrderItems.size() != orderItemIds.size()) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_DELIVERY_INCORRECT_DATA.getCode()); @@ -400,7 +394,12 @@ public class OrderServiceImpl implements OrderService { ); // 子订单是否全部发货,如果发完,就更新 order - if (deliveredOrderItems.size() <= 0) { + List unShippedOrderItems = allOrderItems.stream() + .filter(orderItemDO -> OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus() + && !orderItemIds.contains(orderItemDO.getId())) + .collect(Collectors.toList()); + + if (unShippedOrderItems.size() <= 0) { orderMapper.updateById( new OrderDO() .setId(orderDelivery.getOrderId())