package com.hzs.bonus.bonus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.achieve.service.impl.CuMemberBonusSettle;
import com.hzs.bonus.bonus.service.ICuMemberBonusExpandService;
import com.hzs.common.domain.member.bonus.CuMemberBonusExpand;
import com.hzs.bonus.bonus.mapper.CuMemberBonusExpandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 会员奖金-拓展收益明细表 服务实现类
 */
@Service
public class CuMemberBonusExpandServiceImpl extends ServiceImpl<CuMemberBonusExpandMapper, CuMemberBonusExpand> implements ICuMemberBonusExpandService {

    @Autowired
    private CuMemberBonusSettle cuMemberBonusSettle;

    @Override
    public void deleteCuMemberBonusExpand(Integer period) {
        baseMapper.deleteCuMemberBonusExpand(period);
    }

    @Override
    public void batchInsertCuMemberBonusExpand(List<CuMemberBonusExpand> cuMemberBonusExpandList, Set<Long> memberIdSet) {
        if (cuMemberBonusExpandList.size() == 0) {
            return;
        }
        List<CuMemberBonusExpand> memberBonusExpands = new ArrayList<>();
        for (CuMemberBonusExpand cuMemberBonusExpand : cuMemberBonusExpandList) {
            if (memberIdSet.contains(cuMemberBonusExpand.getPkBonus())) {
                memberBonusExpands.add(cuMemberBonusExpand);
            }
        }
        if (memberBonusExpands.size() == 0) {
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(memberBonusExpands);
        lists.forEach(list ->
                baseMapper.batchInsertCuMemberBonusExpand(list));
    }

}

