fix(system): 修复素材管理搜索中的列名错误
- 修正 FileRecordMapper.xml 中关键词搜索部分,将 b.name 和 b.comments 改为正确字段 - 搜索范围扩展至文件名、路径、注释及用户的用户名、昵称和真实姓名 - 添加关键词数字校验,避免非数字字符串误匹配 create_user_id - 防止因跨 Mapper 复制导致的表别名错误及字段不存在的问题
This commit is contained in:
@@ -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_user;sys_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,13 +59,19 @@
|
|||||||
<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}, '%')
|
||||||
</if>
|
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>
|
||||||
</where>
|
</where>
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user