io.gitee.mingbaobaba.apijson.querycondition.query.conditions.ApiJsonQueryStringWrapper Maven / Gradle / Ivy
The newest version!
package io.gitee.mingbaobaba.apijson.querycondition.query.conditions;
import io.gitee.mingbaobaba.apijson.querycondition.query.exception.ConditionException;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;
/**
* 基于String形式构建查询参数
*
* @author yingsheng.ye
* @version 1.0.0
* @since 2023/6/19 21:40
*/
public class ApiJsonQueryStringWrapper extends AbstractQueryWrapper> implements ApiJsonQuery {
/**
* 添加条件
*
* @param condition 条件false忽略
* @param column 列
* @param keyword 连接条件
* @param val 值
* @return ApiJsonQueryStringWrapper
*/
@Override
protected ApiJsonQueryStringWrapper addCondition(boolean condition, String column, EnumKeyword keyword, Object val) {
if (condition) {
//条件
this.conditionHandle(new Condition(column, keyword, val));
}
return typedThis;
}
/**
* 添加聚合函数
*
* @param condition 条件false忽略
* @param column 列
* @param keyword 连接条件
* @param val 值
* @return ApiJsonQueryStringWrapper
*/
@Override
protected ApiJsonQueryStringWrapper addAggFunc(boolean condition, String column, EnumKeyword keyword, Object val) {
if (condition) {
this.aggFuncHandle(keyword, column, val);
}
return typedThis;
}
/**
* 添加分组函数
*
* @param condition 条件false忽略
* @param column 列
* @param keyword 连接条件
* @return ApiJsonQueryStringWrapper
*/
@Override
protected ApiJsonQueryStringWrapper addGroupFunc(boolean condition, String column, EnumKeyword keyword) {
if (condition && keyword.equals(EnumKeyword.GROUP)) {
this.groupFuncHandle(keyword, column);
}
return typedThis;
}
/**
* 添加排序
*
* @param condition 条件
* @param column 列
* @param keyword 关键字
* @param s 排序值 +升序 -降序
* @return ApiJsonQueryStringWrapper
*/
@Override
protected ApiJsonQueryStringWrapper addOrderByFunc(boolean condition, String column, EnumKeyword keyword, String s) {
if (condition && keyword.equals(EnumKeyword.ORDER_BY)) {
this.orderByFuncHandle(keyword, column + s);
}
return typedThis;
}
/**
* 实例化对象
*
* @return ApiJsonQueryStringWrapper
*/
@Override
protected ApiJsonQueryStringWrapper instance() {
return new ApiJsonQueryStringWrapper<>();
}
/**
* join关联
*
* @param tableName 关联表名
* @param column 列名
* @param consumer Consumer
* @param 泛型
* @return ApiJsonQueryStringWrapper
*/
public ApiJsonQueryStringWrapper join(Class tableName, String column,
String relColumn, Consumer> consumer) {
if (Objects.nonNull(joinOperation)) {
throw new ConditionException("join只支持单个配置");
}
final JoinWrapper instance = joinInstance();
instance.setColumn(column);
instance.setRelColumn(relColumn);
instance.setTableName(tableName);
if (null != consumer) {
consumer.accept(instance);
}
joinOperation = instance;
return typedThis;
}
/**
* join关联
*
* @param tableName 表名
* @param column 列名
* @param relColumn 关联列名
* @param 泛型
* @return ApiJsonQueryLambdaWrapper
*/
public ApiJsonQueryStringWrapper join(Class tableName, String column, String relColumn) {
return join(tableName, column, relColumn, null);
}
/**
* join实例
*
* @param 对象类型
* @return JoinWrapper
*/
@Override
protected JoinWrapper joinInstance() {
return new JoinWrapper<>();
}
/**
* select
*
* @param columns 查询列
* @return ApiJsonQueryStringWrapper
*/
@Override
public ApiJsonQueryStringWrapper select(String... columns) {
return select(true, columns);
}
/**
* select
*
* @param condition 条件false忽略
* @param columns 查询列
* @return ApiJsonQueryStringWrapper
*/
@Override
public ApiJsonQueryStringWrapper select(boolean condition, String... columns) {
if (condition) {
columnList.addAll(Arrays.asList(columns));
}
return typedThis;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy