get_wx_card_list_logic.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package wxcard
  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/wxcard"
  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 GetWxCardListLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewGetWxCardListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWxCardListLogic {
  19. return &GetWxCardListLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx}
  23. }
  24. func (l *GetWxCardListLogic) GetWxCardList(req *types.WxCardListReq) (*types.WxCardListResp, error) {
  25. var predicates []predicate.WxCard
  26. if req.Name != nil && *req.Name != "" {
  27. predicates = append(predicates, wxcard.NameContains(*req.Name))
  28. }
  29. data, err := l.svcCtx.DB.WxCard.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
  30. if err != nil {
  31. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  32. }
  33. resp := &types.WxCardListResp{
  34. BaseDataInfo: types.BaseDataInfo{
  35. Code: 0,
  36. Msg: errormsg.Success,
  37. },
  38. }
  39. for _, v := range data.List {
  40. resp.Data.Data = append(resp.Data.Data, types.WxCardInfo{
  41. BaseIDInfo: types.BaseIDInfo{
  42. Id: &v.ID,
  43. CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
  44. UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
  45. },
  46. Name: &v.Name,
  47. Avatar: &v.Avatar,
  48. Logo: &v.Logo,
  49. Company: &v.Company,
  50. Address: &v.Address,
  51. Phone: &v.Phone,
  52. OfficialAccount: &v.OfficialAccount,
  53. WechatAccount: &v.WechatAccount,
  54. Email: &v.Email,
  55. Intro: &v.Intro,
  56. ApiBase: &v.APIBase,
  57. ApiKey: &v.APIKey,
  58. AiInfo: &v.AiInfo,
  59. })
  60. }
  61. return resp, nil
  62. }