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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.achieve.service.ICuMemberSettlePeriodDetailService;
import com.hzs.common.domain.member.achieve.CuMemberSettlePeriodDetail;
import com.hzs.common.domain.member.achieve.ext.CuMemberSettlePeriodExt;
import com.hzs.bonus.achieve.mapper.CuMemberSettlePeriodDetailMapper;
import org.springframework.stereotype.Service;

/**
 * 会员结算期间明细 服务实现类
 */
@Service
public class CuMemberSettlePeriodDetailServiceImpl extends ServiceImpl<CuMemberSettlePeriodDetailMapper, CuMemberSettlePeriodDetail> implements ICuMemberSettlePeriodDetailService {

    @Override
    public boolean updateCuMemberSettlePeriodDetailByPeriod(CuMemberSettlePeriodExt cuMemberSettlePeriodExt) {
        LambdaUpdateWrapper<CuMemberSettlePeriodDetail> updateWrapper = new LambdaUpdateWrapper<>();
        if (cuMemberSettlePeriodExt.getIsPublish() != null && cuMemberSettlePeriodExt.getPublishDate() != null) {
            updateWrapper.set(CuMemberSettlePeriodDetail::getIsPublish, cuMemberSettlePeriodExt.getIsPublish());
            updateWrapper.set(CuMemberSettlePeriodDetail::getPublishDate, cuMemberSettlePeriodExt.getPublishDate());
        }
        if (cuMemberSettlePeriodExt.getIsGrant() != null && cuMemberSettlePeriodExt.getGrantDate() != null) {
            updateWrapper.set(CuMemberSettlePeriodDetail::getIsGrant, cuMemberSettlePeriodExt.getIsGrant());
            updateWrapper.set(CuMemberSettlePeriodDetail::getGrantDate, cuMemberSettlePeriodExt.getGrantDate());
        }
        if (cuMemberSettlePeriodExt.getIsWithdrawal() != null && cuMemberSettlePeriodExt.getWithdrawalDate() != null) {
            updateWrapper.set(CuMemberSettlePeriodDetail::getIsWithdrawal, cuMemberSettlePeriodExt.getIsWithdrawal());
            updateWrapper.set(CuMemberSettlePeriodDetail::getWithdrawalDate, cuMemberSettlePeriodExt.getWithdrawalDate());
        }
        updateWrapper.eq(CuMemberSettlePeriodDetail::getStartPeriod, cuMemberSettlePeriodExt.getStartPeriod());
        updateWrapper.eq(CuMemberSettlePeriodDetail::getEndPeriod, cuMemberSettlePeriodExt.getEndPeriod());
        if (cuMemberSettlePeriodExt.getPkCountry() != null) {
            updateWrapper.eq(CuMemberSettlePeriodDetail::getPkCountry, cuMemberSettlePeriodExt.getPkCountry());
        }
        return update(updateWrapper);
    }
}
