Commit 3eab2782 by 吕明尚

优化分页接口

parent 5e2c638b
...@@ -36,6 +36,7 @@ import java.util.ArrayList; ...@@ -36,6 +36,7 @@ import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 设备信息Service业务层处理 * 设备信息Service业务层处理
...@@ -170,10 +171,16 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -170,10 +171,16 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override @Override
public TableDataInfo devicePage(DeviceDto device) { public TableDataInfo devicePage(DeviceDto device) {
List<Device> devices = deviceMapper.selectDeviceList(device); List<Device> devices = deviceMapper.selectDeviceList(device);
List<DeviceVo> deviceVoList = convertDosToVos(devices); TableDataInfo tableDataInfo = new TableDataInfo();
PageDomain pageDomain = TableSupport.buildPageRequest();
tableDataInfo.setTotal(devices.size());
int start = (pageDomain.getPageNum() - 1) * pageDomain.getPageSize();
int end = Math.min(start + pageDomain.getPageSize(), devices.size());
List<Device> deviceVos = devices.subList(start, end);
List<DeviceVo> deviceVoList = convertDosToVos(deviceVos);
if (CollectionUtils.isNotEmpty(deviceVoList)) { if (CollectionUtils.isNotEmpty(deviceVoList)) {
List<SStore> sStoreList = storeMapper.selectList(new LambdaQueryWrapper<>()); List<SRoom> sRoomList = roomMapper.selectList(new LambdaQueryWrapper<SRoom>().in(SRoom::getId, deviceVoList.stream().map(DeviceVo::getRoomId).collect(Collectors.toList())));
List<SRoom> sRoomList = roomMapper.selectList(new LambdaQueryWrapper<>()); List<SStore> sStoreList = storeMapper.selectList(new LambdaQueryWrapper<SStore>().in(SStore::getId, sRoomList.stream().map(SRoom::getStoreId).collect(Collectors.toList())));
deviceVoList.stream().forEach(item -> { deviceVoList.stream().forEach(item -> {
if (ObjectUtil.isNotEmpty(item.getRoomId())) { if (ObjectUtil.isNotEmpty(item.getRoomId())) {
SRoom sRoom = sRoomList.stream().filter(room -> room.getId().equals(item.getRoomId())).findFirst().orElse(null); SRoom sRoom = sRoomList.stream().filter(room -> room.getId().equals(item.getRoomId())).findFirst().orElse(null);
...@@ -188,13 +195,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -188,13 +195,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
}); });
} }
deviceVoList.sort(Comparator.comparing(DeviceVo::getCreateTime).reversed()); deviceVoList.sort(Comparator.comparing(DeviceVo::getCreateTime).reversed());
PageDomain pageDomain = TableSupport.buildPageRequest(); tableDataInfo.setRows(deviceVoList);
int start = (pageDomain.getPageNum() - 1) * pageDomain.getPageSize();
int end = Math.min(start + pageDomain.getPageSize(), deviceVoList.size());
List<DeviceVo> deviceVos = deviceVoList.subList(start, end);
TableDataInfo tableDataInfo = new TableDataInfo();
tableDataInfo.setRows(deviceVos);
tableDataInfo.setTotal(deviceVoList.size());
tableDataInfo.setCode(200); tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功"); tableDataInfo.setMsg("查询成功");
return tableDataInfo; return tableDataInfo;
......
...@@ -158,17 +158,16 @@ public class RoomLabelServiceImpl extends ServiceImpl<RoomLabelMapper, RoomLabel ...@@ -158,17 +158,16 @@ public class RoomLabelServiceImpl extends ServiceImpl<RoomLabelMapper, RoomLabel
@Override @Override
public TableDataInfo pageList(RoomLabelDto roomLabel) { public TableDataInfo pageList(RoomLabelDto roomLabel) {
List<RoomLabel> roomLabels = roomLabelMapper.pageList(roomLabel); List<RoomLabel> roomLabels = roomLabelMapper.pageList(roomLabel);
List<RoomLabelVo> voList = doListToVoList(roomLabels); TableDataInfo tableDataInfo = new TableDataInfo();
tableDataInfo.setTotal(roomLabels.size());
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum(); Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize(); Integer pageSize = pageDomain.getPageSize();
int start = (pageNum - 1) * pageSize; int start = (pageNum - 1) * pageSize;
int end = Math.min(start + pageSize, voList.size()); int end = Math.min(start + pageSize, roomLabels.size());
List<RoomLabelVo> pagedList = voList.subList(start, end); List<RoomLabel> pagedList = roomLabels.subList(start, end);
List<RoomLabelVo> voList = doListToVoList(pagedList);
TableDataInfo tableDataInfo = new TableDataInfo(); tableDataInfo.setRows(voList);
tableDataInfo.setRows(pagedList);
tableDataInfo.setTotal(roomLabels.size());
tableDataInfo.setCode(200); tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功"); tableDataInfo.setMsg("查询成功");
return tableDataInfo; return tableDataInfo;
......
...@@ -617,22 +617,22 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -617,22 +617,22 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override @Override
public TableDataInfo queryOrderList(SOrder sOrder) { public TableDataInfo queryOrderList(SOrder sOrder) {
List<SOrder> sOrderList = baseMapper.queryList(sOrder.getRoomId()); List<SOrder> sOrderList = baseMapper.queryList(sOrder.getRoomId());
List<SOrderVo> sOrderVos = convertDosToVos(sOrderList); TableDataInfo tableDataInfo = new TableDataInfo();
List<SStore> list = storeService.list(); tableDataInfo.setTotal(sOrderList.size());
List<SRoom> list1 = roomService.list();
sOrderVos.stream().forEach(vo -> {
vo.setRoomName(list1.stream().filter(room -> room.getId().equals(vo.getRoomId())).findFirst().get().getName());
vo.setStoreName(list.stream().filter(store -> store.getId().equals(vo.getStoreId())).findFirst().get().getName());
});
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum(); Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize(); Integer pageSize = pageDomain.getPageSize();
int start = (pageNum - 1) * pageSize; int start = (pageNum - 1) * pageSize;
int end = Math.min(start + pageSize, sOrderVos.size()); int end = Math.min(start + pageSize, sOrderList.size());
List<SOrderVo> pagedList = sOrderVos.subList(start, end); List<SOrder> pagedList = sOrderList.subList(start, end);
TableDataInfo tableDataInfo = new TableDataInfo(); List<SOrderVo> sOrderVos = convertDosToVos(pagedList);
tableDataInfo.setRows(pagedList); // List<SStore> list = storeService.list();
tableDataInfo.setTotal(sOrderVos.size()); // List<SRoom> list1 = roomService.list();
// sOrderVos.stream().forEach(vo -> {
// vo.setRoomName(list1.stream().filter(room -> room.getId().equals(vo.getRoomId())).findFirst().get().getName());
// vo.setStoreName(list.stream().filter(store -> store.getId().equals(vo.getStoreId())).findFirst().get().getName());
// });
tableDataInfo.setRows(sOrderVos);
tableDataInfo.setCode(200); tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功"); tableDataInfo.setMsg("查询成功");
return tableDataInfo; return tableDataInfo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment