HR管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB

package scheduledtask
import (
"fmt"
"hr_server/api/jindie_docking/dockingorganization"
"hr_server/overall/overallhandle"
"time"
"github.com/robfig/cron/v3"
)
/*
定时任务模块
跟随任务一起启动执行周期性任务操作
*/
func TimeTask() {
fmt.Println("------------准备启动定时任务--------------")
// overallhandle.WriteLog("t", "准备启动定时任务")
go func() {
c := cron.New(cron.WithSeconds()) //声明定时任务启动器
fmt.Printf("time.UTC--->%v\n", time.Now())
/*
加载任务场景
AddFunc("任务时间格式","执行的任务")
*/
// c.AddFunc("10 * * * * *", func() {
c.AddFunc("0 30 22 * * *", func() {
// fmt.Printf("执行定时任务------>%v\n", time.Now())
overallhandle.WriteLog("t", "开始执行行政组织类型对照")
dockingorganization.GetOrgType()
overallhandle.WriteLog("t", "结束执行行政组织类型对照")
overallhandle.WriteLog("t", "开始执行职务类型对照")
dockingorganization.JobClass()
overallhandle.WriteLog("t", "结束执行职务类型对照")
}) //每天22时30分执行
// c.AddFunc("20 * * * * *", func() {
c.AddFunc("0 10 23 * * *", func() {
overallhandle.WriteLog("t", "开始执行职务对照")
dockingorganization.DutiesContrast()
overallhandle.WriteLog("t", "结束执行职务对照")
overallhandle.WriteLog("t", "开始执行行政组织对照")
dockingorganization.OrgAdmin()
overallhandle.WriteLog("t", "结束执行行政组织对照")
}) //每天23时10分执行
c.AddFunc("0 15 0 * * *", func() {
overallhandle.WriteLog("t", "开始执行职位对照")
dockingorganization.Position()
overallhandle.WriteLog("t", "结束执行职位对照")
}) //每天0时15分执行
//启动
c.Start()
//设定全部执行后,最后关闭定时任务
defer c.Stop()
select {}
}()
fmt.Printf("定时任务启动成功!TIME:%v\n", overallhandle.UnixTimeToDay(time.Now().Unix(), 50))
// overallhandle.WriteLog("t", "定时任务启动成功")
}