南昌市物联网技防平台-后台
zengh
2021-03-10 fa9ffa9012d7b1df7692bb99e71be6592f48cd4b
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
<?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.jfpt.animalheat.mapper.AnimalHeatMapper">
 
    <!--查询当天体温数据统计-->
    <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')) = YEARWEEK(now()) and `status`=1
        UNION
        SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
            YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now()) and `status`=0
    </select>
 
    <select id="selectAnimalHeatPageList" resultType="org.springblade.jfpt.animalheat.entity.BladeAnimalHeat">
        SELECT * FROM blade_animal_heat
        <if test="animalHeatVo.begTime!=null and animalHeatVo.begTime!=''">
            and create_time &gt;=#{animalHeatVo.begTime}
        </if>
        <if test="animalHeatVo.endTime!=null and animalHeatVo.endTime!=''">
            and create_time &lt;=#{animalHeatVo.endTime}
        </if>
        ORDER BY create_time asc
    </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>
 
</mapper>