作者 yangfu

Merge branch 'dev' into test

... ... @@ -34,10 +34,15 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
users []*domain.User
departments []*domain.Department
groups = make([]DepartmentUser, 0)
company *domain.Company
)
resp = map[string]interface{}{
"list": groups,
}
company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
}
_, departments, err = l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithFindOnly())
if err != nil {
return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
... ... @@ -46,6 +51,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
if err != nil {
return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
}
departments = append([]*domain.Department{&domain.Department{Id: 0, Name: company.Name}}, departments...)
lo.ForEach(departments, func(item *domain.Department, index int) {
group := DepartmentUser{
Id: item.Id,
... ... @@ -54,7 +60,16 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
}
groupUserSet := collection.NewSet()
for _, user := range users {
// 未分配部门的归类到公司底下
if len(user.Departments) == 0 {
if !groupUserSet.Contains(user.Id) {
group.Users = append(group.Users, &domain.User{
Id: user.Id,
Name: user.Name,
PinYinName: user.PinYinName,
Avatar: user.Avatar,
})
}
continue
}
if lo.Contains(user.Departments, item.Id) && !groupUserSet.Contains(user.Id) {
... ... @@ -68,6 +83,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
}
groups = append(groups, group)
})
resp = map[string]interface{}{
"list": groups,
}
... ...