24282 hai 1 ano
pai
achega
e611fda314

+ 10 - 6
sd-business/src/main/java/com/sd/business/service/order/impl/IssueBillServiceImpl.java

@@ -34,7 +34,10 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -68,7 +71,7 @@ public class IssueBillServiceImpl implements IssueBillService {
         wrapper.orderByDesc("oi", OrderInfo::getWlnCreateTime);
 
         wrapper.eq("oi", OrderInfo::getSource, 1);
-        wrapper.eq("oi", OrderInfo::getStatus, OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
+        wrapper.eq("oi", OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey());
 
         wrapper.like("oi", OrderInfo::getCode, dto.getCode());
         wrapper.eq("oi", OrderInfo::getDepartmentId, dto.getDepartmentId());
@@ -77,6 +80,8 @@ public class IssueBillServiceImpl implements IssueBillService {
         wrapper.ge("ab", OrderInfo::getDeliveryTime, dto.getBeginTime());
         wrapper.le("ab", OrderInfo::getDeliveryTime, dto.getEndTime());
 
+        wrapper.isNull("oi.master_order_id");
+
         if (dto.getPrintStatus() != null) {
             if (dto.getPrintStatus() == 1) {
                 wrapper.isNotNull("oi.wln_print_time");
@@ -220,15 +225,15 @@ public class IssueBillServiceImpl implements IssueBillService {
         List<OrderEncasement> tempOrderEncasementList = orderEncasementService.list(q -> q.eq(OrderEncasement::getOrderId, id));
         if (tempOrderEncasementList.size() == 0) {
             result.setOrderEncasementList(Collections.emptyList());
+            return result;
         }
 
         List<OrderEncasementVo> orderEncasementList = BeanUtil.copyToList(tempOrderEncasementList, OrderEncasementVo.class);
         Map<Long, OrderEncasementVo> orderEncasementVoMap = orderEncasementList.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
-        Set<Long> orderEncasementIdList = orderEncasementVoMap.keySet();
 
         // 查询包裹规格sku列表
         List<OrderEncasementDetail> tempOrderEncasementDetailList = orderEncasementDetailService.list(
-                q -> q.in(OrderEncasementDetail::getOrderEncasementId, orderEncasementIdList));
+                q -> q.in(OrderEncasementDetail::getOrderEncasementId, orderEncasementVoMap.keySet()));
         List<OrderEncasementDetailVo> orderEncasementDetailList = BeanUtil.copyToList(tempOrderEncasementDetailList, OrderEncasementDetailVo.class);
 
         // 设置包裹规格sku品号、品名
@@ -246,8 +251,7 @@ public class IssueBillServiceImpl implements IssueBillService {
         Map<Long, List<OrderEncasementDetailVo>> collect = orderEncasementDetailList.stream()
                 .collect(Collectors.groupingBy(OrderEncasementDetail::getOrderSkuId));
         for (AssemblyDetailVo.SkuInfo skuInfo : skuInfoList) {
-            List<OrderEncasementDetailVo> tempList = collect.getOrDefault(skuInfo.getOrderSkuId(), Collections.emptyList());
-            tempList.forEach(item -> {
+            collect.getOrDefault(skuInfo.getOrderSkuId(), Collections.emptyList()).forEach(item -> {
                 OrderEncasementVo orderEncasementVo = orderEncasementVoMap.get(item.getOrderEncasementId());
                 BigDecimal quantity = item.getQuantity().multiply(new BigDecimal(orderEncasementVo.getTotal()));
                 skuInfo.setSurplusQuantity(skuInfo.getSurplusQuantity().subtract(quantity));

+ 34 - 16
sd-cainiao/src/main/java/com/sd/cainiao/service/impl/IsticeServiceImpl.java

@@ -2,14 +2,12 @@ package com.sd.cainiao.service.impl;
 
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
-import com.sd.business.entity.order.po.OrderEncasement;
-import com.sd.business.entity.order.po.OrderEncasementDetail;
+import com.sd.business.entity.express.po.ExpressDelivery;
+import com.sd.business.entity.order.enums.OrderStatusEnum;
 import com.sd.business.entity.order.po.OrderInfo;
-import com.sd.business.entity.order.po.OrderSku;
-import com.sd.business.service.order.OrderEncasementDetailService;
-import com.sd.business.service.order.OrderEncasementService;
-import com.sd.business.service.order.OrderService;
-import com.sd.business.service.order.OrderSkuService;
+import com.sd.business.entity.order.vo.AssemblyDetailVo;
+import com.sd.business.service.express.ExpressDeliveryService;
+import com.sd.business.service.order.*;
 import com.sd.cainiao.entity.bo.BasicKeyBo;
 import com.sd.cainiao.entity.dto.TakeNumParamDto;
 import com.sd.cainiao.service.IsticeService;
@@ -20,11 +18,14 @@ import com.taobao.pac.sdk.cp.dataobject.response.TMS_WAYBILL_GET.TmsWaybillGetRe
 import com.taobao.pac.sdk.cp.dataobject.response.TMS_WAYBILL_GET.WaybillCloudPrintResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -34,6 +35,9 @@ public class IsticeServiceImpl implements IsticeService {
     private BasicKeyBo basicKeyBo;
 
     @Autowired
+    private IssueBillService issueBillService;
+
+    @Autowired
     private OrderService orderService;
 
     @Autowired
@@ -45,23 +49,37 @@ public class IsticeServiceImpl implements IsticeService {
     @Autowired
     private OrderEncasementDetailService orderEncasementDetailService;
 
+    @Autowired
+    private ExpressDeliveryService expressDeliveryService;
+
+    @Transactional(rollbackFor = Exception.class)
     @Override
-    public List<Map<String, Object>> takeNumBatch(List<Long> orderIdList) {
+    public synchronized List<Map<String, Object>> takeNumBatch(List<Long> orderIdList) {
 
         if (orderIdList.size() == 0) {
             return Collections.emptyList();
         }
 
-        List<OrderInfo> orderList = orderService.list(q -> q
-                .and(r -> r.eq(BaseIdPo::getId, orderIdList).isNull(OrderInfo::getMasterOrderId))
-                .or().in(OrderInfo::getMasterOrderId, orderIdList));
-        List<Long> allOrderIdList = orderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+        List<OrderInfo> orderInfoList = orderService.list(q -> q
+                .in(BaseIdPo::getId, orderIdList)
+                .eq(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey())
+        );
 
-        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, allOrderIdList));
-        List<Long> allOrderSkuIdList = orderSkuList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+        List<String> expressDeliveryIdList = orderInfoList.stream().map(OrderInfo::getExpressDeliveryId).collect(Collectors.toList());
+        List<ExpressDelivery> expressDeliveries = expressDeliveryService.listByIds(expressDeliveryIdList);
+        Map<Long, ExpressDelivery> collect = expressDeliveries.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
 
-        List<OrderEncasement> orderEncasementList = orderEncasementService.list(q -> q.in(OrderEncasement::getOrderId, allOrderIdList));
-        List<OrderEncasementDetail> orderEncasementDetailList = orderEncasementDetailService.list(q -> q.in(OrderEncasementDetail::getOrderSkuId, allOrderSkuIdList));
+        for (OrderInfo orderInfo : orderInfoList) {
+            AssemblyDetailVo assemblyDetailVo = issueBillService.assemblyDetail(orderInfo.getId());
+
+            for (AssemblyDetailVo.SkuInfo skuInfo : assemblyDetailVo.getSkuInfoList()) {
+                if (skuInfo.getSurplusQuantity().compareTo(BigDecimal.ZERO) > 0) {
+                    throw new ServiceException("订单 " + orderInfo.getCode() + " 未包装包裹,打印快递单失败");
+                }
+            }
+
+
+        }
 
 
         // List<Map<String, Object>> resultList = new ArrayList<>();