job.go 869 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package service
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/robfig/cron"
  6. )
  7. func SapJobInit() {
  8. // test()
  9. // c := cron.New()
  10. // 02:00
  11. // if _, e := c.AddFunc("5 5 5 * * ", jobMaterial); e != nil {
  12. // log.Error("jobMaterial", e)
  13. // }
  14. // if _, e := c.AddFunc("1 * * * *", jobTransfer); e != nil {
  15. // // if _, e := c.AddFunc("@every 1m", jobTransfer); e != nil {
  16. // log.Error("transfer ", e)
  17. // }
  18. duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
  19. duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  20. spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  21. c := cron.New()
  22. c.AddFunc(spec, func() {
  23. AutoSapOrderJob()
  24. AutoSrmOrderJob()
  25. // fmt.Println(time.Now())
  26. })
  27. c.Start()
  28. }
  29. func jobMaterial() {
  30. t := time.Now()
  31. var code string
  32. s.SapMaterial(t, code)
  33. }
  34. func jobTransfer() {
  35. autoTransfer()
  36. }