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.AcRecomUpgradeRuleConfigMapper;
import com.hzs.activity.recommend.service.IAcRecomUpgradeRuleConfigService;
import com.hzs.activity.recommend.vo.AcRecommendUpgradeVO;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.domain.activity.recommend.AcRecomUpgradeRuleConfig;
import org.springframework.stereotype.Service;

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

/**
 * 直推-推荐升级 服务实现类
 *
 * @author hzs
 * @since 2023-04-22
 */
@Service
public class AcRecomUpgradeRuleConfigServiceImpl extends ServiceImpl<AcRecomUpgradeRuleConfigMapper, AcRecomUpgradeRuleConfig> implements IAcRecomUpgradeRuleConfigService {

    @Override
    public List<AcRecomUpgradeRuleConfig> selectByActivityId(Long activityId) {
        LambdaQueryWrapper<AcRecomUpgradeRuleConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcRecomUpgradeRuleConfig::getPkBaseId, activityId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<AcRecomUpgradeRuleConfig> selectRuleConfig(AcRecommendUpgradeVO recommendUpgradeVO) {
        return baseMapper.selectRuleConfig(recommendUpgradeVO);
    }

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

}
