applicationlistlogic.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Code scaffolded by goctl. Safe to edit.
  2. // goctl 1.10.2
  3. package application
  4. import (
  5. "context"
  6. "udeServer/internal/apierr"
  7. "udeServer/internal/log"
  8. "udeServer/internal/svc"
  9. "udeServer/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type ApplicationListLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. // 应用凭证列表
  18. func NewApplicationListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplicationListLogic {
  19. return &ApplicationListLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *ApplicationListLogic) ApplicationList(req *types.ApplicationListReq) (*types.ApplicationListResp, error) {
  26. page, pageSize := normalizePage(req.Page, req.PageSize)
  27. // 状态筛选仅接受 1(启用)/2(禁用);其余取值(含 0)视为不过滤,与 sdf 行为一致
  28. var filterStatus int64
  29. switch req.Status {
  30. case 1, 2:
  31. filterStatus = req.Status
  32. }
  33. rows, total, err := l.svcCtx.ApplicationCredModel.FindPage(l.ctx, page, pageSize, filterStatus, req.CredIden, req.Name)
  34. if err != nil {
  35. log.RecordError(l.ctx, err)
  36. return nil, apierr.New(500, "查询应用凭证列表失败")
  37. }
  38. lists := make([]types.ApplicationCredentials, len(rows))
  39. for i := range rows {
  40. lists[i] = toApplicationCredentials(&rows[i])
  41. }
  42. return &types.ApplicationListResp{
  43. Total: total,
  44. ApplicationLists: lists,
  45. }, nil
  46. }