configlistlogic.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Code scaffolded by goctl. Safe to edit.
  2. // goctl 1.10.2
  3. package applicationconfig
  4. import (
  5. "context"
  6. "udeServer/internal/apierr"
  7. "udeServer/internal/log"
  8. "udeServer/internal/model"
  9. "udeServer/internal/svc"
  10. "udeServer/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type ConfigListLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. // 配置分页列表
  19. func NewConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConfigListLogic {
  20. return &ConfigListLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *ConfigListLogic) ConfigList(req *types.ConfigListReq) (*types.ConfigListResp, error) {
  27. page, pageSize := normalizePage(req.Page, req.PageSize)
  28. rows, total, err := l.svcCtx.ConfigModel.FindPage(l.ctx, page, pageSize, req.ConfigItem, req.Description)
  29. if err != nil {
  30. log.RecordError(l.ctx, err)
  31. return nil, apierr.New(500, "查询配置列表失败")
  32. }
  33. configs := make([]types.Config, len(rows))
  34. for i := range rows {
  35. configs[i] = toConfig(&rows[i])
  36. }
  37. return &types.ConfigListResp{
  38. Total: total,
  39. Configs: configs,
  40. }, nil
  41. }
  42. // toConfig 模型行转响应体,字段名 descritpion 沿袭 sdf 契约。
  43. func toConfig(row *model.TConfig) types.Config {
  44. return types.Config{
  45. Id: row.Id,
  46. ConfigItem: row.ConfigItem,
  47. ConfigValue: row.ConfigValue,
  48. EditFlag: row.EditFlag,
  49. Description: row.Description.String,
  50. UpdatedBy: row.UpdatedBy,
  51. UpdatedAt: formatConfigTime(row.UpdatedAt),
  52. }
  53. }