From 10d8d34a019e6c964e297e0c9804b3fb6cc4bcd8 Mon Sep 17 00:00:00 2001 From: yjz <3131811435@qq.com> Date: Fri, 20 Oct 2023 14:57:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=96=87=E6=A1=A3=E6=8B=86=E5=88=86):=20?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=AD=97=E6=AE=B5=E6=9F=A5=E8=AF=A2=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/DocumentSplitCommon.java | 4 ++++ .../handler/impl/DateManyConditionImpl.java | 17 +++++++++++++++++ .../handler/impl/InConditionImpl.java | 19 +++++++++++-------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/laws/documenttool/common/DocumentSplitCommon.java b/laws-modules/src/main/java/com/jero/modules/laws/documenttool/common/DocumentSplitCommon.java index 08551bf2..200ce198 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/documenttool/common/DocumentSplitCommon.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/documenttool/common/DocumentSplitCommon.java @@ -36,6 +36,10 @@ public class DocumentSplitCommon { * 模糊匹配 */ public static final String CONCAT_LIKE_END = "', '%') "; + /** + * 包含 + */ + public static final String INSTR_BEGIN = " instr("; /** * and */ diff --git a/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/DateManyConditionImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/DateManyConditionImpl.java index 30e694a6..eaa5d87f 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/DateManyConditionImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/DateManyConditionImpl.java @@ -17,6 +17,23 @@ import javax.annotation.PostConstruct; @Component public class DateManyConditionImpl extends AbstractConditionBase { + /** + * 实现逻辑,多日期字符串字段(存储时前端从小到大排好序(必须)) + * 逗号拆分获取首位和末尾日期,来分别匹配是否符合查询参数的两个日期区间 + * 实现sql参考:(代码拼接中加入了date_format来格式化日期) + * select + * epr.* + * from + * event_plan_record epr + * where + * substring_index('epr.realStartTime', ',', 1) BETWEEN #{startDate} AND #{endDate} + * or substring_index('epr.realStartTime', ',', -1) BETWEEN #{startDate} AND #{endDate} + * or #{startDate} BETWEEN substring_index('epr.realStartTime', ',', 1) AND substring_index('epr.realStartTime', ',', -1) + * or #{endDate} BETWEEN substring_index('epr.realStartTime', ',', 1) AND substring_index('epr.realStartTime', ',', -1) + * @param fieldName + * @param value + * @return + */ @Override public String buildCondition(String fieldName, String value){ // 多日期查询 diff --git a/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/InConditionImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/InConditionImpl.java index b9d659c5..f561c089 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/InConditionImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/documenttool/handler/impl/InConditionImpl.java @@ -7,11 +7,13 @@ import com.jero.modules.laws.documenttool.handler.AbstractConditionBase; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import java.util.Arrays; +import java.util.List; /** * @Author: yjz * @Date: 2023/10/13/17:05 - * @Description: in查询 + * @Description: 下拉框查询 */ @Component @@ -19,16 +21,17 @@ public class InConditionImpl extends AbstractConditionBase { @Override public String buildCondition(String fieldName, String value){ - // in查询 + // 下拉框查询 StringBuilder in = new StringBuilder(); - in.append(DocumentSplitCommon.AND).append(fieldName).append(DocumentSplitCommon.IN).append("("); - for (String s : value.split(",")) { - in.append("'").append(s).append("'"); - if (value.indexOf(s) != value.length() -1){ - in.append(","); + in.append(DocumentSplitCommon.AND).append("(("); + List list = Arrays.asList(value.split(",")); + for (String s : list) { + in.append(DocumentSplitCommon.INSTR_BEGIN).append(fieldName).append(",").append("'").append(s).append("'").append(")"); + if (list.indexOf(s) != list.size() -1){ + in.append(DocumentSplitCommon.OR); } } - in.append(")"); + in.append("))"); return in.toString(); }