get_api_employee_list_logic.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package employee
  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/employee"
  7. "wechat-api/ent/predicate"
  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 GetApiEmployeeListLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewGetApiEmployeeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiEmployeeListLogic {
  19. return &GetApiEmployeeListLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx}
  23. }
  24. func (l *GetApiEmployeeListLogic) GetApiEmployeeList(req *types.EmployeeListReq) (*types.EmployeeListResp, error) {
  25. var predicates []predicate.Employee
  26. if req.CategoryId != nil && *req.CategoryId > 0 {
  27. predicates = append(predicates, employee.CategoryID(*req.CategoryId))
  28. }
  29. data, err := l.svcCtx.DB.Employee.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.EmployeeListResp{}
  34. resp.Msg = errormsg.Success
  35. resp.Data.Total = data.PageDetails.Total
  36. for _, v := range data.List {
  37. var showChat, showAi, isVip bool
  38. if v.APIKey != "" && v.APIBase != "" {
  39. showChat = true
  40. }
  41. if v.AiInfo != "" {
  42. showAi = true
  43. }
  44. if v.IsVip != 0 {
  45. isVip = true
  46. }
  47. resp.Data.Data = append(resp.Data.Data,
  48. types.EmployeeInfo{
  49. BaseIDInfo: types.BaseIDInfo{
  50. Id: &v.ID,
  51. CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
  52. UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
  53. },
  54. Title: &v.Title,
  55. Avatar: &v.Avatar,
  56. Tags: &v.Tags,
  57. HireCount: &v.HireCount,
  58. ServiceCount: &v.ServiceCount,
  59. AchievementCount: &v.AchievementCount,
  60. Intro: &v.Intro,
  61. Estimate: &v.Estimate,
  62. Skill: &v.Skill,
  63. AbilityType: &v.AbilityType,
  64. Scene: &v.Scene,
  65. SwitchIn: &v.SwitchIn,
  66. VideoUrl: &v.VideoURL,
  67. CategoryId: &v.CategoryID,
  68. ShowChat: &showChat,
  69. ShowAi: &showAi,
  70. IsVip: &isVip,
  71. })
  72. }
  73. return resp, nil
  74. }