|
|
|
@ -3,6 +3,7 @@ package com.os.ems.record.service.impl;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import com.os.common.exception.ServiceException;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.os.ems.record.mapper.RecordIotenvInstantMapper;
|
|
|
|
@ -136,16 +137,13 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
|
*/
|
|
|
|
|
private List<String> getTableNamesByDateRange(Date beginDate, Date endDate) {
|
|
|
|
|
List<String> tableNames = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 如果开始日期晚于结束日期,则返回空列表
|
|
|
|
|
if (beginDate.after(endDate)) {
|
|
|
|
|
return tableNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置日期格式
|
|
|
|
|
SimpleDateFormat tableFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 获取开始日期和结束日期(不含时间部分)
|
|
|
|
|
String beginDateStr = dateFormat.format(beginDate);
|
|
|
|
@ -153,14 +151,12 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
|
|
|
|
|
|
Date currentDate = dateFormat.parse(beginDateStr);
|
|
|
|
|
Date endDateOnly = dateFormat.parse(endDateStr);
|
|
|
|
|
|
|
|
|
|
// 循环添加每一天对应的表名
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
while (!currentDate.after(endDateOnly)) {
|
|
|
|
|
String tableSuffix = tableFormat.format(currentDate);
|
|
|
|
|
String tableName = "record_iotenv_instant_" + tableSuffix;
|
|
|
|
|
tableNames.add(tableName);
|
|
|
|
|
|
|
|
|
|
// 日期加1天
|
|
|
|
|
calendar.setTime(currentDate);
|
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
@ -168,13 +164,12 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
|
}
|
|
|
|
|
for (String tableName : tableNames){
|
|
|
|
|
if (!isTableExists(tableName)){
|
|
|
|
|
throw new SecurityException(tableName + "分表不存在");
|
|
|
|
|
throw new ServiceException(tableName + "分表不存在");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tableNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|