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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.base.service.*;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.*;
import com.hzs.common.domain.member.base.*;
import com.hzs.common.domain.member.detail.CuMemberAwards;
import com.hzs.common.domain.member.detail.CuMemberGrade;
import com.hzs.common.domain.member.ext.CuMemberExt;
import com.hzs.bonus.base.mapper.CuMemberMapper;
import com.hzs.common.domain.vertex.BdVertexBonus;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 会员 服务实现类
 */
@Service
public class CuMemberServiceImpl extends ServiceImpl<CuMemberMapper, CuMember> implements ICuMemberService {

    @Override
    public CuMemberExt getMemberByCode(String memberCode) {
        return baseMapper.queryLoginMember(memberCode, null);
    }

    @Override
    public void updateCuMemberRetailRangeByPeriod(Integer period) {
        baseMapper.updateCuMemberRetailAwardsByPeriod(period, EAwardsType.RANGE_TYPE.getValue());
        baseMapper.updateCuMemberRetailAwardsByPeriod(period, EAwardsType.SHARE_TYPE.getValue());
        // 更新会员最高奖衔
        baseMapper.updateCuMemberMaxAwardsByPeriod(period, EAwardsType.RANGE_TYPE.getValue());
    }

    @Override
    public void updateCuMemberRetailRangeByList(List<CuMemberAwards> cuMemberAwardsList, Integer period) {
        baseMapper.updateCuMemberRetailRangeByList(cuMemberAwardsList, period, EAwardsType.RANGE_TYPE.getValue());
        baseMapper.updateCuMemberRetailRangeByList(cuMemberAwardsList, period, EAwardsType.SHARE_TYPE.getValue());
    }

    @Override
    public void updateCuMemberMinGradeByList(List<CuMemberGrade> cuMemberGradeList, Integer period) {
        baseMapper.updateCuMemberMinGradeByList(cuMemberGradeList, period);
    }

    @Override
    public void updateCuMemberMinAwardsByList(List<CuMemberAwards> cuMemberAwardsList, Integer period) {
        baseMapper.updateCuMemberRetailRangeByList(cuMemberAwardsList, period, EAwardsType.RANGE_TYPE.getValue());
        baseMapper.updateCuMemberRetailRangeByList(cuMemberAwardsList, period, EAwardsType.SHARE_TYPE.getValue());
    }

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

    @Override
    public void updateCuMemberLevel(Date startDate, Date endDate) {
        baseMapper.updateCuMemberLevel(startDate, endDate);
    }

    @Override
    public void updateCuMemberGradeByList(List<CuMemberGrade> cuMemberGradeList, Integer period) {
        baseMapper.updateCuMemberGradeByList(cuMemberGradeList, period);
    }

    @Override
    public void updateBackCuMemberRetailRangeAward(Integer period) {
        baseMapper.updateBackCuMemberRetailRangeAward(period, EAwardsType.RANGE_TYPE.getValue());
        baseMapper.updateBackCuMemberRetailRangeAward(period, EAwardsType.SHARE_TYPE.getValue());
    }

    @Override
    public void updateCuMemberRetailRangeAwardByDate(Date settleDate) {
        baseMapper.updateCuMemberRetailRangeAwardByDate(settleDate, EAwardsType.RANGE_TYPE.getValue());
        baseMapper.updateCuMemberRetailRangeAwardByDate(settleDate, EAwardsType.SHARE_TYPE.getValue());
    }

    @Override
    public void updateCuMemberRetailRangeInitAward() {
        baseMapper.updateCuMemberRetailRangeInitAward();
        baseMapper.updateCuMemberRetailRangeInitV5Award();
    }

    @Override
    public List<CuMember> queryCuMemberShareTotal(Integer pkCountry) {
        return baseMapper.queryCuMemberShareTotal(pkCountry);
    }

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