StringBuilder tableName = new StringBuilder();
//拼接表名
tableName.append(TdwTableNameEnums.GNSS.getValue());
tableName.append("_").append(appCategory.getDictCode());
tableName.append("_").append(nowTime.getYear()).append(String.format("%02d", nowTime.getMonthValue()));
//判断表是否存在
if (!dtCommonService.whetherExistsTableName(tableSchema, tableName.toString())) {
return debugInfoVOList;
}
//封装查询条件
TDtGnssExample gnssExample = new TDtGnssExample(tableName.toString());
TDtGnssExample.Criteria criteria = gnssExample.createCriteria();
criteria.andAnchorIdEqualTo(monitorAnchor.getAnchorId());
criteria.andTimestampGreaterThanOrEqualTo(startTime);
criteria.andTimestampLessThanOrEqualTo(nowTime);
gnssExample.setOrderByClause("timestamp");
//按月查询不同月份的表数据
List<TDtGnss> tDtGnsses = dtGnssService.selectByExample(gnssExample);
//也可以通过${}直接拼接在表名称后面
select count(*) from t_dt_sensor${tableName}
按月创建表链接:https://www.cnblogs.com/smile-wei/p/6424671.html