job.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package service
  2. import (
  3. "fmt"
  4. "github.com/robfig/cron"
  5. "kpt.xdmy/apiserver/model"
  6. "kpt.xdmy/apiserver/service/cownum_sqlserver"
  7. "time"
  8. )
  9. var s *Service
  10. func SapJobInit() {
  11. duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
  12. duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  13. spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  14. c := cron.New()
  15. c.AddFunc(spec, func() {
  16. AutoSapOrderJob()
  17. AutoSrmOrderJob()
  18. AutoSapReturnOrderJob()
  19. AutoSrmReturnOrderJob()
  20. })
  21. c.Start()
  22. c1 := cron.New()
  23. c1.AddFunc("0 50 23 * * ?", func() {
  24. fmt.Println(time.Now())
  25. //更新设备维修和保养费用
  26. var t time.Time
  27. t = time.Now()
  28. var code string
  29. pastureList := make([]*model.Pasture, 0)
  30. err := s.d.DB.Table("pasture").Find(&pastureList)
  31. fmt.Println(err)
  32. for _, pasture := range pastureList {
  33. s.SapSupplier(t, pasture.CompanyCode, pasture.ID)
  34. s.SapAsset(t, code, pasture.CompanyCode)
  35. }
  36. s.SapMaterial(t, code)
  37. s.d.DB.Exec(`call createEqstatus()`)
  38. })
  39. //保养计划
  40. duetimecst, _ = time.ParseInLocation("15:04:05", "01:00:00", time.Local)
  41. duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  42. spec1 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  43. c1.AddFunc(spec1, func() {
  44. pastureList := make([]*model.Pasture, 0)
  45. s.d.DB.Table("pasture").Where("vendor = 1").Find(&pastureList)
  46. for _, pasture := range pastureList {
  47. fmt.Println(pasture.ID)
  48. s.d.DB.Exec(`call createRUcode(?)`, pasture.ID)
  49. }
  50. })
  51. duetimecst, _ = time.ParseInLocation("15:04:05", "00:05:00", time.Local)
  52. duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  53. spec2 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  54. c1.AddFunc(spec2, func() {
  55. s.d.DB.Exec(`call wxmsg()`)
  56. })
  57. c1.AddFunc("0 10 16 * * ?", func() {
  58. cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -1).Format("2006-01-02"))
  59. pastureList := make([]*model.Pasture, 0)
  60. s.d.DB.Table("pasture").Where("vendor = 1 ").Where("factory_code != '' ").Where("factory_code is not null ").Find(&pastureList)
  61. for _, item := range pastureList {
  62. AutoFeeQuery(item.FactoryCode, item.ID)
  63. }
  64. })
  65. timeLocalSub, _ := time.ParseInLocation("15:04:05", "00:30:00", time.Local)
  66. timeLocal, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  67. c1.AddFunc(fmt.Sprintf("@every %v", timeLocalSub.Sub(timeLocal)), func() {
  68. AutoContractToASP()
  69. })
  70. c1.AddFunc("0 50 01 * * ?", func() {
  71. //更新设备维修和保养费用
  72. pastureList := make([]*model.Pasture, 0)
  73. s.d.DB.Table("pasture").Where("vendor = 1 ").Where("id != 18 ").Find(&pastureList)
  74. now := time.Now()
  75. start := now.AddDate(-1, 0, 0).Format("2006-01-02")
  76. end := now.Format("2006-01-02")
  77. for _, pasture := range pastureList {
  78. updateEqYearMaintainCostAndYearUpkeepCost(pasture.ID, start, end)
  79. }
  80. })
  81. c1.Start()
  82. }
  83. func jobMaterial() {
  84. t := time.Now()
  85. var code string
  86. s.SapMaterial(t, code)
  87. }
  88. func jobTransfer() {
  89. autoTransfer()
  90. }