api.go 2.9 KB

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