...
|
...
|
@@ -2,6 +2,7 @@ package department |
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"github.com/samber/lo"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
...
|
...
|
@@ -39,6 +40,28 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty |
|
|
Total: total,
|
|
|
List: make([]types.Department, 0),
|
|
|
}
|
|
|
|
|
|
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
MustWithKV("companyId", userToken.CompanyId).
|
|
|
WithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
|
|
|
var counterByDepartment = make(map[int64]int)
|
|
|
lo.ForEach(users, func(item *domain.User, index int) {
|
|
|
if len(item.Departments) == 0 {
|
|
|
if _, ok := counterByDepartment[domain.DefaultDepartmentId]; ok {
|
|
|
counterByDepartment[domain.DefaultDepartmentId]++
|
|
|
} else {
|
|
|
counterByDepartment[domain.DefaultDepartmentId] = 1
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
for _, dep := range item.Departments {
|
|
|
if _, ok := counterByDepartment[dep]; ok {
|
|
|
counterByDepartment[dep]++
|
|
|
} else {
|
|
|
counterByDepartment[dep] = 1
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
if req.IncludeRootCompany {
|
|
|
company, _ := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId)
|
|
|
if company != nil {
|
...
|
...
|
@@ -47,9 +70,23 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty |
|
|
CompanyId: company.Id,
|
|
|
ParentId: -1,
|
|
|
Name: company.Name,
|
|
|
TotalUser: len(users),
|
|
|
})
|
|
|
}
|
|
|
if req.IncludeDefaultDepartment {
|
|
|
to := types.Department{
|
|
|
Id: domain.DefaultDepartmentId,
|
|
|
CompanyId: company.Id,
|
|
|
ParentId: 0,
|
|
|
Name: "默认分组",
|
|
|
}
|
|
|
if v, ok := counterByDepartment[domain.DefaultDepartmentId]; ok {
|
|
|
to.TotalUser = v
|
|
|
}
|
|
|
resp.List = append(resp.List, to)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for _, item := range list {
|
|
|
to := types.Department{
|
|
|
Id: item.Id,
|
...
|
...
|
@@ -57,6 +94,9 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty |
|
|
ParentId: item.ParentId,
|
|
|
Name: item.Name,
|
|
|
}
|
|
|
if v, ok := counterByDepartment[item.Id]; ok {
|
|
|
to.TotalUser = v
|
|
|
}
|
|
|
resp.List = append(resp.List, to)
|
|
|
}
|
|
|
return resp, nil
|
...
|
...
|
|