From ab50e17810085c474edf0d6c9f5052bea8ecdbd0 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Wed, 2 Dec 2026 11:24:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A8=E9=80=81=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=E6=8C=89=E9=83=A8=E9=97=A8/=E8=81=8C=E4=BD=8D=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=8A=A5=E5=88=97=E4=B8=8D=E5=AD=98=E5=9C=A8,?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E9=99=90=E5=AE=9A=E6=9F=A5=E8=AF=A2=E5=88=97?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D42703?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/repository/tenant_member.go | 18 ++++++++++++------ .../repository/training_manual_push.go | 5 +++++ internal/handler/tenant_member.go | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) 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{}