user_login.go 671 B

12345678910111213141516171819202122232425262728
  1. package services
  2. import (
  3. "context"
  4. "eta/eta_task/models"
  5. "eta/eta_task/services/alarm_msg"
  6. "eta/eta_task/utils"
  7. "fmt"
  8. "time"
  9. )
  10. // ClearUserLoginLog 每天清理两个月前的用户登录日志
  11. func ClearUserLoginLog(cont context.Context) (err error) {
  12. defer func() {
  13. if err != nil {
  14. tips := fmt.Sprintf("用户登录日志清理, ClearUserLoginLog error: %s", err.Error())
  15. fmt.Println(tips)
  16. go alarm_msg.SendAlarmMsg(tips, 2)
  17. }
  18. }()
  19. preTime := time.Now().Local().AddDate(0, -2, 0).Format(utils.FormatDateTime)
  20. e := models.ClearSysUserLoginRecord(preTime)
  21. if e != nil {
  22. err = fmt.Errorf("ClearSysUserLoginRecord: %s", e.Error())
  23. }
  24. return
  25. }