get_user_info_logic.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package User
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/suyuan32/simple-admin-core/rpc/types/core"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type GetUserInfoLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
  16. return &GetUserInfoLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx}
  20. }
  21. func (l *GetUserInfoLogic) GetUserInfo() (resp *types.UserBaseIDInfoResp, err error) {
  22. user, err := l.svcCtx.CoreRpc.GetUserById(l.ctx,
  23. &core.UUIDReq{Id: l.ctx.Value("userId").(string)})
  24. if err != nil {
  25. return nil, err
  26. }
  27. departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: user.GetDepartmentId()})
  28. if err != nil {
  29. return nil, err
  30. }
  31. departmentName := *departmentInfo.Name
  32. if departmentName == "department.managementDepartment" {
  33. departmentName = "冠客数字员工管理系统"
  34. }
  35. roleNameMap := map[string]string{
  36. "role.admin": "管理员",
  37. "role.stuff": "员工",
  38. "role.seller": "销售",
  39. "role.member": "会员",
  40. "role.changeStatusSuccess": "已成功修改角色状态",
  41. "role.changeStatusFailed": "修改角色状态失败",
  42. "role.duplicateRoleValue": "角色值重复",
  43. "role.userExists": "请先删除该角色下的用户",
  44. "role.roleForbidden": "您的角色已停用",
  45. }
  46. var roleNames []string
  47. for _, roleName := range user.GetRoleName() {
  48. roleNames = append(roleNames, roleNameMap[roleName])
  49. }
  50. return &types.UserBaseIDInfoResp{
  51. BaseDataInfo: types.BaseDataInfo{Msg: errormsg.Success},
  52. Data: types.UserBaseIDInfo{
  53. UUID: user.Id,
  54. Username: user.Username,
  55. Nickname: user.Nickname,
  56. Avatar: user.Avatar,
  57. HomePath: user.HomePath,
  58. Description: user.Description,
  59. DepartmentName: departmentName,
  60. DepartmentRemark: *departmentInfo.Remark,
  61. RoleName: roleNames,
  62. },
  63. }, nil
  64. }