job.go 4.1 KB

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