sys_job.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package controller
  2. import (
  3. "Medical_OAuth/common/dto"
  4. "gogs.baozhida.cn/zoie/OAuth-core/api"
  5. toolsConfig "gogs.baozhida.cn/zoie/OAuth-core/sdk/config"
  6. "net/http"
  7. "github.com/gin-gonic/gin"
  8. "Medical_OAuth/app/jobs/service"
  9. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  10. "gogs.baozhida.cn/zoie/OAuth-core/sdk"
  11. )
  12. type SysJob struct {
  13. api.Api
  14. }
  15. // RemoveJobForService 调用service实现
  16. func (e SysJob) RemoveJobForService(c *gin.Context) {
  17. v := dto.GeneralDelDto{}
  18. s := service.SysJob{}
  19. err := e.MakeContext(c).
  20. MakeOrm().
  21. Bind(&v, nil).
  22. MakeService(&s.Service).
  23. Errors
  24. if err != nil {
  25. e.Logger.Error(err)
  26. e.Error(500, err, "")
  27. return
  28. }
  29. s.Cron = sdk.Runtime.GetCrontabKey(toolsConfig.ApplicationConfig.Host)
  30. err = s.RemoveJob(&v)
  31. if err != nil {
  32. e.Logger.Errorf("RemoveJob error, %s", err.Error())
  33. e.Error(500, err, "")
  34. return
  35. }
  36. e.OK(nil, s.Msg)
  37. }
  38. // StartJobForService 启动job service实现
  39. func (e SysJob) StartJobForService(c *gin.Context) {
  40. e.MakeContext(c)
  41. log := e.GetLogger()
  42. db, err := e.GetOrm()
  43. if err != nil {
  44. log.Error(err)
  45. return
  46. }
  47. var v dto.GeneralGetDto
  48. err = c.BindUri(&v)
  49. if err != nil {
  50. log.Warnf("参数验证错误, error: %s", err)
  51. e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
  52. return
  53. }
  54. s := service.SysJob{}
  55. s.Orm = db
  56. s.Log = log
  57. s.Cron = sdk.Runtime.GetCrontabKey(toolsConfig.ApplicationConfig.Host)
  58. err = s.StartJob(&v)
  59. if err != nil {
  60. log.Errorf("GetCrontabKey error, %s", err.Error())
  61. e.Error(500, err, err.Error())
  62. return
  63. }
  64. e.OK(nil, s.Msg)
  65. }