智慧农业后台管理
guoshilong
2022-09-17 eab652f2f1c596c839013172a472bf88466f0c83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?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.stockrecord.mapper.StockrecordMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="stockrecordResultMap" type="org.springblade.modules.stockrecord.entity.Stockrecord">
        <result column="id" property="id"/>
        <result column="stock_id1" property="stockId1"/>
        <result column="amount1" property="amount1"/>
        <result column="time1" property="time1"/>
        <result column="type1" property="type1"/>
        <result column="operator1" property="operator1"/>
        <result column="spn1" property="spn1"/>
        <result column="stock_type1" property="stockType1"/>
        <result column="picture1" property="picture1"/>
        <result column="remarks1" property="remarks1"/>
    </resultMap>
 
 
    <select id="selectStockrecordPage" resultMap="stockrecordResultMap">
        select *
        from sys_stockrecord
        where is_deleted = 0
    </select>
    <select id="seletList" resultType="org.springblade.modules.stock.vo.StockVO">
        SELECT st.*,
        stf.type as stype,
        stf.factory_name as factoryName,
        d.dict_value as dic1,
        c.dict_value as dic2
        FROM `sys_stock` st
        LEFT JOIN sys_stockfactory stf ON st.stock_id = stf.id
        LEFT JOIN (SELECT dict_key,dict_value FROM blade_dict_biz WHERE `code`='stockSpecs1' AND is_deleted=0) 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) c ON
        c.dict_key=st.specs_value2
        WHERE st.is_deleted = 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.type!=null and stock.type!= ''">
            and st.type = #{stock.type}
        </if>
        <if test="stock.state!=null and stock.state!= ''">
            and st.state = #{stock.state}
        </if>
    </select>
 
 
    <!--农资记录查询-->
    <select id="seletStockRecordList" resultType="org.springblade.modules.stockrecord.vo.StockrecordVO">
        SELECT st.*,
        stf.type AS stype,
        stf.factory_name AS factoryName,
        d.dict_value AS dic1,
        c.dict_value AS dic2,
        a.real_name as czr,
        f.agricultural_name as agrname
        FROM `sys_stockrecord` st
        LEFT JOIN sys_stockfactory stf
        ON st.stock_id1 = stf.id
        LEFT JOIN (SELECT dict_key, dict_value
        FROM blade_dict_biz
        WHERE code ='stockSpecs1'
        AND is_deleted = 0 <if test="stockrecord.codes!=null and stockrecord.codes != ''">
        AND blade_dict_biz.tenant_id = #{stockrecord.codes}
    </if>) d ON d.dict_key = st.specs_val1
        LEFT JOIN (SELECT dict_key, dict_value
        FROM blade_dict_biz
        WHERE code ='stockSpecs2'
        AND is_deleted = 0 <if test="stockrecord.codes!=null and stockrecord.codes != ''">
        AND blade_dict_biz.tenant_id = #{stockrecord.codes}
    </if>) c ON c.dict_key = st.specs_val2
        LEFT JOIN (SELECT real_name, id FROM blade_user WHERE is_deleted = 0) a ON a.id = st.create_user
        LEFT JOIN ( SELECT agricultural_name,id FROM sys_stockfactory WHERE is_deleted = 0 ) f ON f.id = st.stock_id1
        WHERE st.is_deleted = 0
        <if test="stockrecord.agrname!=null and stockrecord.agrname != ''">
            and f.agricultural_name like concat ('%',#{stockrecord.agrname},'%')
        </if>
        <if test="stockrecord.stype!=null and stockrecord.stype != ''">
            and stf.type = #{stockrecord.stype}
        </if>
        <if test="stockrecord.sid!=null and stockrecord.sid != ''">
            and st.sid = #{stockrecord.sid}
        </if>
        <if test="stockrecord.deptId != null and stockrecord.deptId !=''">
            and st.dept_id = #{stockrecord.deptId}
        </if>
        <if test="stockrecord.startTime!=null and stockrecord.startTime!=''">
            and st.create_time &gt;= #{stockrecord.startTime}
        </if>
        <if test="stockrecord.endTime!=null and stockrecord.endTime!=''">
            and st.create_time &lt;= #{stockrecord.endTime}
        </if>
        ORDER BY st.create_time desc
    </select>
 
</mapper>