get_xunji_list_logic.go 1.9 KB

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