24282 2 年 前
コミット
1bd89455c7

+ 36 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/logistics/DeliverDetailsVo.java

@@ -3,9 +3,45 @@ package com.fjhx.params.logistics;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 @Getter
 @Setter
 public class DeliverDetailsVo {
 
+    /**
+     * 采购id
+     */
+    private Long purchaseId;
+
+    /**
+     * 申购id
+     */
+    private Long applyPurchaseId;
+
+    /**
+     * 产品id
+     */
+    private Long productId;
+
+    /**
+     * 产品编号
+     */
+    private String productCode;
+
+    /**
+     * 产品名称
+     */
+    private String productName;
+
+    /**
+     * 申购数量
+     */
+    private BigDecimal purchaseQuantity;
+
+    /**
+     * 已发数量
+     */
+    private BigDecimal deliverQuantity;
 
 }

+ 4 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/logistics/LogisticsInfoVo.java

@@ -14,5 +14,9 @@ import lombok.EqualsAndHashCode;
 @EqualsAndHashCode(callSuper = true)
 public class LogisticsInfoVo extends LogisticsInfo {
 
+    /**
+     * 采购id
+     */
+    private Long purchaseId;
 
 }

+ 3 - 3
hx-service/victoriatourist/src/main/java/com/fjhx/controller/logistics/LogisticsInfoController.java

@@ -84,7 +84,7 @@ public class LogisticsInfoController {
      */
     @PostMapping("/deliverDetails")
     public R deliverDetails(@RequestBody LogisticsInfoVo entity) {
-        List<DeliverDetailsVo> list = logisticsInfoService.deliverDetails(entity.getBusinessId());
+        List<DeliverDetailsVo> list = logisticsInfoService.deliverDetails(entity.getId());
         return R.success(list);
     }
 
@@ -96,8 +96,8 @@ public class LogisticsInfoController {
      */
     @PostMapping("/arrival/notice")
     public R arrivalNotice(@RequestBody LogisticsInfoVo entity) {
-        entity.setStatus(LogisticsConstant.Status.STATUS_1);
-        return R.success(logisticsInfoService.updateById(entity));
+        logisticsInfoService.arrivalNotice(entity);
+        return R.success();
     }
 
 }

+ 9 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/LogisticsDetailsService.java

@@ -5,6 +5,7 @@ import com.fjhx.base.BaseService;
 import com.fjhx.entity.logistics.LogisticsDetails;
 import com.fjhx.params.logistics.LogisticsDetailsVo;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -34,4 +35,12 @@ public interface LogisticsDetailsService extends BaseService<LogisticsDetails> {
      */
     List<LogisticsDetails> getByLogisticsInfoId(Long logisticsInfoId);
 
+    /**
+     * 获取已发货数量map
+     *
+     * @param purchaseId 采购单id
+     * @return 已发货数量map<申购单id, 已发货数量>
+     */
+    Map<Long, BigDecimal> getDeliverQuantityMap(Long purchaseId);
+
 }

+ 9 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/LogisticsInfoService.java

@@ -67,6 +67,14 @@ public interface LogisticsInfoService extends BaseService<LogisticsInfo> {
      */
     List<LogisticsInfo> codeSelectByBusinessId(Long businessId);
 
-    List<DeliverDetailsVo> deliverDetails(Long businessId);
+    /**
+     * 发货通知-》发货明细
+     */
+    List<DeliverDetailsVo> deliverDetails(Long id);
+
+    /**
+     * 到货通知
+     */
+    void arrivalNotice(LogisticsInfoVo entity);
 
 }

+ 16 - 3
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsDetailsServiceImpl.java

@@ -2,18 +2,17 @@ package com.fjhx.service.logistics.impl;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fjhx.base.Condition;
 import com.fjhx.entity.logistics.LogisticsDetails;
 import com.fjhx.mapper.logistics.LogisticsDetailsMapper;
 import com.fjhx.params.logistics.LogisticsDetailsVo;
 import com.fjhx.service.logistics.LogisticsDetailsService;
-import com.fjhx.utils.Assert;
 import com.fjhx.utils.wrapperUtil.IWrapper;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -60,4 +59,18 @@ public class LogisticsDetailsServiceImpl extends ServiceImpl<LogisticsDetailsMap
         return baseMapper.getByLogisticsInfoId(logisticsInfoId);
     }
 
+    @Override
+    public Map<Long, BigDecimal> getDeliverQuantityMap(Long purchaseId) {
+
+        // 已发货列表
+        List<LogisticsDetails> list = this.list(q -> q.eq(LogisticsDetails::getPurchaseId, purchaseId));
+        // 计算出每个采购单已出货数量
+        return list.stream().collect(Collectors.toMap(
+                LogisticsDetails::getApplyPurchaseId,
+                LogisticsDetails::getShipmentQuantity,
+                BigDecimal::add
+        ));
+
+    }
+
 }

