fix(organization): 修复组织查询中class_enum字段的多值匹配逻辑

- 将FIND_IN_SET函数替换为LIKE操作符组合,提高PostgreSQL兼容性
- 添加子查询包装器支持多种匹配模式
- 实现精确匹配、前缀匹配、后缀匹配和中间匹配四种查询方式
- 确保逗号分隔的枚举值能够正确匹配查询条件
- 优化查询性能并提升代码可读性
This commit is contained in:
2026-01-18 14:06:44 +08:00
parent 59157fda56
commit 5667e04d12
2 changed files with 22 additions and 3 deletions

View File

@@ -56,7 +56,17 @@ public class OrganizationAppServiceImpl implements IOrganizationAppService {
queryWrapper.and(wrapper -> {
String[] classEnums = classEnum.split(",");
for (String cls : classEnums) {
wrapper.or().apply("FIND_IN_SET(?, class_enum)", cls.trim());
String trimmedCls = cls.trim();
// 使用OR连接多个条件来匹配逗号分隔的值
wrapper.or().and(subWrapper -> {
subWrapper.eq(Organization::getClassEnum, trimmedCls)
.or()
.likeRight(Organization::getClassEnum, trimmedCls + ",")
.or()
.likeLeft(Organization::getClassEnum, "," + trimmedCls)
.or()
.like(Organization::getClassEnum, "," + trimmedCls + ",");
});
}
});
}

View File

@@ -69,8 +69,17 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Org
// 如果organizationClass不为null则添加查询条件
if (organizationClass != null) {
// 支持多选值,使用FIND_IN_SET进行查询
queryWrapper.apply("FIND_IN_SET({0}, class_enum)", organizationClass.toString());
// 支持多选值,使用LIKE操作符进行查询适用于PostgreSQL
String classValue = organizationClass.toString();
queryWrapper.and(subWrapper -> {
subWrapper.eq(Organization::getClassEnum, classValue)
.or()
.likeRight(Organization::getClassEnum, classValue + ",")
.or()
.likeLeft(Organization::getClassEnum, "," + classValue)
.or()
.like(Organization::getClassEnum, "," + classValue + ",");
});
}
return baseMapper.selectList(queryWrapper);