java 定时任务每日晚上凌晨执行数据统计

例如:统计每日会员账户余额

 

Page page = new Page();
page.setPageSize(1000);
page.setPageNum(1);
do{
    //获取所有用户余额
    com.github.pagehelper.Page pages = PageHelper.startPage(page.getPageNum(),page.getPageSize());
    List list = memberBalanceMapper.findMemberBalanceList();
    if(list != null && !list.isEmpty()){
        List balanceList = new ArrayList();
        for(MemberAccountBean account: list){
            MemberBalance entity = new MemberBalance();
            entity.setId(UF.getRandomUUID());
            entity.setDay(currentDate.toString());
            entity.setMemberId(account.getMemberId());
            entity.setAmount(account.getUsableAmount());
            balanceList.add(entity);
        }
        memberBalanceMapper.insert(balanceList);
    }else{
        logger.info("账户统计没有数据了");break;  //跳出循环
    }
    // 下一页
    page.setPageNum(page.getPageNum() + 1);
}while(true);

第二种获取所有数据进行分页,当数据量小可以使用该方法
 

List list = new ArrayList<>();
int subSize = 20;
int subCount = list.size();
int subPageTotal = (subCount / subSize) + ((subCount % subSize > 0) ? 1 : 0);
// 根据页码取数据
for (int i = 0, len = subPageTotal - 1; i <= len; i++) {
   // 分页计算
  int fromIndex = i * subSize;
  int toIndex = ((i == len) ? subCount : ((i + 1) * subSize));
  List strings = list.subList(fromIndex, toIndex);
 }    

你可能感兴趣的:(java)