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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EUpgradeType;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.domain.member.detail.CuMemberGrade;
import com.hzs.common.domain.member.detail.CuMemberLevel;
import com.hzs.member.detail.mapper.CuMemberLevelMapper;
import com.hzs.member.detail.service.ICuMemberLevelService;
import org.springframework.stereotype.Service;

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

/**
 * 会员信息-等级升级记录 服务实现类
 */
@Service
public class CuMemberLevelServiceImpl extends ServiceImpl<CuMemberLevelMapper, CuMemberLevel> implements ICuMemberLevelService {

    @Override
    public void deleteCuMemberLevelRecord(Long pkOrder, Long pkApprove, Date currentDateTime) {
        LambdaUpdateWrapper<CuMemberLevel> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(CuMemberLevel::getDelFlag, EYesNo.NO.getIntValue());
        updateWrapper.set(CuMemberLevel::getPkModified, pkApprove);
        updateWrapper.set(CuMemberLevel::getModifiedTime, currentDateTime);
        updateWrapper.eq(CuMemberLevel::getPkOrder, pkOrder);
        // 购买升级
        updateWrapper.eq(CuMemberLevel::getUpType, EUpgradeType.BUY_UPGRADE.getValue());
        update(updateWrapper);
    }

    @Override
    public CuMemberLevel getLastUpgrade(Long pkMember, Long pkOrder) {
        return baseMapper.getLastUpgrade(pkMember, pkOrder);
    }

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

    @Override
    public int insertBatch(List<CuMemberLevel> memberLevelList) {
        return baseMapper.insertBatch(memberLevelList);
    }

    @Override
    public int insertGradeBatch(List<CuMemberGrade> memberGradeList) {
        return baseMapper.insertGradeBatch(memberGradeList);
    }

    @Override
    public CuMemberLevel getLevelByGradeValue(Long pkMember, Integer gradeValue, Date queryTime, Integer pkCountry) {
        return baseMapper.getLevelByGradeValue(pkMember, gradeValue, queryTime, pkCountry);
    }

}
