洪城义警-正式版后台
zengh
2022-05-26 4c19ddd36bdfb43b5ef4e8df3c9a98cd4d356d6c
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
219
220
<?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.animalheat.mapper.AnimalHeatMapper">
 
    <sql id="animalHeatCondition">
        <if test="animalHeatVo.type==0">
            and to_days(create_time)=to_days(now())
        </if>
        <if test="animalHeatVo.type==1">
            and YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
        </if>
        <if test="animalHeatVo.type==2">
            and date_format(create_time,'%Y%m') = date_format(now(),'%Y%m')
        </if>
        <if test="animalHeatVo.begTime!=null and animalHeatVo.begTime!='' and animalHeatVo.endTime!=null and animalHeatVo.endTime!='' and animalHeatVo.begTime!='undefined' and animalHeatVo.endTime!='undefined' ">
            and date(create_time) between #{animalHeatVo.begTime} and #{animalHeatVo.endTime}
        </if>
        <if test="animalHeatVo.timeDesc!=null and animalHeatVo.timeDesc!='' and animalHeatVo.timeDesc!='undefined'">
            <if test="animalHeatVo.timeDesc=='0-2'">
                and hour(create_time)>=0 and hour(create_time) &lt;2
            </if>
            <if test="animalHeatVo.timeDesc=='2-4'">
                and hour(create_time)>=2 and hour(create_time) &lt;4
            </if>
            <if test="animalHeatVo.timeDesc=='4-6'">
                and hour(create_time)>=4 and hour(create_time) &lt;6
            </if>
            <if test="animalHeatVo.timeDesc=='6-8'">
                and hour(create_time)>=6 and hour(create_time) &lt;8
            </if>
            <if test="animalHeatVo.timeDesc=='8-10'">
                and hour(create_time)>=8 and hour(create_time) &lt;10
            </if>
            <if test="animalHeatVo.timeDesc=='10-12'">
                and hour(create_time)>=10 and hour(create_time) &lt;12
            </if>
            <if test="animalHeatVo.timeDesc=='12-14'">
                and hour(create_time)>=12 and hour(create_time) &lt;14
            </if>
            <if test="animalHeatVo.timeDesc=='14-16'">
                and hour(create_time)>=14 and hour(create_time) &lt;16
            </if>
            <if test="animalHeatVo.timeDesc=='16-18'">
                and hour(create_time)>=16 and hour(create_time) &lt;18
            </if>
            <if test="animalHeatVo.timeDesc=='18-20'">
                and hour(create_time)>=18 and hour(create_time) &lt;20
            </if>
            <if test="animalHeatVo.timeDesc=='20-22'">
                and hour(create_time)>=20 and hour(create_time) &lt;22
            </if>
            <if test="animalHeatVo.timeDesc=='22-24'">
                and hour(create_time)>=22 and hour(create_time) &lt;24
            </if>
        </if>
    </sql>
 
    <!--查询当天体温数据统计-->
    <select id="getAnimalStatis" resultType="java.util.HashMap">
        SELECT 1 `name`,count(`status`) value FROM `blade_animal_heat` where
             TO_DAYS(create_time)=TO_DAYS(now())  and `status`=1
        UNION
        SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
            TO_DAYS(create_time)=TO_DAYS(now())  and `status`=0
    </select>
 
    <!--获取本周的体温统计数据-->
    <select id="getAnimalStatisWeek" resultType="java.util.HashMap">
        SELECT 1 `name`,count(`status`) value FROM `blade_animal_heat` where
            YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1) and `status`=1
        UNION
        SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
            YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1) and `status`=0
    </select>
 
    <!--获取本月的体温统计数据-->
    <select id="getAnimalStatisMonth" resultType="java.util.HashMap">
        SELECT 1 `name`,count(`status`) value FROM `blade_animal_heat` where
            date_format(create_time,'%Y%m') = date_format(now(),'%Y%m') and `status`=1
        UNION
        SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
            date_format(create_time,'%Y%m') = date_format(now(),'%Y%m') and `status`=0
    </select>
 
    <!--查询体温数据的分页数据-->
    <select id="selectAnimalHeatPageList" resultType="org.springblade.modules.animalheat.entity.BladeAnimalHeat">
        SELECT * FROM blade_animal_heat
        where 1=1
        <if test="animalHeatVo.status!=null">
            and status=#{animalHeatVo.status}
        </if>
        <include refid="animalHeatCondition"></include>
        ORDER BY create_time desc
    </select>
 
    <!--查询本周每天的体温数据(按礼拜一开始计算)-->
    <select id="selWeekDayAnimalStatis" resultType="java.util.HashMap">
        select DATE_FORMAT(date(subdate(curdate(),date_format(curdate(),'%w')-1)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
            date_format(create_time,'%Y-%m-%d')=date(subdate(curdate(),date_format(curdate(),'%w')-1))
        union all
        select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 1 day)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
        date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 1 day))
        union all
        select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 2 day)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
            date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 2 day))
        union all
        select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 3 day)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
            date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 3 day))
        union all
        select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 4 day)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
            date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 4 day))
        union all
        select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 5 day)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
            date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 5 day))
        union all
        select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 6 day)),'%m-%d') time,ifNull(count(*),0) as number
            from blade_animal_heat
        where
            date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 6 day))
    </select>
 
 
    <!--统计7天内每天体温异常的的总人数-->
    <select id="selectAnimalHeatDataStatis" resultType="java.lang.Integer">
        select ifnull(b.count,0) as count from
        (
        SELECT DATE_FORMAT(date_sub(curdate(), interval 6 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 5 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 4 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 3 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 2 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 1 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(curdate(),'%Y-%m-%d')  as click_date
        ) a
        left join
        (
        select DATE_FORMAT(create_time,'%Y-%m-%d') as datetime, count(*) as count from blade_animal_heat
            where `status`=1
            group by DATE_FORMAT(create_time,'%Y-%m-%d')
        ) b
         on
         a.click_date = b.datetime
         order by a.click_date asc
    </select>
 
    <!--查询当前时间段体温异常总次数-->
    <select id="selAnimalTimeCount" resultType="java.lang.Integer">
        select count(*) from blade_animal_heat
        where status=1
        <if test="conditionVo.startTime!=null and conditionVo.startTime!='' and conditionVo.endTime!=null and conditionVo.endTime!=''">
            and create_time between #{conditionVo.startTime} and #{conditionVo.endTime}
        </if>
    </select>
 
    <!--查询当前时间段区间时间体温异常次数-->
    <select id="selAnimalTimeData" resultType="org.springblade.modules.animalheat.entity.BladeAnimalHeat">
        select status,create_time from blade_animal_heat
            where status=1
        and create_time between #{conditionVo.startTime} and #{conditionVo.endTime}
    </select>
 
    <!--统计时间段内体温异常人数数量数据-->
    <select id="selectAnimalTimeData" resultType="java.lang.Integer">
        select ifnull(count,0) count from
        (
            SELECT @date := DATE_ADD( @date, INTERVAL + 1 DAY ) days FROM
            (
                SELECT @date := DATE_ADD( #{conditionVo.startTime}, INTERVAL - 1 DAY ) FROM sys_date
            ) time
            WHERE to_days( @date ) &lt; to_days( #{conditionVo.endTime} )
        ) a
        left join
        (
            select DATE_FORMAT(create_time,'%Y-%m-%d') as datetime, count(*) as count from blade_animal_heat
            where status=1
            group by DATE_FORMAT(create_time,'%Y-%m-%d')
        ) b
        on
        a.days = b.datetime
    </select>
 
 
    <!--导出体温数据列表-->
    <select id="exportAnimalHeat" resultType="org.springblade.common.entity.AnimalHeatExcel">
        SELECT * FROM blade_animal_heat
        where 1=1
        <if test="animalHeatVo.status!=null and animalHeatVo.status!='' and animalHeatVo.status!='undefined'">
            and status=#{animalHeatVo.status}
        </if>
        <include refid="animalHeatCondition"></include>
        ORDER BY create_time desc
    </select>
 
    <select id="getAnimalHeatPie" resultType="org.springblade.common.entity.ReportReturnData">
        select if(1=1,'正常',0) type,ifnull(count(*),0) count from blade_animal_heat where status=0
        <include refid="animalHeatCondition"></include>
        union all
        select if(1=1,'异常',0) type,ifnull(count(*),0) count from blade_animal_heat where status=1
        <include refid="animalHeatCondition"></include>
    </select>
 
</mapper>