保证对应条件的数据 都可以轮询一边
@Test
public void testPage(){
int pageSize = 10;
Page objectPage = Page.of(1, pageSize);
LambdaQueryWrapper<com.example.demo.test.entity.Test> lambdaQueryWrapper = Wrappers.lambdaQuery(com.example.demo.test.entity.Test.class)
.isNull(com.example.demo.test.entity.Test::getName)
.orderByDesc(com.example.demo.test.entity.Test::getId);
IPage<com.example.demo.test.entity.Test> infoPage = testService.page(objectPage, lambdaQueryWrapper);
Long pages = infoPage.getPages();
long total = infoPage.getTotal();
updateBalanceAmount(infoPage.getRecords());
for (int i = 1; i <= pages; i++) {
objectPage = Page.of(i, pageSize);
System.out.println("循环 "+i+" 次");
infoPage = testService.page(objectPage,lambdaQueryWrapper);
// 保证 数据都能轮询一边
Long newPage = infoPage.getPages();
long newTotal = infoPage.getTotal();
if(total != newTotal){
// 重新从第一页开始
i = 0;
pages = newPage;
total = newTotal;
}
updateBalanceAmount(infoPage.getRecords());
}
}
private void updateBalanceAmount(List<com.example.demo.test.entity.Test> records) {
List<Long> ids = Lists.newArrayList();
for (int i = 100; i < 112; i++) {
ids.add(Long.valueOf(i));
}
records.forEach(e -> {
System.out.println("id:"+e.getId());
});
records = records.stream().filter(e -> !ids.contains(e.getId())).collect(Collectors.toList());
records.forEach(e -> {
e.setName(e.getId()+"name");
});
testService.updateBatchById(records);
}
网友评论