Browse Source

共享库存列表查询优化

liyuan 8 months ago
parent
commit
86e4a1da8f

+ 13 - 11
blade-service/blade-sales-part/src/main/java/org/springblade/salesPart/shopping/mapper/ShoppingMallDetailMapper.xml

@@ -53,14 +53,14 @@
         5
         END
         ) AS sort
-        FROM (SELECT id, goods_code as goodsCode,
-        goods_name as cname,
-        bill_type as billType,
-        brand_id as brandId,
-        price_one as priceOne,
-        price_two as priceTwo,
-        price_three as priceThree,
-        price_four as priceFour,
+        FROM (SELECT fpd.id, fpd.goods_code as goodsCode,
+        fpd.goods_name as cname,
+        fpd.bill_type as billType,
+        fpd.brand_id as brandId,
+        fpd.price_one as priceOne,
+        fpd.price_two as priceTwo,
+        fpd.price_three as priceThree,
+        fpd.price_four as priceFour,
         fpd.brand_item AS brandItem,
         fpd.cname_int AS cnameInt,
         fpd.inventory AS inventoryLocal,
@@ -69,7 +69,9 @@
         WHERE smd.goods_code = fpd.goods_code
         AND smd.id != fpd.id AND smd.tenant_id = #{tenantId} AND smd.is_deleted = 0) AS inventoryShare,
         COUNT(goods_code) AS gc FROM
-        pjpf_shopping_mall_detail fpd
+        pjpf_shopping_mall_detail fpd JOIN (
+        SELECT id, min(bill_type) as bill_type from pjpf_shopping_mall_detail WHERE tenant_id = #{tenantId} and is_deleted = 0 AND sales_company_id = #{salesCompanyId} GROUP BY id
+        ) spd on fpd.id = spd.id and fpd.bill_type = spd.bill_type
         WHERE
         fpd.tenant_id = #{tenantId}
         AND fpd.is_deleted = 0
@@ -116,10 +118,10 @@
             </foreach>
         </if>
         <if test="inventoryStatus != null">
-            and inventory > #{inventoryStatus}
+            and fpd.inventory > #{inventoryStatus}
         </if>
         GROUP BY
-        goods_code
+        fpd.goods_code
         ) AS allGoods
         <if test="brandId != null or brandName != null  and brandName != ''">
             order by  cnameInt, sort DESC