Kaynağa Gözat

采购退货明细添加次品数量

yzc 1 yıl önce
ebeveyn
işleme
419b3126f9

+ 9 - 4
hx-purchase/src/main/java/com/fjhx/purchase/entity/purchase/po/PurchaseDetail.java

@@ -1,14 +1,13 @@
 package com.fjhx.purchase.entity.purchase.po;
 
 import com.baomidou.mybatisplus.annotation.TableField;
-import com.ruoyi.common.core.domain.BasePo;
 import com.baomidou.mybatisplus.annotation.TableName;
-
-import java.math.BigDecimal;
-import java.util.Date;
+import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * 申购单
@@ -122,4 +121,10 @@ public class PurchaseDetail extends BasePo {
     @TableField(exist = false)
     private String productCustomCode;
 
+    /**
+     * 次品数量
+     */
+    @TableField(exist = false)
+    private BigDecimal defectiveQuantity;
+
 }

+ 20 - 2
hx-purchase/src/main/java/com/fjhx/purchase/service/purchase/impl/PurchaseServiceImpl.java

@@ -44,7 +44,9 @@ import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.purchase.service.subscribe.SubscribeService;
 import com.fjhx.supply.entity.supplier.po.SupplierInfo;
 import com.fjhx.supply.service.supplier.SupplierInfoService;
+import com.fjhx.wms.entity.stock.po.Stock;
 import com.fjhx.wms.entity.warehouse.po.Warehouse;
+import com.fjhx.wms.service.stock.StockService;
 import com.fjhx.wms.service.warehouse.WarehouseService;
 import com.obs.services.internal.ServiceException;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -114,6 +116,9 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
     @Autowired
     private ISysUserService userService;
 
+    @Autowired
+    private StockService stockService;
+
     /**
      * 列表
      *
@@ -298,8 +303,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
         PurchaseVo result = BeanUtil.toBean(purchase, PurchaseVo.class);
         result.setSupplyName(info.getName());
         //查询出采购明细列表
-        List<PurchaseDetail> purchaseDetailList = purchaseDetailService.
-                list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, id));
+        List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, id));
         //查询出产品
         if (CollectionUtils.isNotEmpty(purchaseDetailList)) {
             //赋值申购编号
@@ -315,6 +319,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
             List<Long> productIds = purchaseDetailList.stream().map(PurchaseDetail::getBussinessId).collect(Collectors.toList());
             List<ProductInfoVo> productInfos = productInfoService.getListByProductIds(productIds);
             Map<Long, List<ProductInfoVo>> productMap = productInfos.stream().distinct().collect(Collectors.groupingBy(ProductInfoVo::getId));
+            //获取所有仓库次品数量
+            Map<Long, List<Stock>> stockMap = stockService.mapKGroup(Stock::getProductId, q -> q.in(Stock::getProductId, productIds));
             if (MapUtils.isNotEmpty(productMap)) {
                 for (PurchaseDetail p : purchaseDetailList) {
                     //查询出到货总量
@@ -329,6 +335,18 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
                     p.setProductUnit(vo.getUnit());
                     p.setProductSpec(vo.getSpec());
                     p.setProductCustomCode(vo.getCustomCode());
+                    //赋值次品数量
+                    List<Stock> stockList = stockMap.get(p.getBussinessId());
+                    if (ObjectUtils.isNotEmpty(stockList)) {
+                        BigDecimal defectiveQuantity = BigDecimal.ZERO;
+                        for (Stock stock : stockList) {
+                            JSONObject json = JSONObject.parseObject(stock.getVictoriatouristJson());
+                            if (ObjectUtils.isNotEmpty(json) && ObjectUtil.isNotEmpty(json.get("defectiveQuantity"))) {
+                                defectiveQuantity = defectiveQuantity.add(json.getBigDecimal("defectiveQuantity"));
+                            }
+                        }
+                        p.setDefectiveQuantity(defectiveQuantity);
+                    }
                 }
             }
         }