package worker import ( "enterprise/common/dao" "enterprise/common/global" "enterprise/common/model" "enterprise/service" "fmt" log "github.com/sirupsen/logrus" "github.com/smbrave/goutil" "strings" "time" ) type Checkin struct { corp *model.Corp corpConfig *model.CorpConfig } func NewCheckin(corpId int64) *Checkin { corp, _ := dao.NewCorpDao().Get(corpId) return &Checkin{ corp: corp, corpConfig: corp.GetConfig(), } } func (c *Checkin) SyncCheckinMonth(month string) { if month == "" { month = time.Now().AddDate(0, -1, 0).Format("200601") } startTime, _ := time.ParseInLocation("20060102", month+"01", time.Local) endDay := startTime.AddDate(0, 1, -1).Format("2006-01-02") startDay := startTime.Format("2006-01-02") new(service.Checkin).SyncCheckin(c.corp.Id, startDay, endDay) } func (c *Checkin) SyncCheckinDay(day string) { if day == "" { day = time.Now().AddDate(0, 0, -1).Format("2006-01-02") } new(service.Checkin).SyncCheckin(c.corp.Id, day, day) } func (c *Checkin) MonitorCheckinDay(day string) { if day == "" { day = time.Now().AddDate(0, 0, -1).Format("2006-01-02") } checkins, err := dao.NewCheckinDao().QueryDay(c.corp.Id, day) if err != nil { log.Errorf("db error :%s", err.Error()) return } for _, checkin := range checkins { if checkin.Exception == "" { continue } approvals, err := dao.NewApprovalVacationDao().GetByUsername(c.corp.Id, checkin.Username, "", checkin.Day) if err != nil { log.Errorf("db error :%s", err.Error()) continue } if len(approvals) > 0 { continue } message := make([]string, 0) message = append(message, fmt.Sprintf("【考勤异常】%s", checkin.Username)) message = append(message, fmt.Sprintf("考勤日期:%s", checkin.Day)) message = append(message, fmt.Sprintf("上班时间:%s", goutil.TimeToDateTime(checkin.StartTime))) message = append(message, fmt.Sprintf("下班时间:%s", goutil.TimeToDateTime(checkin.EndTime))) message = append(message, fmt.Sprintf("异常原因:%s", checkin.Exception)) global.SendMessage([]string{"jiangyong", checkin.Username}, strings.Join(message, "\n")) } }