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.param.TripleCycleListParam;
import com.hzs.bonus.bonus.service.ICuMemberBonusPushService;
import com.hzs.common.domain.member.bonus.CuMemberBonusPush;
import com.hzs.bonus.bonus.mapper.CuMemberBonusPushMapper;
import com.hzs.common.domain.member.ext.CuMemberBonusPushExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 会员奖金-直推收益明细表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2022-11-10
 */
@Service
public class CuMemberBonusPushServiceImpl extends ServiceImpl<CuMemberBonusPushMapper, CuMemberBonusPush> implements ICuMemberBonusPushService {

    private CuMemberBonusSettle cuMemberBonusSettle;

    @Autowired
    public void setCuMemberBonusSettle(CuMemberBonusSettle cuMemberBonusSettle) {
        this.cuMemberBonusSettle = cuMemberBonusSettle;
    }

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

    @Override
    public void batchInsertCuMemberBonusPush(List<CuMemberBonusPush> cuMemberBonusPushList, Set<Long> memberIdSet) {
        if(cuMemberBonusPushList.size() == 0){
            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));
    }

    @Override
    public void insertCuMemberBonusPush(CuMemberBonusPush cuMemberBonusPush) {
        baseMapper.insertCuMemberBonusPush(cuMemberBonusPush);
    }

}
