get_alloc_agent_list_logic.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package allocagent
  2. import (
  3. "context"
  4. "wechat-api/ent/predicate"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  9. "github.com/suyuan32/simple-admin-common/utils/pointy"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetAllocAgentListLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewGetAllocAgentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllocAgentListLogic {
  18. return &GetAllocAgentListLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *GetAllocAgentListLogic) GetAllocAgentList(req *types.AllocAgentListReq) (*types.AllocAgentListResp, error) {
  25. var predicates []predicate.AllocAgent
  26. data, err := l.svcCtx.DB.AllocAgent.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
  27. if err != nil {
  28. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  29. }
  30. resp := &types.AllocAgentListResp{}
  31. resp.Msg = errormsg.Success
  32. resp.Data.Total = data.PageDetails.Total
  33. for _, v := range data.List {
  34. resp.Data.Data = append(resp.Data.Data,
  35. types.AllocAgentInfo{
  36. BaseIDInfo: types.BaseIDInfo{
  37. Id: &v.ID,
  38. CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
  39. UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
  40. },
  41. UserId: &v.UserID,
  42. OrganizationId: &v.OrganizationID,
  43. Agents: v.Agents,
  44. Status: &v.Status,
  45. })
  46. }
  47. return resp, nil
  48. }