checkin monitor

This commit is contained in:
jiangyong27 2024-04-03 13:53:48 +08:00
parent c54dea5cb8
commit fa553703fa
3 changed files with 42 additions and 0 deletions

View File

@ -95,3 +95,15 @@ func (d *CheckinDao) Query(username, month string, filterException bool) ([]*mod
}
return u, nil
}
func (d *CheckinDao) QueryDay(day string) ([]*model.Checkin, error) {
tx := GetDB().Table(d.TableName())
tx = tx.Where("day = ?", day)
var u []*model.Checkin
tx = tx.Find(&u)
if tx.Error != nil {
return nil, tx.Error
}
return u, nil
}

View File

@ -3,10 +3,13 @@ package worker
import (
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/global"
"enterprise/common/model"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"gitlab.batiao8.com/open/gosdk/qyweixin"
"strings"
"time"
)
@ -44,6 +47,7 @@ func (c *Checkin) SyncCheckinMonth(month string) error {
}
return nil
}
func (c *Checkin) SyncCheckinDay(day string) {
cfg := config.GetConfig()
qyw := qyweixin.NewAppCheckin(&qyweixin.AppConfig{
@ -71,6 +75,29 @@ func (c *Checkin) SyncCheckinDay(day string) {
}
return
}
func (c *Checkin) MonitorCheckinDay(day string) {
if day == "" {
day = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
}
checkins, err := dao.NewCheckinDao().QueryDay(day)
if err != nil {
log.Errorf("db error :%s", err.Error())
return
}
for _, checkin := range checkins {
if checkin.Exception == "" {
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.TimeToDate(checkin.StartTime)))
message = append(message, fmt.Sprintf("下班时间:%s", goutil.TimeToDate(checkin.EndTime)))
global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n"))
}
}
func (c *Checkin) saveToDB(user *qyweixin.UserCheckIn) error {
checkin, err := dao.NewCheckinDao().GetByDay(user.UserId, user.Day)
if err != nil {

View File

@ -22,6 +22,9 @@ func Init() error {
cron.Every(1).Day().At("05:00").Do(func() {
go checkIn.SyncCheckinDay("")
})
cron.Every(1).Day().At("08:00").Do(func() {
go checkIn.MonitorCheckinDay("")
})
//每月1号同步上月考勤、补卡审批、请假审批、报销审批
cron.Every(1).Month(1).At("05:30").Do(func() {