浏览代码

退回库存

刘俊驰 1 年之前
父节点
当前提交
503109f733

+ 51 - 2
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/open/OpenController.java

@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -105,7 +106,31 @@ public class OpenController {
 
         log.info("创建管乐迷订单:{}", JSON.toJSONString(order));
 
-        orderService.mecProductOrderCreate(order);
+        if (!CollectionUtils.isEmpty(order.getCloseOrderNoList())) {
+
+            RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_REFUND_ORDER_MALL + ":delivery");
+            try {
+                boolean b = lock.tryLock(60, 60, TimeUnit.SECONDS);
+                if (b) {
+                    orderService.mecProductOrderCreate(order);
+
+                    return CommonResult.success(true);
+
+
+                }
+            } catch (InterruptedException e) {
+                log.error("批量修改订单", e);
+            } finally {
+                if (lock.getHoldCount() >0) {
+                    lock.unlock();
+                }
+            }
+        } else {
+            orderService.mecProductOrderCreate(order);
+
+
+        }
+
 
 
         return CommonResult.success(true);
@@ -137,7 +162,31 @@ public class OpenController {
     public CommonResult<Boolean> productUpdateOrderStatus(@RequestParam("orderNo") String orderNo,@RequestParam("status") Integer status) {
         log.info("同步订单状态:{},{}", orderNo, status);
         // 已发货订单不可修改状态
-        orderService.productUpdateOrderStatus(orderNo, status);
+
+        if (status == 4) {
+
+            RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_REFUND_ORDER_MALL + ":delivery");
+            try {
+                boolean b = lock.tryLock(60, 60, TimeUnit.SECONDS);
+                if (b) {
+                    orderService.productUpdateOrderStatus(orderNo, status);
+
+                    return CommonResult.success(true);
+
+
+                }
+            } catch (InterruptedException e) {
+                log.error("批量修改订单", e);
+            } finally {
+                if (lock.getHoldCount() >0) {
+                    lock.unlock();
+                }
+            }
+        } else {
+            orderService.productUpdateOrderStatus(orderNo, status);
+
+
+        }
 
         return CommonResult.success(true);
     }

+ 28 - 11
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -789,11 +789,18 @@ public class OmsOrderServiceImpl implements OmsOrderService {
 
         // 关闭需要关闭的订单
         if(!CollectionUtils.isEmpty(order.getCloseOrderNoList())) {
+
             OmsOrderExample example = new OmsOrderExample();
             example.createCriteria().andOrderSnIn(order.getCloseOrderNoList());
-            OmsOrder record = new OmsOrder();
-            record.setStatus(4);
-            orderMapper.updateByExampleSelective(record, example);
+            List<OmsOrder> omsOrders = orderMapper.selectByExample(example);
+            if (!CollectionUtils.isEmpty(omsOrders)) {
+                List<Long> orderIds = omsOrders.stream().map(OmsOrder::getId).collect(Collectors.toList());
+                OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate = new OmsOrderWrapper.OrderStatusUpdate();
+                orderStatusUpdate.setIds(orderIds);
+                orderStatusUpdate.setStatus(4);
+                updateStatus(orderStatusUpdate);
+            }
+
         }
 
         // 如果订单状态是已发货,扣减库存
@@ -811,14 +818,24 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         if (detail == null) {
             throw new BizException("订单不存在");
         }
-//        if (detail.getStatus() != 1 ) {
-//            throw new BizException("当前订单状态不允许修改");
-//        }
-        OmsOrder omsOrder = new OmsOrder();
-        omsOrder.setId(detail.getId());
-        omsOrder.setStatus(status);
-        omsOrder.setModifyTime(new Date());
-        orderMapper.updateByPrimaryKeySelective(omsOrder);
+        if (status == 4) {
+            OmsOrderExample example = new OmsOrderExample();
+            example.createCriteria().andOrderSnEqualTo(orderNo);
+            List<OmsOrder> omsOrders = orderMapper.selectByExample(example);
+            if (!CollectionUtils.isEmpty(omsOrders)) {
+                List<Long> orderIds = omsOrders.stream().map(OmsOrder::getId).collect(Collectors.toList());
+                OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate = new OmsOrderWrapper.OrderStatusUpdate();
+                orderStatusUpdate.setIds(orderIds);
+                orderStatusUpdate.setStatus(4);
+                updateStatus(orderStatusUpdate);
+            }
+        } else {
+            OmsOrder omsOrder = new OmsOrder();
+            omsOrder.setId(detail.getId());
+            omsOrder.setStatus(status);
+            omsOrder.setModifyTime(new Date());
+            orderMapper.updateByPrimaryKeySelective(omsOrder);
+        }
 
 
         return true;