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

import com.hzs.bonus.achieve.service.impl.CuMemberBonusSettle;
import com.hzs.bonus.bonus.mapper.CuMemberBonusDelayMapper;
import com.hzs.bonus.bonus.param.CuMemberBonusDelayParam;
import com.hzs.bonus.bonus.service.ICuMemberBonusDelayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.member.bonus.CuMemberBonusDelay;
import com.hzs.common.domain.member.bonus.ext.CuMemberBonusDelayExt;
import com.hzs.common.domain.member.ext.CuMemberSettleExt;
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 CuMemberBonusDelayServiceImpl extends ServiceImpl<CuMemberBonusDelayMapper, CuMemberBonusDelay> implements ICuMemberBonusDelayService {

    @Autowired
    private CuMemberBonusSettle cuMemberBonusSettle;

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

    @Override
    public void batchInsertCuMemberBonusDelay(List<CuMemberBonusDelay> cuMemberBonusDelayList, Set<Long> memberIdSet) {
        if (cuMemberBonusDelayList.size() == 0) {
            return;
        }
        List<CuMemberBonusDelay> cuMemberBonusDelays = new ArrayList<>();
        for (CuMemberBonusDelay cuMemberBonusDelay : cuMemberBonusDelayList) {
            if (memberIdSet.contains(cuMemberBonusDelay.getPkBonus())) {
                cuMemberBonusDelays.add(cuMemberBonusDelay);
            }
        }
        if (cuMemberBonusDelays.size() == 0) {
            return;
        }
        List<List<?>> lists = cuMemberBonusSettle.handleCutList(cuMemberBonusDelays);
        lists.forEach(list ->
                baseMapper.batchInsertCuMemberBonusDelay(list));
    }

    @Override
    public List<CuMemberSettleExt> listDelayNotBonus(String currentSettleTableName, Set<Long> pkMemberSet, Integer yesterdayPeriod) {
        return baseMapper.listDelayNotBonus(currentSettleTableName, pkMemberSet, yesterdayPeriod);
    }

    @Override
    public List<CuMemberBonusDelayExt> listDelay(CuMemberBonusDelayParam param) {
        return baseMapper.listDelay(param);
    }
}
