job.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 37 23 * * ?", func() {
  58. AutoContractToASP()
  59. })
  60. c1.AddFunc("0 50 01 * * ?", func() {
  61. //更新设备维修和保养费用
  62. pastureList := make([]*model.Pasture, 0)
  63. s.d.DB.Table("pasture").Where("vendor = 1 ").Where("id != 18 ").Find(&pastureList)
  64. now := time.Now()
  65. start := now.AddDate(-1, 0, 0).Format("2006-01-02")
  66. end := now.Format("2006-01-02")
  67. for _, pasture := range pastureList {
  68. updateEqYearMaintainCostAndYearUpkeepCost(pasture.ID, start, end)
  69. }
  70. })
  71. c1.AddFunc("0 10 16 * * ?", func() {
  72. cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -4).Format("2006-01-02"))
  73. pastureList := make([]*model.Pasture, 0)
  74. s.d.DB.Table("pasture").Where("vendor = 1 ").Where("factory_code != '' ").Where("factory_code is not null ").Find(&pastureList)
  75. for _, item := range pastureList {
  76. AutoFeeQuery(item.FactoryCode, item.ID)
  77. }
  78. })
  79. c1.Start()
  80. }
  81. func jobMaterial() {
  82. t := time.Now()
  83. var code string
  84. s.SapMaterial(t, code)
  85. }
  86. func jobTransfer() {
  87. autoTransfer()
  88. }