diff --git a/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java b/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java index e9ee47b..469401e 100644 --- a/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java @@ -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 getTableNamesByDateRange(Date beginDate, Date endDate) { List 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; } diff --git a/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml b/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml index f158e13..9aab525 100644 --- a/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml +++ b/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml @@ -52,8 +52,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and vibration_temp = #{vibrationTemp} and collectTime = #{collectTime} and recodeTime = #{recodeTime} - - AND recodeTime BETWEEN #{beginRecordTime} AND #{endRecordTime} + + AND recodeTime BETWEEN #{params.beginRecordTime} AND #{params.endRecordTime}