‘linchangsheng’ 1 week ago
parent
commit
c6e1a955b9
1 changed files with 29 additions and 16 deletions
  1. 29 16
      src/main/resources/mapper/CustomGoodsMapper.xml

+ 29 - 16
src/main/resources/mapper/CustomGoodsMapper.xml

@@ -99,40 +99,53 @@
 
     <select id="countByType" resultType="com.gree.mall.manager.bean.goods.GoodsTypeCount">
         select count(1) 'total', sum(if(status = true, 1, 0)) 'csz', sum(if(status = false, 1, 0)) 'ckz'
-        from goods
+        from goods a join goods_company b on a.goods_id = b.goods_id
         where del = false
         <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
-            AND company_id in
+            AND b.company_id in
             <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
                 #{companyWechatId}
             </foreach>
         </if>
+        group by a.goods_id
     </select>
 
     <select id="ysq" resultType="java.lang.Integer">
-        select count(*) total
-        from (select sum(stock_num), goods_id
-              from goods_spec
-              where del = false
-                <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
-                    AND company_id in
-                    <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
-                        #{companyWechatId}
-                    </foreach>
-                </if>
-              group by goods_id
-              having sum(stock_num) = 0) t
+        SELECT
+        count(*) total
+        FROM
+        (
+        SELECT
+        sum( c.stock_num ),
+        c.goods_id
+        FROM
+        goods_spec c
+        JOIN goods t1
+        JOIN goods_company b ON t1.goods_id = b.goods_id
+        WHERE
+        c.del = FALSE
+        <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
+            AND b.company_id in
+            <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
+                #{companyWechatId}
+            </foreach>
+        </if>
+        GROUP BY
+        goods_id
+        HAVING
+        sum( stock_num ) = 0
+        ) t
     </select>
 
     <select id="countByFlag" resultType="java.lang.Integer">
         select count(DISTINCT t1.goods_id)
-        FROM goods t1
+        FROM goods t1 join goods_company b on t1.goods_id = b.goods_id
         left join goods_spec t2 on t1.goods_id = t2.goods_id
         WHERE t1.del = 0
           AND t2.flag = 1
           and t2.del = 0
         <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
-            AND t1.company_id in
+            AND b.company_id in
             <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
                 #{companyWechatId}
             </foreach>