package com.moral.util;
|
|
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList;
|
import com.moral.constant.SeparateTableType;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @ClassName MybatisPLUSUtils
|
* @Description TODO
|
* @Author 陈凯裕
|
* @Date 2021/9/23 10:45
|
* @Version TODO
|
**/
|
public class MybatisPLUSUtils {
|
|
/**
|
* @Description: 根据wrapper查询条件获取分表表名
|
* @Param: [wrapper]
|
* @return: java.util.List<java.lang.String>
|
* @Author: 陈凯裕
|
* @Date: 2021/9/23
|
*/
|
public static List<String> getTableNamesByWrapper(Date startDate, Date endDate,SeparateTableType type) {
|
|
List<String> tableNames = new ArrayList<>();
|
|
if (type == SeparateTableType.MONTH) {
|
List<String> months = DateUtils.getAllMonth(startDate, endDate);
|
for (String month : months) {
|
month = month.replaceAll("-", "");
|
tableNames.add("_" + month);
|
}
|
} else if (type == SeparateTableType.YEAR) {
|
List<String> years = DateUtils.getAllYear(startDate, endDate);
|
for (String year : years) {
|
tableNames.add("_" + year);
|
}
|
} else {
|
List<String> days = DateUtils.getAllDays(startDate, endDate);
|
for (String day : days) {
|
day = day.replaceAll("-", "");
|
tableNames.add("_"+day);
|
}
|
}
|
return tableNames;
|
}
|
|
}
|