作者 tangxvhui
@@ -34,10 +34,15 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs @@ -34,10 +34,15 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
34 users []*domain.User 34 users []*domain.User
35 departments []*domain.Department 35 departments []*domain.Department
36 groups = make([]DepartmentUser, 0) 36 groups = make([]DepartmentUser, 0)
  37 + company *domain.Company
37 ) 38 )
38 resp = map[string]interface{}{ 39 resp = map[string]interface{}{
39 "list": groups, 40 "list": groups,
40 } 41 }
  42 + company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId)
  43 + if err != nil {
  44 + return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
  45 + }
41 _, departments, err = l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithFindOnly()) 46 _, departments, err = l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithFindOnly())
42 if err != nil { 47 if err != nil {
43 return nil, xerr.NewErrMsgErr("查找部门用户失败", err) 48 return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
@@ -46,6 +51,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs @@ -46,6 +51,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
46 if err != nil { 51 if err != nil {
47 return nil, xerr.NewErrMsgErr("查找部门用户失败", err) 52 return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
48 } 53 }
  54 + departments = append([]*domain.Department{&domain.Department{Id: 0, Name: company.Name}}, departments...)
49 lo.ForEach(departments, func(item *domain.Department, index int) { 55 lo.ForEach(departments, func(item *domain.Department, index int) {
50 group := DepartmentUser{ 56 group := DepartmentUser{
51 Id: item.Id, 57 Id: item.Id,
@@ -54,7 +60,16 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs @@ -54,7 +60,16 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
54 } 60 }
55 groupUserSet := collection.NewSet() 61 groupUserSet := collection.NewSet()
56 for _, user := range users { 62 for _, user := range users {
  63 + // 未分配部门的归类到公司底下
57 if len(user.Departments) == 0 { 64 if len(user.Departments) == 0 {
  65 + if !groupUserSet.Contains(user.Id) {
  66 + group.Users = append(group.Users, &domain.User{
  67 + Id: user.Id,
  68 + Name: user.Name,
  69 + PinYinName: user.PinYinName,
  70 + Avatar: user.Avatar,
  71 + })
  72 + }
58 continue 73 continue
59 } 74 }
60 if lo.Contains(user.Departments, item.Id) && !groupUserSet.Contains(user.Id) { 75 if lo.Contains(user.Departments, item.Id) && !groupUserSet.Contains(user.Id) {
@@ -68,6 +83,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs @@ -68,6 +83,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
68 } 83 }
69 groups = append(groups, group) 84 groups = append(groups, group)
70 }) 85 })
  86 +
71 resp = map[string]interface{}{ 87 resp = map[string]interface{}{
72 "list": groups, 88 "list": groups,
73 } 89 }