mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
聚合行数重构
This commit is contained in:
parent
52f947b477
commit
3d13c1af36
@ -7,5 +7,8 @@ package com.github.yulichang.wrapper.enums;
|
||||
*/
|
||||
public interface BaseFuncEnum {
|
||||
|
||||
/**
|
||||
* 获取sql 片段
|
||||
*/
|
||||
String getSql();
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package com.github.yulichang.wrapper.enums;
|
||||
|
||||
/**
|
||||
* 常用的sql函数枚举 默认实现
|
||||
* 可以自己实现 {@link BaseFuncEnum} 自定义函数
|
||||
* 可以自己实现接口 {@link BaseFuncEnum} 自定义函数
|
||||
* 目前支持一个占位符,不支持多个%s
|
||||
* <p>
|
||||
* 只例举几个通用的,其他函数 first() last() len() ucase() lcase() 等 或者数据库自定义函数请自行扩展
|
||||
* <p> mpj的初衷是只针对简单的连表查询,而非相对复杂的查询,
|
||||
* <p> 建议慎用,复杂的查询还是推荐写sql
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import com.github.yulichang.wrapper.enums.DefaultFuncEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.Predicate;
|
||||
@ -13,6 +14,7 @@ import java.util.function.Predicate;
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Query<Children> extends Serializable {
|
||||
|
||||
/**
|
||||
@ -47,15 +49,6 @@ public interface Query<Children> extends Serializable {
|
||||
<S> Children selectAs(SFunction<S, ?> column, String alias);
|
||||
|
||||
|
||||
default <S, X> Children selectFunc(BaseFuncEnum funcEnum, SFunction<S, ?> column) {
|
||||
return selectFunc(funcEnum, column, column);
|
||||
}
|
||||
|
||||
|
||||
default <S, X> Children selectFunc(BaseFuncEnum funcEnum, SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(funcEnum, column, LambdaUtils.getName(alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合函数查询
|
||||
*
|
||||
@ -65,6 +58,15 @@ public interface Query<Children> extends Serializable {
|
||||
*/
|
||||
<S> Children selectFunc(BaseFuncEnum funcEnum, SFunction<S, ?> column, String alias);
|
||||
|
||||
default <S> Children selectFunc(BaseFuncEnum funcEnum, SFunction<S, ?> column) {
|
||||
return selectFunc(funcEnum, column, column);
|
||||
}
|
||||
|
||||
|
||||
default <S, X> Children selectFunc(BaseFuncEnum funcEnum, SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(funcEnum, column, LambdaUtils.getName(alias));
|
||||
}
|
||||
|
||||
default <X> Children selectFunc(BaseFuncEnum funcEnum, Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(funcEnum, column, LambdaUtils.getName(alias));
|
||||
}
|
||||
@ -75,4 +77,120 @@ public interface Query<Children> extends Serializable {
|
||||
* select sql 片段
|
||||
*/
|
||||
String getSqlSelect();
|
||||
|
||||
/* 默认聚合函数扩展 */
|
||||
|
||||
/**
|
||||
* SUM()
|
||||
*/
|
||||
default <S> Children selectSum(SFunction<S, ?> column) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column);
|
||||
}
|
||||
|
||||
default <X> Children selectSum(Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column, alias);
|
||||
}
|
||||
|
||||
default Children selectSum(Object column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectSum(SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* COUNT()
|
||||
*/
|
||||
default <S> Children selectCount(SFunction<S, ?> column) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column);
|
||||
}
|
||||
|
||||
default <X> Children selectCount(Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column, alias);
|
||||
}
|
||||
|
||||
default Children selectCount(Object column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectCount(SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* MAX()
|
||||
*/
|
||||
default <S> Children selectMAX(SFunction<S, ?> column) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column);
|
||||
}
|
||||
|
||||
default <X> Children selectMAX(Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column, alias);
|
||||
}
|
||||
|
||||
default Children selectMAX(Object column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectMAX(SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* MIN()
|
||||
*/
|
||||
default <S> Children selectMIN(SFunction<S, ?> column) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column);
|
||||
}
|
||||
|
||||
default <X> Children selectMIN(Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column, alias);
|
||||
}
|
||||
|
||||
default Children selectMIN(Object column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectMIN(SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* MIN()
|
||||
*/
|
||||
default <S> Children selectAVG(SFunction<S, ?> column) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column);
|
||||
}
|
||||
|
||||
default <X> Children selectAVG(Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column, alias);
|
||||
}
|
||||
|
||||
default Children selectAVG(Object column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectAVG(SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* LEN()
|
||||
*/
|
||||
default <S> Children selectLEN(SFunction<S, ?> column) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column);
|
||||
}
|
||||
|
||||
default <X> Children selectLEN(Object column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column, alias);
|
||||
}
|
||||
|
||||
default Children selectLEN(Object column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectLEN(SFunction<S, ?> column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column, alias);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user