fix(mcp): 生命周期列表改为 selectCount+LIMIT 物理分页
项目未注册 MyBatis-Plus 分页拦截器,selectPage 不做物理分页且 total 恒为 0 (2026-09-24 生产冒烟实测),对齐项目内 battery.fault.list.query 的既有做法
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package me.iiv.agent.mcp.tool;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import me.iiv.agent.entity.m0.Agent;
|
||||
import me.iiv.agent.entity.m0.DeviceLifeCycle;
|
||||
import me.iiv.agent.entity.m0.District;
|
||||
@@ -141,15 +140,18 @@ public class DeviceLifecycleTools implements ToolObject {
|
||||
boolean truncatedRows = rows != null && rows > MAX_ROWS;
|
||||
int pageSize = rows == null || rows < 1 ? DEFAULT_ROWS : Math.min(rows, MAX_ROWS);
|
||||
|
||||
Page<DeviceLifeCycle> result = deviceLifeCycleMapper.selectPage(new Page<>(pageNo, pageSize),
|
||||
new LambdaQueryWrapper<DeviceLifeCycle>()
|
||||
.eq(DeviceLifeCycle::getSoftDelete, 0)
|
||||
.like(DeviceLifeCycle::getSnCode, snCode.trim())
|
||||
.orderByAsc(DeviceLifeCycle::getId));
|
||||
// 项目未注册 MyBatis-Plus 分页拦截器,按惯例 selectCount + LIMIT 物理分页
|
||||
LambdaQueryWrapper<DeviceLifeCycle> wrapper = new LambdaQueryWrapper<DeviceLifeCycle>()
|
||||
.eq(DeviceLifeCycle::getSoftDelete, 0)
|
||||
.like(DeviceLifeCycle::getSnCode, snCode.trim());
|
||||
Long total = deviceLifeCycleMapper.selectCount(wrapper);
|
||||
wrapper.orderByAsc(DeviceLifeCycle::getId)
|
||||
.last("LIMIT " + (long) (pageNo - 1) * pageSize + "," + pageSize);
|
||||
List<DeviceLifeCycle> cycles = deviceLifeCycleMapper.selectList(wrapper);
|
||||
|
||||
Integer maxRoadDays = null;
|
||||
List<Map<String, Object>> records = new ArrayList<>();
|
||||
for (DeviceLifeCycle cycle : result.getRecords()) {
|
||||
for (DeviceLifeCycle cycle : cycles) {
|
||||
if (cycle.getRoadState() != null && cycle.getRoadState() == 1 && cycle.getRoadDate() != null
|
||||
&& maxRoadDays == null) {
|
||||
maxRoadDays = maxRoadDays();
|
||||
@@ -158,7 +160,7 @@ public class DeviceLifecycleTools implements ToolObject {
|
||||
}
|
||||
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("total", result.getTotal());
|
||||
output.put("total", total);
|
||||
output.put("page", pageNo);
|
||||
output.put("rows", pageSize);
|
||||
if (truncatedRows) {
|
||||
|
||||
Reference in New Issue
Block a user