package com.wanma.apps.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.wanma.apps.entity.Seller; import com.wanma.apps.entity.SellerFormat; import com.wanma.apps.mapper.SellerFormatMapper; import com.wanma.apps.service.ISellerFormatService; import com.wanma.apps.service.ISellerService; import com.wanma.framework_noweb.model.ResJson; import org.springframework.stereotype.Service; import javax.annotation.Resource; /** * <p> * 商家清洗表 服务实现类 * </p> * * @author Albert * @since 2022-07-20 */ @Service public class SellerFormatServiceImpl extends ServiceImpl<SellerFormatMapper, SellerFormat> implements ISellerFormatService { @Resource private ISellerService iSellerService; /** * 格式化商家信息 */ @Override public ResJson<Object> formatSeller() { ResJson<Object> res = ResJson.instance().error(); long pageSize = 3; // 商家的分页列表 Page<Seller> sellerPage = this.iSellerService.lambdaQuery() .orderByAsc(Seller::getId) .page(new Page<>(1, pageSize)); long totalPages = sellerPage.getPages(); for (long pageNum = 1; pageNum <= totalPages; pageNum++) { if (pageNum != 1) { sellerPage = this.iSellerService.lambdaQuery() .orderByAsc(Seller::getId) .page(new Page<>(pageNum, pageSize)); } System.out.println("【正在处理分页】" + pageNum + "/" + totalPages); for (Seller seller : sellerPage.getRecords()) { System.out.println(seller.getId()); // 处理逻辑 // .... } } return res.ok(); } }
测试:
package com.wanma; import com.wanma.apps.service.ISellerFormatService; import com.wanma.apps.spider.amazon_us.AmazonUsTool; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; @SpringBootTest class RunAmazonUSTests { @Resource private ISellerFormatService iSellerFormatService; @Test void test_01() { // 格式化 亚马逊商家信息 this.iSellerFormatService.formatSeller(); } }
输出:
【正在处理分页】1/11 1 2 3 【正在处理分页】2/11 4 5 6 【正在处理分页】3/11 7 8 9