package service import ( "fmt" "time" "github.com/robfig/cron" "kpt.xdmy/apiserver/model" ) var s *Service func SapJobInit() { duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local) duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local) spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1)) c := cron.New() c.AddFunc(spec, func() { AutoSapOrderJob() AutoSrmOrderJob() AutoSapReturnOrderJob() AutoSrmReturnOrderJob() }) c.Start() //var t time.Time //t = time.Now() //var code string //pastureList := make([]*model.Pasture, 0) //err := s.d.DB.Table("pasture").Where("id = 1381 ").Find(&pastureList) //fmt.Println(err) //i := -60 //for { // fmt.Println(i, t.AddDate(0, 0, i)) // for _, pasture := range pastureList { // //s.SapSupplier(t, pasture.CompanyCode, pasture.ID) // s.SapAsset(t.AddDate(0, 0, i), code, pasture.CompanyCode) // } // // if t.AddDate(0, 0, i).Format("2006-01-02") == "2023-04-13" { // break // } // i++ //} c1 := cron.New() c1.AddFunc("0 50 23 * * ?", func() { fmt.Println(time.Now()) var t time.Time t = time.Now() var code string pastureList := make([]*model.Pasture, 0) err := s.d.DB.Table("pasture").Find(&pastureList) fmt.Println(err) for _, pasture := range pastureList { s.SapSupplier(t, pasture.CompanyCode, pasture.ID) s.SapAsset(t, code, pasture.CompanyCode) } s.SapMaterial(t, code) s.d.DB.Exec(`call createEqstatus()`) }) //保养计划 duetimecst, _ = time.ParseInLocation("15:04:05", "01:00:00", time.Local) duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local) spec1 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1)) c1.AddFunc(spec1, func() { s.d.DB.Exec(`call createRUcode()`) }) duetimecst, _ = time.ParseInLocation("15:04:05", "00:05:00", time.Local) duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local) spec2 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1)) c1.AddFunc(spec2, func() { s.d.DB.Exec(`call wxmsg()`) }) // 合同信息同步SAP 5分钟同步一次,一次同步limit条数据 timeLocalSub, _ := time.ParseInLocation("15:04:05", "00:05:00", time.Local) timeLocal, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local) c1.AddFunc(fmt.Sprintf("@every %v", timeLocalSub.Sub(timeLocal)), func() { AutoContractToASP() }) c1.Start() } func jobMaterial() { t := time.Now() var code string s.SapMaterial(t, code) } func jobTransfer() { autoTransfer() }