get_api_employee_detail_logic.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/internal/utils/dberrorhandler"
  8. "wechat-api/internal/svc"
  9. "wechat-api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetApiEmployeeDetailLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewGetApiEmployeeDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiEmployeeDetailLogic {
  18. return &GetApiEmployeeDetailLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *GetApiEmployeeDetailLogic) GetApiEmployeeDetail(req *types.IDReq) (*types.EmployeeInfoResp, error) {
  24. data, err := l.svcCtx.DB.Employee.Query().Where(employee.ID(req.Id)).Only(l.ctx)
  25. if err != nil {
  26. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  27. }
  28. // 是否显示聊天,是否显示Ai连线,是否显示VIP
  29. var showChat, isVip bool
  30. if data.APIKey != "" && data.APIBase != "" {
  31. showChat = true
  32. }
  33. if data.IsVip != 0 {
  34. isVip = true
  35. }
  36. return &types.EmployeeInfoResp{
  37. BaseDataInfo: types.BaseDataInfo{
  38. Code: 0,
  39. Msg: errormsg.Success,
  40. },
  41. Data: types.EmployeeInfo{
  42. BaseIDInfo: types.BaseIDInfo{
  43. Id: &data.ID,
  44. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  45. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  46. },
  47. Title: &data.Title,
  48. Avatar: &data.Avatar,
  49. Tags: &data.Tags,
  50. HireCount: &data.HireCount,
  51. ServiceCount: &data.ServiceCount,
  52. AchievementCount: &data.AchievementCount,
  53. Intro: &data.Intro,
  54. Estimate: &data.Estimate,
  55. Skill: &data.Skill,
  56. AbilityType: &data.AbilityType,
  57. Scene: &data.Scene,
  58. SwitchIn: &data.SwitchIn,
  59. VideoUrl: &data.VideoURL,
  60. CategoryId: &data.CategoryID,
  61. ShowChat: &showChat,
  62. IsVip: &isVip,
  63. ChatUrl: &data.ChatURL,
  64. },
  65. }, nil
  66. }