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

import com.hzs.bonus.achieve.service.impl.CuMemberBonusSettle;
import com.hzs.bonus.bonus.mapper.CuMemberBonusDelayDetailMapper;
import com.hzs.bonus.bonus.service.ICuMemberBonusDelayDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.member.bonus.CuMemberBonusDelayDetail;
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 CuMemberBonusDelayDetailServiceImpl extends ServiceImpl<CuMemberBonusDelayDetailMapper, CuMemberBonusDelayDetail> implements ICuMemberBonusDelayDetailService {

    @Autowired
    private CuMemberBonusSettle cuMemberBonusSettle;

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

    @Override
    public void batchInsertCuMemberBonusDelayDetail(List<CuMemberBonusDelayDetail> cuMemberBonusDelayDetailList, Set<Long> memberIdSet) {
        if (cuMemberBonusDelayDetailList.size() == 0) {
            return;
        }
        List<CuMemberBonusDelayDetail> CuMemberBonusDelayDetails = new ArrayList<>();
        for (CuMemberBonusDelayDetail cuMemberBonusDelayDetail : cuMemberBonusDelayDetailList) {
            if (memberIdSet.contains(cuMemberBonusDelayDetail.getPkBonus())) {
                CuMemberBonusDelayDetails.add(cuMemberBonusDelayDetail);
            }
        }
        if (CuMemberBonusDelayDetails.size() == 0) {
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(CuMemberBonusDelayDetails);
        lists.forEach(list ->
                baseMapper.batchInsertCuMemberBonusDelayDetail(list));
    }
}
