simple.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package task_runner
  2. import (
  3. "git.sxidc.com/go-framework/baize/convenient/domain/task_runner/task"
  4. "git.sxidc.com/go-framework/baize/framework/binding"
  5. "git.sxidc.com/go-framework/baize/framework/core/api"
  6. "git.sxidc.com/go-framework/baize/framework/core/api/request"
  7. "git.sxidc.com/go-framework/baize/framework/core/api/response"
  8. "git.sxidc.com/go-framework/baize/framework/core/application"
  9. "git.sxidc.com/go-framework/baize/framework/core/domain"
  10. "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
  11. "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
  12. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
  13. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database/sql"
  14. "git.sxidc.com/go-tools/utils/strutils"
  15. )
  16. // Simple Bind参数
  17. type Simple struct {
  18. // schema
  19. Schema string
  20. }
  21. func (simple *Simple) bind(binder *binding.Binder) {
  22. binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[task.Info]]{
  23. Path: "/task/get",
  24. SendResponseFunc: response.SendInfosResponse[task.Info],
  25. RequestParams: &task.GetTaskQueryParams{},
  26. Objects: []domain.Object{&task.Entity{}},
  27. ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (response.InfosData[task.Info], error) {
  28. errResponse := response.InfosData[task.Info]{
  29. Infos: make([]task.Info, 0),
  30. TotalCount: 0,
  31. PageNo: 0,
  32. }
  33. queryParams, err := request.ToConcrete[task.GetTaskQueryParams](params)
  34. if err != nil {
  35. return errResponse, err
  36. }
  37. conditions := sql.NewConditions()
  38. if strutils.IsStringNotEmpty(queryParams.Group) {
  39. conditions.Equal(task.ColumnGroup, queryParams.Group)
  40. }
  41. if strutils.IsStringNotEmpty(queryParams.Status) {
  42. conditions.Equal(task.ColumnStatus, queryParams.Status)
  43. }
  44. if strutils.IsStringNotEmpty(queryParams.StartCreatedTime) {
  45. conditions.GreaterThanAndEqual(entity.ColumnCreatedTime, queryParams.StartCreatedTime)
  46. }
  47. if strutils.IsStringNotEmpty(queryParams.EndCreatedTime) {
  48. conditions.LessThanAndEqual(entity.ColumnCreatedTime, queryParams.EndCreatedTime)
  49. }
  50. results, totalCount, err := database.Query(i.DBExecutor(), &sql.QueryExecuteParams{
  51. TableName: simple.Schema,
  52. Conditions: conditions,
  53. PageNo: queryParams.PageNo,
  54. PageSize: queryParams.PageSize,
  55. })
  56. if err != nil {
  57. return errResponse, err
  58. }
  59. infos, err := task.FormInfos(results)
  60. if err != nil {
  61. return errResponse, err
  62. }
  63. return response.InfosData[task.Info]{
  64. Infos: infos,
  65. TotalCount: totalCount,
  66. PageNo: queryParams.PageNo,
  67. }, nil
  68. },
  69. })
  70. }
  71. func Bind(app *application.App, simple *Simple) {
  72. binder := binding.NewBinder(app.Api().ChooseRouter(api.RouterPrefix, ""), app.Infrastructure())
  73. simple.bind(binder)
  74. }