package com.hzs.member.account.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.member.account.CuMemberTradeDetail;
import com.hzs.member.account.mapper.CuMemberTradeDetailMapper;
import com.hzs.member.account.service.ICuMemberTradeDetailService;
import com.hzs.member.achieve.service.impl.CuMemberBonusSettle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-03-21
 */
@Service
public class CuMemberTradeDetailServiceImpl extends ServiceImpl<CuMemberTradeDetailMapper, CuMemberTradeDetail> implements ICuMemberTradeDetailService {

    private CuMemberBonusSettle cuMemberBonusSettle;

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

    @Override
    public void batchInsertCuMemberTradeDetail(List<CuMemberTradeDetail> cuMemberTradeDetailList) {
        List<List<?>> cutList = cuMemberBonusSettle.handleCutList(cuMemberTradeDetailList);
        cutList.forEach(memberTradeDetailList ->
                        baseMapper.batchInsertCuMemberTradeDetail(memberTradeDetailList));
    }

    @Override
    public void updateCuMemberTradeDetailByPeriod(Integer startPeriod, Integer endPeriod, Integer pkCountry) {
        baseMapper.updateCuMemberTradeDetailByPeriod(startPeriod, endPeriod, pkCountry);
    }

    @Override
    public List<CuMemberTradeDetail> queryCuMemberTradeDetail(Long pkMember) {
        return baseMapper.queryCuMemberTradeDetail(pkMember);
    }

    @Override
    public void updateCuMemberTradeDetail(List<CuMemberTradeDetail> cuMemberTradeDetailList) {
        if (cuMemberTradeDetailList.size() > 0) {
            List<List<?>> cutList = cuMemberBonusSettle.handleCutList(cuMemberTradeDetailList);
            cutList.forEach(memberTradeDetailList ->
                    baseMapper.updateCuMemberTradeDetail(memberTradeDetailList));
        }
    }

    @Override
    public void updateAddCuMemberTradeDetail(List<CuMemberTradeDetail> cuMemberTradeDetailList) {
        if (cuMemberTradeDetailList.size() > 0) {
            List<List<?>> cutList = cuMemberBonusSettle.handleCutList(cuMemberTradeDetailList);
            cutList.forEach(memberTradeDetailList ->
                    baseMapper.updateAddCuMemberTradeDetail(memberTradeDetailList));
        }
    }

    @Override
    public Integer batchInsertMemberTradeDetailFromTrade(String sourceCode, Integer period){
        return baseMapper.batchInsertMemberTradeDetailFromTrade(sourceCode,period);
    }

    @Override
    public List<CuMemberTradeDetail> selectMemberTradeDetailByPkMember(Long pkMember){
        return baseMapper.selectMemberTradeDetailByPkMember(pkMember);
    }
}
