job.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. //t := time.Now()
  23. //i := 25
  24. //pastureList := make([]*model.Pasture, 0)
  25. //s.d.DB.Table("pasture").Find(&pastureList)
  26. //
  27. //for {
  28. // //for _, pasture := range pastureList {
  29. // //1029
  30. // s.SapAsset(t.AddDate(0, 0, -i), "", "1029")
  31. // //}
  32. //
  33. // if i == 0 {
  34. // panic("break")
  35. // }
  36. // i--
  37. //}
  38. //var t time.Time
  39. //t = time.Now()
  40. //s.SapMaterial(t.AddDate(0, 0, -1), "")
  41. //s.SapMaterial(t.AddDate(0, 0, -2), "")
  42. //s.SapMaterial(t.AddDate(0, 0, -3), "")
  43. //s.SapMaterial(t.AddDate(0, 0, -4), "")
  44. //s.SapMaterial(t.AddDate(0, 0, -5), "")
  45. //s.SapMaterial(t.AddDate(0, 0, -6), "")
  46. //s.SapMaterial(t.AddDate(0, 0, -7), "")
  47. //s.SapMaterial(t.AddDate(0, 0, -8), "")
  48. //s.SapMaterial(t.AddDate(0, 0, -9), "")
  49. //s.SapMaterial(t.AddDate(0, 0, -10), "")
  50. //s.SapMaterial(t.AddDate(0, 0, -11), "")
  51. c1 := cron.New()
  52. c1.AddFunc("0 40 23 * * ?", func() {
  53. fmt.Println(time.Now())
  54. //更新设备维修和保养费用
  55. var t time.Time
  56. t = time.Now()
  57. var code string
  58. pastureList := make([]*model.Pasture, 0)
  59. err := s.d.DB.Table("pasture").Find(&pastureList)
  60. fmt.Println(err)
  61. for _, pasture := range pastureList {
  62. s.SapSupplier(t, pasture.CompanyCode, pasture.ID)
  63. s.SapAsset(t, code, pasture.CompanyCode)
  64. s.SapAssetSalvage(t, pasture.CompanyCode, pasture.ID)
  65. }
  66. s.SapMaterial(t, code)
  67. s.SapMaterial(t.AddDate(0, 0, -1), code)
  68. s.SapMaterial(t.AddDate(0, 0, -2), code)
  69. s.SapMaterial(t.AddDate(0, 0, -3), code)
  70. s.d.DB.Exec(`call createEqstatus()`)
  71. })
  72. //保养计划
  73. duetimecst, _ = time.ParseInLocation("15:04:05", "01:00:00", time.Local)
  74. duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  75. spec1 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  76. c1.AddFunc(spec1, func() {
  77. pastureList := make([]*model.Pasture, 0)
  78. s.d.DB.Table("pasture").Where("vendor = 1").Find(&pastureList)
  79. for _, pasture := range pastureList {
  80. fmt.Println(pasture.ID)
  81. s.d.DB.Exec(`call createRUcode(?)`, pasture.ID)
  82. }
  83. })
  84. duetimecst, _ = time.ParseInLocation("15:04:05", "00:05:00", time.Local)
  85. duetimecst1, _ = time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  86. spec2 := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
  87. c1.AddFunc(spec2, func() {
  88. s.d.DB.Exec(`call wxmsg()`)
  89. })
  90. c1.AddFunc("0 50 01 * * ?", func() {
  91. //更新设备维修和保养费用
  92. pastureList := make([]*model.Pasture, 0)
  93. s.d.DB.Table("pasture").Where("vendor = 1 ").Where("id != 18 ").Find(&pastureList)
  94. now := time.Now()
  95. start := now.AddDate(-1, 0, 0).Format("2006-01-02")
  96. end := now.Format("2006-01-02")
  97. for _, pasture := range pastureList {
  98. updateEqYearMaintainCostAndYearUpkeepCost(pasture.ID, start, end)
  99. }
  100. })
  101. c1.AddFunc("0 20 18 * * ?", func() {
  102. cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -3).Format("2006-01-02"))
  103. cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -2).Format("2006-01-02"))
  104. cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -1).Format("2006-01-02"))
  105. pastureList := make([]*model.Pasture, 0)
  106. s.d.DB.Table("pasture").Where("vendor = 1 ").Where("factory_code != '' ").Where("factory_code is not null ").Find(&pastureList)
  107. for _, item := range pastureList {
  108. AutoFeeQuery(item.FactoryCode, item.ID)
  109. }
  110. })
  111. c1.AddFunc("0 10 12 * * ?", func() {
  112. AutoContractToASP()
  113. })
  114. c1.AddFunc("0 20 23 * * ?", func() {
  115. s.SyncPasture()
  116. s.SyncEquipmentDate()
  117. AutoContractToASP()
  118. })
  119. //AutoContractToASP()
  120. //c1.Start()
  121. //s.SyncEquipmentDate()
  122. //s.SyncPasture()
  123. //s.SyncEquipmentDate()
  124. }
  125. func jobMaterial() {
  126. t := time.Now()
  127. var code string
  128. s.SapMaterial(t, code)
  129. }
  130. func jobTransfer() {
  131. autoTransfer()
  132. }