diff --git a/pom.xml b/pom.xml index b898501..dde4465 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,28 @@ + + org.projectlombok + lombok + true + + + + + org.mapstruct + mapstruct + 1.5.5.Final + + + + + org.mapstruct + mapstruct-processor + 1.5.5.Final + provided + + + com.google.guava guava diff --git a/src/main/java/com/biutag/supervision/repository/base/BaseDAO.java b/src/main/java/com/biutag/supervision/repository/base/BaseDAO.java index c750b96..53d4f0a 100644 --- a/src/main/java/com/biutag/supervision/repository/base/BaseDAO.java +++ b/src/main/java/com/biutag/supervision/repository/base/BaseDAO.java @@ -1,11 +1,14 @@ package com.biutag.supervision.repository.base; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.google.common.collect.Lists; import org.springframework.dao.DuplicateKeyException; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -20,6 +23,7 @@ public abstract class BaseDAO { /** * 整合单个和批量 + * * @param single * @param batch * @param wrapper @@ -48,11 +52,36 @@ public abstract class BaseDAO { } } + public void setBatchLikeQuery(String single, Collection batch, LambdaQueryWrapper qw, SFunction column) { + // 单值 like + if (StrUtil.isNotBlank(single)) { + qw.like(column, single); + return; + } + + // 多值 like(OR) + if (CollectionUtil.isNotEmpty(batch)) { + qw.and(w -> { + boolean first = true; + for (String val : batch) { + if (StrUtil.isBlank(val)) continue; + if (first) { + w.like(column, val); + first = false; + } else { + w.or().like(column, val); + } + } + }); + } + } + /** * 批量添加 20一组 - * @return + * * @param + * @return */ protected void innerBatchInsert(HBaseMapper mapper, List entities, String message) { try {