package com.ruoyi.web.controller.ai;

import com.ruoyi.ai.domain.AiBalanceChangeRecord;
import com.ruoyi.ai.service.IAiBalanceChangeRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 余额使用记录Controller
 * 
 * @author shi
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/ai/balance-change-record")
public class AiBalanceChangeRecordController extends BaseController
{
    @Autowired
    private IAiBalanceChangeRecordService aiBalanceChangeRecordService;

    /**
     * 查询余额使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('ai:balanceChangeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiBalanceChangeRecord aiBalanceChangeRecord)
    {
        startPage();
        List<AiBalanceChangeRecord> list = aiBalanceChangeRecordService.selectAiBalanceChangeRecordList(aiBalanceChangeRecord);
        return getDataTable(list);
    }

    /**
     * 导出余额使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('ai:balanceChangeRecord:export')")
    @Log(title = "余额使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiBalanceChangeRecord aiBalanceChangeRecord)
    {
        List<AiBalanceChangeRecord> list = aiBalanceChangeRecordService.selectAiBalanceChangeRecordList(aiBalanceChangeRecord);
        ExcelUtil<AiBalanceChangeRecord> util = new ExcelUtil<AiBalanceChangeRecord>(AiBalanceChangeRecord.class);
        util.exportExcel(response, list, "余额使用记录数据");
    }

    /**
     * 获取余额使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:balanceChangeRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiBalanceChangeRecordService.selectAiBalanceChangeRecordById(id));
    }

    /**
     * 新增余额使用记录
     */
    @PreAuthorize("@ss.hasPermi('ai:balanceChangeRecord:add')")
    @Log(title = "余额使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiBalanceChangeRecord aiBalanceChangeRecord)
    {
        return toAjax(aiBalanceChangeRecordService.insertAiBalanceChangeRecord(aiBalanceChangeRecord));
    }

    /**
     * 修改余额使用记录
     */
    @PreAuthorize("@ss.hasPermi('ai:balanceChangeRecord:edit')")
    @Log(title = "余额使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiBalanceChangeRecord aiBalanceChangeRecord)
    {
        return toAjax(aiBalanceChangeRecordService.updateAiBalanceChangeRecord(aiBalanceChangeRecord));
    }

    /**
     * 删除余额使用记录
     */
    @PreAuthorize("@ss.hasPermi('ai:balanceChangeRecord:remove')")
    @Log(title = "余额使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiBalanceChangeRecordService.deleteAiBalanceChangeRecordByIds(ids));
    }
}
