|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.os.ems.record.service.impl;
|
|
|
|
package com.os.ems.record.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
@ -47,12 +48,10 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
// return recordIotenvInstantMapper.selectRecordIotenvInstantList(recordIotenvInstant);
|
|
|
|
// return recordIotenvInstantMapper.selectRecordIotenvInstantList(recordIotenvInstant);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant) {
|
|
|
|
public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant) throws ParseException {
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> params = recordIotenvInstant.getParams();
|
|
|
|
Map<String, Object> params = recordIotenvInstant.getParams();
|
|
|
|
// 检查是否有时间范围参数
|
|
|
|
// 检查是否有时间范围参数
|
|
|
|
if (params != null && params.containsKey("beginRecordTime") && params.containsKey("endRecordTime")) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 获取开始和结束时间
|
|
|
|
// 获取开始和结束时间
|
|
|
|
String beginTimeStr = params.get("beginRecordTime").toString();
|
|
|
|
String beginTimeStr = params.get("beginRecordTime").toString();
|
|
|
|
String endTimeStr = params.get("endRecordTime").toString();
|
|
|
|
String endTimeStr = params.get("endRecordTime").toString();
|
|
|
@ -67,16 +66,8 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
if (tableNames.isEmpty()) {
|
|
|
|
if (tableNames.isEmpty()) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 执行分表查询
|
|
|
|
// 执行分表查询
|
|
|
|
return recordIotenvInstantMapper.selectRecordIotenvInstantListFromTables(tableNames, recordIotenvInstant);
|
|
|
|
return recordIotenvInstantMapper.selectRecordIotenvInstantListFromTables(tableNames, recordIotenvInstant);
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果没有时间范围或发生异常,则使用原始查询方法
|
|
|
|
|
|
|
|
return recordIotenvInstantMapper.selectRecordIotenvInstantList(recordIotenvInstant);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -135,7 +126,7 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
* @param endDate 结束日期
|
|
|
|
* @param endDate 结束日期
|
|
|
|
* @return 表名列表
|
|
|
|
* @return 表名列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private List<String> getTableNamesByDateRange(Date beginDate, Date endDate) {
|
|
|
|
private List<String> getTableNamesByDateRange(Date beginDate, Date endDate) throws ParseException {
|
|
|
|
List<String> tableNames = new ArrayList<>();
|
|
|
|
List<String> tableNames = new ArrayList<>();
|
|
|
|
// 如果开始日期晚于结束日期,则返回空列表
|
|
|
|
// 如果开始日期晚于结束日期,则返回空列表
|
|
|
|
if (beginDate.after(endDate)) {
|
|
|
|
if (beginDate.after(endDate)) {
|
|
|
@ -144,7 +135,7 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
// 设置日期格式
|
|
|
|
// 设置日期格式
|
|
|
|
SimpleDateFormat tableFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
SimpleDateFormat tableFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 获取开始日期和结束日期(不含时间部分)
|
|
|
|
// 获取开始日期和结束日期(不含时间部分)
|
|
|
|
String beginDateStr = dateFormat.format(beginDate);
|
|
|
|
String beginDateStr = dateFormat.format(beginDate);
|
|
|
|
String endDateStr = dateFormat.format(endDate);
|
|
|
|
String endDateStr = dateFormat.format(endDate);
|
|
|
@ -164,12 +155,10 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (String tableName : tableNames){
|
|
|
|
for (String tableName : tableNames){
|
|
|
|
if (!isTableExists(tableName)){
|
|
|
|
if (!isTableExists(tableName)){
|
|
|
|
throw new ServiceException(tableName + "分表不存在");
|
|
|
|
throw new ServiceException(tableName + "分表不存在,未记录数据");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tableNames;
|
|
|
|
return tableNames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -181,14 +170,11 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
* @return 是否存在
|
|
|
|
* @return 是否存在
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean isTableExists(String tableName) {
|
|
|
|
private boolean isTableExists(String tableName) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 查询数据库中是否存在该表
|
|
|
|
// 查询数据库中是否存在该表
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("tableName", tableName);
|
|
|
|
params.put("tableName", tableName);
|
|
|
|
Integer count = recordIotenvInstantMapper.checkTableExists(params);
|
|
|
|
Integer count = recordIotenvInstantMapper.checkTableExists(params);
|
|
|
|
return count != null && count > 0;
|
|
|
|
return count != null && count > 0;
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|