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

com.github.wz2cool.dynamic.mybatis.mapper.SelectMinByDynamicQueryMapper Maven / Gradle / Ivy

There is a newer version: 3.2.32
Show newest version
package com.github.wz2cool.dynamic.mybatis.mapper;

import com.github.wz2cool.dynamic.DynamicQuery;
import com.github.wz2cool.dynamic.helper.CommonsHelper;
import com.github.wz2cool.dynamic.lambda.*;
import com.github.wz2cool.dynamic.mybatis.TypeHelper;
import com.github.wz2cool.dynamic.mybatis.QueryHelper;
import com.github.wz2cool.dynamic.mybatis.mapper.constant.MapperConstants;
import com.github.wz2cool.dynamic.mybatis.mapper.provider.DynamicQueryProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import tk.mybatis.mapper.annotation.RegisterMapper;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Optional;

/**
 * @author Frank
 */
@RegisterMapper
@SuppressWarnings("squid:S1214")
public interface SelectMinByDynamicQueryMapper {

    QueryHelper QUERY_HELPER = new QueryHelper();

    /**
     * Select min value of column by dynamic query.
     *
     * @param column       the column need get min value
     * @param dynamicQuery dynamic query
     * @return min value of column.
     */
    @SelectProvider(type = DynamicQueryProvider.class, method = "dynamicSQL")
    Object selectMinByDynamicQuery(
            @Param(MapperConstants.COLUMN) String column, @Param(MapperConstants.DYNAMIC_QUERY) DynamicQuery dynamicQuery);

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default  Object selectMinByDynamicQueryInternal(
            GetPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        String propertyName = CommonsHelper.getPropertyName(getPropertyFunction);
        Class entityClass = dynamicQuery.getEntityClass();
        String queryColumn = QUERY_HELPER.getQueryColumnByProperty(entityClass, propertyName);
        return selectMinByDynamicQuery(queryColumn, dynamicQuery);
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetBigDecimalPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getBigDecimal(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetBytePropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getByte(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetDatePropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getDate(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetDoublePropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getDouble(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetFloatPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getFloat(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetIntegerPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getInteger(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetLongPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getLong(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetShortPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getShort(result));
    }

    /**
     * Select min value of property by dynamic query.
     *
     * @param getPropertyFunction the property need get min value
     * @param dynamicQuery        dynamic query.
     * @return min value of property.
     */
    default Optional selectMinByDynamicQuery(
            GetStringPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
        return Optional.ofNullable(TypeHelper.getString(result));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy