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

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.achieve.service.impl.CuMemberBonusSettle;
import com.hzs.bonus.bonus.service.ICuMemberBonusPushService;
import com.hzs.common.domain.member.bonus.CuMemberBonusPush;
import com.hzs.bonus.bonus.mapper.CuMemberBonusPushMapper;
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 CuMemberBonusPushServiceImpl extends ServiceImpl<CuMemberBonusPushMapper, CuMemberBonusPush> implements ICuMemberBonusPushService {

    @Autowired
    private CuMemberBonusSettle cuMemberBonusSettle;

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

    @Override
    public void batchInsertCuMemberBonusPush(List<CuMemberBonusPush> cuMemberBonusPushList, Set<Long> memberIdSet) {
        if (CollectionUtil.isEmpty(cuMemberBonusPushList)) {
            return;
        }
        List<CuMemberBonusPush> addMemberBonusPushList = new ArrayList<>();
        for (CuMemberBonusPush cuMemberBonusPush : cuMemberBonusPushList) {
            if (memberIdSet.contains(cuMemberBonusPush.getPkBonus())) {
                addMemberBonusPushList.add(cuMemberBonusPush);
            }
        }
        if (addMemberBonusPushList.size() == 0) {
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(addMemberBonusPushList);
        lists.forEach(list ->
                baseMapper.batchInsertCuMemberBonusPush(list));
    }

}