+ 120 - 5
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsInfoServiceImpl.java

@@ -1,19 +1,27 @@
 package com.fjhx.service.logistics.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.base.BaseIdEntity;
 import com.fjhx.constants.logistics.LogisticsConstant;
 import com.fjhx.entity.apply.ApplyPurchase;
+import com.fjhx.entity.logistics.LogisticsDetails;
 import com.fjhx.entity.logistics.LogisticsInfo;
+import com.fjhx.entity.product.ProductInfo;
 import com.fjhx.entity.purchase.Purchase;
 import com.fjhx.enums.purchase.PurchaseStatusEnum;
 import com.fjhx.mapper.logistics.LogisticsInfoMapper;
 import com.fjhx.params.logistics.DeliverDetailsVo;
 import com.fjhx.params.logistics.LogisticsInfoVo;
+import com.fjhx.service.apply.ApplyPurchaseService;
 import com.fjhx.service.logistics.LogisticsDetailsService;
 import com.fjhx.service.logistics.LogisticsInfoService;
+import com.fjhx.service.product.ProductInfoService;
+import com.fjhx.service.purchase.PurchaseService;
 import com.fjhx.uitl.kd100.KD100Util;
+import com.fjhx.utils.Assert;
 import com.fjhx.utils.FileClientUtil;
 import com.fjhx.utils.UserClientUtil;
 import com.fjhx.utils.wrapperUtil.IWrapper;
@@ -42,6 +50,15 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
     @Autowired
     private LogisticsDetailsService logisticsDetailsService;
 
+    @Autowired
+    private ApplyPurchaseService applyPurchaseService;
+
+    @Autowired
+    private ProductInfoService productInfoService;
+
+    @Autowired
+    private PurchaseService purchaseService;
+
     @Override
     public Page<LogisticsInfo> getPage(Map<String, Object> condition) {
 
@@ -90,6 +107,37 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
             throw new ServiceException("物流信息不能为空");
         }
 
+        List<LogisticsDetails> details = logisticsInfoVo.getDetails();
+        Assert.notEmpty(details, "发货明细不能为空");
+
+        // 获取已发货数量map<申购单id, 已发货数量>
+        Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(logisticsInfoVo.getBusinessId());
+        // 获取申购数量
+        Map<Long, BigDecimal> applyPurchaseQuantityMap = applyPurchaseService.list(ApplyPurchase::getPurchaseId, logisticsInfoVo.getBusinessId())
+                .stream().collect(Collectors.toMap(BaseIdEntity::getId, ApplyPurchase::getQuantity, BigDecimal::add));
+
+        details = details.stream()
+                .filter(item ->
+                        ObjectUtil.isNotEmpty(item.getShipmentQuantity()) && item.getShipmentQuantity().compareTo(BigDecimal.ZERO) > 0
+                ).peek(item -> {
+                    Long applyPurchaseId = item.getApplyPurchaseId();
+                    Assert.notEmpty(applyPurchaseId, "申购id不能为空");
+
+                    // 获取已发货数量
+                    BigDecimal deliverQuantity = ObjectUtil.defaultIfNull(deliverQuantityMap.get(applyPurchaseId), BigDecimal.ZERO);
+                    // 获取申购数量
+                    BigDecimal applyQuantity = ObjectUtil.defaultIfNull(applyPurchaseQuantityMap.get(applyPurchaseId), BigDecimal.ZERO);
+
+                    // 判断申购数量是否大于发货数量
+                    if (deliverQuantity.add(item.getShipmentQuantity()).compareTo(applyQuantity) > 0) {
+                        throw new ServiceException("发货总数量不能大于发货数量");
+                    }
+
+                })
+                .collect(Collectors.toList());
+        Assert.notEmpty(details, "发货数量不能全为0");
+
+
         Integer state = -1;
         // 查询快递100的物流信息
         try {
@@ -103,21 +151,22 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
             // 如果不是已签收状态,则开启订阅(物流状态跟踪并推送)
             KD100Util.subscribe(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode(), new Date());
         }
+
         logisticsInfoVo.setLogisticsStatus(state);
         logisticsInfoVo.setStatus(LogisticsConstant.Status.STATUS_0);
         logisticsInfoVo.setInStockStatus(LogisticsConstant.InStockStatus.STATUS_10);
         save(logisticsInfoVo);
 
