package com.ruoyi.ai.service.impl;

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.AiBalanceChangeRecordMapper;
import com.ruoyi.ai.domain.AiBalanceChangeRecord;
import com.ruoyi.ai.service.IAiBalanceChangeRecordService;

/**
 * 余额使用记录Service业务层处理
 * 
 * @author shi
 * @date 2025-11-13
 */
@Service
public class AiBalanceChangeRecordServiceImpl implements IAiBalanceChangeRecordService {

    @Autowired
    private AiBalanceChangeRecordMapper aiBalanceChangeRecordMapper;

    /**
     * 查询余额使用记录
     * 
     * @param id 余额使用记录主键
     * @return 余额使用记录
     */
    @Override
    public AiBalanceChangeRecord selectAiBalanceChangeRecordById(Long id) {
        return aiBalanceChangeRecordMapper.selectById(id);
    }

    /**
     * 查询余额使用记录列表
     * 
     * @param aiBalanceChangeRecord 余额使用记录
     * @return 余额使用记录
     */
    @Override
    public List<AiBalanceChangeRecord> selectAiBalanceChangeRecordList(AiBalanceChangeRecord aiBalanceChangeRecord) {
//        LambdaQueryWrapper<AiBalanceChangeRecord> query = Wrappers.lambdaQuery(aiBalanceChangeRecord);
//        query.orderByDesc(AiBalanceChangeRecord::getId);
//        query.eq(AiBalanceChangeRecord::getDelFlag, "0");
        return aiBalanceChangeRecordMapper.selectAiBalanceChangeRecordList(aiBalanceChangeRecord);
    }

    /**
     * 分页查询余额使用记录列表
     *
     * @param aiBalanceChangeRecord 余额使用记录
     * @return 余额使用记录
     */
    @Override
    public IPage<AiBalanceChangeRecord> selectAiBalanceChangeRecordPage(Page page, AiBalanceChangeRecord aiBalanceChangeRecord) {
        LambdaQueryWrapper<AiBalanceChangeRecord> query = Wrappers.lambdaQuery(aiBalanceChangeRecord);
        query.eq(AiBalanceChangeRecord::getDelFlag, "0");
        return aiBalanceChangeRecordMapper.selectPage(page, query);
    }

    /**
     * 新增余额使用记录
     * 
     * @param aiBalanceChangeRecord 余额使用记录
     * @return 结果
     */
    @Override
    public int insertAiBalanceChangeRecord(AiBalanceChangeRecord aiBalanceChangeRecord) {
        aiBalanceChangeRecord.setDelFlag("0");
        aiBalanceChangeRecord.setCreateTime(DateUtils.getNowDate());
        return aiBalanceChangeRecordMapper.insert(aiBalanceChangeRecord);
    }

    /**
     * 修改余额使用记录
     * 
     * @param aiBalanceChangeRecord 余额使用记录
     * @return 结果
     */
    @Override
    public int updateAiBalanceChangeRecord(AiBalanceChangeRecord aiBalanceChangeRecord) {
        aiBalanceChangeRecord.setUpdateBy(SecurityUtils.getUsername());
        aiBalanceChangeRecord.setUpdateTime(DateUtils.getNowDate());
        return aiBalanceChangeRecordMapper.updateById(aiBalanceChangeRecord);
    }

    /**
     * 批量删除余额使用记录
     * 
     * @param ids 需要删除的余额使用记录主键
     * @return 结果
     */
    @Override
    public int deleteAiBalanceChangeRecordByIds(Long[] ids)
    {
        return aiBalanceChangeRecordMapper.deleteAiBalanceChangeRecordByIds(ids);
    }

    /**
     * 删除余额使用记录信息
     * 
     * @param id 余额使用记录主键
     * @return 结果
     */
    @Override
    public int deleteAiBalanceChangeRecordById(Long id)
    {
        return aiBalanceChangeRecordMapper.deleteAiBalanceChangeRecordById(id);
    }
}
