正在显示
8 个修改的文件
包含
62 行增加
和
8 行删除
| @@ -60,6 +60,7 @@ type ( | @@ -60,6 +60,7 @@ type ( | ||
| 60 | Page int `json:"page"` | 60 | Page int `json:"page"` |
| 61 | Size int `json:"size"` | 61 | Size int `json:"size"` |
| 62 | IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0) | 62 | IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0) |
| 63 | + IncludeDefaultDepartment bool `json:"includeDefaultDepartment,optional"` // 包含默认分组 | ||
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | DepartmentListResponse { | 66 | DepartmentListResponse { |
| @@ -279,6 +279,7 @@ type( | @@ -279,6 +279,7 @@ type( | ||
| 279 | ParentId int64 `json:"parentId"` // 父级ID | 279 | ParentId int64 `json:"parentId"` // 父级ID |
| 280 | Name string `json:"name"` // 部门名称 | 280 | Name string `json:"name"` // 部门名称 |
| 281 | UserIds []int64 `json:"userIds"` // 部门下的用户 | 281 | UserIds []int64 `json:"userIds"` // 部门下的用户 |
| 282 | + TotalUser int `json:"totalUser"` // 累计用户 | ||
| 282 | } | 283 | } |
| 283 | UserSearchRequest{ | 284 | UserSearchRequest{ |
| 284 | Page int `json:"page,optional"` | 285 | Page int `json:"page,optional"` |
| @@ -471,7 +472,7 @@ type( | @@ -471,7 +472,7 @@ type( | ||
| 471 | Phone string `json:"phone,optional"` // 手机号 唯一 | 472 | Phone string `json:"phone,optional"` // 手机号 唯一 |
| 472 | Position string `json:"position,optional"` // 职位 | 473 | Position string `json:"position,optional"` // 职位 |
| 473 | Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用 | 474 | Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用 |
| 474 | - DepartmentId int64 `json:"departmentId,optional"` // 所属部门 | 475 | + DepartmentId *int64 `json:"departmentId,optional"` // 所属部门 |
| 475 | } | 476 | } |
| 476 | SystemUserSearchResponse{ | 477 | SystemUserSearchResponse{ |
| 477 | List []SystemUser `json:"list"` | 478 | List []SystemUser `json:"list"` |
| @@ -2,6 +2,7 @@ package department | @@ -2,6 +2,7 @@ package department | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "github.com/samber/lo" | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 8 | "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 | @@ -39,6 +40,28 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty | ||
| 39 | Total: total, | 40 | Total: total, |
| 40 | List: make([]types.Department, 0), | 41 | List: make([]types.Department, 0), |
| 41 | } | 42 | } |
| 43 | + | ||
| 44 | + _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | ||
| 45 | + MustWithKV("companyId", userToken.CompanyId). | ||
| 46 | + WithKV("auditStatus", []int{domain.UserAuditStatusPassed})) | ||
| 47 | + var counterByDepartment = make(map[int64]int) | ||
| 48 | + lo.ForEach(users, func(item *domain.User, index int) { | ||
| 49 | + if len(item.Departments) == 0 { | ||
| 50 | + if _, ok := counterByDepartment[domain.DefaultDepartmentId]; ok { | ||
| 51 | + counterByDepartment[domain.DefaultDepartmentId]++ | ||
| 52 | + } else { | ||
| 53 | + counterByDepartment[domain.DefaultDepartmentId] = 1 | ||
| 54 | + } | ||
| 55 | + return | ||
| 56 | + } | ||
| 57 | + for _, dep := range item.Departments { | ||
| 58 | + if _, ok := counterByDepartment[dep]; ok { | ||
| 59 | + counterByDepartment[dep]++ | ||
| 60 | + } else { | ||
| 61 | + counterByDepartment[dep] = 1 | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + }) | ||
| 42 | if req.IncludeRootCompany { | 65 | if req.IncludeRootCompany { |
| 43 | company, _ := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId) | 66 | company, _ := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId) |
| 44 | if company != nil { | 67 | if company != nil { |
| @@ -47,9 +70,23 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty | @@ -47,9 +70,23 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty | ||
| 47 | CompanyId: company.Id, | 70 | CompanyId: company.Id, |
| 48 | ParentId: -1, | 71 | ParentId: -1, |
| 49 | Name: company.Name, | 72 | Name: company.Name, |
| 73 | + TotalUser: len(users), | ||
| 50 | }) | 74 | }) |
| 51 | } | 75 | } |
| 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) | ||
| 87 | + } | ||
| 52 | } | 88 | } |
| 89 | + | ||
| 53 | for _, item := range list { | 90 | for _, item := range list { |
| 54 | to := types.Department{ | 91 | to := types.Department{ |
| 55 | Id: item.Id, | 92 | Id: item.Id, |
| @@ -57,6 +94,9 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty | @@ -57,6 +94,9 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty | ||
| 57 | ParentId: item.ParentId, | 94 | ParentId: item.ParentId, |
| 58 | Name: item.Name, | 95 | Name: item.Name, |
| 59 | } | 96 | } |
| 97 | + if v, ok := counterByDepartment[item.Id]; ok { | ||
| 98 | + to.TotalUser = v | ||
| 99 | + } | ||
| 60 | resp.List = append(resp.List, to) | 100 | resp.List = append(resp.List, to) |
| 61 | } | 101 | } |
| 62 | return resp, nil | 102 | return resp, nil |
| @@ -61,7 +61,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs | @@ -61,7 +61,7 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs | ||
| 61 | groupUserSet := collection.NewSet() | 61 | groupUserSet := collection.NewSet() |
| 62 | for _, user := range users { | 62 | for _, user := range users { |
| 63 | // 未分配部门的归类到公司底下 | 63 | // 未分配部门的归类到公司底下 |
| 64 | - if len(user.Departments) == 0 { | 64 | + if item.Id == 0 && len(user.Departments) == 0 { |
| 65 | if !groupUserSet.Contains(user.Id) { | 65 | if !groupUserSet.Contains(user.Id) { |
| 66 | group.Users = append(group.Users, &domain.User{ | 66 | group.Users = append(group.Users, &domain.User{ |
| 67 | Id: user.Id, | 67 | Id: user.Id, |
| @@ -41,8 +41,11 @@ func (l *SystemUserSearchLogic) SystemUserSearch(req *types.SystemUserSearchRequ | @@ -41,8 +41,11 @@ func (l *SystemUserSearchLogic) SystemUserSearch(req *types.SystemUserSearchRequ | ||
| 41 | WithKV("likePhone", req.Phone). | 41 | WithKV("likePhone", req.Phone). |
| 42 | WithKV("position", req.Position). | 42 | WithKV("position", req.Position). |
| 43 | WithKV("enable", req.Enable). | 43 | WithKV("enable", req.Enable). |
| 44 | - WithKV("departmentId", req.DepartmentId). | ||
| 45 | WithKV("auditStatus", []int{domain.UserAuditStatusPassed}) | 44 | WithKV("auditStatus", []int{domain.UserAuditStatusPassed}) |
| 45 | + | ||
| 46 | + if req.DepartmentId != nil { | ||
| 47 | + queryOptions.MustWithKV("departmentId", *req.DepartmentId) | ||
| 48 | + } | ||
| 46 | if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil { | 49 | if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil { |
| 47 | return nil, xerr.NewErr(err) | 50 | return nil, xerr.NewErr(err) |
| 48 | } | 51 | } |
| @@ -637,6 +637,7 @@ type Department struct { | @@ -637,6 +637,7 @@ type Department struct { | ||
| 637 | ParentId int64 `json:"parentId"` // 父级ID | 637 | ParentId int64 `json:"parentId"` // 父级ID |
| 638 | Name string `json:"name"` // 部门名称 | 638 | Name string `json:"name"` // 部门名称 |
| 639 | UserIds []int64 `json:"userIds"` // 部门下的用户 | 639 | UserIds []int64 `json:"userIds"` // 部门下的用户 |
| 640 | + TotalUser int `json:"totalUser"` // 累计用户 | ||
| 640 | } | 641 | } |
| 641 | 642 | ||
| 642 | type UserSearchRequest struct { | 643 | type UserSearchRequest struct { |
| @@ -786,7 +787,7 @@ type SystemUserSearchRequest struct { | @@ -786,7 +787,7 @@ type SystemUserSearchRequest struct { | ||
| 786 | Phone string `json:"phone,optional"` // 手机号 唯一 | 787 | Phone string `json:"phone,optional"` // 手机号 唯一 |
| 787 | Position string `json:"position,optional"` // 职位 | 788 | Position string `json:"position,optional"` // 职位 |
| 788 | Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用 | 789 | Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用 |
| 789 | - DepartmentId int64 `json:"departmentId,optional"` // 所属部门 | 790 | + DepartmentId *int64 `json:"departmentId,optional"` // 所属部门 |
| 790 | } | 791 | } |
| 791 | 792 | ||
| 792 | type SystemUserSearchResponse struct { | 793 | type SystemUserSearchResponse struct { |
| @@ -1727,9 +1728,10 @@ type DepartmentUpdateRequest struct { | @@ -1727,9 +1728,10 @@ type DepartmentUpdateRequest struct { | ||
| 1727 | } | 1728 | } |
| 1728 | 1729 | ||
| 1729 | type DepartmentListRequest struct { | 1730 | type DepartmentListRequest struct { |
| 1730 | - Page int `json:"page"` | ||
| 1731 | - Size int `json:"size"` | ||
| 1732 | - IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0) | 1731 | + Page int `json:"page"` |
| 1732 | + Size int `json:"size"` | ||
| 1733 | + IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0) | ||
| 1734 | + IncludeDefaultDepartment bool `json:"includeDefaultDepartment,optional"` // 包含默认分组 | ||
| 1733 | } | 1735 | } |
| 1734 | 1736 | ||
| 1735 | type DepartmentListResponse struct { | 1737 | type DepartmentListResponse struct { |
| @@ -174,7 +174,12 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con | @@ -174,7 +174,12 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con | ||
| 174 | tx.Where("position = ? ", v) | 174 | tx.Where("position = ? ", v) |
| 175 | } | 175 | } |
| 176 | if v, ok := queryOptions["departmentId"]; ok { | 176 | if v, ok := queryOptions["departmentId"]; ok { |
| 177 | - tx.Where(fmt.Sprintf("departments @>'[%v]'", v)) | 177 | + // 未分组用户部门ID=0 |
| 178 | + if vi, okVi := v.(int64); okVi && vi == domain.DefaultDepartmentId { | ||
| 179 | + tx.Where(fmt.Sprintf("departments = '[]'")) | ||
| 180 | + } else { | ||
| 181 | + tx.Where(fmt.Sprintf("departments @>'[%v]'", v)) | ||
| 182 | + } | ||
| 178 | } | 183 | } |
| 179 | if v, ok := queryOptions["roleId"]; ok { | 184 | if v, ok := queryOptions["roleId"]; ok { |
| 180 | tx.Where(fmt.Sprintf("roles @>'[%v]'", v)) | 185 | tx.Where(fmt.Sprintf("roles @>'[%v]'", v)) |
-
请 注册 或 登录 后发表评论