package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WyPlatformActivityRewardMapper;
import com.ruoyi.system.domain.WyPlatformActivityReward;
import com.ruoyi.system.service.IWyPlatformActivityRewardService;

/**
 * 平台活动奖励Service业务层处理
 * 
 * @author kxl
 * @date 2025-02-09
 */
@Service
public class WyPlatformActivityRewardServiceImpl implements IWyPlatformActivityRewardService 
{
    @Autowired
    private WyPlatformActivityRewardMapper wyPlatformActivityRewardMapper;

    /**
     * 查询平台活动奖励
     * 
     * @param id 平台活动奖励主键
     * @return 平台活动奖励
     */
    @Override
    public WyPlatformActivityReward selectWyPlatformActivityRewardById(Long id)
    {
        return wyPlatformActivityRewardMapper.selectWyPlatformActivityRewardById(id);
    }

    /**
     * 通过批次id查询奖励
     * @param batchId 批次id
     * @return 奖励
     */
    @Override
    public WyPlatformActivityReward selectRewardByBatchId(Long batchId)
    {
        return wyPlatformActivityRewardMapper.selectRewardByBatchId(batchId);
    }

    @Override
    public WyPlatformActivityReward selectWyPlatformActivityRewardByActivityIdAndBarId(Long activityId, Long barId,Long joinBatchId){
        return wyPlatformActivityRewardMapper.selectWyPlatformActivityRewardByActivityIdAndBarId(activityId, barId,joinBatchId);
    }

    /**
     * 查询平台活动奖励列表
     * 
     * @param wyPlatformActivityReward 平台活动奖励
     * @return 平台活动奖励
     */
    @Override
    public List<WyPlatformActivityReward> selectWyPlatformActivityRewardList(WyPlatformActivityReward wyPlatformActivityReward)
    {
        return wyPlatformActivityRewardMapper.selectWyPlatformActivityRewardList(wyPlatformActivityReward);
    }

    /**
     * 新增平台活动奖励
     * 
     * @param wyPlatformActivityReward 平台活动奖励
     * @return 结果
     */
    @Override
    public int insertWyPlatformActivityReward(WyPlatformActivityReward wyPlatformActivityReward)
    {
        final WyPlatformActivityReward reward = selectRewardByBatchId(wyPlatformActivityReward.getJoinBatchId());
        if(reward!= null){
            throw new RuntimeException("该批次已存在奖励");
        }
        wyPlatformActivityReward.setCreateTime(DateUtils.getNowDate());
        return wyPlatformActivityRewardMapper.insertWyPlatformActivityReward(wyPlatformActivityReward);
    }

    /**
     * 修改平台活动奖励
     * 
     * @param wyPlatformActivityReward 平台活动奖励
     * @return 结果
     */
    @Override
    public int updateWyPlatformActivityReward(WyPlatformActivityReward wyPlatformActivityReward)
    {
        final WyPlatformActivityReward reward = selectRewardByBatchId(wyPlatformActivityReward.getJoinBatchId());
        if(reward!= null && !reward.getId().equals(wyPlatformActivityReward.getId())){
            throw new RuntimeException("该批次已存在奖励");
        }
        wyPlatformActivityReward.setUpdateTime(DateUtils.getNowDate());
        return wyPlatformActivityRewardMapper.updateWyPlatformActivityReward(wyPlatformActivityReward);
    }

    /**
     * 批量删除平台活动奖励
     * 
     * @param ids 需要删除的平台活动奖励主键
     * @return 结果
     */
    @Override
    public int deleteWyPlatformActivityRewardByIds(Long[] ids)
    {
        return wyPlatformActivityRewardMapper.deleteWyPlatformActivityRewardByIds(ids);
    }

    /**
     * 删除平台活动奖励信息
     * 
     * @param id 平台活动奖励主键
     * @return 结果
     */
    @Override
    public int deleteWyPlatformActivityRewardById(Long id)
    {
        return wyPlatformActivityRewardMapper.deleteWyPlatformActivityRewardById(id);
    }
}
