http_job.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package http
  2. import (
  3. "context"
  4. "go-common/app/job/main/up/model"
  5. "go-common/app/job/main/up/model/upcrmmodel"
  6. "go-common/library/log"
  7. "go-common/library/net/http/blademaster"
  8. "strings"
  9. "time"
  10. )
  11. func runJob(c *blademaster.Context) {
  12. var err error
  13. var res interface{}
  14. switch {
  15. default:
  16. var arg struct {
  17. Date string `form:"date"`
  18. Job string `form:"job"`
  19. }
  20. var err = c.Bind(&arg)
  21. if err != nil {
  22. break
  23. }
  24. var date time.Time
  25. if arg.Date == "" {
  26. date = time.Now()
  27. } else {
  28. date, err = time.Parse(upcrmmodel.TimeFmtDate, arg.Date)
  29. if err != nil {
  30. log.Error("parse date err")
  31. break
  32. }
  33. }
  34. switch strings.ToLower(arg.Job) {
  35. case "task":
  36. svc.CheckTaskFinish(date)
  37. case "due":
  38. svc.CheckDateDueJob(date)
  39. case "state":
  40. svc.CheckStateJob(date)
  41. case "tid":
  42. svc.UpdateUpTidJob(date)
  43. case "":
  44. svc.UpdateUpTidJob(date)
  45. svc.CheckStateJob(date)
  46. svc.CheckDateDueJob(date)
  47. svc.CheckTaskFinish(date)
  48. }
  49. }
  50. if err != nil {
  51. c.JSON(nil, err)
  52. } else {
  53. c.JSON(res, err)
  54. }
  55. }
  56. func warmUp(c *blademaster.Context) {
  57. var err error
  58. var res interface{}
  59. switch {
  60. default:
  61. var arg = &model.WarmUpReq{}
  62. var err = c.Bind(arg)
  63. if err != nil {
  64. break
  65. }
  66. go func() {
  67. res, err = svc.WarmUp(context.Background(), arg)
  68. }()
  69. }
  70. if err != nil {
  71. c.JSON(nil, err)
  72. } else {
  73. c.JSON(res, err)
  74. }
  75. }
  76. func warmUpMid(c *blademaster.Context) {
  77. var err error
  78. var res interface{}
  79. switch {
  80. default:
  81. var arg = &model.WarmUpReq{}
  82. var err = c.Bind(arg)
  83. if err != nil {
  84. break
  85. }
  86. go func() {
  87. res, err = svc.WarmUpMid(context.Background(), arg)
  88. }()
  89. }
  90. if err != nil {
  91. c.JSON(nil, err)
  92. } else {
  93. c.JSON(res, err)
  94. }
  95. }
  96. func addStaff(c *blademaster.Context) {
  97. var err error
  98. var res interface{}
  99. switch {
  100. default:
  101. var arg = &model.AddStaffReq{}
  102. var err = c.Bind(arg)
  103. if err != nil {
  104. break
  105. }
  106. res, _ = svc.AddStaff(c, arg)
  107. }
  108. if err != nil {
  109. c.JSON(nil, err)
  110. } else {
  111. c.JSON(res, err)
  112. }
  113. }
  114. func deleteStaff(c *blademaster.Context) {
  115. var err error
  116. var res interface{}
  117. switch {
  118. default:
  119. var arg = &model.AddStaffReq{}
  120. var err = c.Bind(arg)
  121. if err != nil {
  122. break
  123. }
  124. res, _ = svc.DeleteStaff(c, arg)
  125. }
  126. if err != nil {
  127. c.JSON(nil, err)
  128. } else {
  129. c.JSON(res, err)
  130. }
  131. }