智慧农业后台管理
zengh
2022-07-01 defe17cd356718eaf925e7fb48ea5a80211569e5
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
<?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 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="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
        where 1=1
          and YEAR (time)= YEAR (NOW())
          and dept_id=#{deptId}
    </select>
 
    <!--查询统计本年农事记录操作总数-->
    <select id="getFarmingStatis" resultType="org.springblade.modules.farm.vo.FarmingStatisVO">
        select 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 name,
               ifnull(count(*), 0) value
        from sys_farming_record
        where 1=1
          and YEAR (time)= YEAR (NOW())
          and dept_id=#{deptId}
        group by type
    </select>
 
    <!--今年农资使用量-->
    <select id="selectJyCount" resultType="java.lang.Double">
        SELECT IFNULL(SUM(census), 0) AS jynum
        FROM sys_farming_record
        WHERE
            YEAR ( time ) = YEAR ( NOW( ) )
          AND stock_id != NULL
          and dept_id=#{deptId}
    </select>
    <!--去年农资使用量-->
    <select id="selectQyCount" resultType="java.lang.Double">
        SELECT IFNULL(SUM(census), 0) AS qynum
        FROM sys_farming_record
        WHERE
            YEAR (time) = YEAR ( date_sub(now()
            , INTERVAL 1 YEAR))
          and dept_id=#{deptId}
    </select>
 
    <!--本月农资使用量-->
    <select id="selectByCount" resultType="java.lang.Double">
        SELECT IFNULL(SUM(census), 0) AS bynum
        FROM sys_farming_record
        WHERE DATE_FORMAT(time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
          and dept_id = #{deptId}
    </select>
</mapper>