job.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package service
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/robfig/cron"
  6. "kpt.xdmy/apiserver/model"
  7. )
  8. var s *Service
  9. func SapJobInit() {
  10. duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
  11. duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  12. spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  13. c := cron.New()
  14. c.AddFunc(spec, func() {
  15. AutoSapOrderJob()
  16. AutoSrmOrderJob()
  17. AutoSapReturnOrderJob()
  18. AutoSrmReturnOrderJob()
  19. })
  20. c.Start()
  21. //var t time.Time
  22. //t = time.Now()
  23. //var code string
  24. //pastureList := make([]*model.Pasture, 0)
  25. //err := s.d.DB.Table("pasture").Where("id = 1381 ").Find(&pastureList)
  26. //fmt.Println(err)
  27. //i := -60
  28. //for {
  29. // fmt.Println(i, t.AddDate(0, 0, i))
  30. // for _, pasture := range pastureList {
  31. // //s.SapSupplier(t, pasture.CompanyCode, pasture.ID)
  32. // s.SapAsset(t.AddDate(0, 0, i), code, pasture.CompanyCode)
  33. // }
  34. //
  35. // if t.AddDate(0, 0, i).Format("2006-01-02") == "2023-04-13" {
  36. // break
  37. // }
  38. // i++
  39. //}
  40. c1 := cron.New()
  41. c1.AddFunc("0 50 23 * * ?", func() {
  42. fmt.Println(time.Now())
  43. var t time.Time
  44. t = time.Now()
  45. var code string
  46. pastureList := make([]*model.Pasture, 0)
  47. err := s.d.DB.Table("pasture").Find(&pastureList)
  48. fmt.Println(err)
  49. for _, pasture := range pastureList {
  50. s.SapSupplier(t, pasture.CompanyCode, pasture.ID)
  51. s.SapAsset(t, code, pasture.CompanyCode)
  52. }
  53. s.SapMaterial(t, code)
  54. s.d.DB.Exec(`call createEqstatus()`)
  55. })
  56. //保养计划
  57. duetimecst, _ = time.ParseInLocation("15:04:05", "01:00:00", time.Local)
  58. duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  59. spec1 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  60. c1.AddFunc(spec1, func() {
  61. s.d.DB.Exec(`call createRUcode()`)
  62. })
  63. duetimecst, _ = time.ParseInLocation("15:04:05", "00:05:00", time.Local)
  64. duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  65. spec2 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  66. c1.AddFunc(spec2, func() {
  67. s.d.DB.Exec(`call wxmsg()`)
  68. })
  69. // 合同信息同步SAP 5分钟同步一次,一次同步limit条数据
  70. timeLocalSub, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
  71. timeLocal, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  72. c1.AddFunc(fmt.Sprintf("@every %v", timeLocalSub.Sub(timeLocal)), func() {
  73. AutoContractToASP()
  74. })
  75. c1.Start()
  76. }
  77. func jobMaterial() {
  78. t := time.Now()
  79. var code string
  80. s.SapMaterial(t, code)
  81. }
  82. func jobTransfer() {
  83. autoTransfer()
  84. }