package main import ( "fmt" "github.com/jasonlvhit/gocron" "log" "udesk/exceldeal" "udesk/udesk/modifystate" ) func main() { log.Printf("准备执行...") // 定义任务 //gocron.Every(5).Second().Do(job) gocron.Every(1).Day().At("09:30").Do(job) //gocron.Every(1).Minutes().Do(job) // 开始定时任务 <-gocron.Start() } // 定义执行的job func job() { fmt.Println("任务开始") remindList, closeList, err := exceldeal.GetSheetName("/rota/standby.xlsx") if err != nil { log.Fatalf("打开值班表失败:%v", err) } log.Println("应在线人员名字:", remindList) log.Println("应离线人员名字:", closeList) remindEmail, closeEmail := exceldeal.JsonDeal("/conf/email.json", remindList, closeList) log.Println("应在线人员邮箱:", remindEmail) log.Println("应离线人员邮箱:", closeEmail) for _, rEmail := range closeEmail { //2024.07.02 杨慧 if rEmail == "huiyang1@alauda.io" { continue } err = modifystate.PostToModifyState(rEmail, "offline") if err != nil { return } } for _, rEmail := range remindEmail { err = modifystate.PostToModifyState(rEmail, "idle") if err != nil { return } } message := fmt.Sprintf("今日小雀: %v,备班1: %v\n昨日小雀: %v,备班1: %v\nudesk呼叫状态已修改。", remindList[0], remindList[1], closeList[0], closeList[1]) exceldeal.Send(message) fmt.Println("任务结束") }