<?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) <2
|
</if>
|
<if test="animalHeatVo.timeDesc=='2-4'">
|
and hour(create_time)>=2 and hour(create_time) <4
|
</if>
|
<if test="animalHeatVo.timeDesc=='4-6'">
|
and hour(create_time)>=4 and hour(create_time) <6
|
</if>
|
<if test="animalHeatVo.timeDesc=='6-8'">
|
and hour(create_time)>=6 and hour(create_time) <8
|
</if>
|
<if test="animalHeatVo.timeDesc=='8-10'">
|
and hour(create_time)>=8 and hour(create_time) <10
|
</if>
|
<if test="animalHeatVo.timeDesc=='10-12'">
|
and hour(create_time)>=10 and hour(create_time) <12
|
</if>
|
<if test="animalHeatVo.timeDesc=='12-14'">
|
and hour(create_time)>=12 and hour(create_time) <14
|
</if>
|
<if test="animalHeatVo.timeDesc=='14-16'">
|
and hour(create_time)>=14 and hour(create_time) <16
|
</if>
|
<if test="animalHeatVo.timeDesc=='16-18'">
|
and hour(create_time)>=16 and hour(create_time) <18
|
</if>
|
<if test="animalHeatVo.timeDesc=='18-20'">
|
and hour(create_time)>=18 and hour(create_time) <20
|
</if>
|
<if test="animalHeatVo.timeDesc=='20-22'">
|
and hour(create_time)>=20 and hour(create_time) <22
|
</if>
|
<if test="animalHeatVo.timeDesc=='22-24'">
|
and hour(create_time)>=22 and hour(create_time) <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 ) < 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>
|