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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.base.CuMemberRegister;
import com.hzs.member.base.mapper.CuMemberRegisterMapper;
import com.hzs.member.base.service.ICuMemberRegisterService;
import com.hzs.member.base.vo.CuMemberVO;
import com.hzs.member.param.MemberParam;
import org.springframework.stereotype.Service;

import java.time.temporal.ChronoUnit;
import java.util.List;

/**
 * 会员历史记录 服务实现类
 */
@Service
public class CuMemberRegisterServiceImpl extends ServiceImpl<CuMemberRegisterMapper, CuMemberRegister> implements ICuMemberRegisterService {

    @Override
    public List<CuMemberVO> queryCuMemberRegisterExeByCondition(MemberParam memberParam) {
        if (memberParam.getEndDate() != null) {
            memberParam.setEndDate(DateUtils.afterDate(1, ChronoUnit.DAYS, memberParam.getEndDate()));
        }
        return baseMapper.queryCuMemberRegisterExeByCondition(memberParam);
    }

    @Override
    public CuMemberRegister queryCuMemberRegister(Long pkMember) {
        LambdaQueryWrapper<CuMemberRegister> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CuMemberRegister::getPkMember, pkMember);
        queryWrapper.orderByAsc(CuMemberRegister::getPayTime);
        List<CuMemberRegister> cuMemberRegisters = baseMapper.selectList(queryWrapper);
        return cuMemberRegisters.get(0);
    }

    @Override
    public void updateCuMemberRegister(CuMemberRegister cuMemberRegister) {
        baseMapper.updateCuMemberRegister(cuMemberRegister);
    }

    @Override
    public int insertBatchMemberRegister(List<CuMemberRegister> registerMemberList) {
        return baseMapper.insertBatchMemberRegister(registerMemberList);
    }

}
