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.ICuMemberBonusDetailService;
import com.hzs.common.domain.member.bonus.CuMemberBonusDetail;
import com.hzs.bonus.bonus.mapper.CuMemberBonusDetailMapper;
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 CuMemberBonusDetailServiceImpl extends ServiceImpl<CuMemberBonusDetailMapper, CuMemberBonusDetail> implements ICuMemberBonusDetailService {

    @Autowired
    private CuMemberBonusSettle cuMemberBonusSettle;

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

    @Override
    public void batchInsertCuMemberBonusDetail(List<CuMemberBonusDetail> cuMemberBonusDetailList, Set<Long> memberIdSet) {
        if (cuMemberBonusDetailList.size() == 0) {
            return;
        }
        List<CuMemberBonusDetail> cuMemberBonusDetails = new ArrayList<>();
        for (CuMemberBonusDetail cuMemberBonusDetail : cuMemberBonusDetailList) {
            if (memberIdSet.contains(cuMemberBonusDetail.getPkBonus())) {
                cuMemberBonusDetails.add(cuMemberBonusDetail);
            }
        }
        if (cuMemberBonusDetails.size() == 0) {
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(cuMemberBonusDetails);
        lists.forEach(list ->
                baseMapper.batchInsertCuMemberBonusDetail(list));
    }

}
