From f14c50cb0036d3ddd655ce4e34732ba396a836c4 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 30 五月 2023 12:42:03 +0800
Subject: [PATCH] optimize 统计

---
 java110-db/src/main/resources/mapper/store/ResourceStoreTimesV1ServiceDaoImplMapper.xml |  292 +++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 206 insertions(+), 86 deletions(-)

diff --git a/java110-db/src/main/resources/mapper/store/ResourceStoreTimesV1ServiceDaoImplMapper.xml b/java110-db/src/main/resources/mapper/store/ResourceStoreTimesV1ServiceDaoImplMapper.xml
index 731d964..4bc0839 100644
--- a/java110-db/src/main/resources/mapper/store/ResourceStoreTimesV1ServiceDaoImplMapper.xml
+++ b/java110-db/src/main/resources/mapper/store/ResourceStoreTimesV1ServiceDaoImplMapper.xml
@@ -5,111 +5,231 @@
 <mapper namespace="resourceStoreTimesV1ServiceDaoImpl">
 
 
-
-
-
     <!-- 淇濆瓨鐗╁搧娆℃暟淇℃伅 add by wuxw 2018-07-03 -->
     <insert id="saveResourceStoreTimesInfo" parameterType="Map">
         insert into resource_store_times(
-price,apply_order_id,store_id,stock,res_id,times_id
-) values (
-#{price},#{applyOrderId},#{storeId},#{stock},#{resId},#{timesId}
-)
+        price,apply_order_id,store_id,stock,res_code,times_id,sh_id
+        ) values (
+        #{price},#{applyOrderId},#{storeId},#{stock},#{resCode},#{timesId},#{shId}
+        )
     </insert>
-
 
 
     <!-- 鏌ヨ鐗╁搧娆℃暟淇℃伅 add by wuxw 2018-07-03 -->
     <select id="getResourceStoreTimesInfo" parameterType="Map" resultType="Map">
-        select  t.price,t.apply_order_id,t.apply_order_id applyOrderId,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id storeId,t.stock,t.res_id,t.res_id resId,t.times_id,t.times_id timesId 
-from resource_store_times t 
-where 1 =1 
-<if test="price !=null and price != ''">
-   and t.price= #{price}
-</if> 
-<if test="applyOrderId !=null and applyOrderId != ''">
-   and t.apply_order_id= #{applyOrderId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-<if test="stock !=null and stock != ''">
-   and t.stock= #{stock}
-</if> 
-<if test="resId !=null and resId != ''">
-   and t.res_id= #{resId}
-</if> 
-<if test="timesId !=null and timesId != ''">
-   and t.times_id= #{timesId}
-</if> 
-order by t.create_time desc
-<if test="page != -1 and page != null ">
-   limit #{page}, #{row}
-</if> 
+        select t.price,t.apply_order_id,t.apply_order_id applyOrderId,t.status_cd,t.status_cd
+        statusCd,t.store_id,t.store_id storeId,t.stock,t.res_code,t.res_code resCode,t.times_id,
+        t.times_id timesId,t.create_time createTime,(t.price * t.stock) totalPrice,
+        rs.res_name,rs.res_name resName,rs.description,rs.store_id,rs.store_id storeId,
+        rs.stock,rs.warning_stock,rs.warning_stock warningStock,rs.res_id,rs.res_id resId,rs.out_low_price,rs.rss_id,rs.rss_id rssId,
+        rs.out_low_price outLowPrice,rs.out_high_price,rs.out_high_price outHighPrice,
+        rs.unit_code,rs.unit_code unitCode,rs.remark,rs.show_mobile,rs.show_mobile showMobile,
+        rs.sh_id,rs.sh_id shId,sh.sh_name shName,rs.average_price,rs.average_price
+        averagePrice,rss.spec_name rssName,rs.mini_unit_code,rs.mini_unit_code miniUnitCode,rs.mini_stock,rs.mini_stock
+        miniStock,rs.mini_unit_stock,rs.mini_unit_stock miniUnitStock,td.name unitCodeName,td1.name
+        miniUnitCodeName,sh.sh_type shType,rs.parent_rst_id parentRstId,rs.rst_id rstId,rst1.name parentRstName,rst.name
+        rstName,
+        rs.is_fixed,rs.is_fixed isFixed,td2.name isFixedName
+        from resource_store_times t
+        inner join resource_store rs on t.res_code = rs.res_code and rs.status_cd = '0'
+        left join resource_store_type rst on rs.rst_id = rst.rst_id and rst.status_cd = '0'
+        left join resource_store_type rst1 on rs.parent_rst_id = rst1.rst_id and rst1.status_cd = '0'
+        left join resource_store_specification rss on rs.rss_id = rss.rss_id and rss.status_cd = '0'
+        left join storehouse sh on rs.sh_id = sh.sh_id and rs.store_id = sh.store_id and sh.status_cd = '0'
+        left join t_dict td on rs.unit_code = td.status_cd and td.table_name = 'resource_store' and td.table_columns =
+        'unit_code'
+        left join t_dict td1 on rs.mini_unit_code = td1.status_cd and td1.table_name = 'resource_store' and
+        td1.table_columns = 'unit_code'
+        left join t_dict td2 on rs.is_fixed = td2.status_cd and td2.table_name='resource_store' and td2.table_columns =
+        'is_fixed'
+        where 1 =1
+        <if test="resName !=null and resName != ''">
+            and rs.res_name like concat('%',#{resName},'%')
+        </if>
+        <if test="name != null and name != ''">
+            and rs.res_name = #{name}
+        </if>
+        <if test="rstId !=null and rstId != ''">
+            and rs.rst_id= #{rstId}
+        </if>
+        <if test="parentRstId !=null and parentRstId != ''">
+            and rs.parent_rst_id= #{parentRstId}
+        </if>
+        <if test="resCode !=null and resCode != ''">
+            and t.res_code like concat('%',#{resCode},'%')
+        </if>
+        <if test="price !=null and price != ''">
+            and t.price= #{price}
+        </if>
+        <if test="applyOrderId !=null and applyOrderId != ''">
+            and t.apply_order_id= #{applyOrderId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="stock !=null and stock != ''">
+            and t.stock= #{stock}
+        </if>
+        <if test="hasStock !=null and hasStock != ''">
+            and t.stock > 0
+        </if>
+        <if test="resCodes != null ">
+            and t.res_code in
+            <foreach collection="resCodes" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        <if test="timesId !=null and timesId != ''">
+            and t.times_id= #{timesId}
+        </if>
+        <if test="shId !=null and shId != ''">
+            and t.sh_id= #{shId}
+        </if>
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
 
     </select>
 
 
-
-
     <!-- 淇敼鐗╁搧娆℃暟淇℃伅 add by wuxw 2018-07-03 -->
     <update id="updateResourceStoreTimesInfo" parameterType="Map">
-        update  resource_store_times t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="price !=null and price != ''">
-, t.price= #{price}
-</if> 
-<if test="applyOrderId !=null and applyOrderId != ''">
-, t.apply_order_id= #{applyOrderId}
-</if> 
-<if test="storeId !=null and storeId != ''">
-, t.store_id= #{storeId}
-</if> 
-<if test="stock !=null and stock != ''">
-, t.stock= #{stock}
-</if> 
-<if test="resId !=null and resId != ''">
-, t.res_id= #{resId}
-</if> 
- where 1=1 <if test="timesId !=null and timesId != ''">
-and t.times_id= #{timesId}
-</if> 
+        update resource_store_times t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="price !=null and price != ''">
+            , t.price= #{price}
+        </if>
+        <if test="applyOrderId !=null and applyOrderId != ''">
+            , t.apply_order_id= #{applyOrderId}
+        </if>
+
+        <if test="stock !=null and stock != ''">
+            , t.stock= #{stock}
+        </if>
+        <if test="resCode !=null and resCode != ''">
+            , t.res_code= #{resCode}
+        </if>
+        where 1=1
+        <if test="timesId !=null and timesId != ''">
+            and t.times_id= #{timesId}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
 
     </update>
 
     <!-- 鏌ヨ鐗╁搧娆℃暟鏁伴噺 add by wuxw 2018-07-03 -->
-     <select id="queryResourceStoreTimessCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from resource_store_times t 
-where 1 =1 
-<if test="price !=null and price != ''">
-   and t.price= #{price}
-</if> 
-<if test="applyOrderId !=null and applyOrderId != ''">
-   and t.apply_order_id= #{applyOrderId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-<if test="stock !=null and stock != ''">
-   and t.stock= #{stock}
-</if> 
-<if test="resId !=null and resId != ''">
-   and t.res_id= #{resId}
-</if> 
-<if test="timesId !=null and timesId != ''">
-   and t.times_id= #{timesId}
-</if> 
+    <select id="queryResourceStoreTimessCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from resource_store_times t
+        inner join resource_store rs on t.res_code = rs.res_code and rs.status_cd = '0'
+        left join resource_store_type rst on rs.rst_id = rst.rst_id and rst.status_cd = '0'
+        left join resource_store_type rst1 on rs.parent_rst_id = rst1.rst_id and rst1.status_cd = '0'
+        left join resource_store_specification rss on rs.rss_id = rss.rss_id and rss.status_cd = '0'
+        left join storehouse sh on rs.sh_id = sh.sh_id and rs.store_id = sh.store_id and sh.status_cd = '0'
+        left join t_dict td on rs.unit_code = td.status_cd and td.table_name = 'resource_store' and td.table_columns =
+        'unit_code'
+        left join t_dict td1 on rs.mini_unit_code = td1.status_cd and td1.table_name = 'resource_store' and
+        td1.table_columns = 'unit_code'
+        left join t_dict td2 on rs.is_fixed = td2.status_cd and td2.table_name='resource_store' and td2.table_columns =
+        'is_fixed'
+        where 1 =1
+        <if test="resName !=null and resName != ''">
+            and rs.res_name like concat('%',#{resName},'%')
+        </if>
+        <if test="name != null and name != ''">
+            and rs.res_name = #{name}
+        </if>
+        <if test="rstId !=null and rstId != ''">
+            and rs.rst_id= #{rstId}
+        </if>
+        <if test="parentRstId !=null and parentRstId != ''">
+            and rs.parent_rst_id= #{parentRstId}
+        </if>
+        <if test="resCode !=null and resCode != ''">
+            and t.res_code like concat('%',#{resCode},'%')
+        </if>
+        <if test="price !=null and price != ''">
+            and t.price= #{price}
+        </if>
+        <if test="applyOrderId !=null and applyOrderId != ''">
+            and t.apply_order_id= #{applyOrderId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="stock !=null and stock != ''">
+            and t.stock= #{stock}
+        </if>
+        <if test="hasStock !=null and hasStock != ''">
+            and t.stock > 0
+        </if>
+        <if test="resCodes != null ">
+            and t.res_code in
+            <foreach collection="resCodes" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        <if test="timesId !=null and timesId != ''">
+            and t.times_id= #{timesId}
+        </if>
+        <if test="shId !=null and shId != ''">
+            and t.sh_id= #{shId}
+        </if>
 
 
-     </select>
+    </select>
+
+    <!-- 鏌ヨ鐗╁搧娆℃暟鏁伴噺 add by wuxw 2018-07-03 -->
+    <select id="queryResourceStoreTimessCountStock" parameterType="Map" resultType="Map">
+        select sum(stock) stock
+        from resource_store_times t
+        where 1 =1
+        <if test="price !=null and price != ''">
+            and t.price= #{price}
+        </if>
+        <if test="applyOrderId !=null and applyOrderId != ''">
+            and t.apply_order_id= #{applyOrderId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="stock !=null and stock != ''">
+            and t.stock= #{stock}
+        </if>
+        <if test="hasStock !=null and hasStock != ''">
+            and t.stock > 0
+        </if>
+        <if test="resCode !=null and resCode != ''">
+            and t.res_code= #{resCode}
+        </if>
+        <if test="resCodes != null ">
+            and t.res_code in
+            <foreach collection="resCodes" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        <if test="timesId !=null and timesId != ''">
+            and t.times_id= #{timesId}
+        </if>
+        <if test="shId !=null and shId != ''">
+            and t.sh_id= #{shId}
+        </if>
+
+
+    </select>
 
 </mapper>

--
Gitblit v1.8.0