get_xunji_list_logic.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package xunji
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/suyuan32/simple-admin-common/utils/pointy"
  6. "wechat-api/ent/predicate"
  7. "wechat-api/ent/xunji"
  8. "wechat-api/internal/utils/dberrorhandler"
  9. "wechat-api/internal/svc"
  10. "wechat-api/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type GetXunjiListLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewGetXunjiListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiListLogic {
  19. return &GetXunjiListLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx}
  23. }
  24. func (l *GetXunjiListLogic) GetXunjiList(req *types.XunjiListReq) (*types.XunjiListResp, error) {
  25. var predicates []predicate.Xunji
  26. if req.AppKey != nil {
  27. predicates = append(predicates, xunji.AppKeyContains(*req.AppKey))
  28. }
  29. if req.AppSecret != nil {
  30. predicates = append(predicates, xunji.AppSecretContains(*req.AppSecret))
  31. }
  32. if req.Token != nil {
  33. predicates = append(predicates, xunji.TokenContains(*req.Token))
  34. }
  35. data, err := l.svcCtx.DB.Xunji.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
  36. if err != nil {
  37. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  38. }
  39. resp := &types.XunjiListResp{}
  40. resp.Msg = errormsg.Success
  41. resp.Data.Total = data.PageDetails.Total
  42. for _, v := range data.List {
  43. resp.Data.Data = append(resp.Data.Data,
  44. types.XunjiInfo{
  45. BaseIDInfo: types.BaseIDInfo{
  46. Id: &v.ID,
  47. CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
  48. UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
  49. },
  50. Status: &v.Status,
  51. AppKey: &v.AppKey,
  52. AppSecret: &v.AppSecret,
  53. Token: &v.Token,
  54. EncodingKey: &v.EncodingKey,
  55. OrganizationId: &v.OrganizationID,
  56. })
  57. }
  58. return resp, nil
  59. }