暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

tabulator_adapter.go 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package metamanagement
  2. import (
  3. "context"
  4. "encoding/json"
  5. "git.x2erp.com/qdy/go-base/ctx"
  6. "git.x2erp.com/qdy/go-base/logger"
  7. "git.x2erp.com/qdy/go-base/model/request/tabulatorreq"
  8. "git.x2erp.com/qdy/go-base/model/response"
  9. "git.x2erp.com/qdy/go-db/factory/database"
  10. "git.x2erp.com/qdy/go-svc-configure/internal/tables"
  11. )
  12. // TabulatorConfigMetaRequest Tabulator专用的配置元请求
  13. //type TabulatorConfigMetaRequest struct {
  14. // tabulatorreq.TabulatorRequest
  15. //}
  16. // ListConfigMetaTabulator Tabulator格式的配置元查询
  17. func ListConfigMetaTabulator(req *tabulatorreq.TabulatorRequest, ctx context.Context, dbFactory *database.DBFactory, reqCtx *ctx.RequestContext) *response.QueryResult[[]tables.ConfigMetaDB] {
  18. // 调试:记录接收到的原始请求
  19. if logger.IsDebug() {
  20. logger.Debug("TabulatorConfigMetaRequest 原始请求: %+v", req)
  21. if req != nil {
  22. jsonBytes, _ := json.Marshal(req)
  23. logger.Debug("TabulatorRequest: %s", jsonBytes)
  24. }
  25. }
  26. // 验证请求参数
  27. if req == nil {
  28. req = &tabulatorreq.TabulatorRequest{}
  29. req.Page = 1
  30. req.Size = 10
  31. }
  32. req.Validate()
  33. // 调试:验证后的值
  34. if logger.IsDebug() {
  35. logger.Debug("TabulatorConfigMetaRequest 验证后: Page=%d, Size=%d", req.Page, req.Size)
  36. }
  37. // 定义字段映射:前端字段名 -> 后端字段名
  38. fieldMapper := func(field string) string {
  39. switch field {
  40. case "id":
  41. return "id"
  42. case "configName":
  43. return "configName"
  44. case "fieldName":
  45. return "fieldName"
  46. case "fieldType":
  47. return "fieldType"
  48. case "yamlName":
  49. return "yamlName"
  50. case "fieldDesc":
  51. return "fieldDesc"
  52. case "creator":
  53. return "creator"
  54. case "createdAt":
  55. return "createdAt"
  56. default:
  57. // 未知字段,返回空字符串(将被忽略)
  58. return ""
  59. }
  60. }
  61. // 转换为通用查询请求
  62. queryReq := req.ToQueryRequest(fieldMapper)
  63. // 创建ConfigMetaQueryRequest
  64. configMetaReq := &ConfigMetaQueryRequest{
  65. QueryRequest: *queryReq,
  66. }
  67. // 调用现有的查询逻辑
  68. result := ListConfigMeta(configMetaReq, ctx, dbFactory, reqCtx)
  69. // 直接返回QueryResult,包含LastPage字段
  70. return &response.QueryResult[[]tables.ConfigMetaDB]{
  71. Success: result.Success,
  72. LastPage: result.LastPage,
  73. Data: result.Data,
  74. Error: result.Error,
  75. Count: len(result.Data),
  76. Time: result.Time,
  77. QueryTime: result.QueryTime,
  78. SaveTime: result.SaveTime,
  79. TotalCount: result.TotalCount,
  80. Message: result.Message,
  81. Metadata: result.Metadata,
  82. }
  83. }