This commit is contained in:
jiangyong27 2024-01-24 17:39:05 +08:00
parent f12156cfed
commit 866b71f49e
3 changed files with 24 additions and 19 deletions

View File

@ -3,11 +3,12 @@ package main
import ( import (
"enterprise/common/config" "enterprise/common/config"
"enterprise/common/global" "enterprise/common/global"
"enterprise/common/model"
"enterprise/server" "enterprise/server"
"enterprise/worker" "enterprise/worker"
) )
func main() { func main22() {
config.LoadServerConfig() config.LoadServerConfig()
global.InitGlobal() global.InitGlobal()
@ -20,11 +21,11 @@ func main() {
} }
} }
func main22() { func main() {
config.LoadServerConfig() config.LoadServerConfig()
global.InitGlobal() global.InitGlobal()
//cfg := config.GetConfig() //cfg := config.GetConfig()
//new(worker.Checkin).SyncCheckinDay("2024-01-17") //new(worker.Checkin).SyncCheckinDay("2024-01-17")
new(worker.Staff).SyncStaffInfo() new(worker.Approval).Sync("202401", model.ApprovalTypeRefund)
} }

View File

@ -41,6 +41,9 @@ func (s *Approval) Sync(month, tp string) {
log.Errorf("approve GetDetail error :%s", err.Error()) log.Errorf("approve GetDetail error :%s", err.Error())
continue continue
} }
if detail.SpStatus != 2 {
continue
}
if tp == model.ApprovalTypeCheckin { if tp == model.ApprovalTypeCheckin {
s.saveCheckin(detail) s.saveCheckin(detail)
} else if tp == model.ApprovalTypeRefund { } else if tp == model.ApprovalTypeRefund {
@ -83,13 +86,10 @@ func (s *Approval) saveRefund(detail *qyweixin.ApproveDetail) {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
} }
if old == nil { if old != nil {
_, err = dbDao.Create(newData) return
} else {
newData.Id = old.Id
newData.CreateTime = old.CreateTime
err = dbDao.Update(newData)
} }
_, err = dbDao.Create(newData)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
} }
@ -104,13 +104,10 @@ func (s *Approval) saveVacation(detail *qyweixin.ApproveDetail) {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
} }
if old == nil { if old != nil {
_, err = dbDao.Create(newData) return
} else {
newData.Id = old.Id
newData.CreateTime = old.CreateTime
err = dbDao.Update(newData)
} }
_, err = dbDao.Create(newData)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
} }

View File

@ -1,6 +1,7 @@
package worker package worker
import ( import (
"enterprise/common/model"
"github.com/go-co-op/gocron" "github.com/go-co-op/gocron"
"time" "time"
) )
@ -10,6 +11,7 @@ func Init() error {
cron := gocron.NewScheduler(timezone) cron := gocron.NewScheduler(timezone)
staff := new(Staff) staff := new(Staff)
checkIn := new(Checkin) checkIn := new(Checkin)
approve := new(Approval)
// 每天同步企业人事信息 // 每天同步企业人事信息
cron.Every(1).Day().At("01:00").Do(func() { cron.Every(1).Day().At("01:00").Do(func() {
@ -21,12 +23,17 @@ func Init() error {
go checkIn.SyncCheckinDay("") go checkIn.SyncCheckinDay("")
}) })
cron.Every(1).Month(1).At("05:20").Do(func() { //每月1号同步上月考勤、补卡审批、请假审批、报销审批
go checkIn.SyncCheckinMonth("") 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-10号计算工资信息 // 1号计算工资信息
cron.Every(1).Month(1).At("05:30").Do(func() { cron.Every(1).Month(1).At("06:00").Do(func() {
go staff.SyncStaffSalary("") go staff.SyncStaffSalary("")
}) })