qt5107 2 년 전
부모
커밋
ffafda2644

+ 51 - 23
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/apply/ApplyPurchaseMapper.xml

@@ -3,28 +3,30 @@
 <mapper namespace="com.fjhx.mapper.apply.ApplyPurchaseMapper">
 
     <select id="getPage" resultType="com.fjhx.entity.apply.ApplyPurchase">
-        SELECT t1.id,
-               t1.`code`,
-               t1.purchase_id,
-               t1.purchase_code,
-               t1.goods_id,
-               t1.quantity,
-               t1.unit_price,
-               t1.plan_arrival_time,
-               t1.receipt_warehouse_id,
-               t1.`status`,
-               t1.cause,
-               t1.create_user,
-               t1.create_time,
-               t2.`type` goodsType,
-               t2.`code` goodsCode,
-               t2.`name` goodsName,
-               t2.unit   goodsUnit,
-               t3.`name` warehouseName
-        FROM apply_purchase t1
-                 LEFT JOIN material t2 ON t1.goods_id = t2.id
-                 LEFT JOIN warehouse t3 ON t1.receipt_warehouse_id = t3.id
-            ${ew.customSqlSegment}
+        SELECT
+            t1.id,
+            t1.`code`,
+            t1.purchase_id,
+            t1.purchase_code,
+            t1.goods_id,
+            t1.quantity,
+            t1.unit_price,
+            t1.plan_arrival_time,
+            t1.receipt_warehouse_id,
+            t1.`status`,
+            t1.cause,
+            t1.create_user,
+            t1.create_time,
+            t2.`type` goodsType,
+            t2.`code` goodsCode,
+            t2.`name` goodsName,
+            t2.unit goodsUnit,
+            t3.`name` warehouseName
+        FROM
+            apply_purchase t1
+            LEFT JOIN product_info t2 ON t1.goods_id = t2.id
+            LEFT JOIN warehouse t3 ON t1.receipt_warehouse_id = t3.id
+        ${ew.customSqlSegment}
     </select>
 
     <select id="applyInPage" resultType="java.util.LinkedHashMap">
@@ -44,6 +46,32 @@
                  left join product_info pi on ap.goods_id = pi.id
                  LEFT JOIN warehouse w ON ap.receipt_warehouse_id = w.id
             ${ew.customSqlSegment}
+        SELECT
+            t1.id,
+            t1.`code`,
+            t1.purchase_id,
+            t1.purchase_code,
+            t1.goods_id,
+            t1.quantity,
+            t1.arrival_quantity,
+            t1.unit_price,
+            t1.apply_price,
+            t1.arrival_price,
+            t1.plan_arrival_time,
+            t1.receipt_warehouse_id,
+            t1.`status`,
+            t1.cause,
+            t1.create_user,
+            t1.create_time,
+            t2.`type` goodsType,
+            t2.`code` goodsCode,
+            t2.`name` goodsName,
+            t2.unit goodsUnit,
+	        t3.`name` warehouseName
+        FROM
+            apply_purchase t1
+            LEFT JOIN product_info t2 ON t1.goods_id = t2.id
+	        LEFT JOIN warehouse t3 ON t1.receipt_warehouse_id = t3.id
+        ${ew.customSqlSegment}
     </select>
-
 </mapper>

+ 25 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/product/impl/ProductInfoServiceImpl.java

@@ -8,15 +8,18 @@ import com.fjhx.base.Condition;
 import com.fjhx.constants.StatusConstant;
 import com.fjhx.entity.product.ProductCombination;
 import com.fjhx.entity.product.ProductInfo;
+import com.fjhx.entity.stock.Stock;
 import com.fjhx.mapper.product.ProductInfoMapper;
 import com.fjhx.params.product.ProductCombinationEx;
 import com.fjhx.params.product.ProductInfoVo;
 import com.fjhx.service.product.ProductCombinationService;
 import com.fjhx.service.product.ProductInfoService;
+import com.fjhx.service.stock.StockService;
 import com.fjhx.uitl.code.CodeEnum;
 import com.fjhx.utils.Assert;
 import com.fjhx.utils.wrapperUtil.IWrapper;
 import com.fjhx.utils.wrapperUtil.KeywordData;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.system.entity.Dept;
 import org.springblade.system.feign.ISysClient;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,8 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -47,6 +52,9 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
     @Autowired
     private ProductCombinationService productCombinationService;
 
+    @Autowired
+    private StockService stockService;
+
     @Override
     public Page<Map<String, Object>> getPage(Map<String, Object> condition) {
         IWrapper<ProductInfo> wrapper = IWrapper.getWrapper(condition);
@@ -93,9 +101,26 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         List<Long> deptIdList = records.stream().map(item -> Convert.toLong(item.get("deptId"))).collect(Collectors.toList());
         Map<Long, Dept> deptMap = iSysClient.getDeptByIdsToMap(deptIdList);
 
+        //查询产品库存
+        Map<Long, Stock> stockMap = new HashMap<>();
+        //查询库存量
+        if (Func.isNotEmpty(condition.get("warehouseId"))) {
+            //产品ID集合
+            List<Long> ids = page.getRecords().stream().map(item -> Convert.toLong(item.get("id"))).distinct().collect(Collectors.toList());
+            List<Stock> stocks = stockService.lambdaQuery().eq(Stock::getWarehouseId, condition.get("warehouseId")).in(Stock::getGoodsId, ids).list();
+            if (Func.isNotEmpty(stocks)) {
+                stockMap = stocks.stream().collect(Collectors.toMap(Stock::getGoodsId, Function.identity(), (key1, key2) -> key2));
+            }
+        }
+
         for (Map<String, Object> record : records) {
             Dept dept = deptMap.get(Convert.toLong(record.get("deptId")));
             record.put("deptName", dept == null ? "" : dept.getDeptName());
+
+            if (Func.isNotEmpty(stockMap) && Func.isNotEmpty(stockMap.get(Convert.toLong(record.get("id"))))) {
+                Stock stock = stockMap.get(Convert.toLong(record.get("id")));
+                record.put("stockQuantity", stock.getQuantity());
+            }
         }
 
         return page;