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


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.constant.SystemFieldConstants;
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;

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


    @Override
    public AcRepurSharRuleConfig selectAcRepurSharRuleConfigByBaseId(Long pkBaseId) {
        QueryWrapper<AcRepurSharRuleConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_BASE_ID", pkBaseId);
        return baseMapper.selectOne(queryWrapper);
    }


    @Override
    public Boolean deleteSharRuleConfigByActivityId(Long activityId, Long pkModifyId) {
        UpdateWrapper<AcRepurSharRuleConfig> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EDelFlag.DELETE.getValue());
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, pkModifyId);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, new Date());
        updateWrapper.eq("PK_BASE_ID", activityId);
        return update(updateWrapper);
    }

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