数据20250916优化-点位最新值+时间
This commit is contained in:
@ -51,4 +51,9 @@ public class RedisKeyConstants
|
||||
* BMSD原始数据 redis key
|
||||
*/
|
||||
public static final String ORIGINAL_BMSD = "BMSD_";
|
||||
|
||||
/**
|
||||
* 存放单个设备同步过来的原始数据
|
||||
*/
|
||||
public static final String ORIGINAL_MQTT_DATA = "MQTT_";
|
||||
}
|
||||
|
||||
@ -208,28 +208,42 @@ public class BaseController
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected TableDataInfo getDataTable2(List<?> list)
|
||||
{
|
||||
List<?> subList = new ArrayList<>();
|
||||
// 分页梳理
|
||||
// 1. 处理原列表为null的情况,避免空指针
|
||||
List<?> targetList = (list == null) ? Collections.emptyList() : list;
|
||||
List<?> subList;
|
||||
|
||||
// 2. 获取分页参数
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
int pageNum = pageDomain.getPageNum();
|
||||
int pageSize = pageDomain.getPageSize();
|
||||
|
||||
// 3. 判断分页参数是否有效(pageNum和pageSize均为正数时才分页)
|
||||
if (pageNum > 0 && pageSize > 0) {
|
||||
// 计算分页起始和结束索引
|
||||
int startIndex = (pageNum - 1) * pageSize;
|
||||
int endIndex = Math.min(startIndex + pageSize, list.size());
|
||||
// 防止越界
|
||||
if (startIndex >= list.size()) {
|
||||
subList = Collections.emptyList();
|
||||
// 计算起始索引(确保不小于0)
|
||||
int startIndex = Math.max((pageNum - 1) * pageSize, 0);
|
||||
|
||||
// 关键修复:若起始索引已超出列表大小,直接返回空列表
|
||||
if (startIndex >= targetList.size()) {
|
||||
subList = Collections.emptyList();
|
||||
} else {
|
||||
// 计算结束索引(不超过列表大小,且不小于起始索引)
|
||||
int endIndex = Math.min(startIndex + pageSize, targetList.size());
|
||||
endIndex = Math.max(endIndex, startIndex); // 防止endIndex < startIndex
|
||||
|
||||
// 截取子列表(转换为新ArrayList,避免视图依赖)
|
||||
subList = new ArrayList<>(targetList.subList(startIndex, endIndex));
|
||||
}
|
||||
// 截取当前页数据
|
||||
subList = list.subList(startIndex, endIndex);
|
||||
} else {
|
||||
// 分页参数无效时,返回全部数据
|
||||
subList = new ArrayList<>(targetList);
|
||||
}
|
||||
|
||||
// 4. 封装返回结果
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(subList);
|
||||
rspData.setTotal(list.size());
|
||||
rspData.setTotal(targetList.size());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user