From 7e6b4d0547e1b46df3cb3f0385e5d50ce3ca8a5d Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Wed, 17 Mar 2021 15:48:42 +0800
Subject: [PATCH] 1.警情保留数据

---
 blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/animalheat/mapper/AnimalHeatMapper.xml |   92 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/animalheat/mapper/AnimalHeatMapper.xml b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/animalheat/mapper/AnimalHeatMapper.xml
index a899abe..102d895 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/animalheat/mapper/AnimalHeatMapper.xml
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/animalheat/mapper/AnimalHeatMapper.xml
@@ -3,23 +3,33 @@
 <mapper namespace="org.springblade.jfpt.animalheat.mapper.AnimalHeatMapper">
 
     <!--查询当天体温数据统计-->
-    <select id="getAnimalStatis" resultType="org.springblade.jfpt.animalheat.vo.StatisVo">
-        SELECT 1 `status`,count(`status`) number FROM `blade_animal_heat` where
+    <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 `status`,count(`status`) number FROM `blade_animal_heat` where
+        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="org.springblade.jfpt.animalheat.vo.StatisVo">
-        SELECT 1 `status`,count(`status`) number FROM `blade_animal_heat` where
-            YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now()) and `status`=1
+    <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 `status`,count(`status`) number FROM `blade_animal_heat` where
-            YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now()) and `status`=0
+        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.jfpt.animalheat.entity.BladeAnimalHeat">
         SELECT * FROM blade_animal_heat
         <if test="animalHeatVo.begTime!=null and animalHeatVo.begTime!=''">
@@ -31,4 +41,70 @@
         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>
+
+
+    <!--统计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
+    </select>
 </mapper>

--
Gitblit v1.9.3