智慧农业后台管理
guoshilong
2022-07-22 fdff4ca4813fc77a9006309ed4e5c232b4f3c85e
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?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.farm.mapper.FarmingRecordMapper">
 
    <!--自定义查询农事记录分页数据-->
    <select id="selectFarmingRecordPage" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
        SELECT
        sfr.*,
        sl.land_name landName,
        user.real_name,
        strain.strain_name
        FROM
        sys_farming_record sfr
        LEFT JOIN sys_land sl ON sl.id = sfr.land_id
        LEFT JOIN blade_user user on sfr.operator = user.id
        LEFT JOIN sys_strain strain on sfr.strain_id = strain.id
        WHERE
        1 =1
        <if test="farmingRecord.landId!=null and farmingRecord.landId!=''">
            and sfr.land_id = #{farmingRecord.landId}
        </if>
        <if test="farmingRecord.type!=null and farmingRecord.type!=''">
            and sfr.type = #{farmingRecord.type}
        </if>
        <if test="farmingRecord.stockId!=null and farmingRecord.stockId!=''">
            and sfr.stock_id = #{farmingRecord.stockId}
        </if>
        <if test="farmingRecord.jobWay!=null and farmingRecord.jobWay!=''">
            and sfr.job_way = #{farmingRecord.jobWay}
        </if>
        <if test="farmingRecord.operator!=null and farmingRecord.operator!=''">
            and sfr.operator = #{farmingRecord.operator}
        </if>
        <if test="farmingRecord.deptId!=null and farmingRecord.deptId!=''">
            and sfr.dept_id = #{farmingRecord.deptId}
        </if>
        <if test="farmingRecord.tenantId!=null and farmingRecord.tenantId!=''">
            and sfr.tenant_id = #{farmingRecord.tenantId}
        </if>
        <if test="farmingRecord.strainId!=null and farmingRecord.strainId!=''">
            and sfr.strain_id = #{farmingRecord.strainId}
        </if>
        <if test="farmingRecord.farmId!=null and farmingRecord.farmId!=''">
            and sl.farm_id = #{farmingRecord.farmId}
        </if>
    </select>
 
    <select id="selectFarmingRecordPages" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
        select sfr.*,sl.land_name landName from sys_farming_record sfr
        left join sys_land sl on sl.id = sfr.land_id
        where 1=1
        <if test="farmingRecord.landId!=null and farmingRecord.landId!=''">
            and sfr.land_id = #{farmingRecord.landId}
        </if>
        <if test="farmingRecord.type!=null and farmingRecord.type!=''">
            and sfr.type = #{farmingRecord.type}
        </if>
        <if test="farmingRecord.stockId!=null and farmingRecord.stockId!=''">
            and sfr.stock_id = #{farmingRecord.stockId}
        </if>
        <if test="farmingRecord.jobWay!=null and farmingRecord.jobWay!=''">
            and sfr.job_way = #{farmingRecord.jobWay}
        </if>
        <if test="farmingRecord.operator!=null and farmingRecord.operator!=''">
            and sfr.operator = #{farmingRecord.operator}
        </if>
        <if test="farmingRecord.deptId!=null and farmingRecord.deptId!=''">
            and sfr.dept_id = #{farmingRecord.deptId}
        </if>
        <if test="farmingRecord.tenantId!=null and farmingRecord.tenantId!=''">
            and sfr.tenant_id = #{farmingRecord.tenantId}
        </if>
        <if test="farmingRecord.strainId!=null and farmingRecord.strainId!=''">
            and sfr.strain_id = #{farmingRecord.strainId}
        </if>
    </select>
 
    <!--查询统计本年农事记录操作总数-->
    <select id="getFarmingCount" resultType="java.lang.Integer">
        select ifnull(count(*), 0) count
        from sys_farming_record ss
        LEFT JOIN sys_land sl ON sl.id = ss.land_id
        where 1=1
          and YEAR (time)= YEAR (NOW())
        <if test="farmId != null and farmId != ''">
            and sl.farm_id = #{sale.farmId}
        </if>
    </select>
 
    <!--查询统计本年农事记录操作总数-->
    <select id="getFarmingStatis" resultType="org.springblade.modules.farm.vo.FarmingStatisVO">
        select ss.type,case when ss.type = 0 then '施肥'
                   when ss.type = 1 then '翻耕'
                   when ss.type = 2 then '灌溉'
                   when ss.type = 3 then '起垄'
                   when ss.type = 4 then '用药'
                   when ss.type = 5 then '追肥'
                   when ss.type = 6 then '除草'
                   when ss.type = 7 then '修剪'
                   when ss.type = 8 then '浸种'
                   when ss.type = 9 then '拌种'
                   when ss.type = 10 then '移栽'
                   when ss.type = 11 then '直播'
                   when ss.type = 12 then '采收'
                   else '其他' end as name,
               ifnull(count(*), 0) value
        from sys_farming_record ss
        LEFT JOIN sys_land sl ON sl.id = ss.land_id
        where 1=1
          and YEAR (time)= YEAR (NOW())
        <if test="farmId != null and farmId != ''">
            and sl.farm_id = #{sale.farmId}
        </if>
        group by ss.type
    </select>
 
    <!--今年农资使用量-->
    <select id="selectJyCount" resultType="java.lang.Double">
        SELECT IFNULL(SUM(census), 0) AS jynum FROM sys_farming_record sfr
        left join sys_land sl on sl.id = sfr.land_id
        WHERE
            YEAR(sfr.time) = YEAR(NOW())
          AND sfr.stock_id != NULL
          and sl.farm_id=#{farmId}
    </select>
    <!--去年农资使用量-->
    <select id="selectQyCount" resultType="java.lang.Double">
        SELECT IFNULL(SUM(census), 0) AS qynum from sys_farming_record sfr
        left join sys_land sl on sl.id = sfr.land_id
        WHERE
            YEAR (sfr.time) = YEAR ( date_sub(now()
            , INTERVAL 1 YEAR))
          and sl.farm_id=#{farmId}
    </select>
 
    <!--本月农资使用量-->
    <select id="selectByCount" resultType="java.lang.Double">
        SELECT IFNULL(SUM(census), 0) AS bynum from sys_farming_record sfr
        left join sys_land sl on sl.id = sfr.land_id
        WHERE DATE_FORMAT(sfr.time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
        and sl.farm_id=#{farmId}
    </select>
 
    <!--查询农事记录信息(种植开始起)-->
    <select id="getFarmingRecordByFarmPlantId" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
        select bu.real_name realName,sfr.time,case
                   when type = 0 then '施肥'
                   when type = 1 then '翻耕'
                   when type = 2 then '灌溉'
                   when type = 3 then '起垄'
                   when type = 4 then '用药'
                   when type = 5 then '追肥'
                   when type = 6 then '除草'
                   when type = 7 then '修剪'
                   when type = 8 then '浸种'
                   when type = 9 then '拌种'
                   when type = 10 then '移栽'
                   when type = 11 then '直播'
                   when type = 12 then '采收'
                   else '其他' end as typeName
        from sys_farming_record sfr
        left join blade_user bu on bu.id = sfr.operator
        where land_id = #{recovery.landId}
        and strain_id = #{recovery.strainId}
        order by sfr.time asc,sfr.create_time asc
    </select>
 
    <!--查询农事操作记录(不分页)-->
    <select id="getFarmingRecordListfarm" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
        select sfr.*,case
            when sfr.type = 0 then '施肥'
            when sfr.type = 1 then '翻耕'
            when sfr.type = 2 then '灌溉'
            when sfr.type = 3 then '起垄'
            when sfr.type = 4 then '用药'
            when sfr.type = 5 then '追肥'
            when sfr.type = 6 then '除草'
            when sfr.type = 7 then '修剪'
            when sfr.type = 8 then '浸种'
            when sfr.type = 9 then '拌种'
            when sfr.type = 10 then '移栽'
            when sfr.type = 11 then '直播'
            when sfr.type = 12 then '采收'
        else '其他' end as typeName,sl.land_name landName,ss.strain_name strainName,
        bu.real_name realName,ss1.agricultural_name agriculturalName
        from sys_farming_record sfr
        left join blade_user bu on bu.id = sfr.operator
        left join sys_land sl on sl.id = sfr.land_id
        left join sys_strain ss on ss.id = sfr.strain_id
        left join sys_stockfactory ss1 on ss1.id = sfr.stock_id
        where 1=1
        <if test="farm.landId!=null and farm.landId!=''">
            and sfr.land_id = #{farm.landId}
        </if>
        <if test="farm.type!=null and farm.type!=''">
            and sfr.type = #{farm.type}
        </if>
        <if test="farm.stockId!=null and farm.stockId!=''">
            and sfr.stock_id = #{farm.stockId}
        </if>
        <if test="farm.jobWay!=null and farm.jobWay!=''">
            and sfr.job_way = #{farm.jobWay}
        </if>
        <if test="farm.operator!=null and farm.operator!=''">
            and sfr.operator = #{farm.operator}
        </if>
        <if test="farm.deptId!=null and farm.deptId!=''">
            and sfr.dept_id = #{farm.deptId}
        </if>
        <if test="farm.farmId!=null and farm.farmId!=''">
            and sl.farm_id = #{farm.farmId}
        </if>
        <if test="farm.strainId!=null and farm.strainId!=''">
            and sfr.strain_id = #{farm.strainId}
        </if>
        order by sfr.time desc,sfr.create_time desc
    </select>
</mapper>