From f475a829b96f2d011448da87e171e46d068baee1 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Tue, 4 Mar 2025 23:27:13 +0800 Subject: [PATCH] new salary2 --- cmd/enterprise.go | 9 ++++--- worker/checkin.go | 10 +++----- worker/worker.go | 63 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/cmd/enterprise.go b/cmd/enterprise.go index 758fb1a..8851715 100644 --- a/cmd/enterprise.go +++ b/cmd/enterprise.go @@ -13,9 +13,12 @@ func main() { config.LoadAliPay() global.InitGlobal() - if err := worker.InitCorp(1000); err != nil { - panic(err) - } + checkIn := worker.NewCheckin(1002) + checkIn.SyncCheckinMonth("") + + return + + worker.InitCorp() if err := server.Start(); err != nil { panic(err) diff --git a/worker/checkin.go b/worker/checkin.go index bf2c1b1..fdd80d9 100644 --- a/worker/checkin.go +++ b/worker/checkin.go @@ -24,17 +24,12 @@ func NewCheckin(corpId int64) *Checkin { corpConfig: corp.GetConfig(), } } -func (c *Checkin) SyncCheckinMonth(corpId int64, month string) error { +func (c *Checkin) SyncCheckinMonth(month string) error { if month == "" { month = time.Now().AddDate(0, -1, 0).Format("200601") } - corp, err := dao.NewCorpDao().Get(corpId) - if err != nil { - log.Errorf("db error :%s", err.Error()) - return err - } - cfg := corp.GetConfig() + cfg := c.corp.GetConfig() startTime, _ := time.ParseInLocation("20060102", month+"01", time.Local) endDay := startTime.AddDate(0, 1, -1).Format("2006-01-02") @@ -147,6 +142,7 @@ func (c *Checkin) saveToDB(user *qyweixin.UserCheckIn) error { checkin.EndTime = user.EndTime checkin.Month = user.Month checkin.Rawdata = user.Rawdata + checkin.CorpId = c.corp.Id if isNew { _, err = dao.NewCheckinDao().Create(checkin) diff --git a/worker/worker.go b/worker/worker.go index ae6d14a..7f3ca62 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -6,15 +6,18 @@ import ( "time" ) -func InitCorp(corpId int64) error { - +func InitCorp() { timezone, _ := time.LoadLocation("Asia/Shanghai") cron := gocron.NewScheduler(timezone) - staff := new(Staff) + InitCorp1000(cron) + InitCorp1002(cron) - cron.Every(1).Day().At("09:00").Do(func() { - go staff.MontorWorkAge(corpId) - }) + cron.StartAsync() +} + +func InitCorp1002(cron *gocron.Scheduler) { + corpId := int64(1002) + staff := new(Staff) //同步每日考勤数据 cron.Every(1).Day().At("05:00").Do(func() { @@ -29,7 +32,7 @@ func InitCorp(corpId int64) error { //每月1号同步上月考勤、补卡审批、请假审批、报销审批 cron.Every(1).Month(1).At("05:30").Do(func() { checkIn := NewCheckin(corpId) - checkIn.SyncCheckinMonth(corpId, "") + checkIn.SyncCheckinMonth("") lastMonth := time.Now().AddDate(0, -1, 0).Format("200601") approve := NewApproval(corpId) @@ -50,6 +53,48 @@ func InitCorp(corpId int64) error { go staff.SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601")) //go staff.SendStaffSalaryBill(1002, time.Now().AddDate(0, -1, 0).Format("200601")) }) - cron.StartAsync() - return nil +} + +func InitCorp1000(cron *gocron.Scheduler) { + corpId := int64(1000) + staff := new(Staff) + cron.Every(1).Day().At("09:00").Do(func() { + go staff.MontorWorkAge(corpId) + }) + + //同步每日考勤数据 + cron.Every(1).Day().At("05:00").Do(func() { + checkIn := NewCheckin(corpId) + go checkIn.SyncCheckinDay(corpId, "") + }) + cron.Every(1).Day().At("08:00").Do(func() { + checkIn := NewCheckin(corpId) + go checkIn.MonitorCheckinDay(corpId, "") + }) + + //每月1号同步上月考勤、补卡审批、请假审批、报销审批 + cron.Every(1).Month(1).At("05:30").Do(func() { + checkIn := NewCheckin(corpId) + checkIn.SyncCheckinMonth("") + lastMonth := time.Now().AddDate(0, -1, 0).Format("200601") + + approve := NewApproval(corpId) + approve.Sync(corpId, lastMonth, model.ApprovalTypeCheckin) + approve.Sync(corpId, lastMonth, model.ApprovalTypeVacation) + approve.Sync(corpId, lastMonth, model.ApprovalTypeRefund) + approve.Sync(corpId, lastMonth, model.ApprovalTypePayment) + }) + + // 1号计算工资信息 + cron.Every(1).Month(1, 2, 3, 4, 5, 6, 7, 8, 9).At("06:00").Do(func() { + go staff.SyncStaffSalary(corpId, "") + //go staff.SyncStaffSalary(1002, "") + }) + + //10号晚上8点发送工资单 + cron.Every(1).Month(10).At("20:00").Do(func() { + go staff.SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601")) + //go staff.SendStaffSalaryBill(1002, time.Now().AddDate(0, -1, 0).Format("200601")) + }) + }