enterprise/worker/worker.go

50 lines
1.3 KiB
Go

package worker
import (
"enterprise/common/model"
"github.com/go-co-op/gocron"
"time"
)
func Init() error {
timezone, _ := time.LoadLocation("Asia/Shanghai")
cron := gocron.NewScheduler(timezone)
staff := new(Staff)
checkIn := new(Checkin)
approve := new(Approval)
// 每天同步企业人事信息
cron.Every(1).Day().At("01:00").Do(func() {
go staff.SyncStaffInfo()
})
//同步每日考勤数据
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() {
lastMonth := time.Now().AddDate(0, -1, 0).Format("200601")
checkIn.SyncCheckinMonth("")
approve.Sync(lastMonth, model.ApprovalTypeCheckin)
approve.Sync(lastMonth, model.ApprovalTypeVacation)
approve.Sync(lastMonth, model.ApprovalTypeRefund)
})
// 1号计算工资信息
cron.Every(1).Month(1, 2, 3, 4, 5, 6, 7, 8, 9).At("06:00").Do(func() {
go staff.SyncStaffSalary("")
})
//10号晚上8点发送工资单
cron.Every(1).Month(10).At("20:00").Do(func() {
go staff.SendStaffSalaryBill(time.Now().AddDate(0, -1, 0).Format("200601"))
})
cron.StartAsync()
return nil
}