com.github.wz2cool.dynamic.mybatis.mapper.SelectAvgByDynamicQueryMapper Maven / Gradle / Ivy
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.QueryHelper;
import com.github.wz2cool.dynamic.mybatis.TypeHelper;
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.Optional;
/**
* @author Frank
**/
@RegisterMapper
public interface SelectAvgByDynamicQueryMapper {
QueryHelper QUERY_HELPER = new QueryHelper();
/**
* Select avg value of column by dynamic query.
*
* @param column the column need get avg value
* @param dynamicQuery dynamic query
* @return max value of column.
*/
@SelectProvider(type = DynamicQueryProvider.class, method = "dynamicSQL")
Object selectAvgByDynamicQuery(
@Param(MapperConstants.COLUMN) String column, @Param(MapperConstants.DYNAMIC_QUERY) DynamicQuery dynamicQuery);
/**
* Select sum value of property by dynamic query.
*
* @param getPropertyFunction the property need get sum value
* @param dynamicQuery dynamic query.
* @return sum value of property.
*/
default Optional selectAvgByDynamicQueryInternal(
GetPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
String propertyName = CommonsHelper.getPropertyName(getPropertyFunction);
Class entityClass = dynamicQuery.getEntityClass();
String queryColumn = QUERY_HELPER.getQueryColumnByProperty(entityClass, propertyName);
Object result = selectAvgByDynamicQuery(queryColumn, dynamicQuery);
return Optional.ofNullable(TypeHelper.getBigDecimal(result));
}
/**
* Select sum value of property by dynamic query.
*
* @param getPropertyFunction the property need get sum value
* @param dynamicQuery dynamic query.
* @return sum value of property.
*/
default Optional selectAvgByDynamicQuery(
GetBigDecimalPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
/**
* Select sum value of property by dynamic query.
*
* @param getPropertyFunction the property need get sum value
* @param dynamicQuery dynamic query.
* @return sum value of property.
*/
default Optional selectAvgByDynamicQuery(
GetBytePropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
/**
* Select sum value of property by dynamic query.
*
* @param getPropertyFunction the property need get sum value
* @param dynamicQuery dynamic query.
* @return sum value of property.
*/
default Optional selectAvgByDynamicQuery(
GetDoublePropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
/**
* Select sum value of property by dynamic query.
*
* @param getPropertyFunction the property need get sum value
* @param dynamicQuery dynamic query.
* @return sum value of property.
*/
default Optional selectAvgByDynamicQuery(
GetFloatPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
/**
* Select sum value of property by dynamic query.
*
* @param getPropertyFunction the property need get sum value
* @param dynamicQuery dynamic query.
* @return sum value of property.
*/
default Optional selectAvgByDynamicQuery(
GetIntegerPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
/**
* Select avg value of property by dynamic query.
*
* @param getPropertyFunction the property need get avg value
* @param dynamicQuery dynamic query.
* @return avg value of property.
*/
default Optional selectAvgByDynamicQuery(
GetLongPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
/**
* Select avg value of property by dynamic query.
*
* @param getPropertyFunction the property need get avg value
* @param dynamicQuery dynamic query.
* @return avg value of property.
*/
default Optional selectAvgByDynamicQuery(
GetShortPropertyFunction getPropertyFunction, DynamicQuery dynamicQuery) {
return selectAvgByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy