feat(record): 第一版分表查询代码(物联网数据记录)
-比如说我想查询 2025-04-23 12:11:12 到 2024-04-25 17:42:26 的数据,就需要关联 20240423、0424、0425 这几张表,就是根据搜索条件中的开始结束时间去关联需要查询的表取数据 -使用foreach遍历表名,暂时测试 UNION ALL能否分页boardTest
parent
31cb429756
commit
fb766cc673
@ -0,0 +1,104 @@
|
||||
package com.os.ems.record.controller;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.os.common.annotation.Log;
|
||||
import com.os.common.core.controller.BaseController;
|
||||
import com.os.common.core.domain.AjaxResult;
|
||||
import com.os.common.enums.BusinessType;
|
||||
import com.os.ems.record.domain.RecordIotenvInstant;
|
||||
import com.os.ems.record.service.IRecordIotenvInstantService;
|
||||
import com.os.common.utils.poi.ExcelUtil;
|
||||
import com.os.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 物联网数据Controller
|
||||
*
|
||||
* @author zch
|
||||
* @date 2025-04-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ems/record/recordIotenvInstant")
|
||||
public class RecordIotenvInstantController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRecordIotenvInstantService recordIotenvInstantService;
|
||||
|
||||
/**
|
||||
* 查询物联网数据列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ems/record:recordIotenvInstant:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(RecordIotenvInstant recordIotenvInstant)
|
||||
{
|
||||
startPage();
|
||||
|
||||
List<RecordIotenvInstant> list = recordIotenvInstantService.selectRecordIotenvInstantList(recordIotenvInstant);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出物联网数据列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ems/record:recordIotenvInstant:export')")
|
||||
@Log(title = "物联网数据", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RecordIotenvInstant recordIotenvInstant)
|
||||
{
|
||||
List<RecordIotenvInstant> list = recordIotenvInstantService.selectRecordIotenvInstantList(recordIotenvInstant);
|
||||
ExcelUtil<RecordIotenvInstant> util = new ExcelUtil<RecordIotenvInstant>(RecordIotenvInstant.class);
|
||||
util.exportExcel(response, list, "物联网数据数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物联网数据详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ems/record:recordIotenvInstant:query')")
|
||||
@GetMapping(value = "/{objid}")
|
||||
public AjaxResult getInfo(@PathVariable("objid") Long objid)
|
||||
{
|
||||
return success(recordIotenvInstantService.selectRecordIotenvInstantByObjid(objid));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增物联网数据
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ems/record:recordIotenvInstant:add')")
|
||||
@Log(title = "物联网数据", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RecordIotenvInstant recordIotenvInstant)
|
||||
{
|
||||
recordIotenvInstant.setCreateBy(getUsername());
|
||||
return toAjax(recordIotenvInstantService.insertRecordIotenvInstant(recordIotenvInstant));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改物联网数据
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ems/record:recordIotenvInstant:edit')")
|
||||
@Log(title = "物联网数据", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RecordIotenvInstant recordIotenvInstant)
|
||||
{
|
||||
recordIotenvInstant.setUpdateBy(getUsername());
|
||||
return toAjax(recordIotenvInstantService.updateRecordIotenvInstant(recordIotenvInstant));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物联网数据
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ems/record:recordIotenvInstant:remove')")
|
||||
@Log(title = "物联网数据", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{objids}")
|
||||
public AjaxResult remove(@PathVariable Long[] objids)
|
||||
{
|
||||
return toAjax(recordIotenvInstantService.deleteRecordIotenvInstantByObjids(objids));
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
package com.os.ems.record.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.os.common.annotation.Excel;
|
||||
import com.os.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 物联网数据对象 record_iotenv_instant
|
||||
*
|
||||
* @author zch
|
||||
* @date 2025-04-28
|
||||
*/
|
||||
public class RecordIotenvInstant extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键标识 */
|
||||
private Long objid;
|
||||
|
||||
/** 计量设备编号 */
|
||||
@Excel(name = "计量设备编号")
|
||||
private String monitorId;
|
||||
|
||||
/** 温度 */
|
||||
@Excel(name = "温度")
|
||||
private BigDecimal temperature;
|
||||
|
||||
/** 湿度 */
|
||||
@Excel(name = "湿度")
|
||||
private BigDecimal humidity;
|
||||
|
||||
/** 照度 */
|
||||
@Excel(name = "照度")
|
||||
private BigDecimal illuminance;
|
||||
|
||||
/** 噪声 */
|
||||
@Excel(name = "噪声")
|
||||
private BigDecimal noise;
|
||||
|
||||
/** 硫化氢浓度 */
|
||||
@Excel(name = "硫化氢浓度")
|
||||
private BigDecimal concentration;
|
||||
|
||||
/** 振动-速度(mm/s) */
|
||||
@Excel(name = "振动-速度(mm/s)")
|
||||
private BigDecimal vibrationSpeed;
|
||||
|
||||
/** 振动-位移(um) */
|
||||
@Excel(name = "振动-位移(um)")
|
||||
private BigDecimal vibrationDisplacement;
|
||||
|
||||
/** 振动-加速度(g) */
|
||||
@Excel(name = "振动-加速度(g)")
|
||||
private BigDecimal vibrationAcceleration;
|
||||
|
||||
/** 振动-温度(℃) */
|
||||
@Excel(name = "振动-温度(℃)")
|
||||
private BigDecimal vibrationTemp;
|
||||
|
||||
/** 采集时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "采集时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date collectTime;
|
||||
|
||||
/** 记录时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "记录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date recodeTime;
|
||||
|
||||
public void setObjid(Long objid)
|
||||
{
|
||||
this.objid = objid;
|
||||
}
|
||||
|
||||
public Long getObjid()
|
||||
{
|
||||
return objid;
|
||||
}
|
||||
public void setMonitorId(String monitorId)
|
||||
{
|
||||
this.monitorId = monitorId;
|
||||
}
|
||||
|
||||
public String getMonitorId()
|
||||
{
|
||||
return monitorId;
|
||||
}
|
||||
public void setTemperature(BigDecimal temperature)
|
||||
{
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public BigDecimal getTemperature()
|
||||
{
|
||||
return temperature;
|
||||
}
|
||||
public void setHumidity(BigDecimal humidity)
|
||||
{
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public BigDecimal getHumidity()
|
||||
{
|
||||
return humidity;
|
||||
}
|
||||
public void setIlluminance(BigDecimal illuminance)
|
||||
{
|
||||
this.illuminance = illuminance;
|
||||
}
|
||||
|
||||
public BigDecimal getIlluminance()
|
||||
{
|
||||
return illuminance;
|
||||
}
|
||||
public void setNoise(BigDecimal noise)
|
||||
{
|
||||
this.noise = noise;
|
||||
}
|
||||
|
||||
public BigDecimal getNoise()
|
||||
{
|
||||
return noise;
|
||||
}
|
||||
public void setConcentration(BigDecimal concentration)
|
||||
{
|
||||
this.concentration = concentration;
|
||||
}
|
||||
|
||||
public BigDecimal getConcentration()
|
||||
{
|
||||
return concentration;
|
||||
}
|
||||
public void setVibrationSpeed(BigDecimal vibrationSpeed)
|
||||
{
|
||||
this.vibrationSpeed = vibrationSpeed;
|
||||
}
|
||||
|
||||
public BigDecimal getVibrationSpeed()
|
||||
{
|
||||
return vibrationSpeed;
|
||||
}
|
||||
public void setVibrationDisplacement(BigDecimal vibrationDisplacement)
|
||||
{
|
||||
this.vibrationDisplacement = vibrationDisplacement;
|
||||
}
|
||||
|
||||
public BigDecimal getVibrationDisplacement()
|
||||
{
|
||||
return vibrationDisplacement;
|
||||
}
|
||||
public void setVibrationAcceleration(BigDecimal vibrationAcceleration)
|
||||
{
|
||||
this.vibrationAcceleration = vibrationAcceleration;
|
||||
}
|
||||
|
||||
public BigDecimal getVibrationAcceleration()
|
||||
{
|
||||
return vibrationAcceleration;
|
||||
}
|
||||
public void setVibrationTemp(BigDecimal vibrationTemp)
|
||||
{
|
||||
this.vibrationTemp = vibrationTemp;
|
||||
}
|
||||
|
||||
public BigDecimal getVibrationTemp()
|
||||
{
|
||||
return vibrationTemp;
|
||||
}
|
||||
public void setCollectTime(Date collectTime)
|
||||
{
|
||||
this.collectTime = collectTime;
|
||||
}
|
||||
|
||||
public Date getCollectTime()
|
||||
{
|
||||
return collectTime;
|
||||
}
|
||||
public void setRecodeTime(Date recodeTime)
|
||||
{
|
||||
this.recodeTime = recodeTime;
|
||||
}
|
||||
|
||||
public Date getRecodeTime()
|
||||
{
|
||||
return recodeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("objid", getObjid())
|
||||
.append("monitorId", getMonitorId())
|
||||
.append("temperature", getTemperature())
|
||||
.append("humidity", getHumidity())
|
||||
.append("illuminance", getIlluminance())
|
||||
.append("noise", getNoise())
|
||||
.append("concentration", getConcentration())
|
||||
.append("vibrationSpeed", getVibrationSpeed())
|
||||
.append("vibrationDisplacement", getVibrationDisplacement())
|
||||
.append("vibrationAcceleration", getVibrationAcceleration())
|
||||
.append("vibrationTemp", getVibrationTemp())
|
||||
.append("collectTime", getCollectTime())
|
||||
.append("recodeTime", getRecodeTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.os.ems.record.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.os.ems.record.domain.RecordIotenvInstant;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
|
||||
/**
|
||||
* 物联网数据Mapper接口
|
||||
*
|
||||
* @author zch
|
||||
* @date 2025-04-28
|
||||
*/
|
||||
public interface RecordIotenvInstantMapper
|
||||
{
|
||||
/**
|
||||
* 查询物联网数据
|
||||
*
|
||||
* @param objid 物联网数据主键
|
||||
* @return 物联网数据
|
||||
*/
|
||||
public RecordIotenvInstant selectRecordIotenvInstantByObjid(Long objid);
|
||||
|
||||
/**
|
||||
* 查询物联网数据列表
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 物联网数据集合
|
||||
*/
|
||||
public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
/**
|
||||
* 新增物联网数据
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRecordIotenvInstant(RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
/**
|
||||
* 修改物联网数据
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRecordIotenvInstant(RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
/**
|
||||
* 删除物联网数据
|
||||
*
|
||||
* @param objid 物联网数据主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordIotenvInstantByObjid(Long objid);
|
||||
|
||||
/**
|
||||
* 批量删除物联网数据
|
||||
*
|
||||
* @param objids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordIotenvInstantByObjids(Long[] objids);
|
||||
|
||||
|
||||
/**
|
||||
* 根据指定表名查询物联网数据列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param recordIotenvInstant 查询条件
|
||||
* @return 物联网数据集合
|
||||
*/
|
||||
// List<RecordIotenvInstant> selectRecordIotenvInstantListFromTable(@Param("tableName") String tableName,
|
||||
// @Param("record") RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
/**
|
||||
* 使用 UNION ALL 从多个表查询物联网数据列表
|
||||
*
|
||||
* @param tableNames 表名列表
|
||||
* @param recordIotenvInstant 查询条件
|
||||
* @return 物联网数据集合
|
||||
*/
|
||||
List<RecordIotenvInstant> selectRecordIotenvInstantListFromTables(@Param("tableNames") List<String> tableNames,
|
||||
@Param("record") RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
Integer checkTableExists(Map<String, Object> params);
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.os.ems.record.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.os.ems.record.domain.RecordIotenvInstant;
|
||||
|
||||
/**
|
||||
* 物联网数据Service接口
|
||||
*
|
||||
* @author zch
|
||||
* @date 2025-04-28
|
||||
*/
|
||||
public interface IRecordIotenvInstantService
|
||||
{
|
||||
/**
|
||||
* 查询物联网数据
|
||||
*
|
||||
* @param objid 物联网数据主键
|
||||
* @return 物联网数据
|
||||
*/
|
||||
public RecordIotenvInstant selectRecordIotenvInstantByObjid(Long objid);
|
||||
|
||||
/**
|
||||
* 查询物联网数据列表
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 物联网数据集合
|
||||
*/
|
||||
public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
|
||||
/**
|
||||
* 新增物联网数据
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRecordIotenvInstant(RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
/**
|
||||
* 修改物联网数据
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRecordIotenvInstant(RecordIotenvInstant recordIotenvInstant);
|
||||
|
||||
/**
|
||||
* 批量删除物联网数据
|
||||
*
|
||||
* @param objids 需要删除的物联网数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordIotenvInstantByObjids(Long[] objids);
|
||||
|
||||
/**
|
||||
* 删除物联网数据信息
|
||||
*
|
||||
* @param objid 物联网数据主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordIotenvInstantByObjid(Long objid);
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
package com.os.ems.record.service.impl;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.os.ems.record.mapper.RecordIotenvInstantMapper;
|
||||
import com.os.ems.record.domain.RecordIotenvInstant;
|
||||
import com.os.ems.record.service.IRecordIotenvInstantService;
|
||||
|
||||
/**
|
||||
* 物联网数据Service业务层处理
|
||||
*
|
||||
* @author zch
|
||||
* @date 2025-04-28
|
||||
*/
|
||||
@Service
|
||||
public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantService
|
||||
{
|
||||
@Autowired
|
||||
private RecordIotenvInstantMapper recordIotenvInstantMapper;
|
||||
|
||||
/**
|
||||
* 查询物联网数据
|
||||
*
|
||||
* @param objid 物联网数据主键
|
||||
* @return 物联网数据
|
||||
*/
|
||||
@Override
|
||||
public RecordIotenvInstant selectRecordIotenvInstantByObjid(Long objid)
|
||||
{
|
||||
return recordIotenvInstantMapper.selectRecordIotenvInstantByObjid(objid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询物联网数据列表
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 物联网数据
|
||||
*/
|
||||
// @Override
|
||||
// public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant)
|
||||
// {
|
||||
// Map<String, Object> params = recordIotenvInstant.getParams();
|
||||
// return recordIotenvInstantMapper.selectRecordIotenvInstantList(recordIotenvInstant);
|
||||
// }
|
||||
@Override
|
||||
public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant) {
|
||||
|
||||
Map<String, Object> params = recordIotenvInstant.getParams();
|
||||
// 检查是否有时间范围参数
|
||||
if (params != null && params.containsKey("beginRecordTime") && params.containsKey("endRecordTime")) {
|
||||
try {
|
||||
// 获取开始和结束时间
|
||||
String beginTimeStr = params.get("beginRecordTime").toString();
|
||||
String endTimeStr = params.get("endRecordTime").toString();
|
||||
|
||||
// 解析日期
|
||||
SimpleDateFormat fullFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date beginDate = fullFormat.parse(beginTimeStr);
|
||||
Date endDate = fullFormat.parse(endTimeStr);
|
||||
|
||||
// 获取需要查询的表名列表
|
||||
List<String> tableNames = getTableNamesByDateRange(beginDate, endDate);
|
||||
if (tableNames.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 执行分表查询
|
||||
return recordIotenvInstantMapper.selectRecordIotenvInstantListFromTables(tableNames, recordIotenvInstant);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有时间范围或发生异常,则使用原始查询方法
|
||||
return recordIotenvInstantMapper.selectRecordIotenvInstantList(recordIotenvInstant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增物联网数据
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRecordIotenvInstant(RecordIotenvInstant recordIotenvInstant)
|
||||
{
|
||||
return recordIotenvInstantMapper.insertRecordIotenvInstant(recordIotenvInstant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改物联网数据
|
||||
*
|
||||
* @param recordIotenvInstant 物联网数据
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRecordIotenvInstant(RecordIotenvInstant recordIotenvInstant)
|
||||
{
|
||||
return recordIotenvInstantMapper.updateRecordIotenvInstant(recordIotenvInstant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除物联网数据
|
||||
*
|
||||
* @param objids 需要删除的物联网数据主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRecordIotenvInstantByObjids(Long[] objids)
|
||||
{
|
||||
return recordIotenvInstantMapper.deleteRecordIotenvInstantByObjids(objids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物联网数据信息
|
||||
*
|
||||
* @param objid 物联网数据主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRecordIotenvInstantByObjid(Long objid)
|
||||
{
|
||||
return recordIotenvInstantMapper.deleteRecordIotenvInstantByObjid(objid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据日期范围获取需要查询的表名列表
|
||||
*
|
||||
* @param beginDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @return 表名列表
|
||||
*/
|
||||
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);
|
||||
String endDateStr = dateFormat.format(endDate);
|
||||
|
||||
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);
|
||||
currentDate = calendar.getTime();
|
||||
}
|
||||
for (String tableName : tableNames){
|
||||
if (!isTableExists(tableName)){
|
||||
throw new SecurityException(tableName + "分表不存在");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return tableNames;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证表是否存在
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return 是否存在
|
||||
*/
|
||||
private boolean isTableExists(String tableName) {
|
||||
try {
|
||||
// 查询数据库中是否存在该表
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("tableName", tableName);
|
||||
Integer count = recordIotenvInstantMapper.checkTableExists(params);
|
||||
return count != null && count > 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.os.ems.record.mapper.RecordIotenvInstantMapper">
|
||||
|
||||
<resultMap type="RecordIotenvInstant" id="RecordIotenvInstantResult">
|
||||
<result property="objid" column="objid" />
|
||||
<result property="monitorId" column="monitorId" />
|
||||
<result property="temperature" column="temperature" />
|
||||
<result property="humidity" column="humidity" />
|
||||
<result property="illuminance" column="illuminance" />
|
||||
<result property="noise" column="noise" />
|
||||
<result property="concentration" column="concentration" />
|
||||
<result property="vibrationSpeed" column="vibration_speed" />
|
||||
<result property="vibrationDisplacement" column="vibration_displacement" />
|
||||
<result property="vibrationAcceleration" column="vibration_acceleration" />
|
||||
<result property="vibrationTemp" column="vibration_temp" />
|
||||
<result property="collectTime" column="collectTime" />
|
||||
<result property="recodeTime" column="recodeTime" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRecordIotenvInstantVo">
|
||||
select objid, monitorId, temperature, humidity, illuminance, noise, concentration, vibration_speed, vibration_displacement, vibration_acceleration, vibration_temp, collectTime, recodeTime from record_iotenv_instant
|
||||
</sql>
|
||||
|
||||
<select id="selectRecordIotenvInstantList" parameterType="RecordIotenvInstant" resultMap="RecordIotenvInstantResult">
|
||||
<include refid="selectRecordIotenvInstantVo"/>
|
||||
<where>
|
||||
<if test="monitorId != null and monitorId != ''"> and monitorId like concat('%', #{monitorId}, '%')</if>
|
||||
<if test="temperature != null "> and temperature = #{temperature}</if>
|
||||
<if test="humidity != null "> and humidity = #{humidity}</if>
|
||||
<if test="illuminance != null "> and illuminance = #{illuminance}</if>
|
||||
<if test="noise != null "> and noise = #{noise}</if>
|
||||
<if test="concentration != null "> and concentration = #{concentration}</if>
|
||||
<if test="vibrationSpeed != null "> and vibration_speed = #{vibrationSpeed}</if>
|
||||
<if test="vibrationDisplacement != null "> and vibration_displacement = #{vibrationDisplacement}</if>
|
||||
<if test="vibrationAcceleration != null "> and vibration_acceleration = #{vibrationAcceleration}</if>
|
||||
<if test="vibrationTemp != null "> and vibration_temp = #{vibrationTemp}</if>
|
||||
<if test="collectTime != null "> and collectTime = #{collectTime}</if>
|
||||
<if test="recodeTime != null "> and recodeTime = #{recodeTime}</if>
|
||||
<if test="params.beginCollectTime != null adn params.endCollectTime != null ">collectTime <= #{params.endCollectTime} and collectTime >= #{params.beginCollectTime} </if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRecordIotenvInstantByObjid" parameterType="Long" resultMap="RecordIotenvInstantResult">
|
||||
<include refid="selectRecordIotenvInstantVo"/>
|
||||
where objid = #{objid}
|
||||
</select>
|
||||
|
||||
<insert id="insertRecordIotenvInstant" parameterType="RecordIotenvInstant" useGeneratedKeys="true" keyProperty="objid">
|
||||
insert into record_iotenv_instant
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="monitorId != null">monitorId,</if>
|
||||
<if test="temperature != null">temperature,</if>
|
||||
<if test="humidity != null">humidity,</if>
|
||||
<if test="illuminance != null">illuminance,</if>
|
||||
<if test="noise != null">noise,</if>
|
||||
<if test="concentration != null">concentration,</if>
|
||||
<if test="vibrationSpeed != null">vibration_speed,</if>
|
||||
<if test="vibrationDisplacement != null">vibration_displacement,</if>
|
||||
<if test="vibrationAcceleration != null">vibration_acceleration,</if>
|
||||
<if test="vibrationTemp != null">vibration_temp,</if>
|
||||
<if test="collectTime != null">collectTime,</if>
|
||||
<if test="recodeTime != null">recodeTime,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="monitorId != null">#{monitorId},</if>
|
||||
<if test="temperature != null">#{temperature},</if>
|
||||
<if test="humidity != null">#{humidity},</if>
|
||||
<if test="illuminance != null">#{illuminance},</if>
|
||||
<if test="noise != null">#{noise},</if>
|
||||
<if test="concentration != null">#{concentration},</if>
|
||||
<if test="vibrationSpeed != null">#{vibrationSpeed},</if>
|
||||
<if test="vibrationDisplacement != null">#{vibrationDisplacement},</if>
|
||||
<if test="vibrationAcceleration != null">#{vibrationAcceleration},</if>
|
||||
<if test="vibrationTemp != null">#{vibrationTemp},</if>
|
||||
<if test="collectTime != null">#{collectTime},</if>
|
||||
<if test="recodeTime != null">#{recodeTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRecordIotenvInstant" parameterType="RecordIotenvInstant">
|
||||
update record_iotenv_instant
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="monitorId != null">monitorId = #{monitorId},</if>
|
||||
<if test="temperature != null">temperature = #{temperature},</if>
|
||||
<if test="humidity != null">humidity = #{humidity},</if>
|
||||
<if test="illuminance != null">illuminance = #{illuminance},</if>
|
||||
<if test="noise != null">noise = #{noise},</if>
|
||||
<if test="concentration != null">concentration = #{concentration},</if>
|
||||
<if test="vibrationSpeed != null">vibration_speed = #{vibrationSpeed},</if>
|
||||
<if test="vibrationDisplacement != null">vibration_displacement = #{vibrationDisplacement},</if>
|
||||
<if test="vibrationAcceleration != null">vibration_acceleration = #{vibrationAcceleration},</if>
|
||||
<if test="vibrationTemp != null">vibration_temp = #{vibrationTemp},</if>
|
||||
<if test="collectTime != null">collectTime = #{collectTime},</if>
|
||||
<if test="recodeTime != null">recodeTime = #{recodeTime},</if>
|
||||
</trim>
|
||||
where objid = #{objid}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRecordIotenvInstantByObjid" parameterType="Long">
|
||||
delete from record_iotenv_instant where objid = #{objid}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRecordIotenvInstantByObjids" parameterType="String">
|
||||
delete from record_iotenv_instant where objid in
|
||||
<foreach item="objid" collection="array" open="(" separator="," close=")">
|
||||
#{objid}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
|
||||
<!-- 从指定表查询物联网数据列表 -->
|
||||
<select id="selectRecordIotenvInstantListFromTable" resultMap="RecordIotenvInstantResult">
|
||||
SELECT objid, monitorId, temperature, humidity, illuminance, noise, concentration,
|
||||
vibration_speed, vibration_displacement, vibration_acceleration, vibration_temp,
|
||||
collectTime, recodeTime
|
||||
FROM ${tableName}
|
||||
<where>
|
||||
|
||||
<if test="record.monitorId != null and record.monitorId != ''"> and monitorId like concat('%', #{record.monitorId}, '%')</if>
|
||||
<if test="record.temperature != null "> and temperature = #{record.temperature}</if>
|
||||
<if test="record.humidity != null "> and humidity = #{record.humidity}</if>
|
||||
<if test="record.illuminance != null "> and illuminance = #{record.illuminance}</if>
|
||||
<if test="record.noise != null "> and noise = #{record.noise}</if>
|
||||
<if test="record.concentration != null "> and concentration = #{record.concentration}</if>
|
||||
<if test="record.vibrationSpeed != null "> and vibration_speed = #{record.vibrationSpeed}</if>
|
||||
<if test="record.vibrationDisplacement != null "> and vibration_displacement = #{record.vibrationDisplacement}</if>
|
||||
<if test="record.vibrationAcceleration != null "> and vibration_acceleration = #{record.vibrationAcceleration}</if>
|
||||
<if test="record.vibrationTemp != null "> and vibration_temp = #{record.vibrationTemp}</if>
|
||||
<if test="record.collectTime != null "> and collectTime = #{record.collectTime}</if>
|
||||
<if test="record.recodeTime != null "> and recodeTime = #{record.recodeTime}</if>
|
||||
|
||||
<if test="record.params.beginCollectTime != null and record.params.endCollectTime != null">
|
||||
AND collectTime BETWEEN #{record.params.beginCollectTime} AND #{record.params.endCollectTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 使用 UNION ALL 从多个表查询物联网数据列表 -->
|
||||
<select id="selectRecordIotenvInstantListFromTables" resultMap="RecordIotenvInstantResult">
|
||||
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
||||
SELECT objid, monitorId, temperature, humidity, illuminance, noise, concentration,
|
||||
vibration_speed, vibration_displacement, vibration_acceleration, vibration_temp,
|
||||
collectTime, recodeTime
|
||||
FROM ${tableName}
|
||||
<where>
|
||||
|
||||
<if test="record.monitorId != null and record.monitorId != ''"> and monitorId like concat('%', #{record.monitorId}, '%')</if>
|
||||
<if test="record.temperature != null "> and temperature = #{record.temperature}</if>
|
||||
<if test="record.humidity != null "> and humidity = #{record.humidity}</if>
|
||||
<if test="record.illuminance != null "> and illuminance = #{record.illuminance}</if>
|
||||
<if test="record.noise != null "> and noise = #{record.noise}</if>
|
||||
<if test="record.concentration != null "> and concentration = #{record.concentration}</if>
|
||||
<if test="record.vibrationSpeed != null "> and vibration_speed = #{record.vibrationSpeed}</if>
|
||||
<if test="record.vibrationDisplacement != null "> and vibration_displacement = #{record.vibrationDisplacement}</if>
|
||||
<if test="record.vibrationAcceleration != null "> and vibration_acceleration = #{record.vibrationAcceleration}</if>
|
||||
<if test="record.vibrationTemp != null "> and vibration_temp = #{record.vibrationTemp}</if>
|
||||
<if test="record.collectTime != null "> and collectTime = #{record.collectTime}</if>
|
||||
<if test="record.recodeTime != null "> and recodeTime = #{record.recodeTime}</if>
|
||||
|
||||
<if test="record.params.beginCollectTime != null and record.params.endCollectTime != null">
|
||||
AND collectTime BETWEEN #{record.params.beginCollectTime} AND #{record.params.endCollectTime}
|
||||
</if>
|
||||
</where>
|
||||
</foreach>
|
||||
ORDER BY collectTime ASC
|
||||
</select>
|
||||
|
||||
<!-- 检查表是否存在 -->
|
||||
<select id="checkTableExists" parameterType="java.util.Map" resultType="java.lang.Integer">
|
||||
SELECT COUNT(1) FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE() AND table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue