fix(system): 修复素材管理搜索中的列名错误

- 修正 FileRecordMapper.xml 中关键词搜索部分,将 b.name 和 b.comments 改为正确字段
- 搜索范围扩展至文件名、路径、注释及用户的用户名、昵称和真实姓名
- 添加关键词数字校验,避免非数字字符串误匹配 create_user_id
- 防止因跨 Mapper 复制导致的表别名错误及字段不存在的问题
This commit is contained in:
2026-09-03 11:15:01 +08:00
parent c88b41fd46
commit e7a12d8828
2 changed files with 23 additions and 7 deletions
+10
View File
@@ -0,0 +1,10 @@
# 2026-09-03
## 修复:素材管理搜索报 Unknown column 'b.name'
- 文件:`src/main/java/com/gxwebsoft/common/system/mapper/xml/FileRecordMapper.xml`
- 根因:`selectSql``keywords` 模糊搜索块(2024-11-25 提交 cf4f010 引入,疑似从 UserVerifyMapper 复制过来未改别名)写成了 `b.name` / `b.comments`
该块中 `a` = sys_file_record`b` = sys_usersys_user **没有** `name` 字段(只有 username / nickname / real_name / phone),故 MySQL 报 `Unknown column 'b.name' in 'where clause'`
- 修复:关键词改为搜索文件侧字段 `a.name` / `a.path` / `a.comments`,加上传者 `b.username` / `b.nickname` / `b.real_name`
`a.create_user_id = #{param.keywords}``<if test="param.keywords.matches('[0-9]+')">` 包住,避免非数字关键词被 MySQL 隐式转成 0。
- 教训:跨 mapper 复制动态 SQL 片段时,务必核对表别名与目标表字段(sys_user 无 name 列)。
@@ -59,11 +59,17 @@
<if test="param.contentType != null"> <if test="param.contentType != null">
AND a.content_type LIKE CONCAT('%', #{param.contentType}, '%') AND a.content_type LIKE CONCAT('%', #{param.contentType}, '%')
</if> </if>
<if test="param.keywords != null"> <if test="param.keywords != null and param.keywords != ''">
AND ( AND (
a.create_user_id = #{param.keywords} a.`name` LIKE CONCAT('%', #{param.keywords}, '%')
OR b.name LIKE CONCAT('%', #{param.keywords}, '%') OR a.path LIKE CONCAT('%', #{param.keywords}, '%')
OR b.comments LIKE CONCAT('%', #{param.keywords}, '%') OR a.comments LIKE CONCAT('%', #{param.keywords}, '%')
OR b.username LIKE CONCAT('%', #{param.keywords}, '%')
OR b.nickname LIKE CONCAT('%', #{param.keywords}, '%')
OR b.real_name LIKE CONCAT('%', #{param.keywords}, '%')
<if test="param.keywords.matches('[0-9]+')">
OR a.create_user_id = #{param.keywords}
</if>
) )
</if> </if>
</where> </where>