fix(权限完善):1.权限优化以下模块按钮查看权限全部归属超级管理员,只有职称角色未超级管理员用户才可以查看进入操作
deploy-hxtesting / build-and-deploy (push) Successful in 1m17s
deploy-hxtesting / build-and-deploy (push) Successful in 1m17s
1)如图一所示点击左下角个人信息弹出框中的“空间设置”、“成员管理“、”模型管理“、”全部设置“、”系统管理“ 2)点击进入”设置“页面中”空间“、”模型“、”发布集成“、”数据与扩展“、”系统管理“这几个大模块相关内容入口 2.成员管理页面增加一个字段”状态“:1-5 在职状态(试用/试用延期/正式/临时/实习)、6离职/7退休(顺便对数据进行清洗,工号首位带字母的都标记为离职其他都标记为正式) 3.检查各业务需求里所有选择员工相关都只能拉取选择正式员工!
This commit is contained in:
1 parent
b762deaf15
commit
7034d93256
49 files changed
+809
-130
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -415,12 +416,19 @@ func (t *XlsxTranslateTool) ingestOne(ctx context.Context, tenantID uint64, name
|
||||
if err := writer.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
reader := multipart.NewReader(&body, writer.FormDataContentType())
|
||||
form, err := reader.ReadForm(int64(len(data)) + 1<<20)
|
||||
// Parse through http.Request.ParseMultipartForm — the same battle-tested
|
||||
// path as the chat upload handler. multipart.NewReader().ReadForm()
|
||||
// fails on large binary parts with "bufio: buffer full" (a 62 MB
|
||||
// workbook overflows its fixed-size line buffer during boundary scan).
|
||||
req, err := http.NewRequest(http.MethodPost, "/", &body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
files := form.File["file"]
|
||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
if err := req.ParseMultipartForm(32 << 20); err != nil {
|
||||
return fmt.Errorf("parse multipart form: %w", err)
|
||||
}
|
||||
files := req.MultipartForm.File["file"]
|
||||
if len(files) == 0 {
|
||||
return fmt.Errorf("multipart form has no file part")
|
||||
}
|
||||
|
||||
@@ -239,11 +239,11 @@ func TestTenantMemberSearchTreatsLikeWildcardsLiterally(t *testing.T) {
|
||||
seedMember(literalID, "ann_bob", "ann_bob@example.com")
|
||||
seedMember(uuid.New().String(), "annxbob", "annxbob@example.com")
|
||||
|
||||
total, err := repo.CountFilteredByTenant(ctx, tenantID, "ann_bob")
|
||||
total, err := repo.CountFilteredByTenant(ctx, tenantID, "ann_bob", 0)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), total, "underscore must match literally, not as a wildcard")
|
||||
|
||||
members, err := repo.ListPagedByTenant(ctx, tenantID, "ann_bob", 0, 20)
|
||||
members, err := repo.ListPagedByTenant(ctx, tenantID, "ann_bob", 0, 0, 20)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, members, 1)
|
||||
assert.Equal(t, literalID, members[0].UserID)
|
||||
|
||||
@@ -77,6 +77,10 @@ func (r *orgCenterRepository) employeeFilter(ctx context.Context, tenantID uint6
|
||||
if q.DeptID != "" {
|
||||
tx = tx.Where("org_employees.dept_id = ?", q.DeptID)
|
||||
}
|
||||
// 在职状态过滤(000167):选人场景(学员/讲师/推送等)按正式员工口径拉取。
|
||||
if q.EmploymentStatus > 0 {
|
||||
tx = tx.Where("u.employment_status = ?", q.EmploymentStatus)
|
||||
}
|
||||
if q.Keyword != "" {
|
||||
// 按姓名/工号/部门名/岗位模糊查找;姓名取真实姓名(display_name)
|
||||
// 回退平台账号(username),与列表展示口径一致。
|
||||
@@ -242,7 +246,9 @@ func (r *orgCenterRepository) ListTenantUsers(ctx context.Context, tenantID uint
|
||||
Joins("JOIN tenant_members tm ON tm.user_id = u.id AND tm.tenant_id = ? "+
|
||||
"AND tm.status = 'active' AND tm.deleted_at IS NULL", tenantID).
|
||||
Joins("LEFT JOIN org_employees m ON m.user_id = u.id AND m.tenant_id = ? AND m.deleted_at IS NULL", tenantID).
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL").
|
||||
// 「从平台用户添加员工档案」属选人场景:仅正式员工(000167)可选入册,
|
||||
// 离职/退休账号不再出现在档案添加下拉。
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL AND u.employment_status = ?", types.EmploymentStatusFormal).
|
||||
Order("u.created_at ASC").
|
||||
Scan(&users).Error
|
||||
return users, err
|
||||
|
||||
@@ -111,32 +111,36 @@ func (r *tenantMemberRepository) ListByTenant(ctx context.Context, tenantID uint
|
||||
}
|
||||
|
||||
// CountFilteredByTenant counts active tenant membership rows, optionally
|
||||
// restricted to users whose email or username matches search.
|
||||
// restricted to users whose email or username matches search. employmentStatus
|
||||
// 非 0 时仅统计该在职状态(users.employment_status,000167)的成员。
|
||||
func (r *tenantMemberRepository) CountFilteredByTenant(
|
||||
ctx context.Context, tenantID uint64, search string,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int,
|
||||
) (int64, error) {
|
||||
search = strings.TrimSpace(search)
|
||||
q := r.db.WithContext(ctx).Model(&types.TenantMember{}).
|
||||
Where("tenant_members.tenant_id = ?", tenantID)
|
||||
var total int64
|
||||
var err error
|
||||
if search == "" {
|
||||
err = q.Count(&total).Error
|
||||
} else {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
err = q.
|
||||
Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`).
|
||||
Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar).
|
||||
Count(&total).Error
|
||||
// 搜索与在职状态过滤都依赖 users 表,按需挂一次 JOIN(重复 Joins 会
|
||||
// 生成重复 JOIN 子句)。
|
||||
if search != "" || employmentStatus > 0 {
|
||||
q = q.Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`)
|
||||
}
|
||||
if search != "" {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
q = q.Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar)
|
||||
}
|
||||
if employmentStatus > 0 {
|
||||
q = q.Where("users.employment_status = ?", employmentStatus)
|
||||
}
|
||||
var total int64
|
||||
err := q.Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
// ListPagedByTenant lists active memberships with stable sort.
|
||||
func (r *tenantMemberRepository) ListPagedByTenant(
|
||||
ctx context.Context, tenantID uint64, search string, offset, limit int,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int, offset, limit int,
|
||||
) ([]*types.TenantMember, error) {
|
||||
search = strings.TrimSpace(search)
|
||||
var members []*types.TenantMember
|
||||
@@ -146,18 +150,19 @@ func (r *tenantMemberRepository) ListPagedByTenant(
|
||||
Offset(offset).
|
||||
Limit(limit)
|
||||
|
||||
var err error
|
||||
if search == "" {
|
||||
err = q.Find(&members).Error
|
||||
} else {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
err = q.
|
||||
Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`).
|
||||
Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar).
|
||||
Find(&members).Error
|
||||
if search != "" || employmentStatus > 0 {
|
||||
q = q.Joins(`INNER JOIN users ON users.id = tenant_members.user_id AND users.deleted_at IS NULL`)
|
||||
}
|
||||
if search != "" {
|
||||
like := "%" + escapeLikePattern(search) + "%"
|
||||
q = q.Where(
|
||||
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`,
|
||||
like, likeEscapeChar, like, likeEscapeChar)
|
||||
}
|
||||
if employmentStatus > 0 {
|
||||
q = q.Where("users.employment_status = ?", employmentStatus)
|
||||
}
|
||||
err := q.Find(&members).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -125,6 +125,10 @@ func (r *trainingRepository) CancelPushTask(ctx context.Context, tenantID uint64
|
||||
// 含未入员工名册的账号,站内通知可达;企微投递时无绑定者自然 skipped)
|
||||
// - dept / post:org_employees 按 dept_id / post 过滤(active 档案)
|
||||
// - user:直接采用指定名单(仍按空间成员口径过滤,防越租户投递)
|
||||
//
|
||||
// 在职状态口径(000167):all/dept/post 三个自动圈定分支仅正式员工
|
||||
// (users.employment_status=3)——离职/退休不再收到培训推送;user 分支为
|
||||
// 历史已保存的指定名单,保持原样不受影响。
|
||||
func (r *trainingRepository) ListManualPushAudience(
|
||||
ctx context.Context, tenantID uint64, mode string, deptIDs, posts, userIDs []string,
|
||||
) ([]string, error) {
|
||||
@@ -152,8 +156,10 @@ func (r *trainingRepository) ListManualPushAudience(
|
||||
}
|
||||
var rows []types.OrgEmployee
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND "+column+" IN ? AND status = 'active' AND user_id <> '' AND deleted_at IS NULL",
|
||||
tenantID, values).
|
||||
Joins("JOIN users u ON u.id = org_employees.user_id AND u.deleted_at IS NULL").
|
||||
Where("org_employees.tenant_id = ? AND org_employees."+column+" IN ? AND org_employees.status = 'active'"+
|
||||
" AND org_employees.user_id <> '' AND org_employees.deleted_at IS NULL"+
|
||||
" AND u.employment_status = ?", tenantID, values, types.EmploymentStatusFormal).
|
||||
Find(&rows).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -195,7 +201,8 @@ func (r *trainingRepository) ListManualPushAudience(
|
||||
Select("u.id").
|
||||
Joins("JOIN tenant_members tm ON tm.user_id = u.id AND tm.tenant_id = ? "+
|
||||
"AND tm.status = 'active' AND tm.deleted_at IS NULL", tenantID).
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL").
|
||||
Where("u.is_active = TRUE AND u.deleted_at IS NULL AND u.employment_status = ?",
|
||||
types.EmploymentStatusFormal).
|
||||
Order("u.created_at ASC").
|
||||
Scan(&rows).Error; err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -148,7 +148,8 @@ func (r *trainingRepository) DeleteDemand(ctx context.Context, tenantID uint64,
|
||||
// ListLecturers returns the lecturer roster (user_id + 姓名) for pickers.
|
||||
// 讲师角色存于组织中心模块绑定表(module_key='training'),按 roles 文本包含判定;
|
||||
// 姓名取 display_name 优先(工号型 IdP 的 username 为工号,真实姓名在 display_name),
|
||||
// 与年度收集模板「培训讲师」下拉展示口径一致。
|
||||
// 与年度收集模板「培训讲师」下拉展示口径一致。讲师下拉属选人场景:仅正式员工
|
||||
// (users.employment_status=3,000167),离职/退休讲师不再出现。
|
||||
func (r *trainingRepository) ListLecturers(ctx context.Context, tenantID uint64) ([]*types.TrainingLecturerOption, error) {
|
||||
var rows []*types.TrainingLecturerOption
|
||||
err := r.db.WithContext(ctx).
|
||||
@@ -159,6 +160,7 @@ func (r *trainingRepository) ListLecturers(ctx context.Context, tenantID uint64)
|
||||
" AND mm.module_key = 'training' AND mm.deleted_at IS NULL").
|
||||
Where("m.tenant_id = ? AND m.deleted_at IS NULL AND m.status = 'active'"+
|
||||
" AND mm.roles::text LIKE '%\"lecturer\"%'", tenantID).
|
||||
Where("u.employment_status = ?", types.EmploymentStatusFormal).
|
||||
Order("name ASC").
|
||||
Scan(&rows).Error
|
||||
return rows, err
|
||||
|
||||
@@ -141,6 +141,22 @@ func (r *userRepository) UpdateUser(ctx context.Context, user *types.User) error
|
||||
return r.db.WithContext(ctx).Omit("is_active").Save(user).Error
|
||||
}
|
||||
|
||||
// UpdateEmploymentStatus updates users.employment_status (000167 在职状态).
|
||||
// Explicit column update avoids the zero-value pitfalls of struct Save; the
|
||||
// RowsAffected check maps a missing user to ErrUserNotFound.
|
||||
func (r *userRepository) UpdateEmploymentStatus(ctx context.Context, userID string, status int) error {
|
||||
res := r.db.WithContext(ctx).Model(&types.User{}).
|
||||
Where("id = ?", userID).
|
||||
UpdateColumn("employment_status", status)
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
if res.RowsAffected == 0 {
|
||||
return ErrUserNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user
|
||||
func (r *userRepository) DeleteUser(ctx context.Context, id string) error {
|
||||
return r.db.WithContext(ctx).Where("id = ?", id).Delete(&types.User{}).Error
|
||||
|
||||
@@ -311,11 +311,13 @@ func (s *tenantMemberService) ListByTenant(ctx context.Context, tenantID uint64)
|
||||
|
||||
// ListMembersPage returns a slice plus total matching query (handlers parse
|
||||
// page/page_size; defensive clamps here mirror list handler limits).
|
||||
// employmentStatus 非 0 时仅返回该在职状态(users.employment_status)的成员。
|
||||
func (s *tenantMemberService) ListMembersPage(
|
||||
ctx context.Context,
|
||||
tenantID uint64,
|
||||
query string,
|
||||
page, pageSize int,
|
||||
employmentStatus int,
|
||||
) ([]*types.TenantMember, int64, error) {
|
||||
query = strings.TrimSpace(query)
|
||||
if page < 1 {
|
||||
@@ -327,12 +329,12 @@ func (s *tenantMemberService) ListMembersPage(
|
||||
if pageSize > listMembersMaxPageSize {
|
||||
pageSize = listMembersMaxPageSize
|
||||
}
|
||||
total, err := s.repo.CountFilteredByTenant(ctx, tenantID, query)
|
||||
total, err := s.repo.CountFilteredByTenant(ctx, tenantID, query, employmentStatus)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
members, err := s.repo.ListPagedByTenant(ctx, tenantID, query, offset, pageSize)
|
||||
members, err := s.repo.ListPagedByTenant(ctx, tenantID, query, employmentStatus, offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -132,13 +132,13 @@ func (r *fakeTenantMemberRepo) filterTenantRows(tenantID uint64, search string)
|
||||
}
|
||||
|
||||
func (r *fakeTenantMemberRepo) CountFilteredByTenant(
|
||||
ctx context.Context, tenantID uint64, search string,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int,
|
||||
) (int64, error) {
|
||||
return int64(len(r.filterTenantRows(tenantID, search))), nil
|
||||
}
|
||||
|
||||
func (r *fakeTenantMemberRepo) ListPagedByTenant(
|
||||
ctx context.Context, tenantID uint64, search string, offset, limit int,
|
||||
ctx context.Context, tenantID uint64, search string, employmentStatus int, offset, limit int,
|
||||
) ([]*types.TenantMember, error) {
|
||||
all := r.filterTenantRows(tenantID, search)
|
||||
if offset >= len(all) {
|
||||
@@ -317,6 +317,9 @@ func (r *cleanupUserRepo) ListSystemAdmins(context.Context, int, int) ([]*types.
|
||||
func (r *cleanupUserRepo) RevokeSystemAdmin(context.Context, string, string) (*types.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (r *cleanupUserRepo) UpdateEmploymentStatus(context.Context, string, int) error {
|
||||
return nil
|
||||
}
|
||||
func (r *cleanupUserRepo) SearchUsers(context.Context, string, int) ([]*types.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -185,6 +185,8 @@ func (s *trainingService) ListMembers(ctx context.Context, tenantID uint64, q *i
|
||||
if q != nil {
|
||||
oq.DeptID = q.DeptID
|
||||
oq.Keyword = q.Keyword
|
||||
// 在职状态过滤(000167):选人场景按正式员工口径拉取。
|
||||
oq.EmploymentStatus = q.EmploymentStatus
|
||||
oq.Page = q.Page
|
||||
oq.PageSize = q.PageSize
|
||||
}
|
||||
|
||||
@@ -199,8 +199,11 @@ func (s *userService) Register(ctx context.Context, req *types.RegisterRequest)
|
||||
PasswordHash: string(hashedPassword),
|
||||
TenantID: 0,
|
||||
IsActive: true,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
// 在职状态随工号规则落库(首位字母→离职,否则→正式,000167):
|
||||
// Excel 批量导入 / CASDOOR 同步 / 管理员开户都经此漏斗,一处生效。
|
||||
EmploymentStatus: types.EmploymentStatusFromUsername(req.Username),
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
if createdTenant != nil {
|
||||
user.TenantID = createdTenant.ID
|
||||
@@ -906,6 +909,15 @@ func (s *userService) RevokeSystemAdmin(ctx context.Context, userID, actorID str
|
||||
// UpdateUserPreferences applies a partial update over the user's
|
||||
// preferences blob. PATCH semantics: only keys present in `patch`
|
||||
// (non-nil pointer fields) replace the existing value; everything else
|
||||
// UpdateEmploymentStatus 修改人员在册在职状态(000167)。调用方(成员管理
|
||||
// handler,Owner+)已校验 1-7;此处仅做兜底校验后直写 users 列。
|
||||
func (s *userService) UpdateEmploymentStatus(ctx context.Context, userID string, status int) error {
|
||||
if !types.IsValidEmploymentStatus(status) {
|
||||
return errors.New("employment_status must be one of 1-7")
|
||||
}
|
||||
return s.userRepo.UpdateEmploymentStatus(ctx, userID, status)
|
||||
}
|
||||
|
||||
// is preserved. This lets the front-end PUT only the preference that
|
||||
// changed without having to read-modify-write the whole struct, and
|
||||
// also makes the endpoint forward-compatible — older clients that
|
||||
|
||||
@@ -79,6 +79,9 @@ type stubUserRepoForAuth struct {
|
||||
}
|
||||
|
||||
func (s *stubUserRepoForAuth) CreateUser(context.Context, *types.User) error { return nil }
|
||||
func (s *stubUserRepoForAuth) UpdateEmploymentStatus(context.Context, string, int) error {
|
||||
return nil
|
||||
}
|
||||
func (s *stubUserRepoForAuth) GetUserByID(_ context.Context, id string) (*types.User, error) {
|
||||
user, ok := s.users[id]
|
||||
if !ok {
|
||||
|
||||
@@ -36,6 +36,10 @@ func orgListQueryFromRequest(c *gin.Context) *types.OrgListQuery {
|
||||
DeptID: c.Query("dept_id"),
|
||||
Keyword: c.Query("keyword"),
|
||||
}
|
||||
// 在职状态过滤(000167):选人场景按正式员工口径拉取,非法值视同不过滤。
|
||||
if v, err := strconv.Atoi(c.Query("employment_status")); err == nil && types.IsValidEmploymentStatus(v) {
|
||||
q.EmploymentStatus = v
|
||||
}
|
||||
if v, err := strconv.Atoi(c.Query("page")); err == nil {
|
||||
q.Page = v
|
||||
}
|
||||
|
||||
@@ -87,6 +87,12 @@ type updateMemberRoleRequest struct {
|
||||
Role types.TenantRole `json:"role" binding:"required"`
|
||||
}
|
||||
|
||||
// updateMemberEmploymentStatusRequest is the JSON body for
|
||||
// PUT /tenants/:id/members/:user_id/employment-status(在职状态 1-7,000167)。
|
||||
type updateMemberEmploymentStatusRequest struct {
|
||||
EmploymentStatus int `json:"employment_status" binding:"required"`
|
||||
}
|
||||
|
||||
// parseTenantIDFromPath reads :id from the gin route and validates it as
|
||||
// a tenant ID. Returning (0, false) means we already wrote the error to
|
||||
// the gin context and the caller should `return` immediately.
|
||||
@@ -128,8 +134,14 @@ func (h *TenantMemberHandler) ListMembers(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// employment_status 在职状态过滤(000167):0/缺省 = 不过滤,1-7 按
|
||||
// users.employment_status 精确匹配,非法值视同不过滤。
|
||||
employmentStatus, _ := strconv.Atoi(c.Query("employment_status"))
|
||||
if !types.IsValidEmploymentStatus(employmentStatus) {
|
||||
employmentStatus = 0
|
||||
}
|
||||
|
||||
members, total, err := h.memberService.ListMembersPage(ctx, tenantID, q, page, pageSize)
|
||||
members, total, err := h.memberService.ListMembersPage(ctx, tenantID, q, page, pageSize, employmentStatus)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "ListMembersPage failed: tenant=%d err=%v", tenantID, err)
|
||||
c.Error(apperrors.NewInternalServerError("failed to list members").WithDetails(err.Error()))
|
||||
@@ -168,6 +180,7 @@ func (h *TenantMemberHandler) ListMembers(c *gin.Context) {
|
||||
row.DisplayName = u.DisplayName
|
||||
row.DeptName = u.DeptName
|
||||
row.Avatar = u.Avatar
|
||||
row.EmploymentStatus = u.EmploymentStatus
|
||||
}
|
||||
resp = append(resp, row)
|
||||
}
|
||||
@@ -381,6 +394,55 @@ func (h *TenantMemberHandler) UpdateMemberRole(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true})
|
||||
}
|
||||
|
||||
// UpdateMemberEmploymentStatus godoc
|
||||
// @Summary 修改成员在职状态
|
||||
// @Description Owner 修改某位成员的在职状态(1试用/2试用延期/3正式/4临时/5实习/6离职/7退休,000167)。
|
||||
// 状态是 users 表的人员属性,跨空间一致;业务选人接口按正式(3)过滤不受本接口影响。
|
||||
// @Tags 空间成员
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "空间 ID"
|
||||
// @Param user_id path string true "用户 ID"
|
||||
// @Param request body updateMemberEmploymentStatusRequest true "目标状态"
|
||||
// @Success 200 {object} handler.SuccessResponse
|
||||
// @Security Bearer
|
||||
// @Router /tenants/{id}/members/{user_id}/employment-status [put]
|
||||
func (h *TenantMemberHandler) UpdateMemberEmploymentStatus(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
tenantID, ok := parseTenantIDFromPath(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
userID := strings.TrimSpace(c.Param("user_id"))
|
||||
if userID == "" {
|
||||
c.Error(apperrors.NewValidationError("user_id is required"))
|
||||
return
|
||||
}
|
||||
|
||||
var req updateMemberEmploymentStatusRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.Error(apperrors.NewValidationError("invalid request body").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
if !types.IsValidEmploymentStatus(req.EmploymentStatus) {
|
||||
c.Error(apperrors.NewValidationError("employment_status must be one of 1-7 (1试用/2试用延期/3正式/4临时/5实习/6离职/7退休)"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.userService.UpdateEmploymentStatus(ctx, userID, req.EmploymentStatus); err != nil {
|
||||
if errors.Is(err, apprepo.ErrUserNotFound) {
|
||||
c.Error(apperrors.NewNotFoundError("user not found"))
|
||||
return
|
||||
}
|
||||
logger.Errorf(ctx, "UpdateEmploymentStatus failed: user=%s tenant=%d err=%v",
|
||||
userID, tenantID, err)
|
||||
c.Error(apperrors.NewInternalServerError("failed to update employment status").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"success": true})
|
||||
}
|
||||
|
||||
// RemoveMember godoc
|
||||
// @Summary 移除空间成员
|
||||
// @Description Owner 将某位成员从当前空间中移除(软删除 tenant_members 行);不能移除最后一位 Owner
|
||||
|
||||
@@ -28,7 +28,7 @@ type stubMemberService struct {
|
||||
interfaces.TenantMemberService
|
||||
add func(ctx context.Context, userID string, tenantID uint64, role types.TenantRole, invitedBy *string) (*types.TenantMember, error)
|
||||
listTenant func(ctx context.Context, tenantID uint64) ([]*types.TenantMember, error)
|
||||
listMembersPage func(ctx context.Context, tenantID uint64, query string, page, pageSize int) ([]*types.TenantMember, int64, error)
|
||||
listMembersPage func(ctx context.Context, tenantID uint64, query string, page, pageSize int, employmentStatus int) ([]*types.TenantMember, int64, error)
|
||||
updateRole func(ctx context.Context, userID string, tenantID uint64, newRole types.TenantRole) error
|
||||
remove func(ctx context.Context, userID string, tenantID uint64) error
|
||||
}
|
||||
@@ -38,9 +38,10 @@ func (s *stubMemberService) ListMembersPage(
|
||||
tenantID uint64,
|
||||
query string,
|
||||
page, pageSize int,
|
||||
employmentStatus int,
|
||||
) ([]*types.TenantMember, int64, error) {
|
||||
if s.listMembersPage != nil {
|
||||
return s.listMembersPage(ctx, tenantID, query, page, pageSize)
|
||||
return s.listMembersPage(ctx, tenantID, query, page, pageSize, employmentStatus)
|
||||
}
|
||||
if s.listTenant != nil {
|
||||
members, err := s.listTenant(ctx, tenantID)
|
||||
|
||||
@@ -92,6 +92,10 @@ func listQueryFromRequest(c *gin.Context) *interfaces.TrainingListQuery {
|
||||
if v, err := strconv.Atoi(c.Query("month")); err == nil {
|
||||
q.Month = v
|
||||
}
|
||||
// 在职状态过滤(000167):员工名册选人场景传 3(正式),其余端点忽略该参数。
|
||||
if v, err := strconv.Atoi(c.Query("employment_status")); err == nil && types.IsValidEmploymentStatus(v) {
|
||||
q.EmploymentStatus = v
|
||||
}
|
||||
if v, err := strconv.Atoi(c.Query("page")); err == nil {
|
||||
q.Page = v
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ func TestCurrentWorkspaceMembersPaginationAndProjection(t *testing.T) {
|
||||
id uint64,
|
||||
q string,
|
||||
page, size int,
|
||||
_ int,
|
||||
) (
|
||||
[]*types.TenantMember,
|
||||
int64,
|
||||
|
||||
@@ -125,7 +125,7 @@ func (f *fakeMemberService) ListByTenant(ctx context.Context, tenantID uint64) (
|
||||
return nil, nil
|
||||
}
|
||||
func (f *fakeMemberService) ListMembersPage(
|
||||
ctx context.Context, tenantID uint64, query string, page, pageSize int,
|
||||
ctx context.Context, tenantID uint64, query string, page, pageSize int, employmentStatus int,
|
||||
) ([]*types.TenantMember, int64, error) {
|
||||
return nil, 0, nil
|
||||
}
|
||||
|
||||
@@ -123,6 +123,8 @@ func RegisterTenantRoutes(
|
||||
// Casdoor 用户目录同步(000156):管理 API 拉用户自动开户/入空间。
|
||||
g.apiKeyRoute(tenantByID, http.MethodPost, "/members/sync-casdoor", apiKeyManageMembers(apiKeyFullAccess()), g.Owner(), memberHandler.SyncCasdoorMembers)
|
||||
g.apiKeyRoute(tenantByID, http.MethodPut, "/members/:user_id", apiKeyManageMembers(apiKeyFullAccess()), g.Owner(), memberHandler.UpdateMemberRole)
|
||||
// 在职状态维护(000167):成员管理页「状态」列行内下拉,Owner+ 与其他成员变更一致。
|
||||
g.apiKeyRoute(tenantByID, http.MethodPut, "/members/:user_id/employment-status", apiKeyManageMembers(apiKeyFullAccess()), g.Owner(), memberHandler.UpdateMemberEmploymentStatus)
|
||||
g.apiKeyRoute(tenantByID, http.MethodDelete, "/members/:user_id", apiKeyManageMembers(apiKeyFullAccess()), g.Owner(), memberHandler.RemoveMember)
|
||||
tenantByID.POST("/leave", g.Viewer(), memberHandler.LeaveTenant)
|
||||
}
|
||||
|
||||
@@ -37,13 +37,15 @@ type TenantMemberRepository interface {
|
||||
|
||||
// CountFilteredByTenant counts active memberships in tenant. Optional
|
||||
// search matches user email/username (join users table); empty search
|
||||
// counts all memberships.
|
||||
CountFilteredByTenant(ctx context.Context, tenantID uint64, search string) (int64, error)
|
||||
// counts all memberships. employmentStatus 非 0 时仅统计该在职状态
|
||||
// (users.employment_status,000167)的成员。
|
||||
CountFilteredByTenant(ctx context.Context, tenantID uint64, search string, employmentStatus int) (int64, error)
|
||||
|
||||
// ListPagedByTenant returns active memberships sorted joined_at ASC, id ASC.
|
||||
// search filters by user email/username (join users table); empty
|
||||
// search lists all memberships in tenant.
|
||||
ListPagedByTenant(ctx context.Context, tenantID uint64, search string, offset, limit int) ([]*types.TenantMember, error)
|
||||
// search lists all memberships in tenant. employmentStatus 非 0 时仅
|
||||
// 返回该在职状态的成员。
|
||||
ListPagedByTenant(ctx context.Context, tenantID uint64, search string, employmentStatus int, offset, limit int) ([]*types.TenantMember, error)
|
||||
|
||||
// UpdateRole changes the role of an existing active membership. Returns
|
||||
// gorm.ErrRecordNotFound if no active row matches.
|
||||
|
||||
@@ -40,7 +40,8 @@ type TenantMemberService interface {
|
||||
|
||||
// ListMembersPage lists members with pagination. Query matches email or
|
||||
// username case-insensitively; empty query returns full tenant list slice.
|
||||
ListMembersPage(ctx context.Context, tenantID uint64, query string, page, pageSize int) ([]*types.TenantMember, int64, error)
|
||||
// employmentStatus 非 0 时仅返回该在职状态(users.employment_status)的成员。
|
||||
ListMembersPage(ctx context.Context, tenantID uint64, query string, page, pageSize int, employmentStatus int) ([]*types.TenantMember, int64, error)
|
||||
|
||||
// HasAnyMembers reports whether the tenant has at least one active
|
||||
// member. The auth middleware uses this to recover orphan tenants
|
||||
|
||||
@@ -38,8 +38,11 @@ type TrainingListQuery struct {
|
||||
Status string
|
||||
CheckStatus string
|
||||
Keyword string
|
||||
Page int
|
||||
PageSize int
|
||||
// EmploymentStatus 在职状态过滤(000167):0 = 不过滤;仅 /training/members
|
||||
// 员工名册消费(选人场景传 3 正式),其余列表端点忽略。
|
||||
EmploymentStatus int
|
||||
Page int
|
||||
PageSize int
|
||||
// 课程管理学员目录口径(000160,scope=catalog 时 handler 注入):
|
||||
// CatalogOnly 仅返回已发布课程,且适合人员须覆盖调用方 ——
|
||||
// suitable='全部' 或 =调用方部门名;未设置适合人员的存量课程沿用
|
||||
|
||||
@@ -124,6 +124,10 @@ type UserService interface {
|
||||
// preferences blob (PATCH semantics: only keys present in `patch`
|
||||
// overwrite existing values). Returns the updated, persisted prefs.
|
||||
UpdateUserPreferences(ctx context.Context, userID string, patch types.UserPreferences) (types.UserPreferences, error)
|
||||
// UpdateEmploymentStatus 修改人员在册在职状态(000167,1-7)。成员管理
|
||||
// 页(Owner+)调用;状态为人员属性,跨空间一致。用户不存在时返回
|
||||
// ErrUserNotFound。
|
||||
UpdateEmploymentStatus(ctx context.Context, userID string, status int) error
|
||||
}
|
||||
|
||||
// UserRepository defines the user repository interface
|
||||
@@ -143,6 +147,9 @@ type UserRepository interface {
|
||||
GetUserByTenantID(ctx context.Context, tenantID uint64) (*types.User, error)
|
||||
// UpdateUser updates user data without changing account status; use SetUserActive for that.
|
||||
UpdateUser(ctx context.Context, user *types.User) error
|
||||
// UpdateEmploymentStatus updates users.employment_status (000167).
|
||||
// Returns gorm.ErrRecordNotFound when no user matches.
|
||||
UpdateEmploymentStatus(ctx context.Context, userID string, status int) error
|
||||
// SetUserActive atomically changes status and revokes sessions on disable,
|
||||
// preserving at least one active system administrator.
|
||||
SetUserActive(ctx context.Context, userID, actorID string, active bool) (*types.User, error)
|
||||
|
||||
@@ -91,11 +91,14 @@ type OrgModuleMember struct {
|
||||
func (OrgModuleMember) TableName() string { return "org_module_members" }
|
||||
|
||||
// OrgListQuery 组织中心通用列表查询(分页 + 关键词 + 部门过滤)。
|
||||
// EmploymentStatus 在职状态过滤(000167):0 = 不过滤;选人场景传
|
||||
// EmploymentStatusFormal(3) 仅拉取正式员工。
|
||||
type OrgListQuery struct {
|
||||
DeptID string
|
||||
Keyword string
|
||||
Page int
|
||||
PageSize int
|
||||
DeptID string
|
||||
Keyword string
|
||||
EmploymentStatus int
|
||||
Page int
|
||||
PageSize int
|
||||
}
|
||||
|
||||
// OrgAdoptableUser 可收编成员(归属空间不在本空间的活跃成员),「收编到本空间」
|
||||
|
||||
@@ -134,6 +134,8 @@ type TenantMemberResponse struct {
|
||||
// DeptName 所属部门(000156 同步态:Casdoor 目录随账号回写 users.dept_name;
|
||||
// 组织架构内手动调整的 org_employees.dept_id 不改这里,两处口径解耦)。
|
||||
DeptName string `json:"dept_name,omitempty" extensions:"x-agent"`
|
||||
// EmploymentStatus 在职状态(000167):1试用/2试用延期/3正式/4临时/5实习/6离职/7退休。
|
||||
EmploymentStatus int `json:"employment_status" extensions:"x-agent"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
Role TenantRole `json:"role" extensions:"x-agent"`
|
||||
Status TenantMemberStatus `json:"status" extensions:"x-agent"`
|
||||
|
||||
@@ -105,6 +105,35 @@ func (p *UserPreferences) Scan(value interface{}) error {
|
||||
return json.Unmarshal(data, p)
|
||||
}
|
||||
|
||||
// Employment status codes (users.employment_status, 000167). 1-5 在职、
|
||||
// 6 离职、7 退休;业务选人(讲师/学员/推送受众/平台用户选择器)一律按
|
||||
// EmploymentStatusFormal 过滤。
|
||||
const (
|
||||
EmploymentStatusProbation = 1 // 试用
|
||||
EmploymentStatusProbationExtended = 2 // 试用延期
|
||||
EmploymentStatusFormal = 3 // 正式
|
||||
EmploymentStatusTemporary = 4 // 临时
|
||||
EmploymentStatusIntern = 5 // 实习
|
||||
EmploymentStatusResigned = 6 // 离职
|
||||
EmploymentStatusRetired = 7 // 退休
|
||||
)
|
||||
|
||||
// IsValidEmploymentStatus reports whether v is one of the 1-7 codes.
|
||||
func IsValidEmploymentStatus(v int) bool {
|
||||
return v >= EmploymentStatusProbation && v <= EmploymentStatusRetired
|
||||
}
|
||||
|
||||
// EmploymentStatusFromUsername 按工号规则推导开户时的初始在职状态:
|
||||
// 工号首位为字母的历史账号 → 离职,其余 → 正式(与 000167 迁移清洗口径一致)。
|
||||
func EmploymentStatusFromUsername(username string) int {
|
||||
if username != "" {
|
||||
if c := username[0]; (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') {
|
||||
return EmploymentStatusResigned
|
||||
}
|
||||
}
|
||||
return EmploymentStatusFormal
|
||||
}
|
||||
|
||||
// User represents a user in the system
|
||||
type User struct {
|
||||
// Unique identifier of the user
|
||||
@@ -134,6 +163,10 @@ type User struct {
|
||||
CanAccessAllTenants bool `json:"can_access_all_tenants" gorm:"default:false"`
|
||||
// Whether the user is a system administrator (independent of workspace roles)
|
||||
IsSystemAdmin bool `json:"is_system_admin" gorm:"default:false;index"`
|
||||
// EmploymentStatus 在职状态:1 试用 / 2 试用延期 / 3 正式 / 4 临时 /
|
||||
// 5 实习 / 6 离职 / 7 退休(000167)。人员属性,开户时按工号规则写入
|
||||
// (首位字母→离职,否则→正式),成员管理页可改;业务选人按 =3 正式过滤。
|
||||
EmploymentStatus int `json:"employment_status" gorm:"column:employment_status;type:smallint;not null;default:3"`
|
||||
// Per-user UI/feature preferences.
|
||||
// Stored as JSON (jsonb on Postgres, TEXT on SQLite) via the
|
||||
// driver.Valuer / sql.Scanner methods on UserPreferences.
|
||||
|
||||
Reference in new issue
Block a user