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.mapper.CuMemberBonusPointMapper;
import com.hzs.bonus.bonus.service.ICuMemberBonusPointService;
import com.hzs.common.domain.member.bonus.CuMemberBonusPoint;
import com.hzs.common.domain.member.bonus.CuMemberBonusRange;
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 2023-10-12
 */
@Service
public class CuMemberBonusPointServiceImpl extends ServiceImpl<CuMemberBonusPointMapper, CuMemberBonusPoint> implements ICuMemberBonusPointService {

    private CuMemberBonusSettle cuMemberBonusSettle;

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

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

    @Override
    public void batchInsertCuMemberBonusPoint(List<CuMemberBonusPoint> cuMemberBonusPointList, Set<Long> memberIdSet) {
        if(cuMemberBonusPointList.size() == 0){
            return;
        }
        List<CuMemberBonusPoint> cuMemberBonusPoints = new ArrayList<>();
        for (CuMemberBonusPoint cuMemberBonusPoint : cuMemberBonusPointList) {
            if(memberIdSet.contains(cuMemberBonusPoint.getPkBonus())){
                cuMemberBonusPoints.add(cuMemberBonusPoint);
            }
        }
        if(cuMemberBonusPoints.size()==0){
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(cuMemberBonusPoints);
        lists.forEach(list ->
                baseMapper.batchInsertCuMemberBonusPoint(list));
    }
}