-        logisticsInfoVo.getDetails().forEach(o -> {
+        details.forEach(o -> {
             o.setLogisticsInfoId(logisticsInfoVo.getId());
             o.setLogisticsInfoCode(logisticsInfoVo.getCode());
-            o.setReceiptQuantity(new BigDecimal(BigDecimal.ZERO.intValue()));
+            o.setReceiptQuantity(BigDecimal.ZERO);
         });
 
         //保存附件
         FileClientUtil.bindingFile(logisticsInfoVo.getId(), logisticsInfoVo.getFileInfos());
 
-        logisticsDetailsService.saveBatch(logisticsInfoVo.getDetails());
+        logisticsDetailsService.saveBatch(details);
     }
 
     @Override
@@ -187,8 +236,74 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
     }
 
     @Override
-    public List<DeliverDetailsVo> deliverDetails(Long businessId) {
+    public List<DeliverDetailsVo> deliverDetails(Long id) {
+
+        // 获取采购的产品
+        List<ApplyPurchase> applyPurchaseList = applyPurchaseService.list(q -> q.eq(ApplyPurchase::getPurchaseId, id));
+        if (applyPurchaseList.size() == 0) {
+            return new ArrayList<>();
+        }
+
+        // 产品id列表
+        List<Long> productIdList = applyPurchaseList.stream().map(ApplyPurchase::getGoodsId).collect(Collectors.toList());
+        // 采购map
+        Map<Long, ProductInfo> productMap = productInfoService.getKEntity(BaseIdEntity::getId, q -> q.in(BaseIdEntity::getId, productIdList));
+
+        // 获取已发货数量
+        Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(id);
+
+        return applyPurchaseList.stream().map(item -> {
+            DeliverDetailsVo deliverDetailsVo = new DeliverDetailsVo();
+
+            // 赋值申购信息
+            deliverDetailsVo.setProductId(item.getGoodsId());
+            deliverDetailsVo.setPurchaseId(item.getPurchaseId());
+            deliverDetailsVo.setApplyPurchaseId(item.getId());
+            deliverDetailsVo.setPurchaseQuantity(item.getQuantity());
+
+            // 赋值产品信息
+            ProductInfo productInfo = productMap.get(item.getGoodsId());
+            if (productInfo != null) {
+                deliverDetailsVo.setProductName(productInfo.getName());
+                deliverDetailsVo.setProductCode(productInfo.getCode());
+            }
+
+            // 赋值已发货数量
+            deliverDetailsVo.setDeliverQuantity(ObjectUtil.defaultIfNull(deliverQuantityMap.get(item.getId()), BigDecimal.ZERO));
+            return deliverDetailsVo;
+
+        }).collect(Collectors.toList());
+    }
+
+    @Override
+    public void arrivalNotice(LogisticsInfoVo entity) {
+
+        // 采购id
+        Long purchaseId = entity.getPurchaseId();
+        Assert.notEmpty(purchaseId, "采购id不能为空");
+
+        entity.setStatus(LogisticsConstant.Status.STATUS_1);
+        updateById(entity);
+
+        // // 获取已发货数量
+        // Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(purchaseId);
+        //
+        // List<ApplyPurchase> list = applyPurchaseService.list(q -> q.eq(ApplyPurchase::getPurchaseId, purchaseId));
+        // for (ApplyPurchase applyPurchase : list) {
+        //     Long id = applyPurchase.getId();
+        //
+        //     // 获取已申购数量
+        //     BigDecimal bigDecimal = deliverQuantityMap.get(id);
+        //
+        // }
+
+        // TODO 判断部分到货还是全部到货
+        Purchase purchase = new Purchase();
+        purchase.setId(purchaseId);
+        purchase.setStatus(PurchaseStatusEnum.STATUS_40.getKey());
+        purchaseService.updateById(purchase);
+
 
-        return null;
     }
+
 }

+ 5 - 0
hx-service/victoriatourist/src/main/resources/application-dev.yml

@@ -4,6 +4,11 @@ server:
 
 # 数据源配置
 spring:
+
+  # 允许依赖循环
+  main:
+    allow-circular-references: true
+
   # 数据库
   datasource:
     url: ${blade.datasource.victoriatourist.dev.url}

+ 5 - 0
hx-service/victoriatourist/src/main/resources/application-prod.yml

@@ -4,6 +4,11 @@ server:
 
 # 数据源配置
 spring:
+
+  # 允许依赖循环
+  main:
+    allow-circular-references: true
+
   # 数据库
   datasource:
     url: ${blade.datasource.victoriatourist.prod.url}

+ 5 - 0
hx-service/victoriatourist/src/main/resources/application-test.yml

@@ -4,6 +4,11 @@ server:
 
 # 数据源配置
 spring:
+
+  # 允许依赖循环
+  main:
+    allow-circular-references: true
+
   # 数据库
   datasource:
     url: ${blade.datasource.victoriatourist.test.url}