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.ICuMemberBonusCoachService;
import com.hzs.common.domain.member.bonus.CuMemberBonusCoach;
import com.hzs.bonus.bonus.mapper.CuMemberBonusCoachMapper;
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 CuMemberBonusCoachServiceImpl extends ServiceImpl<CuMemberBonusCoachMapper, CuMemberBonusCoach> implements ICuMemberBonusCoachService {

    private CuMemberBonusSettle cuMemberBonusSettle;

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

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

    @Override
    public void batchInsertCuMemberBonusCoach(List<CuMemberBonusCoach> cuMemberBonusCoachList, Set<Long> memberIdSet) {
        if (cuMemberBonusCoachList.size() == 0) {
            return;
        }
        List<CuMemberBonusCoach> cuMemberBonusCoaches = new ArrayList<>();
        for (CuMemberBonusCoach cuMemberBonusCoach : cuMemberBonusCoachList) {
            if (memberIdSet.contains(cuMemberBonusCoach.getPkBonus())) {
                cuMemberBonusCoaches.add(cuMemberBonusCoach);
            }
        }
        if (cuMemberBonusCoaches.size() == 0) {
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(cuMemberBonusCoaches);
        lists.forEach(list -> baseMapper.batchInsertCuMemberBonusCoach(list));
    }
}
