package com.ruoyi.ai.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ai.mapper.AiRebateRecordMapper;
import com.ruoyi.ai.domain.AiRebateRecord;
import com.ruoyi.ai.service.IAiRebateRecordService;

/**
 * 返佣记录Service业务层处理
 * 
 * @author shi
 * @date 2025-11-13
 */
@Service
public class AiRebateRecordServiceImpl implements IAiRebateRecordService {

    @Autowired
    private AiRebateRecordMapper aiRebateRecordMapper;

    /**
     * 查询返佣记录
     * 
     * @param id 返佣记录主键
     * @return 返佣记录
     */
    @Override
    public AiRebateRecord selectAiRebateRecordById(Long id) {
        return aiRebateRecordMapper.selectById(id);
    }

    /**
     * 查询返佣记录列表
     * 
     * @param aiRebateRecord 返佣记录
     * @return 返佣记录
     */
    @Override
    public List<AiRebateRecord> selectAiRebateRecordList(AiRebateRecord aiRebateRecord) {
        return aiRebateRecordMapper.selectAiRebateRecordList(aiRebateRecord);
    }

    /**
     * 分页查询返佣记录列表
     *
     * @param aiRebateRecord 返佣记录
     * @return 返佣记录
     */
    @Override
    public IPage<AiRebateRecord> selectAiRebateRecordPage(Page page, AiRebateRecord aiRebateRecord) {
        LambdaQueryWrapper<AiRebateRecord> query = Wrappers.lambdaQuery(aiRebateRecord);
        query.eq(AiRebateRecord::getDelFlag, "0");
        return aiRebateRecordMapper.selectPage(page, query);
    }

    /**
     * 新增返佣记录
     * 
     * @param aiRebateRecord 返佣记录
     * @return 结果
     */
    @Override
    public int insertAiRebateRecord(AiRebateRecord aiRebateRecord) {
        aiRebateRecord.setDelFlag("0");
        aiRebateRecord.setCreateTime(DateUtils.getNowDate());
        return aiRebateRecordMapper.insert(aiRebateRecord);
    }

    /**
     * 修改返佣记录
     * 
     * @param aiRebateRecord 返佣记录
     * @return 结果
     */
    @Override
    public int updateAiRebateRecord(AiRebateRecord aiRebateRecord) {
        aiRebateRecord.setUpdateBy(SecurityUtils.getUsername());
        aiRebateRecord.setUpdateTime(DateUtils.getNowDate());
        return aiRebateRecordMapper.updateById(aiRebateRecord);
    }

    /**
     * 批量删除返佣记录
     * 
     * @param ids 需要删除的返佣记录主键
     * @return 结果
     */
    @Override
    public int deleteAiRebateRecordByIds(Long[] ids)
    {
        return aiRebateRecordMapper.deleteAiRebateRecordByIds(ids);
    }

    /**
     * 删除返佣记录信息
     * 
     * @param id 返佣记录主键
     * @return 结果
     */
    @Override
    public int deleteAiRebateRecordById(Long id)
    {
        return aiRebateRecordMapper.deleteAiRebateRecordById(id);
    }

    @Override
    public BigDecimal getTotalAmount(AiRebateRecord aiRebateRecord) {
        return aiRebateRecordMapper.getTotalAmount(aiRebateRecord);
    }

    @Override
    public List<AiRebateRecord> getAiRebateRecordList(AiRebateRecord aiRebateRecord) {
        return aiRebateRecordMapper.getAiRebateRecordList(aiRebateRecord);
    }
}
