From 0a6b3444ff858b04b5b80b2f6df8003005d6e41b Mon Sep 17 00:00:00 2001 From: caihaohan Date: Tue, 30 Jul 2024 15:44:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=2087490=20=E5=A4=96=E6=9D=A5=E6=A0=87?= =?UTF-8?q?=E5=87=86=E6=B3=95=E8=A7=84=E6=96=87=E6=9C=AC=E5=BA=93--?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2--=E5=A4=9A=E6=97=A5=E6=9C=9F=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E6=9F=A5=E7=9A=84=E6=98=AF=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/LawsCommonServiceImpl.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java index a8f58764..e6925867 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java @@ -2368,19 +2368,33 @@ public class LawsCommonServiceImpl implements ILawsCommonService { **/ private void processDateManyTypeCondition(StringBuilder selectCondition, String key, String value) { if (value.contains(",")) { - String startDate = "date_format('" + value.split(",")[0] + "', '%Y-%m-%d')"; - String endDate = "date_format('" + value.split(",")[1] + "', '%Y-%m-%d')"; - selectCondition.append(" and (( date_format(SUBSTRING_INDEX(").append(key).append(", ',', 1),'%Y-%m-%d') >= ").append(startDate) - .append(" and date_format(SUBSTRING_INDEX(").append(key).append(", ',', 1),'%Y-%m-%d') <= ").append(endDate).append(")"); - selectCondition.append(" or ( date_format(SUBSTRING_INDEX(").append(key).append(", ',', 1),'%Y-%m-%d') <= ").append(startDate) - .append(" and date_format(SUBSTRING_INDEX(").append(key).append(", ',', -1),'%Y-%m-%d') >= ").append(endDate).append(")"); - selectCondition.append(" or ( date_format(SUBSTRING_INDEX(").append(key).append(", ',', -1),'%Y-%m-%d') >= ").append(startDate) - .append(" and date_format(SUBSTRING_INDEX(").append(key).append(", ',', -1),'%Y-%m-%d') <= ").append(endDate).append("))"); + // 提取输入的开始日期和结束日期 + String[] dates = value.split(","); + String startDate = "STR_TO_DATE('" + dates[0] + "', '%Y-%m-%d')"; + String endDate = "STR_TO_DATE('" + dates[1] + "', '%Y-%m-%d')"; + + // 添加 SQL 条件,使用 EXISTS 和一个子查询 + selectCondition.append(" AND EXISTS (") + .append("SELECT 1 FROM (") + .append("SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5") + .append(") numbers WHERE (") + .append(key) + .append(" REGEXP REPLACE(CONCAT('^', REPEAT('.*?,', numbers.n - 1), '.*'), ',{2,}', ',,') AND ") + .append("STR_TO_DATE(SUBSTRING_INDEX(SUBSTRING_INDEX(") + .append(key) + .append(", ',', numbers.n), ',', -1), '%Y-%m-%d') BETWEEN ") + .append(startDate) + .append(" AND ") + .append(endDate) + .append("))"); } else { - selectCondition.append(" and " + key + " like concat(concat('%','" + value + "'),'%')"); + // 单个日期的处理,使用 LIKE 进行模糊匹配 + selectCondition.append(" AND ").append(key).append(" LIKE CONCAT('%', '").append(value).append("', '%')"); } } + + @Override public byte[] getMinioFileContent(OSSFile file) throws Exception { return this.getMinioFileContentNormal(file, false);