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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.detail.mapper.CuMemberGradeMapper;
import com.hzs.bonus.detail.service.ICuMemberGradeService;
import com.hzs.common.domain.member.achieve.ext.CuMemberRetailRangeExt;
import com.hzs.common.domain.member.detail.CuMemberGrade;
import com.hzs.common.domain.member.detail.CuMemberLevel;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 会员信息-等级升级记录 服务实现类
 */
@Service
public class CuMemberGradeServiceImpl extends ServiceImpl<CuMemberGradeMapper, CuMemberGrade> implements ICuMemberGradeService {

    @Override
    public List<CuMemberLevel> calculateCuMemberRetailGradeInit(Integer period, Date startDate, Date endDate, String rangeTableName) {
        // 更新奖衔，回退等级
        baseMapper.deleteCuMemberGrade(period);
        baseMapper.updateCuMemberGrade(rangeTableName, period);
        return baseMapper.queryCuMemberLevel(startDate, endDate);
    }

    @Override
    public void updateCuMemberGradeSecond(String secondRangeTableName, Integer period) {
        baseMapper.updateCuMemberGradeSecond(secondRangeTableName, period);
    }

    @Override
    public List<CuMemberGrade> queryCuMemberGradeByList(Integer period, List<CuMemberRetailRangeExt> memberRetailRangeExtList) {
        return baseMapper.queryCuMemberGradeByList(period, memberRetailRangeExtList);
    }

    @Override
    public void updateCuMemberGrade(String rangeTableName, Long pkOrder) {
        baseMapper.updateCuMemberGradeLevel(rangeTableName, pkOrder);
    }

    @Override
    public CuMemberRetailRangeExt getMemberLevel(Long pkMember, Long pkOrder) {
        return baseMapper.getMemberLevel(pkMember, pkOrder);
    }

    @Override
    public void insertCuMemberGrade(List<CuMemberGrade> cuMemberGradeList) {
        saveBatch(cuMemberGradeList);
    }

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

    @Override
    public List<CuMemberGrade> queryCuMemberGrade(List<CuMemberRetailRangeExt> cuMemberRetailRangeExtList, Integer period) {
        return baseMapper.queryCuMemberGrade(cuMemberRetailRangeExtList, period);
    }
}
