attendance_day_clear.go 813 B

123456789101112131415161718192021222324252627
  1. package timetask
  2. import (
  3. model "access-control-monitor/model/v1"
  4. "github.com/jaryhe/gopkgs/database"
  5. "time"
  6. )
  7. func clearAttendanceDay() {
  8. now := time.Now().Format("2006-01-02")
  9. attendance := model.WorkerAttendanceInfo{TabType:model.AttendanceTabDay}
  10. where := map[string]interface{}{
  11. "day_time <":now,
  12. }
  13. attendance.Delete(database.DB(), where)
  14. }
  15. //定时创建数据库
  16. func ClearAttendanceDay() {
  17. for {
  18. now := time.Now() //获取当前时间,放到now里面,要给next用
  19. next := now.Add(time.Hour * 24) //通过now偏移24小时
  20. next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location()) //获取下一个凌晨的日期
  21. t := time.NewTimer(next.Sub(now))//计算当前时间到凌晨的时间间隔,设置一个定时器
  22. <-t.C
  23. clearAttendanceDay()
  24. }
  25. }