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

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.achieve.service.ICuMemberSettlePeriodDetailService;
import com.hzs.common.core.constant.BonusFieldConstants;
import com.hzs.common.core.constant.MemberFieldConstants;
import com.hzs.common.core.constant.SystemFieldConstants;
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;

/**
 * <p>
 * 会员结算期间明细 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-07-27
 */
@Service
public class CuMemberSettlePeriodDetailServiceImpl extends ServiceImpl<CuMemberSettlePeriodDetailMapper, CuMemberSettlePeriodDetail> implements ICuMemberSettlePeriodDetailService {


    @Override
    public boolean updateCuMemberSettlePeriodDetailByPeriod(CuMemberSettlePeriodExt cuMemberSettlePeriodExt) {
        UpdateWrapper<CuMemberSettlePeriodDetail> updateWrapper = new UpdateWrapper<>();
        if(cuMemberSettlePeriodExt.getIsPublish() != null && cuMemberSettlePeriodExt.getPublishDate() != null){
            updateWrapper.set(BonusFieldConstants.IS_PUBLISH, cuMemberSettlePeriodExt.getIsPublish());
            updateWrapper.set(BonusFieldConstants.PUBLISH_DATE, cuMemberSettlePeriodExt.getPublishDate());
        }
        if(cuMemberSettlePeriodExt.getIsGrant() != null && cuMemberSettlePeriodExt.getGrantDate() != null){
            updateWrapper.set(BonusFieldConstants.IS_GRANT, cuMemberSettlePeriodExt.getIsGrant());
            updateWrapper.set(BonusFieldConstants.GRANT_DATE, cuMemberSettlePeriodExt.getGrantDate());
        }
        if(cuMemberSettlePeriodExt.getIsWithdrawal() != null && cuMemberSettlePeriodExt.getWithdrawalDate() != null){
            updateWrapper.set(BonusFieldConstants.IS_WITHDRAWAL, cuMemberSettlePeriodExt.getIsWithdrawal());
            updateWrapper.set(BonusFieldConstants.WITHDRAWAL_DATE, cuMemberSettlePeriodExt.getWithdrawalDate());
        }
        updateWrapper.eq(MemberFieldConstants.START_PERIOD, cuMemberSettlePeriodExt.getStartPeriod());
        updateWrapper.eq(MemberFieldConstants.END_PERIOD, cuMemberSettlePeriodExt.getEndPeriod());
        if(cuMemberSettlePeriodExt.getPkCountry() != null){
            updateWrapper.eq(SystemFieldConstants.PK_COUNTRY, cuMemberSettlePeriodExt.getPkCountry());
        }
        return update(updateWrapper);
    }
}
