2023-08-04 11:13:41 +08:00
|
|
|
package worker
|
|
|
|
|
2023-08-04 18:27:37 +08:00
|
|
|
import (
|
2024-01-24 17:39:05 +08:00
|
|
|
"enterprise/common/model"
|
2023-08-04 18:27:37 +08:00
|
|
|
"github.com/go-co-op/gocron"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-08-04 11:13:41 +08:00
|
|
|
func Init() error {
|
2023-08-04 18:27:37 +08:00
|
|
|
timezone, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
cron := gocron.NewScheduler(timezone)
|
2024-01-07 17:17:33 +08:00
|
|
|
staff := new(Staff)
|
2024-01-07 18:53:21 +08:00
|
|
|
checkIn := new(Checkin)
|
2024-01-24 17:39:05 +08:00
|
|
|
approve := new(Approval)
|
2023-10-19 10:07:41 +08:00
|
|
|
|
2023-10-08 21:22:49 +08:00
|
|
|
// 每天同步企业人事信息
|
2023-09-05 10:49:24 +08:00
|
|
|
cron.Every(1).Day().At("01:00").Do(func() {
|
2024-01-07 17:17:33 +08:00
|
|
|
go staff.SyncStaffInfo()
|
|
|
|
})
|
|
|
|
|
|
|
|
//同步每日考勤数据
|
2024-01-17 22:30:38 +08:00
|
|
|
cron.Every(1).Day().At("05:00").Do(func() {
|
2024-01-07 17:17:33 +08:00
|
|
|
go checkIn.SyncCheckinDay("")
|
2023-08-31 22:20:40 +08:00
|
|
|
})
|
2024-04-03 13:53:48 +08:00
|
|
|
cron.Every(1).Day().At("08:00").Do(func() {
|
|
|
|
go checkIn.MonitorCheckinDay("")
|
|
|
|
})
|
2023-10-08 21:22:49 +08:00
|
|
|
|
2024-01-24 17:39:05 +08:00
|
|
|
//每月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)
|
2024-01-10 12:16:48 +08:00
|
|
|
})
|
|
|
|
|
2024-01-24 17:39:05 +08:00
|
|
|
// 1号计算工资信息
|
|
|
|
cron.Every(1).Month(1).At("06:00").Do(func() {
|
2024-01-07 17:17:33 +08:00
|
|
|
go staff.SyncStaffSalary("")
|
2023-09-04 19:14:02 +08:00
|
|
|
})
|
2023-10-08 21:22:49 +08:00
|
|
|
|
|
|
|
//10号晚上8点发送工资单
|
2024-01-07 17:17:33 +08:00
|
|
|
cron.Every(1).Month(10).At("20:00").Do(func() {
|
|
|
|
go staff.SendStaffSalaryBill(time.Now().AddDate(0, -1, 0).Format("200601"))
|
2023-10-08 21:22:49 +08:00
|
|
|
})
|
2023-08-04 18:47:12 +08:00
|
|
|
cron.StartAsync()
|
2023-08-04 11:13:41 +08:00
|
|
|
return nil
|
|
|
|
}
|