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
// 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)
@@ -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"+