|
@@ -30,41 +30,31 @@ public class YtDeviceStatusServiceImpl extends AbstractCrudService<YtDeviceStatu
|
|
|
@Override
|
|
|
public CommonPage<YtDeviceStatus> page(YtDeviceStatusRequestVO requestVO) {
|
|
|
|
|
|
-// IPage<YtDeviceStatus> page = new Page<>(requestVO.getCurrent(),requestVO.getSize());
|
|
|
-// LambdaQueryWrapper<YtDeviceStatus> queryWrapper = Wrappers.lambdaQuery();
|
|
|
-// queryWrapper.eq(StringUtils.isNotBlank(requestVO.getDeviceType()),YtDeviceStatus::getDeviceType,
|
|
|
-// requestVO.getDeviceType())
|
|
|
-// .orderByDesc(YtDeviceStatus::getDeviceType);
|
|
|
-// page = this.page(page,queryWrapper);
|
|
|
-// return new CommonPage<>(page.getRecords(),page.getTotal(),page.getSize(),page.getCurrent());
|
|
|
+ String deviceType = requestVO.getDeviceType();
|
|
|
+ int pageCurrent = requestVO.getCurrent();
|
|
|
+ int pageSize = requestVO.getSize();
|
|
|
|
|
|
-// LambdaQueryWrapper<YtDeviceStatus> queryWrapper = Wrappers.lambdaQuery();
|
|
|
-// queryWrapper.eq(requestVO.getDeviceType() != null,YtDeviceStatus::getId,requestVO.getDeviceType())
|
|
|
-// .eq(StringUtils.isNotBlank(requestVO.getDeviceType()),YtDeviceStatus::getDeviceType,requestVO.getDeviceType())
|
|
|
-// .orderByDesc(YtDeviceStatus::getId);
|
|
|
+ List<YtDeviceStatus> list = ytDeviceStatusMapper.getDeviceStatusType(deviceType, pageCurrent, pageSize);
|
|
|
+ // 计算总记录数
|
|
|
+ int total = list.size();
|
|
|
|
|
|
+ // 计算总页数
|
|
|
+ int current = (total + pageSize - 1) / pageSize;
|
|
|
|
|
|
- List<YtDeviceStatus> list = ytDeviceStatusMapper.getDeviceStatusType(requestVO.getDeviceType());
|
|
|
- Integer total = list.size();
|
|
|
- if (total == 0) {
|
|
|
- return null;
|
|
|
- }
|
|
|
+ // 计算当前页的起始索引
|
|
|
+ int startIndex = (pageCurrent - 1) * pageSize;
|
|
|
|
|
|
- Integer pageSize = 10;
|
|
|
- if (total < pageSize) {
|
|
|
- pageSize = total;
|
|
|
- }
|
|
|
+ //对传入类型进行判断筛选
|
|
|
+ List<YtDeviceStatus> filteredList = list.stream()
|
|
|
+ .filter(device -> device.getDeviceType().equals(deviceType))
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- Integer pageCurrent = 1;
|
|
|
- if (total < 0) {
|
|
|
- pageCurrent = (total / pageSize) + 1;
|
|
|
- }
|
|
|
-
|
|
|
- Integer current = (pageCurrent - 1) * pageSize;
|
|
|
-
|
|
|
- List<YtDeviceStatus> records = list.stream().skip(current).limit(pageSize).collect(Collectors.toList());
|
|
|
+ // 对记录进行分页操作
|
|
|
+ List<YtDeviceStatus> records = filteredList.stream()
|
|
|
+ .skip(startIndex)//跳过startIndex个元素,从startIndex+1开始
|
|
|
+ .limit(pageSize)//限制显示大小,只处理pageSize个元素
|
|
|
+ .collect(Collectors.toList());//将流中的元素收集到List<YtDeviceStatus> == 获取当前页记录
|
|
|
|
|
|
return new CommonPage<>(records, total, pageSize, pageCurrent);
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
+}
|