fix(推送管理):按部门/职位推送报列不存在,显式限定查询列修复42703
deploy-hxtesting / build-and-deploy (push) Successful in 1m15s

This commit is contained in:
runny committed 2026-12-02 11:24:28 +08:00
1 parent aa85aab2b9
commit ab50e17810
3 files changed
+19 -8

No files matched your search

@@ -111,8 +111,8 @@ func (r *tenantMemberRepository) ListByTenant(ctx context.Context, tenantID uint
} }
// CountFilteredByTenant counts active tenant membership rows, optionally // CountFilteredByTenant counts active tenant membership rows, optionally
// restricted to users whose email or username matches search. employmentStatus // restricted to users whose email, username or display name matches search.
// 非 0 时仅统计该在职状态(users.employment_status,000167)的成员。 // employmentStatus 非 0 时仅统计该在职状态(users.employment_status,000167)的成员。
func (r *tenantMemberRepository) CountFilteredByTenant( func (r *tenantMemberRepository) CountFilteredByTenant(
ctx context.Context, tenantID uint64, search string, employmentStatus int, ctx context.Context, tenantID uint64, search string, employmentStatus int,
) (int64, error) { ) (int64, error) {
@@ -126,9 +126,12 @@ func (r *tenantMemberRepository) CountFilteredByTenant(
} }
if search != "" { if search != "" {
like := "%" + escapeLikePattern(search) + "%" like := "%" + escapeLikePattern(search) + "%"
// 姓名一并纳入(000168):前端搜索框文案为「按姓名或邮箱搜索」,姓名在
// users.display_name,而 username 存的是工号,只搜中文名此前恒为空。
q = q.Where( q = q.Where(
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`, `(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?`+
like, likeEscapeChar, like, likeEscapeChar) ` OR LOWER(users.display_name) LIKE LOWER(?) ESCAPE ?)`,
like, likeEscapeChar, like, likeEscapeChar, like, likeEscapeChar)
} }
if employmentStatus > 0 { if employmentStatus > 0 {
q = q.Where("users.employment_status = ?", employmentStatus) q = q.Where("users.employment_status = ?", employmentStatus)
@@ -155,9 +158,12 @@ func (r *tenantMemberRepository) ListPagedByTenant(
} }
if search != "" { if search != "" {
like := "%" + escapeLikePattern(search) + "%" like := "%" + escapeLikePattern(search) + "%"
// 姓名一并纳入(000168):前端搜索框文案为「按姓名或邮箱搜索」,姓名在
// users.display_name,而 username 存的是工号,只搜中文名此前恒为空。
q = q.Where( q = q.Where(
`(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?)`, `(LOWER(users.email) LIKE LOWER(?) ESCAPE ? OR LOWER(users.username) LIKE LOWER(?) ESCAPE ?`+
like, likeEscapeChar, like, likeEscapeChar) ` OR LOWER(users.display_name) LIKE LOWER(?) ESCAPE ?)`,
like, likeEscapeChar, like, likeEscapeChar, like, likeEscapeChar)
} }
if employmentStatus > 0 { if employmentStatus > 0 {
q = q.Where("users.employment_status = ?", employmentStatus) q = q.Where("users.employment_status = ?", employmentStatus)
@@ -156,6 +156,11 @@ func (r *trainingRepository) ListManualPushAudience(
} }
var rows []types.OrgEmployee var rows []types.OrgEmployee
if err := r.db.WithContext(ctx). 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"). 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'"+ 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 org_employees.user_id <> '' AND org_employees.deleted_at IS NULL"+
+2 -2
View File
@@ -112,11 +112,11 @@ func parseTenantIDFromPath(c *gin.Context) (uint64, bool) {
// ListMembers godoc // ListMembers godoc
// @Summary 列出空间成员 // @Summary 列出空间成员
// @Description 分页返回当前空间内 active 成员(含每位成员的角色、邮箱、头像);支持 q 按邮箱/用户名筛选 // @Description 分页返回当前空间内 active 成员(含每位成员的角色、邮箱、头像);支持 q 按邮箱/用户名/姓名筛选
// @Tags 空间成员 // @Tags 空间成员
// @Produce json // @Produce json
// @Param id path string true "空间 ID" // @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 query int false "页码(从 1 起)" default(1)
// @Param page_size query int false "每页数量(最大 100)" default(20) // @Param page_size query int false "每页数量(最大 100)" default(20)
// @Success 200 {object} map[string]interface{} // @Success 200 {object} map[string]interface{}