Bootstrap

mybatisPlus指定字段批量执行

saveOrUpdateBatchByColumn(memberCompanyByBrainList, item -> new LambdaQueryWrapper<MmsMemberCompany>()
                        .eq(MmsMemberCompany::getUnifiedSocialCreditCode, item.getUnifiedSocialCreditCode())
                        .eq(MmsMemberCompany::getSite, item.getSite())
                );
public  boolean saveOrUpdateBatchByColumn(Collection<MmsMemberCompany> entityList, Function<MmsMemberCompany, LambdaQueryWrapper> function) {
        return this.saveOrUpdateBatch(this.entityClass, this.mapperClass, LogFactory.getLog(getClass()), entityList, 100, (sqlSession, entity) -> {
            Map<String, Object> param = Maps.newHashMap();
            param.put(com.baomidou.mybatisplus.core.toolkit.Constants.ENTITY, entity);
            param.put(com.baomidou.mybatisplus.core.toolkit.Constants.WRAPPER, function.apply(entity));
            return CollectionUtils.isEmpty(sqlSession.selectList(this.getSqlStatement(SqlMethod.SELECT_MAPS), param));
        }, (sqlSession, entity) -> {
            Map<String, Object> param = Maps.newHashMap();
            param.put(com.baomidou.mybatisplus.core.toolkit.Constants.ENTITY, entity);
            param.put(com.baomidou.mybatisplus.core.toolkit.Constants.WRAPPER, function.apply(entity));
            sqlSession.update(this.getSqlStatement(SqlMethod.UPDATE), param);
        });
    }

    public static <E> boolean saveOrUpdateBatch(Class<?> entityClass, Class<?> mapper, Log log, Collection<MmsMemberCompany> list, int batchSize, BiPredicate<SqlSession,MmsMemberCompany> predicate, BiConsumer<SqlSession, MmsMemberCompany> consumer) {
        String sqlStatement = SqlHelper.getSqlStatement(mapper, SqlMethod.INSERT_ONE);
        return SqlHelper.executeBatch(entityClass, log, list, batchSize, (sqlSession, entity) -> {
            if (predicate.test(sqlSession, entity)) {
                sqlSession.insert(sqlStatement, entity);
            } else {
                consumer.accept(sqlSession, entity);
            }
        });
    }
;