作者 yangfu

fix:分组用户修改

... ... @@ -60,6 +60,7 @@ type (
Page int `json:"page"`
Size int `json:"size"`
IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0)
IncludeDefaultDepartment bool `json:"includeDefaultDepartment,optional"` // 包含默认分组
}
DepartmentListResponse {
... ...
... ... @@ -279,6 +279,7 @@ type(
ParentId int64 `json:"parentId"` // 父级ID
Name string `json:"name"` // 部门名称
UserIds []int64 `json:"userIds"` // 部门下的用户
TotalUser int `json:"totalUser"` // 累计用户
}
UserSearchRequest{
Page int `json:"page,optional"`
... ... @@ -471,7 +472,7 @@ type(
Phone string `json:"phone,optional"` // 手机号 唯一
Position string `json:"position,optional"` // 职位
Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用
DepartmentId int64 `json:"departmentId,optional"` // 所属部门
DepartmentId *int64 `json:"departmentId,optional"` // 所属部门
}
SystemUserSearchResponse{
List []SystemUser `json:"list"`
... ...
... ... @@ -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
... ...
... ... @@ -61,7 +61,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
groupUserSet := collection.NewSet()
for _, user := range users {
// 未分配部门的归类到公司底下
if len(user.Departments) == 0 {
if item.Id == 0 && len(user.Departments) == 0 {
if !groupUserSet.Contains(user.Id) {
group.Users = append(group.Users, &domain.User{
Id: user.Id,
... ...
... ... @@ -41,8 +41,11 @@ func (l *SystemUserSearchLogic) SystemUserSearch(req *types.SystemUserSearchRequ
WithKV("likePhone", req.Phone).
WithKV("position", req.Position).
WithKV("enable", req.Enable).
WithKV("departmentId", req.DepartmentId).
WithKV("auditStatus", []int{domain.UserAuditStatusPassed})
if req.DepartmentId != nil {
queryOptions.MustWithKV("departmentId", *req.DepartmentId)
}
if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErr(err)
}
... ...
... ... @@ -637,6 +637,7 @@ type Department struct {
ParentId int64 `json:"parentId"` // 父级ID
Name string `json:"name"` // 部门名称
UserIds []int64 `json:"userIds"` // 部门下的用户
TotalUser int `json:"totalUser"` // 累计用户
}
type UserSearchRequest struct {
... ... @@ -786,7 +787,7 @@ type SystemUserSearchRequest struct {
Phone string `json:"phone,optional"` // 手机号 唯一
Position string `json:"position,optional"` // 职位
Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用
DepartmentId int64 `json:"departmentId,optional"` // 所属部门
DepartmentId *int64 `json:"departmentId,optional"` // 所属部门
}
type SystemUserSearchResponse struct {
... ... @@ -1730,6 +1731,7 @@ type DepartmentListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0)
IncludeDefaultDepartment bool `json:"includeDefaultDepartment,optional"` // 包含默认分组
}
type DepartmentListResponse struct {
... ...
... ... @@ -174,8 +174,13 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
tx.Where("position = ? ", v)
}
if v, ok := queryOptions["departmentId"]; ok {
// 未分组用户部门ID=0
if vi, okVi := v.(int64); okVi && vi == domain.DefaultDepartmentId {
tx.Where(fmt.Sprintf("departments = '[]'"))
} else {
tx.Where(fmt.Sprintf("departments @>'[%v]'", v))
}
}
if v, ok := queryOptions["roleId"]; ok {
tx.Where(fmt.Sprintf("roles @>'[%v]'", v))
}
... ...
... ... @@ -31,3 +31,5 @@ func (m *Department) Identify() interface{} {
}
return m.Id
}
const DefaultDepartmentId = -1
... ...