All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dengchen2020.mybatis.base.ComplexMybatisRepository Maven / Gradle / Ivy

There is a newer version: 0.0.28
Show newest version
package io.github.dengchen2020.mybatis.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.dengchen2020.core.exception.call.ViewToastException;
import io.github.dengchen2020.core.support.model.PageParam;
import io.github.dengchen2020.core.support.model.SimplePage;
import org.apache.ibatis.session.ResultHandler;
import java.util.Collections;
import java.util.List;

/**
 * @author dengchen
 * @since 2024/6/22
 */
public interface ComplexMybatisRepository extends BaseMapper {

    /**
     * 统一的查querydsl查询接口
     *
     * @param param 查询参数
     * @return LambdaQueryWrapper
     */
    default LambdaQueryWrapper findAllQuery(P param) {
        throw new ViewToastException("该功能尚未实现");
    }

    /**
     * Querydsl分页条件查询
     *
     * @param param 分页参数
     * @return 分页后的数据
     */
    default SimplePage findAll(P param, OrderItem... o) {
        LambdaQueryWrapper query = findAllQuery(param);
        return pageList(query, param, o);
    }

    /**
     * Querydsl分页查询
     *
     * @param query LambdaQueryWrapper
     * @param param 分页参数
     * @param o     排序方式
     * @return SimplePage
     */
    default SimplePage pageList(LambdaQueryWrapper query, PageParam param, OrderItem... o) {
        Page page = new Page<>(param.getPage(), param.getSize());
        if (param.getSize() != null && param.getSize() == 0) {
            return new SimplePage<>(selectCount(query), Collections.emptyList());
        }
        if (o != null && o.length > 0) {
            page.orders().addAll(List.of(o));
        }
        if (!param.isSelectCount()) {
            page.setSearchCount(false);
            selectPage(page, query);
            return new SimplePage<>(null, page.getRecords());
        }
        selectPage(page, query);
        return new SimplePage<>(page.getTotal(), page.getRecords());
    }

    /**
     * 返回流读取器
     *
     * @param query LambdaQueryWrapper
     * @param param 查询参数
     */
    default void streamList(LambdaQueryWrapper query, PageParam param, ResultHandler handler) {
        selectList(query,handler);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy