|
|
|
package com.qs.serve.common.util;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.qs.serve.common.framework.mybatis.query.AnnotationQueryStorage;
|
|
|
|
import com.qs.serve.common.framework.mybatis.query.model.QueryFieldDataValue;
|
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成SQL条件包装对象
|
|
|
|
* @author YenHex
|
|
|
|
* @date 2022/2/28
|
|
|
|
**/
|
|
|
|
@UtilityClass
|
|
|
|
@Slf4j
|
|
|
|
public class WarpUtil extends AnnotationQueryStorage {
|
|
|
|
|
|
|
|
private static final String ORDER_PROP_NAME = "prop";
|
|
|
|
private static final String ORDER_TYPE_NAME = "order";
|
|
|
|
private static final String ORDER_DESC = "desc";
|
|
|
|
private static final String CREATE_TIME = "create_time";
|
|
|
|
|
|
|
|
private static final String START_TIME = "startTime";
|
|
|
|
private static final String END_TIME = "endTime";
|
|
|
|
|
|
|
|
public static <T> QueryWrapper<T> build(T query){
|
|
|
|
return build(query,false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> QueryWrapper<T> build(T query,Boolean orderAble){
|
|
|
|
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
|
|
|
List<QueryFieldDataValue> dataValues = loadQueryFieldDataValues(query);
|
|
|
|
assert dataValues != null;
|
|
|
|
initWrap(dataValues,queryWrapper);
|
|
|
|
initBetweenTime(queryWrapper);
|
|
|
|
if(orderAble){
|
|
|
|
String columnsString = ServletUtils.getParameter(ORDER_PROP_NAME);
|
|
|
|
String orderType = ServletUtils.getParameter(ORDER_TYPE_NAME);
|
|
|
|
if(StringUtils.isNotEmpty(columnsString)){
|
|
|
|
String[] columns = columnsString.split(",");
|
|
|
|
// if(orderType.equals(ORDER_DESC)){
|
|
|
|
// queryWrapper.orderByDesc(columns);
|
|
|
|
// }else {
|
|
|
|
// queryWrapper.orderByAsc(columns);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return queryWrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void initBetweenTime(QueryWrapper<?> queryWrapper){
|
|
|
|
String startTime = ServletUtils.getParameter(START_TIME);
|
|
|
|
String endTime = ServletUtils.getParameter(END_TIME);
|
|
|
|
if(!StringUtils.hasEmpty(startTime,endTime)){
|
|
|
|
queryWrapper.ge(CREATE_TIME,startTime);
|
|
|
|
queryWrapper.le(CREATE_TIME,endTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|