From 72b971c98c46531064d74b68fc8fe8864ed0b544 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 08 Nov 2022 09:04:56 +0800
Subject: [PATCH] 大屏溯源统计次数sql修改

---
 src/main/java/org/springblade/modules/stock/mapper/StockMapper.xml |  344 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 344 insertions(+), 0 deletions(-)

diff --git a/src/main/java/org/springblade/modules/stock/mapper/StockMapper.xml b/src/main/java/org/springblade/modules/stock/mapper/StockMapper.xml
new file mode 100644
index 0000000..0e55b4f
--- /dev/null
+++ b/src/main/java/org/springblade/modules/stock/mapper/StockMapper.xml
@@ -0,0 +1,344 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.modules.stock.mapper.StockMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="stockResultMap" type="org.springblade.modules.stock.entity.Stock">
+        <result column="id" property="id"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_dept" property="createDept"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="stock_id" property="stockId"/>
+        <result column="specs" property="specs"/>
+        <result column="specs_value1" property="specsValue1"/>
+        <result column="specs_value2" property="specsValue2"/>
+        <result column="amount" property="amount"/>
+        <result column="type" property="type"/>
+        <result column="time" property="time"/>
+        <result column="picture" property="picture"/>
+        <result column="remarks" property="remarks"/>
+        <result column="state" property="state"/>
+    </resultMap>
+
+
+    <select id="selectStockPage" resultMap="stockResultMap">
+        select * from sys_stock where is_deleted = 0
+    </select>
+
+    <select id="selectLists" resultType="org.springblade.modules.stock.vo.StockVO">
+        SELECT st.*,
+        stf.factory_name AS factoryName,
+        a.dict_value AS stype,
+        d.dict_value AS dic1,
+        c.dict_value AS dic2,
+        stf.agricultural_name as agrname
+        FROM sys_stock st
+        LEFT JOIN sys_stockfactory stf ON stf.id = st.stock_id
+        LEFT JOIN (SELECT dict_key, dict_value
+        FROM blade_dict_biz
+        WHERE CODE = 'stockSpecs1' AND is_deleted = 0
+        <if test="stock.codes!=null and stock.codes != ''">
+            AND blade_dict_biz.tenant_id = #{stock.codes}
+        </if>) d ON d.dict_key = st.specs_value1
+        LEFT JOIN (SELECT dict_key, dict_value
+        FROM blade_dict_biz
+        WHERE CODE = 'stockSpecs2' AND is_deleted = 0  <if test="stock.codes!=null and stock.codes != ''">
+        AND blade_dict_biz.tenant_id = #{stock.codes}
+    </if>) c ON c.dict_key = st.specs_value2
+        LEFT JOIN ( SELECT dict_key, dict_value FROM blade_dict_biz WHERE CODE = 'stockType' AND is_deleted = 0
+        <if test="stock.codes!=null and stock.codes != ''">
+            AND blade_dict_biz.tenant_id = #{stock.codes}
+        </if>) a ON
+        a.dict_key = stf.type
+        WHERE st.is_deleted = 0 and state=0 AND st.amount != 0
+        <if test="stock.deptId !=null and stock.deptId !=''">
+            and st.dept_id = #{stock.deptId}
+        </if>
+        <if test="stock.stype!=null and stock.stype != ''">
+            and stf.type = #{stock.stype}
+        </if>
+        <if test="stock.specsValue1!=null and stock.specsValue1 != ''">
+            and st.specs_value1 = #{stock.specsValue1}
+        </if>
+        <if test="stock.year!=null and stock.year != ''">
+            and st.create_time like concat('%',#{stock.year},'%')
+        </if>
+        <if test="stock.specsValue2!=null and stock.specsValue2 != ''">
+            and st.specs_value2 = #{stock.specsValue2}
+        </if>
+        <if test="stock.state!=null and stock.state != ''">
+            and st.state = #{stock.state}
+        </if>
+        <if test="stock.type!=null and stock.type != ''">
+            and st.type = #{stock.type}
+        </if>
+        <if test="stock.agrname!=null and stock.agrname != ''">
+            and stf.agricultural_name like concat('%', #{stock.agrname},'%')
+        </if>
+    </select>
+
+    <select id="selectListss" resultType="org.springblade.modules.stock.vo.StockVO">
+        SELECT st.*,
+        stf.factory_name AS factoryName,
+        a.dict_value AS stype,
+        d.dict_value AS dic1,
+        c.dict_value AS dic2,
+        stf.agricultural_name as agrname
+        FROM sys_stock st
+        LEFT JOIN sys_stockfactory stf ON stf.id = st.stock_id
+        LEFT JOIN (SELECT dict_key, dict_value
+        FROM blade_dict_biz
+        WHERE CODE = 'stockSpecs1' AND is_deleted = 0
+        <if test="stock.codes!=null and stock.codes != ''">
+            AND blade_dict_biz.tenant_id = #{stock.codes}
+        </if>) d ON d.dict_key = st.specs_value1
+        LEFT JOIN (SELECT dict_key, dict_value
+        FROM blade_dict_biz
+        WHERE CODE = 'stockSpecs2' AND is_deleted = 0  <if test="stock.codes!=null and stock.codes != ''">
+        AND blade_dict_biz.tenant_id = #{stock.codes}
+    </if>) c ON c.dict_key = st.specs_value2
+        LEFT JOIN ( SELECT dict_key, dict_value FROM blade_dict_biz WHERE CODE = 'stockType' AND is_deleted = 0
+        <if test="stock.codes!=null and stock.codes != ''">
+            AND blade_dict_biz.tenant_id = #{stock.codes}
+        </if>) a ON
+        a.dict_key = stf.type
+        WHERE st.is_deleted = 0 and state=0
+        <if test="stock.stype!=null and stock.stype != ''">
+            and stf.type = #{stock.stype}
+        </if>
+        <if test="stock.specsValue1!=null and stock.specsValue1 != ''">
+            and st.specs_value1 = #{stock.specsValue1}
+        </if>
+        <if test="stock.specsValue2!=null and stock.specsValue2 != ''">
+            and st.specs_value2 = #{stock.specsValue2}
+        </if>
+        <if test="stock.state!=null and stock.state != ''">
+            and st.state = #{stock.state}
+        </if>
+        <if test="stock.type!=null and stock.type != ''">
+            and st.type = #{stock.type}
+        </if>
+        <if test="stock.agrname!=null and stock.agrname != ''">
+            and stf.agricultural_name like concat('%', #{stock.agrname},'%')
+        </if>
+    </select>
+    <!--入库出库-->
+    <update id="UpdaeAmountc">
+        update sys_stock
+        set amount = #{stock.amount},
+            state=#{stock.state}
+        where id = #{stock.id}
+    </update>
+
+    <!--入库出库-->
+    <update id="Updaet">
+        update sys_stock
+        set amount = #{stock.amount},state = #{stock.state}
+        where id = #{stock.id}
+    </update>
+
+    <select id="slectNum" resultType="org.springblade.modules.stock.vo.StocksVO">
+        SELECT id,
+            a.agricultural_name as agrname,
+            a.factory_name as facname,
+            IFNULL(cg.cgnum, 0) AS cgnum,
+            IFNULL(dbr.dbrknum, 0) AS dbrknum,
+            IFNULL(lyc.lycknum, 0) AS lycknum,
+            IFNULL(dbc.dbcknum, 0) AS dbcknum,
+            IFNULL(bfc.bfcknum, 0) AS bfcknum
+        FROM (
+            SELECT stf.id,
+                stf.agricultural_name,
+                stf.factory_name
+            FROM
+                 sys_stockrecord st
+            LEFT JOIN (SELECT id, agricultural_name, factory_name,type FROM sys_stockfactory) stf
+            ON st.stock_id1 = stf.id
+        <if test="stock.stockType !=null and stock.stockType !=''">
+            WHERE stf.type =#{stock.stockType}
+        </if>
+        GROUP BY
+                 stf.id,
+            stf.agricultural_name,
+            stf.factory_name
+        ) a
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS cgnum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 1
+        AND type1 = 0
+        <if test="stock.startTime!=null and stock.startTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &gt;= #{stock.startTime}
+        </if>
+        <if test="stock.endTime!=null and stock.endTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &lt;= #{stock.endTime}
+        </if>
+        <if test="stock.deptId!=null and stock.deptId!=''">
+            and dept_id = #{stock.deptId}
+        </if>
+        GROUP BY stock_id1) cg ON cg.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS dbrknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 1
+        AND type1 = 1
+        <if test="stock.startTime!=null and stock.startTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &gt;= #{stock.startTime}
+        </if>
+        <if test="stock.endTime!=null and stock.endTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &lt;= #{stock.endTime}
+        </if>
+        <if test="stock.deptId!=null and stock.deptId!=''">
+            and dept_id = #{stock.deptId}
+        </if>
+        GROUP BY stock_id1) dbr ON dbr.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS lycknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 0
+        AND type1 = 0
+        <if test="stock.startTime!=null and stock.startTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &gt;= #{stock.startTime}
+        </if>
+        <if test="stock.endTime!=null and stock.endTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &lt;= #{stock.endTime}
+        </if>
+        <if test="stock.deptId!=null and stock.deptId!=''">
+            and dept_id = #{stock.deptId}
+        </if>
+        GROUP BY stock_id1) lyc ON lyc.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS dbcknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 0
+        AND type1 = 1
+        <if test="stock.startTime!=null and stock.startTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &gt;= #{stock.startTime}
+        </if>
+        <if test="stock.endTime!=null and stock.endTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &lt;= #{stock.endTime}
+        </if>
+        <if test="stock.deptId!=null and stock.deptId!=''">
+            and dept_id = #{stock.deptId}
+        </if>
+        GROUP BY stock_id1) dbc ON dbc.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS bfcknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 0
+        AND type1 = 2
+        <if test="stock.startTime!=null and stock.startTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &gt;= #{stock.startTime}
+        </if>
+        <if test="stock.endTime!=null and stock.endTime!=''">
+            and DATE_FORMAT(sys_stockrecord.time1,'%Y-%m-%d') &lt;= #{stock.endTime}
+        </if>
+        <if test="stock.deptId!=null and stock.deptId!=''">
+            and dept_id = #{stock.deptId}
+        </if>
+        GROUP BY stock_id1) bfc ON bfc.stock_id1 = a.id
+    </select>
+
+    <select id="StockCount" resultType="java.util.Map">
+        SELECT st.specs,
+               st.amount,
+               st.specs_value1 as spe,
+               sto.type
+        FROM `sys_stock` st
+                 LEFT JOIN (SELECT id, type FROM sys_stockfactory) sto ON st.stock_id = sto.id
+        WHERE st.is_deleted = 0
+          and dept_id = #{deptId}
+    </select>
+
+    <!--小程序数据统计-->
+    <select id="slectNumx" resultType="org.springblade.modules.stock.vo.StocksVO">
+        SELECT id,
+        a.agricultural_name as agrname,
+        a.factory_name as facname,
+        IFNULL(cg.cgnum, 0) AS cgnum,
+        IFNULL(dbr.dbrknum, 0) AS dbrknum,
+        IFNULL(lyc.lycknum, 0) AS lycknum,
+        IFNULL(dbc.dbcknum, 0) AS dbcknum,
+        IFNULL(bfc.bfcknum, 0) AS bfcknum
+        FROM (
+        SELECT stf.id,
+        stf.agricultural_name,
+        stf.factory_name
+        FROM sys_stockrecord st
+        LEFT JOIN (SELECT id, agricultural_name, factory_name FROM sys_stockfactory) stf
+        ON st.stock_id1 = stf.id
+        GROUP BY stf.id,
+        stf.agricultural_name,
+        stf.factory_name
+        ) a
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS cgnum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 1
+        AND type1 = 0
+        <if test="startTime!=null and startTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null and endTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        <if test="deptId!=null and deptId!=''">
+            and dept_id = #{deptId}
+        </if>
+        GROUP BY stock_id1) cg ON cg.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS dbrknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 1
+        AND type1 = 1
+        <if test="startTime!=null and startTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null and endTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        <if test="deptId!=null and deptId!=''">
+            and dept_id = #{deptId}
+        </if>
+        GROUP BY stock_id1) dbr ON dbr.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS lycknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 0
+        AND type1 = 0
+        <if test="startTime!=null and startTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null and endTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        <if test="deptId!=null and deptId!=''">
+            and dept_id = #{deptId}
+        </if>
+        GROUP BY stock_id1) lyc ON lyc.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS dbcknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 0
+        AND type1 = 1
+        <if test="startTime!=null and startTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null and endTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        <if test="deptId!=null and deptId!=''">
+            and dept_id = #{deptId}
+        </if>
+        GROUP BY stock_id1) dbc ON dbc.stock_id1 = a.id
+        LEFT JOIN (SELECT stock_id1, SUM(census) AS bfcknum
+        FROM sys_stockrecord
+        WHERE stock_type1 = 0
+        AND type1 = 2
+        <if test="startTime!=null and startTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null and endTime!=''">
+            and DATE_FORMAT(time1,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        <if test="deptId!=null and deptId!=''">
+            and dept_id = #{deptId}
+        </if>
+        GROUP BY stock_id1) bfc ON bfc.stock_id1 = a.id
+    </select>
+</mapper>

--
Gitblit v1.9.3