isNotEmpty isNotNull isset empty

今天遇到一个问题,在编辑提交表单时,有些input没有内容,不能提交到后台更新数据库,但是form里没有填写内容时,接受到是""空串,

在如果不让提交数据库覆盖之前的内容,可以使用ibatis的isNotEmpty而不是isNotNull

 

ibatis : isNotEmpty:过滤空串""和空null

 isNotNull: 只过滤空null

   php : isset:过滤null和未定义

          isEmpty:过滤false、空串""、null

for (HistoricActivityInstance activityInstance : historicActivityInstanceList) { WfProcNodeVo elementVo = new WfProcNodeVo(); elementVo.setProcDefId(activityInstance.getProcessDefinitionId()); elementVo.setActivityId(activityInstance.getActivityId()); elementVo.setActivityName(activityInstance.getActivityName()); elementVo.setActivityType(activityInstance.getActivityType()); elementVo.setCreateTime(activityInstance.getStartTime()); elementVo.setEndTime(activityInstance.getEndTime()); if (ObjectUtil.isNotNull(activityInstance.getDurationInMillis())) { elementVo.setDuration(DateUtil.formatBetween(activityInstance.getDurationInMillis(), BetweenFormatter.Level.SECOND)); } if ("startEvent".equals(activityInstance.getActivityType())) { if (ObjectUtil.isNotNull(historicProcIns)) { Long userId = Long.parseLong(historicProcIns.getStartUserId()); String nickName = userService.selectNickNameById(userId); if (nickName != null) { elementVo.setAssigneeId(userId); elementVo.setAssigneeName(nickName); } } } else if ("userTask".equals(activityInstance.getActivityType())) { if (StringUtils.isNotBlank(activityInstance.getAssignee())) { Long userId = Long.parseLong(activityInstance.getAssignee()); String nickName = userService.selectNickNameById(userId); elementVo.setAssigneeId(userId); elementVo.setAssigneeName(nickName); } // 展示审批人员 List<HistoricIdentityLinkLog> linksForTask = historyService.createHistoricIdentityLinkLogQuery().taskId(activityInstance.getTaskId()).list(); StringBuilder stringBuilder = new StringBuilder(); for (HistoricIdentityLinkLog identityLink : linksForTask) { if ("candidate".equals(identityLink.getType())) { if (StringUtils.isNotBlank(identityLink.getUserId())) { Long userId = Long.parseLong(identityLink.getUserId()); String nickName = userService.selectNickNameById(userId); stringBuilder.append(nickName).append(","); } if (StringUtils.isNotBlank(identityLink.getGroupId())) { if (identityLink.getGroupId().startsWith(TaskConstants.ROLE_GROUP_PREFIX)) { Long roleId = Long.parseLong(StringUtils.stripStart(identityLink.getGroupId(), TaskConstants.ROLE_GROUP_PREFIX)); SysRole role = roleService.selectRoleById(roleId); stringBuilder.append(role.getRoleName()).append(","); } else if (identityLink.getGroupId().startsWith(TaskConstants.DEPT_GROUP_PREFIX)) { Long deptId = Long.parseLong(StringUtils.stripStart(identityLink.getGroupId(), TaskConstants.DEPT_GROUP_PREFIX)); SysDept dept = deptService.selectDeptById(deptId); stringBuilder.append(dept.getDeptName()).append(","); } } } } if (StringUtils.isNotBlank(stringBuilder)) { elementVo.setCandidate(stringBuilder.substring(0, stringBuilder.length() - 1)); } // 获取意见评论内容 if (CollUtil.isNotEmpty(commentList)) { List<CommentDto> comments = new ArrayList<>(); for (Comment comment : commentList) { CommentDto target = new CommentDto(); if (comment.getTaskId().equals(activityInstance.getTaskId())) { BeanUtils.copyProperties(comment, target); comments.add(target); } } elementVo.setCommentList(comments); } } elementVoList.add(elementVo); }主要是我需要优化这个four循环,不想在for循环里面查询sql语句
09-16
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package org.dromara.easyes.core.kernel; import co.elastic.clients.elasticsearch._types.DistanceUnit; import co.elastic.clients.elasticsearch._types.GeoDistanceType; import co.elastic.clients.elasticsearch._types.GeoLocation; import co.elastic.clients.elasticsearch._types.GeoShapeRelation; import co.elastic.clients.elasticsearch._types.SortOptions; import co.elastic.clients.elasticsearch._types.SortOrder; import co.elastic.clients.elasticsearch._types.mapping.TypeMapping; import co.elastic.clients.elasticsearch._types.query_dsl.ChildScoreMode; import co.elastic.clients.elasticsearch._types.query_dsl.Operator; import co.elastic.clients.elasticsearch.core.SearchRequest; import co.elastic.clients.elasticsearch.indices.IndexSettings; import co.elastic.clients.util.NamedValue; import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Stack; import java.util.UUID; import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Predicate; import org.dromara.easyes.annotation.rely.FieldType; import org.dromara.easyes.common.enums.AggregationTypeEnum; import org.dromara.easyes.common.enums.EsQueryTypeEnum; import org.dromara.easyes.common.enums.OrderTypeEnum; import org.dromara.easyes.common.utils.ArrayUtils; import org.dromara.easyes.common.utils.Assert; import org.dromara.easyes.common.utils.CollectionUtils; import org.dromara.easyes.common.utils.ExceptionUtils; import org.dromara.easyes.common.utils.StringUtils; import org.dromara.easyes.core.biz.AggregationParam; import org.dromara.easyes.core.biz.BaseSortParam; import org.dromara.easyes.core.biz.EntityFieldInfo; import org.dromara.easyes.core.biz.EsIndexParam; import org.dromara.easyes.core.biz.EsUpdateParam; import org.dromara.easyes.core.biz.OrderByParam; import org.dromara.easyes.core.biz.Param; import org.dromara.easyes.core.conditions.function.Compare; import org.dromara.easyes.core.conditions.function.Func; import org.dromara.easyes.core.conditions.function.Geo; import org.dromara.easyes.core.conditions.function.Index; import org.dromara.easyes.core.conditions.function.Join; import org.dromara.easyes.core.conditions.function.Nested; import org.dromara.easyes.core.conditions.function.Query; import org.dromara.easyes.core.conditions.function.Update; import org.dromara.easyes.core.toolkit.EntityInfoHelper; import org.dromara.easyes.core.toolkit.GeoUtils; import org.elasticsearch.geometry.Geometry; public abstract class AbstractWrapper<T, R, Children extends AbstractWrapper<T, R, Children>> extends Wrapper<T> implements Compare<Children, R>, Nested<Children, Children>, Func<Children, R>, Join<Children>, Geo<Children, R>, Query<Children, T, R>, Update<Children, R>, Index<Children, R> { protected final Children typedThis = this; protected int level; protected String parentId; protected EsQueryTypeEnum prevQueryType; protected Stack<String> parentIdStack; protected LinkedList<EsQueryTypeEnum> prevQueryTypeQueue; public AbstractWrapper() { } public Children setEntity(T entity) { this.entity = entity; this.initEntityClass(); return this.typedThis; } public Children setEntityClass(Class<T> entityClass) { this.entityClass = entityClass; this.initEntityClass(); return this.typedThis; } protected void initEntityClass() { if (this.entityClass == null && this.entity != null) { this.entityClass = this.entity.getClass(); } } protected Class<T> getCheckEntityClass() { Assert.notNull(this.entityClass, "entityClass must not null,please set entity before use this method!"); return this.entityClass; } protected final void initNeed() { this.baseSortParams = new ArrayList(); this.aggregationParamList = new ArrayList(); this.paramQueue = new LinkedList(); this.prevQueryType = EsQueryTypeEnum.NESTED_AND; this.parentIdStack = new Stack(); this.prevQueryTypeQueue = new LinkedList(); } public <V> Children allEq(boolean condition, Map<String, V> params) { if (condition && CollectionUtils.isNotEmpty(params)) { params.forEach(this::eq); } return this.typedThis; } public <V> Children allEq(boolean condition, BiPredicate<String, V> filter, Map<String, V> params) { if (condition && CollectionUtils.isNotEmpty(params)) { params.forEach((k, v) -> { if (filter.test(k, v) && StringUtils.checkValNotNull(v)) { this.eq(k, v); } }); } return this.typedThis; } public Children eq(boolean condition, String column, Object val, Float boost) { return this.addParam(condition, EsQueryTypeEnum.TERM, column, val, boost); } public Children and(boolean condition, Consumer<Children> consumer) { return this.addNested(condition, EsQueryTypeEnum.NESTED_AND, consumer); } public Children or(boolean condition, Consumer<Children> consumer) { return this.addNested(condition, EsQueryTypeEnum.NESTED_OR, consumer); } public Children or(boolean condition) { for(int i = this.paramQueue.size() - 1; i >= 0; --i) { Param param = (Param)this.paramQueue.get(i); if (Objects.equals(this.level, param.getLevel())) { param.setPrevQueryType(EsQueryTypeEnum.NESTED_OR); break; } } return this.addParam(condition, EsQueryTypeEnum.OR, (String)null, (Object)null, (Float)null); } public Children must(boolean condition, Consumer<Children> consumer) { return this.addNested(condition, EsQueryTypeEnum.NESTED_AND, consumer); } public Children should(boolean condition, Consumer<Children> consumer) { return this.addNested(condition, EsQueryTypeEnum.NESTED_OR, consumer); } public Children filter(boolean condition, Consumer<Children> consumer) { return this.addNested(condition, EsQueryTypeEnum.NESTED_FILTER, consumer); } public Children filter(boolean condition) { return this.addParam(condition, EsQueryTypeEnum.FILTER, (String)null, (Object)null, (Float)null); } public Children not(boolean condition) { return this.addParam(condition, EsQueryTypeEnum.NOT, (String)null, (Object)null, (Float)null); } public Children not(boolean condition, Consumer<Children> consumer) { return this.addNested(condition, EsQueryTypeEnum.NESTED_NOT, consumer); } public Children nested(boolean condition, String path, Consumer<Children> consumer, ChildScoreMode scoreMode) { return this.addNested(condition, path, scoreMode, consumer); } public Children match(boolean condition, String column, Object val, Float boost) { return this.addParam(condition, EsQueryTypeEnum.MATCH, column, val, boost); } public Children hasChild(boolean condition, String type, Consumer<Children> consumer, ChildScoreMode scoreMode) { return this.addJoin(condition, EsQueryTypeEnum.HAS_CHILD, type, scoreMode, consumer); } public Children hasParent(boolean condition, String parentType, Consumer<Children> consumer, boolean score) { return this.addJoin(condition, EsQueryTypeEnum.HAS_PARENT, parentType, score, consumer); } public Children parentId(boolean condition, Object parentId, String type, Float boost) { if (condition) { Assert.notNull(parentId, "parentId could not be null"); } return this.addParam(condition, EsQueryTypeEnum.PARENT_ID, type, parentId, boost); } public Children matchPhrase(boolean condition, String column, Object val, Float boost) { return this.addParam(condition, EsQueryTypeEnum.MATCH_PHRASE, column, val, boost); } public Children matchAllQuery(boolean condition, Float boost) { return this.addParam(condition, EsQueryTypeEnum.MATCH_ALL, (String)null, (Object)null, boost); } public Children matchPhrasePrefixQuery(boolean condition, String column, Object val, int maxExpansions, Float boost) { return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.MATCH_PHRASE_PREFIX, (String)column, val, maxExpansions, (Object)null, boost); } @SafeVarargs public final Children multiMatchQuery(boolean condition, Object val, Operator operator, int minimumShouldMatch, Float boost, String... columns) { return this.addParam(condition, val, operator, minimumShouldMatch, boost, columns); } public Children queryStringQuery(boolean condition, String queryString, Float boost) { return this.addParam(condition, EsQueryTypeEnum.QUERY_STRING, queryString, (Object)null, boost); } public Children prefixQuery(boolean condition, String column, String prefix, Float boost) { if (condition) { Assert.notBlank(prefix, "prefix can't be blank"); } return this.addParam(condition, EsQueryTypeEnum.PREFIX, column, prefix, boost); } public Children gt(boolean condition, String column, Object val, ZoneId timeZone, String format, Float boost) { return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.GT, (String)column, val, timeZone, format, boost); } public Children ge(boolean condition, String column, Object val, ZoneId timeZone, String format, Float boost) { return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.GE, (String)column, val, timeZone, format, boost); } public Children lt(boolean condition, String column, Object val, ZoneId timeZone, String format, Float boost) { return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.LT, (String)column, val, timeZone, format, boost); } public Children le(boolean condition, String column, Object val, ZoneId timeZone, String format, Float boost) { return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.LE, (String)column, val, timeZone, format, boost); } public Children between(boolean condition, String column, Object from, Object to, ZoneId timeZone, String format, Float boost) { return this.addParam(condition, (String)column, (Object)from, to, timeZone, format, boost); } public Children like(boolean condition, String column, Object val, Float boost) { val = Optional.ofNullable(val).map((v) -> { return "*" + v + "*"; }).orElse("*"); return this.addParam(condition, EsQueryTypeEnum.WILDCARD, column, val, boost); } public Children likeLeft(boolean condition, String column, Object val, Float boost) { val = Optional.ofNullable(val).map((v) -> { return "*" + v; }).orElse("*"); return this.addParam(condition, EsQueryTypeEnum.WILDCARD, column, val, boost); } public Children likeRight(boolean condition, String column, Object val, Float boost) { val = Optional.ofNullable(val).map((v) -> { return v + "*"; }).orElse("*"); return this.addParam(condition, EsQueryTypeEnum.WILDCARD, column, val, boost); } public Children in(boolean condition, String column, Collection<?> coll, Float boost) { return CollectionUtils.isEmpty(coll) ? this.typedThis : this.addParam(condition, EsQueryTypeEnum.TERMS, column, coll, boost); } public Children exists(boolean condition, String column, Float boost) { return this.addParam(condition, EsQueryTypeEnum.EXISTS, column, (Object)null, boost); } public Children geoBoundingBox(boolean condition, String column, String topLeft, String bottomRight, Float boost) { if (condition) { Assert.notBlank(topLeft, "TopLeft must not be null in geoBoundingBox query"); Assert.notBlank(bottomRight, "BottomRight must not be null in geoBoundingBox query"); return this.geoBoundingBox(true, column, GeoUtils.create(topLeft), GeoUtils.create(bottomRight), boost); } else { return this.typedThis; } } public Children geoBoundingBox(boolean condition, String column, GeoLocation topLeft, GeoLocation bottomRight, Float boost) { if (condition) { Assert.notNull(topLeft, "TopLeft point must not be null in geoBoundingBox query"); Assert.notNull(bottomRight, "BottomRight point must not be null in geoBoundingBox query"); } return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.GEO_BOUNDING_BOX, (String)column, (Object)null, topLeft, bottomRight, boost); } public Children geoDistance(boolean condition, String column, Double distance, DistanceUnit distanceUnit, GeoLocation centralGeoLocation, Float boost) { if (condition) { Assert.notNull(distance, "Distance must not be null in geoDistance query"); Assert.notNull(distanceUnit, "Distance unit must not be null in geoDistance query"); Assert.notNull(centralGeoLocation, "CentralGeoLocation must not be null in geoDistance query"); } return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.GEO_DISTANCE, (String)column, distance, distanceUnit, centralGeoLocation, boost); } public Children geoDistance(boolean condition, String column, Double distance, DistanceUnit distanceUnit, String centralGeoLocation, Float boost) { if (condition) { Assert.notBlank(centralGeoLocation, "centralGeoLocation must not be null in geoDistance query"); return this.geoDistance(true, column, distance, distanceUnit, GeoUtils.create(centralGeoLocation), boost); } else { return this.typedThis; } } public Children geoDistance(boolean condition, String column, String distance, GeoLocation centralGeoLocation, Float boost) { if (condition) { Assert.notBlank(distance, "Distance must not be null in geoDistance query"); Assert.notNull(centralGeoLocation, "CentralGeoLocation must not be null in geoDistance query"); } return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.GEO_DISTANCE, (String)column, distance, (Object)null, centralGeoLocation, boost); } public Children geoDistance(boolean condition, String column, String distance, String centralGeoLocation, Float boost) { if (condition) { Assert.notBlank(centralGeoLocation, "centralGeoLocation must not be null in geoDistance query"); return this.geoDistance(true, column, distance, GeoUtils.create(centralGeoLocation), boost); } else { return this.typedThis; } } public Children geoPolygon(boolean condition, String column, List<GeoLocation> geoPoints, Float boost) { if (condition) { Assert.notEmpty(geoPoints, "GeoLocations must not be null in geoPolygon query"); } return this.addParam(condition, EsQueryTypeEnum.GEO_POLYGON, column, geoPoints, boost); } public Children geoShape(boolean condition, String column, String indexedShapeId, Float boost) { if (condition) { Assert.notNull(indexedShapeId, "IndexedShapeId must not be null in geoShape query"); } return this.addParam(condition, EsQueryTypeEnum.GEO_SHAPE_ID, column, indexedShapeId, boost); } public Children geoShape(boolean condition, String column, Geometry geometry, GeoShapeRelation shapeRelation, Float boost) { if (condition) { Assert.notNull(geometry, "Geometry must not be null in geoShape query"); Assert.notNull(geometry, "GeoShapeRelation must not be null in geoShape query"); } return this.addParam(condition, (EsQueryTypeEnum)EsQueryTypeEnum.GEO_SHAPE, (String)column, geometry, shapeRelation, (Object)null, boost); } public final Children orderBy(boolean condition, boolean isAsc, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { if (condition) { Arrays.stream(columns).forEach((column) -> { BaseSortParam baseSortParam = BaseSortParam.builder().sortField(column).sortOrder(isAsc ? SortOrder.Asc : SortOrder.Desc).orderTypeEnum(OrderTypeEnum.FIELD).build(); this.baseSortParams.add(baseSortParam); }); } return this.typedThis; } } public Children orderBy(boolean condition, List<OrderByParam> orderByParams) { if (CollectionUtils.isNotEmpty(orderByParams)) { this.orderByParams = orderByParams; } return this.typedThis; } public Children orderByDistanceAsc(boolean condition, String column, DistanceUnit unit, GeoDistanceType geoDistance, GeoLocation... geoPoints) { if (ArrayUtils.isNotEmpty(geoPoints) && condition) { BaseSortParam baseSortParam = BaseSortParam.builder().sortField(column).sortOrder(SortOrder.Asc).orderTypeEnum(OrderTypeEnum.GEO).geoPoints(Arrays.asList(geoPoints)).unit(unit).geoDistanceType(geoDistance).build(); this.baseSortParams.add(baseSortParam); } return this.typedThis; } public Children orderByDistanceDesc(boolean condition, String column, DistanceUnit unit, GeoDistanceType geoDistance, GeoLocation... geoPoints) { if (ArrayUtils.isNotEmpty(geoPoints) && condition) { BaseSortParam baseSortParam = BaseSortParam.builder().sortField(column).sortOrder(SortOrder.Desc).orderTypeEnum(OrderTypeEnum.GEO).geoPoints(Arrays.asList(geoPoints)).unit(unit).geoDistanceType(geoDistance).build(); this.baseSortParams.add(baseSortParam); } return this.typedThis; } public Children sort(boolean condition, List<SortOptions> sortBuilders) { if (CollectionUtils.isEmpty(sortBuilders)) { return this.typedThis; } else { if (condition) { sortBuilders.forEach((sortBuilder) -> { BaseSortParam baseSortParam = BaseSortParam.builder().orderTypeEnum(OrderTypeEnum.CUSTOMIZE).sortBuilder(sortBuilder).build(); this.baseSortParams.add(baseSortParam); }); } return this.typedThis; } } public Children sortByScore(boolean condition, SortOrder sortOrder) { if (condition) { BaseSortParam baseSortParam = BaseSortParam.builder().sortOrder(sortOrder).orderTypeEnum(OrderTypeEnum.SCORE).build(); this.baseSortParams.add(baseSortParam); } return this.typedThis; } public final Children groupBy(boolean condition, boolean enablePipeline, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { Arrays.stream(columns).forEach((column) -> { this.doIt(condition, enablePipeline, AggregationTypeEnum.TERMS, column); }); return this.typedThis; } } public Children termsAggregation(boolean condition, boolean enablePipeline, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { Arrays.stream(columns).forEach((column) -> { this.doIt(condition, enablePipeline, AggregationTypeEnum.TERMS, column); }); return this.typedThis; } } public Children avg(boolean condition, boolean enablePipeline, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { Arrays.stream(columns).forEach((column) -> { this.doIt(condition, enablePipeline, AggregationTypeEnum.AVG, column); }); return this.typedThis; } } public Children min(boolean condition, boolean enablePipeline, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { Arrays.stream(columns).forEach((column) -> { this.doIt(condition, enablePipeline, AggregationTypeEnum.MIN, column); }); return this.typedThis; } } public Children max(boolean condition, boolean enablePipeline, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { Arrays.stream(columns).forEach((column) -> { this.doIt(condition, enablePipeline, AggregationTypeEnum.MAX, column); }); return this.typedThis; } } public Children sum(boolean condition, boolean enablePipeline, String... columns) { if (ArrayUtils.isEmpty(columns)) { return this.typedThis; } else { Arrays.stream(columns).forEach((column) -> { this.doIt(condition, enablePipeline, AggregationTypeEnum.SUM, column); }); return this.typedThis; } } public Children distinct(boolean condition, String column) { if (condition) { this.distinctField = column; } return this.typedThis; } public Children from(Integer from) { this.from = from; return this.typedThis; } public Children size(Integer size) { this.size = size; return this.typedThis; } public Children limit(Integer m) { this.size = m; return this.typedThis; } public Children limit(Integer m, Integer n) { this.from = m; this.size = n; return this.typedThis; } public Children index(boolean condition, String... indexNames) { if (condition) { if (ArrayUtils.isEmpty(indexNames)) { throw ExceptionUtils.eee("indexNames can not be empty"); } this.indexNames.addAll(Arrays.asList(indexNames)); } return this.typedThis; } public Children routing(boolean condition, String routing) { if (condition) { this.routing = routing; } return this.typedThis; } public Children preference(boolean condition, String preference) { if (condition) { if (StringUtils.isBlank(preference)) { return this.typedThis; } this.preference = preference; } return this.typedThis; } public Children setSearchBuilder(boolean condition, SearchRequest.Builder searchBuilder) { if (condition) { this.searchBuilder = searchBuilder; } return this.typedThis; } public Children mix(boolean condition, co.elastic.clients.elasticsearch._types.query_dsl.Query query) { return this.addParam(condition, query); } public Children bucketOrder(boolean condition, List<NamedValue<SortOrder>> bucketOrders) { if (condition) { this.bucketOrders = bucketOrders; } return this.typedThis; } public Children select(String... columns) { this.include = columns; return this.typedThis; } public Children select(Predicate<EntityFieldInfo> predicate) { return this.select(this.entityClass, predicate); } public Children select(Class<T> entityClass, Predicate<EntityFieldInfo> predicate) { this.entityClass = entityClass; List<String> list = EntityInfoHelper.getEntityInfo(this.getCheckEntityClass()).chooseSelect(predicate); this.include = (String[])list.toArray(this.include); return this.typedThis; } public Children minScore(Double score) { this.minScore = score; return this.typedThis; } public Children trackScores() { this.trackScores = Boolean.TRUE; return this.typedThis; } public Children notSelect(String... columns) { this.exclude = columns; return this.typedThis; } public Children set(boolean condition, String column, Object val) { if (condition) { EsUpdateParam esUpdateParam = new EsUpdateParam(); esUpdateParam.setField(column); esUpdateParam.setValue(val); this.updateParamList.add(esUpdateParam); } return this.typedThis; } public Children indexName(String... indexNames) { if (ArrayUtils.isEmpty(indexNames)) { throw new RuntimeException("indexNames can not be empty"); } else { this.indexNames.addAll(Arrays.asList(indexNames)); return this.typedThis; } } public Children settings(Integer shards, Integer replicas, Integer maxResultWindow) { this.settings = this.settings == null ? new IndexSettings.Builder() : this.settings; if (Objects.nonNull(shards)) { this.settings.numberOfShards(shards + ""); } if (Objects.nonNull(replicas)) { this.settings.numberOfReplicas(replicas + ""); } if (Objects.nonNull(maxResultWindow)) { this.settings.maxResultWindow(maxResultWindow); } return this.typedThis; } public Children settings(IndexSettings.Builder settings) { this.settings = settings; return this.typedThis; } public Children mapping(TypeMapping.Builder mapping) { this.mapping = mapping; return this.typedThis; } public Children mapping(String column, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat, Boolean fieldData, Double boost) { this.addEsIndexParam(column, fieldType, analyzer, searchAnalyzer, dateFormat, fieldData, boost); return this.typedThis; } public Children createAlias(String aliasName) { if (CollectionUtils.isEmpty(this.indexNames)) { throw new RuntimeException("indexNames can not be empty"); } else if (StringUtils.isEmpty(aliasName)) { throw new RuntimeException("aliasName can not be empty"); } else { this.aliasName = aliasName; return this.typedThis; } } public Children join(String column, String parentName, String childName) { EsIndexParam esIndexParam = new EsIndexParam(); esIndexParam.setFieldName(column); esIndexParam.setFieldType(FieldType.JOIN.getType()); this.esIndexParamList.add(esIndexParam); return this.typedThis; } protected abstract Children instance(); private void addBaseParam(Param param, EsQueryTypeEnum queryTypeEnum, String column, Object val, Float boost) { param.setId(UUID.randomUUID().toString()); Optional.ofNullable(this.parentId).ifPresent(param::setParentId); param.setPrevQueryType(this.prevQueryType); param.setQueryTypeEnum(queryTypeEnum); param.setVal(val); param.setColumn(column); param.setBoost(boost); param.setLevel(this.level); this.processJoin(param); this.paramQueue.add(param); } private void addBaseNested(Param param, EsQueryTypeEnum queryTypeEnum, Consumer<Children> consumer) { param.setId(UUID.randomUUID().toString()); Optional.ofNullable(this.parentId).ifPresent(param::setParentId); param.setQueryTypeEnum(queryTypeEnum); param.setLevel(this.level); param.setPrevQueryType(queryTypeEnum); this.processJoin(param); this.paramQueue.add(param); this.parentId = param.getId(); this.parentIdStack.push(this.parentId); ++this.level; consumer.accept(this.instance()); --this.level; if (!this.parentIdStack.isEmpty()) { this.parentIdStack.pop(); if (this.parentIdStack.isEmpty()) { this.parentId = null; } else { this.parentId = (String)this.parentIdStack.peek(); } } } private void processJoin(Param param) { if (!this.paramQueue.isEmpty()) { Param prev = (Param)this.paramQueue.peekLast(); if (EsQueryTypeEnum.OR.equals(prev.getQueryTypeEnum())) { param.setPrevQueryType(EsQueryTypeEnum.NESTED_OR); } else if (EsQueryTypeEnum.NOT.equals(prev.getQueryTypeEnum())) { param.setPrevQueryType(EsQueryTypeEnum.NESTED_NOT); } else if (EsQueryTypeEnum.FILTER.equals(prev.getPrevQueryType())) { param.setPrevQueryType(EsQueryTypeEnum.NESTED_FILTER); } } } private Children addParam(boolean condition, co.elastic.clients.elasticsearch._types.query_dsl.Query query) { if (condition) { Param param = new Param(); param.setQuery(query); this.addBaseParam(param, EsQueryTypeEnum.MIX, (String)null, (Object)null, (Float)null); } return this.typedThis; } private Children addParam(boolean condition, EsQueryTypeEnum queryTypeEnum, String column, Object val, Float boost) { if (condition) { Param param = new Param(); this.addBaseParam(param, queryTypeEnum, column, val, boost); } return this.typedThis; } private Children addParam(boolean condition, EsQueryTypeEnum queryTypeEnum, String column, Object val, Object var1, Object var2, Float boost) { if (condition) { Param param = new Param(); param.setExt1(var1); param.setExt2(var2); this.addBaseParam(param, queryTypeEnum, column, val, boost); } return this.typedThis; } private Children addParam(boolean condition, String column, Object var1, Object var2, Object var3, Object var4, Float boost) { if (condition) { Assert.notNull(var1, "from must not be null in between query"); Assert.notNull(var2, "to must not be null in between query"); Param param = new Param(); param.setExt1(var1); param.setExt2(var2); param.setExt3(var3); param.setExt4(var4); this.addBaseParam(param, EsQueryTypeEnum.BETWEEN, column, (Object)null, boost); } return this.typedThis; } private Children addParam(boolean condition, Object val, Operator operator, int minimumShouldMatch, Float boost, String... columns) { if (condition) { Param param = new Param(); param.setExt1(operator); param.setExt2(minimumShouldMatch); param.setColumns(columns); this.addBaseParam(param, EsQueryTypeEnum.MULTI_MATCH, (String)null, val, boost); } return this.typedThis; } private Children addNested(boolean condition, EsQueryTypeEnum queryTypeEnum, Consumer<Children> consumer) { if (condition) { Param param = new Param(); this.addBaseNested(param, queryTypeEnum, consumer); } return this.typedThis; } private Children addJoin(boolean condition, EsQueryTypeEnum queryTypeEnum, String path, Object ext, Consumer<Children> consumer) { if (condition) { Param param = new Param(); param.setColumn(path); param.setVal(ext); this.addBaseNested(param, queryTypeEnum, consumer); } return this.typedThis; } private Children addNested(boolean condition, String path, ChildScoreMode scoreMode, Consumer<Children> consumer) { if (condition) { Param param = new Param(); param.setColumn(path); param.setVal(scoreMode); this.addBaseNested(param, EsQueryTypeEnum.NESTED, consumer); } return this.typedThis; } private Children doIt(boolean condition, boolean enablePipeline, AggregationTypeEnum aggregationTypeEnum, String column) { if (condition) { AggregationParam aggregationParam = new AggregationParam(); aggregationParam.setEnablePipeline(enablePipeline); aggregationParam.setName(column); aggregationParam.setField(column); aggregationParam.setAggregationType(aggregationTypeEnum); this.aggregationParamList.add(aggregationParam); } return this.typedThis; } private void addEsIndexParam(String fieldName, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat, Boolean fieldData, Double boost) { EsIndexParam esIndexParam = new EsIndexParam(); esIndexParam.setFieldName(fieldName); esIndexParam.setFieldType(fieldType.getType()); esIndexParam.setAnalyzer(analyzer); esIndexParam.setSearchAnalyzer(searchAnalyzer); esIndexParam.setDateFormat(dateFormat); esIndexParam.setFieldData(fieldData); esIndexParam.setBoost(boost); this.esIndexParamList.add(esIndexParam); } } 哪个方法适用我上诉情况
10-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值