package com.hzs.activity.recommend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.recommend.mapper.AcRepurSharRuleConfigMapper;
import com.hzs.activity.recommend.service.IAcRepurSharRuleConfigService;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.domain.activity.recommend.AcRepurSharRuleConfig;
import com.hzs.common.domain.activity.recommend.ext.AcRepurSharRuleConfigExt;
import org.springframework.stereotype.Service;

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

/**
 * 复购均分配置 服务实现类
 *
 * @author hzs
 * @since 2023-05-04
 */
@Service
public class AcRepurSharRuleConfigServiceImpl extends ServiceImpl<AcRepurSharRuleConfigMapper, AcRepurSharRuleConfig> implements IAcRepurSharRuleConfigService {

    @Override
    public AcRepurSharRuleConfig selectAcRepurSharRuleConfigByBaseId(Long pkBaseId) {
        LambdaQueryWrapper<AcRepurSharRuleConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcRepurSharRuleConfig::getPkBaseId, pkBaseId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Boolean deleteSharRuleConfigByActivityId(Long activityId, Long pkModifyId) {
        LambdaUpdateWrapper<AcRepurSharRuleConfig> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(AcRepurSharRuleConfig::getDelFlag, EDelFlag.DELETE.getValue());
        updateWrapper.set(AcRepurSharRuleConfig::getPkModified, pkModifyId);
        updateWrapper.set(AcRepurSharRuleConfig::getModifiedTime, new Date());
        updateWrapper.eq(AcRepurSharRuleConfig::getPkBaseId, activityId);
        return update(updateWrapper);
    }

    @Override
    public List<AcRepurSharRuleConfigExt> queryRepurSharRuleConfig(Date startDate, Date endDate) {
        return baseMapper.queryRepurSharRuleConfig(startDate, endDate);
    }
}
