package com.ruoyi.project.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.project.business.domain.TbSalesDiscount;
import com.ruoyi.project.business.domain.vo.salesDiscount.SalesDiscountReq;
import com.ruoyi.project.business.mapper.TbSalesDiscountMapper;
import com.ruoyi.project.business.service.ITbSalesDiscountService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-14
 */
@Service
public class TbSalesDiscountServiceImpl extends ServiceImpl<TbSalesDiscountMapper, TbSalesDiscount> implements ITbSalesDiscountService {


    /**
     * 查询【请填写功能名称】列表
     *
     * @param tbSalesDiscount 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TbSalesDiscount> selectTbSalesDiscountList(SalesDiscountReq tbSalesDiscount) {
        return baseMapper.selectTbSalesDiscountList(tbSalesDiscount);
    }

    @Override
    public boolean add(TbSalesDiscount tbSalesDiscount) {
        // 校验角色是否存在
        boolean exists = baseMapper.exists(new LambdaQueryWrapper<TbSalesDiscount>().eq(TbSalesDiscount::getRoleId, tbSalesDiscount.getRoleId()));
        if (exists) throw new RuntimeException(MessageUtils.message("discount.saveFail.existRole"));
        return save(tbSalesDiscount);
    }

}
