基于springboot的打卡签到
返回指定日期是早上、下午、晚上、凌晨的哪个时间段
/**
* 返回判断当前时间是早、下、晚、凌晨的哪个时间段。
* @return
*/
private int timePerods(Date time){
long mT = 0l;
long zT = 0l;
long eT = 0l;
long dT = 0l;
long tm = 0l;
try {
mT = DateUtils.parseDate("06:00:00", "HH:mm:ss").getTime();
zT = DateUtils.parseDate("12:00:00", "HH:mm:ss").getTime();
eT = DateUtils.parseDate("18:00:00", "HH:mm:ss").getTime();
dT = DateUtils.parseDate("24:00:00", "HH:mm:ss").getTime();
tm = DateUtils.parseDate(DateUtils.formatDate(time,"HH:mm:ss"),"HH:mm:ss").getTime();
} catch (ParseException e) {
e.printStackTrace();
}
if (tm >= mT && tm < zT){
//早上
return 0;
}else if (tm >= zT && tm < eT){
//下午
return 1;
}else if (tm >= eT && tm < dT){
//晚上
return 2;
}else {
//凌晨
return 3;
}
}
mapper.xml
<?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="com.example.signtime.mapper.SignTimeMapper">
<select id="getSignList" resultType="com.example.signtime.modules.vo.SignTimeVO">
SELECT
st.*,
sign_in_time signDate,
p.periods_info periodsInfo
FROM
sign_time st
LEFT JOIN periods p ON p.periods = st.periods
WHERE
DATE_SUB( CURRENT_DATE, INTERVAL #{
countDays} DAY ) <= date(sign_in_time) order by signDate
</select>
<select id="getSignRecord" resultType="integer">
SELECT
count( 1 ) signRecordTotals
FROM
(
SELECT
user_id
FROM
sign_time st
WHERE
user_id = #{
userId}
AND YEARWEEK(
date_format( sign_in_time, %Y-%m-%d )) = YEARWEEK(
now())
GROUP BY
date( sign_in_time )
) sign_count
</select>
<select id="signDates" resultType="date">
SELECT
date( sign_in_time ) signTime
FROM
sign_time
WHERE
user_id = #{
userId}
AND YEARWEEK(
date_format( sign_in_time, %Y-%m-%d )) = YEARWEEK(
now())
GROUP BY
date(
sign_in_time)
</select>
</mapper>
项目地址:https://gitee.com/yzq1831914/sign-time.git
