From b3efd9917e66cdf32375db29b21e1bd9a60c8f55 Mon Sep 17 00:00:00 2001 From: shiyang <316555390@qq.com> Date: Thu, 6 Jan 2022 17:00:15 +0800 Subject: [PATCH] update --- .../com/lyms/platform/query/AntExChuQuery.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java b/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java index 332fed6..d2d9ebf 100644 --- a/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java +++ b/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java @@ -5,6 +5,7 @@ import com.lyms.platform.common.dao.BaseQuery; import com.lyms.platform.common.dao.operator.MongoCondition; import com.lyms.platform.common.dao.operator.MongoOper; import com.lyms.platform.common.dao.operator.MongoQuery; +import com.lyms.platform.common.utils.StringUtils; import org.apache.commons.collections.CollectionUtils; import org.springframework.data.mongodb.core.query.Criteria; @@ -325,9 +326,6 @@ public class AntExChuQuery extends BaseQuery implements IConvertToNativeQuery { if (null != xhdb) { condition = condition.and("xhdb", xhdb, MongoOper.NE); } - if (null != xhdbXiao) { - condition = condition.and("xhdb", xhdbXiao, MongoOper.LT); - } if (null != hivkt) { condition = condition.and("hivkt", hivkt, MongoOper.IS); @@ -424,10 +422,24 @@ public class AntExChuQuery extends BaseQuery implements IConvertToNativeQuery { condition = condition.orCondition(new MongoCondition[]{mongoCondition, condition2}); } if (null != lpXhdbStart&&null!=lpXhdbEnd) { + //字符串判断大小 + String formatXhdb = String.format("function() {\n" + + " return this.xhdb >= %s &&this.xhdb <= %s \n" + + " }",lpXhdbStart,lpXhdbEnd); if (null != c) { - c = c.and("xhdb").gte(lpXhdbStart).lte(lpXhdbEnd); + c.and("$where").is(formatXhdb).and("xhdb").ne("");//加ne:该字段在mongo中是”“ ,如果表达式有>=0也可查出。可以避免空数据 } else { - c = Criteria.where("xhdb").gte(lpXhdbStart).lte(lpXhdbEnd); + c = Criteria.where("$where").is(formatXhdb).and("xhdb").ne(""); + } + } + if(StringUtils.isNotEmpty(xhdbXiao)){ + String formatXhdb = String.format("function() {\n" + + " return this.xhdb < %s \n" + + " }",xhdbXiao); + if(null != c){ + c = c.and("$where").is(formatXhdb).and("xhdb").ne("");//加ne:该字段在mongo中是”“ ,如果表达式有>=0也可查出。可以避免空数据 + }else{ + c = Criteria.where("$where").is(formatXhdb).and("xhdb").ne(""); } } -- 1.8.3.1