package com.hzs.member.achieve.service.impl;

import com.hzs.common.core.constant.MagicNumberConstants;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Description: 奖金计算工具类
 * @Author: sui q
 * @Time: 2022/11/2 11:25
 * @Classname: CuMemberBonusSettle
 * @PackageName: com.hzs.member.achieve.service.impl
 */
@Component
public class CuMemberBonusSettle {

    public List<List<?>> handleCutList(List<?> baseEntityList, Integer... batchNum) {
        int batchUpdateNum = MagicNumberConstants.BATCH_UPDATE_NUM;
        if(batchNum != null && batchNum.length >0){
            batchUpdateNum = batchNum[0];
        }
        List<List<?>> returnList = new ArrayList<>();
        if (baseEntityList.size() > batchUpdateNum) {
            int num = baseEntityList.size() / batchUpdateNum + (baseEntityList.size() % batchUpdateNum > 0 ? 1 : 0);
            for (int i = 0; i < num; i++) {
                if (i == num - 1) {
                    returnList.add(baseEntityList.subList(i * batchUpdateNum, baseEntityList.size()));
                } else {
                    returnList.add(baseEntityList.subList(i * batchUpdateNum, (i + 1) * batchUpdateNum));
                }
            }
        } else {
            returnList.add(baseEntityList);
        }
        return returnList;
    }

    public List<List<?>> handleCutList(Set<?> baseEntityList, Integer... batchNum) {
        List<?> oriList = Arrays.asList(baseEntityList.toArray());
        return handleCutList(oriList, batchNum);
    }
}
