diff --git a/internal/application/repository/tenant_member.go b/internal/application/repository/tenant_member.go index 5f8e0d3..419ab5d 100644 --- a/internal/application/repository/tenant_member.go +++ b/internal/application/repository/tenant_member.go @@ -111,8 +111,8 @@ 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. employmentStatus -// 非 0 时仅统计该在职状态(users.employment_status,000167)的成员。 +// restricted to users whose email, username or display name matches search. +// employmentStatus 非 0 时仅统计该在职状态(users.employment_status,000167)的成员。 func (r *tenantMemberRepository) CountFilteredByTenant( ctx context.Context, tenantID uint64, search string, employmentStatus int, ) (int64, error) { @@ -126,9 +126,12 @@ func (r *tenantMemberRepository) CountFilteredByTenant( } if search != "" { like := "%" + escapeLikePattern(search) + "%" + // 姓名一并纳入(000168):前端搜索框文案为「按姓名或邮箱搜索」,姓名在 + // users.display_name,而 username 存的是工号,只搜中文名此前恒为空。 q = q.Where( - `(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`, - like, likeEscapeChar, like, likeEscapeChar) + `(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?`+ + ` OR LOWER(users.display_name) LIKE LOWER(?) ESCAPE ?)`, + like, likeEscapeChar, like, likeEscapeChar, like, likeEscapeChar) } if employmentStatus > 0 { q = q.Where("users.employment_status = ?", employmentStatus) @@ -155,9 +158,12 @@ func (r *tenantMemberRepository) ListPagedByTenant( } if search != "" { like := "%" + escapeLikePattern(search) + "%" + // 姓名一并纳入(000168):前端搜索框文案为「按姓名或邮箱搜索」,姓名在 + // users.display_name,而 username 存的是工号,只搜中文名此前恒为空。 q = q.Where( - `(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`, - like, likeEscapeChar, like, likeEscapeChar) + `(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?`+ + ` OR LOWER(users.display_name) LIKE LOWER(?) ESCAPE ?)`, + like, likeEscapeChar, like, likeEscapeChar, like, likeEscapeChar) } if employmentStatus > 0 { q = q.Where("users.employment_status = ?", employmentStatus) diff --git a/internal/application/repository/training_manual_push.go b/internal/application/repository/training_manual_push.go index 975e92a..a8d650f 100644 --- a/internal/application/repository/training_manual_push.go +++ b/internal/application/repository/training_manual_push.go @@ -156,6 +156,11 @@ func (r *trainingRepository) ListManualPushAudience( } var rows []types.OrgEmployee if err := r.db.WithContext(ctx). + // 显式限定查询列:GORM 在带 Joins 时会按 schema 展开全部字段,而 + // OrgEmployee 的 user_name/dept_name/roles 是联查只读展示字段 + // (gorm:"->"),org_employees 表里并无这些列,展开会报 42703 + // (column does not exist)导致按部门/职位推送 500;此处只用 user_id。 + Select("org_employees.*"). 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"+ diff --git a/internal/handler/tenant_member.go b/internal/handler/tenant_member.go index 9c6d9fe..0cd4a89 100644 --- a/internal/handler/tenant_member.go +++ b/internal/handler/tenant_member.go @@ -112,11 +112,11 @@ func parseTenantIDFromPath(c *gin.Context) (uint64, bool) { // ListMembers godoc // @Summary 列出空间成员 -// @Description 分页返回当前空间内 active 成员(含每位成员的角色、邮箱、头像);支持 q 按邮箱/用户名筛选 +// @Description 分页返回当前空间内 active 成员(含每位成员的角色、邮箱、头像);支持 q 按邮箱/用户名/姓名筛选 // @Tags 空间成员 // @Produce json // @Param id path string true "空间 ID" -// @Param q query string false "按邮箱/用户名模糊筛选" +// @Param q query string false "按邮箱/用户名/姓名模糊筛选" // @Param page query int false "页码(从 1 起)" default(1) // @Param page_size query int false "每页数量(最大 100)" default(20) // @Success 200 {object} map[string]interface{}