作者 yangfu

fix:分组用户修改

@@ -44,6 +44,8 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty @@ -44,6 +44,8 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty
44 _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). 44 _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
45 MustWithKV("companyId", userToken.CompanyId). 45 MustWithKV("companyId", userToken.CompanyId).
46 WithKV("auditStatus", []int{domain.UserAuditStatusPassed})) 46 WithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
  47 +
  48 + // 统计部门用户数量
47 var counterByDepartment = make(map[int64]int) 49 var counterByDepartment = make(map[int64]int)
48 lo.ForEach(users, func(item *domain.User, index int) { 50 lo.ForEach(users, func(item *domain.User, index int) {
49 if len(item.Departments) == 0 { 51 if len(item.Departments) == 0 {
@@ -73,18 +75,19 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty @@ -73,18 +75,19 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty
73 TotalUser: len(users), 75 TotalUser: len(users),
74 }) 76 })
75 } 77 }
76 - if req.IncludeDefaultDepartment {  
77 - to := types.Department{  
78 - Id: domain.DefaultDepartmentId,  
79 - CompanyId: company.Id,  
80 - ParentId: 0,  
81 - Name: "默认分组",  
82 - }  
83 - if v, ok := counterByDepartment[domain.DefaultDepartmentId]; ok {  
84 - to.TotalUser = v  
85 - }  
86 - resp.List = append(resp.List, to) 78 + }
  79 +
  80 + if req.IncludeDefaultDepartment {
  81 + to := types.Department{
  82 + Id: domain.DefaultDepartmentId,
  83 + CompanyId: userToken.CompanyId,
  84 + ParentId: 0,
  85 + Name: "未分组",
87 } 86 }
  87 + if v, ok := counterByDepartment[domain.DefaultDepartmentId]; ok {
  88 + to.TotalUser = v
  89 + }
  90 + resp.List = append(resp.List, to)
88 } 91 }
89 92
90 for _, item := range list { 93 for _, item := range list {
@@ -40,7 +40,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs @@ -40,7 +40,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
40 "list": groups, 40 "list": groups,
41 } 41 }
42 company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId) 42 company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId)
43 - if err != nil { 43 + if err != nil || company == nil {
44 return nil, xerr.NewErrMsgErr("查找部门用户失败", err) 44 return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
45 } 45 }
46 _, 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())
@@ -51,7 +51,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs @@ -51,7 +51,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
51 if err != nil { 51 if err != nil {
52 return nil, xerr.NewErrMsgErr("查找部门用户失败", err) 52 return nil, xerr.NewErrMsgErr("查找部门用户失败", err)
53 } 53 }
54 - departments = append([]*domain.Department{&domain.Department{Id: 0, Name: company.Name}}, departments...) 54 + departments = append([]*domain.Department{&domain.Department{Id: 0, Name: "未分组"}}, departments...)
55 lo.ForEach(departments, func(item *domain.Department, index int) { 55 lo.ForEach(departments, func(item *domain.Department, index int) {
56 group := DepartmentUser{ 56 group := DepartmentUser{
57 Id: item.Id, 57 Id: item.Id,