fix: 高级搜索代替被代替SQL拼接问题

This commit is contained in:
2023-12-11 11:36:42 +08:00
parent 967de5e773
commit 8474c22961
@@ -1910,7 +1910,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
String replacedByStandard = (String) parameterMap.get(FieldCommon.REPLACED_BY_STANDARD);
if (StrUtil.isNotBlank(replacedByStandard)) {
List<String> standardNo = Arrays.asList(replacedByStandard.split(","));
String sql = getLawsReplacedStandardSql(tableName, standardNo, " replaced_by ", "1");
String sql = getLawsReplacedByStandardSql(tableName, standardNo, " replaced_by ", "1");
selectCondition.append(sql);
parameterMap.remove(FieldCommon.REPLACED_BY_STANDARD);
}
@@ -1926,7 +1926,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
String referencedStandard = (String) parameterMap.get(FieldCommon.REFERENCED_STANDARD);
if (StrUtil.isNotBlank(referencedStandard)) {
List<String> standardNo = Arrays.asList(referencedStandard.split(","));
String sql = getLawsReplacedStandardSql(tableName, standardNo, " replaced_by ", "2");
String sql = getLawsReplacedByStandardSql(tableName, standardNo, " replaced_by ", "2");
selectCondition.append(sql);
parameterMap.remove(FieldCommon.REFERENCED_STANDARD);
}
@@ -1973,17 +1973,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
}
selectCondition.append(idSql).append(")");
}
// if (standNoSearch) {
// String noSql = standNoSet.stream()
// .map(item -> "'" + item + "'")
// .collect(Collectors.joining(","));
// // 拼接SQL
// selectCondition.append(" AND standard_number IN (");
// if (StrUtil.isBlank(noSql)) {
// noSql = "''";
// }
// selectCondition.append(noSql).append(")");
// }
selectCondition.append(" AND del_flag = 0");
// 删除pageNo和pageSize,不参与条件查询
@@ -2058,6 +2047,19 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
@NotNull
private String getLawsReplacedStandardSql(String tableName, List<String> standardNo, String replaced, String type) {
StringBuilder str = new StringBuilder();
for (int i = 0; i < standardNo.size(); i++) {
str.append(replaced).append(" like '%").append(standardNo.get(i)).append("%' ");
if (i != standardNo.size() - 1) {
str.append(" and ");
}
}
return "and exists (select id from laws_replaced_standard where " + tableName + ".standard_number = replaced_by" +
" and type = " + type + " and " + str + ")";
}
@NotNull
private String getLawsReplacedByStandardSql(String tableName, List<String> standardNo, String replaced, String type) {
StringBuilder str = new StringBuilder();
for (int i = 0; i < standardNo.size(); i++) {
str.append(replaced).append(" like '%").append(standardNo.get(i)).append("%' ");