package com.ruoyi.web.controller.ai;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.domain.AiTemplate;
import com.ruoyi.ai.service.IAiTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AI模版Controller
 * 
 * @author shi
 * @date 2026-01-15
 */
@RestController
@RequestMapping("/ai/template")
public class AiTemplateController extends BaseController
{
    @Autowired
    private IAiTemplateService aiTemplateService;

    /**
     * 查询AI模版列表
     */
    @PreAuthorize("@ss.hasPermi('ai:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiTemplate aiTemplate)
    {
        startPage();
        List<AiTemplate> list = aiTemplateService.selectAiTemplateList(aiTemplate);
        return getDataTable(list);
    }

    /**
     * 导出AI模版列表
     */
    @PreAuthorize("@ss.hasPermi('ai:template:export')")
    @Log(title = "AI模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiTemplate aiTemplate)
    {
        List<AiTemplate> list = aiTemplateService.selectAiTemplateList(aiTemplate);
        ExcelUtil<AiTemplate> util = new ExcelUtil<AiTemplate>(AiTemplate.class);
        util.exportExcel(response, list, "AI模版数据");
    }

    /**
     * 获取AI模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiTemplateService.selectAiTemplateById(id));
    }

    /**
     * 新增AI模版
     */
    @PreAuthorize("@ss.hasPermi('ai:template:add')")
    @Log(title = "AI模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiTemplate aiTemplate)
    {
        return toAjax(aiTemplateService.insertAiTemplate(aiTemplate));
    }

    /**
     * 修改AI模版
     */
    @PreAuthorize("@ss.hasPermi('ai:template:edit')")
    @Log(title = "AI模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiTemplate aiTemplate)
    {
        return toAjax(aiTemplateService.updateAiTemplate(aiTemplate));
    }

    /**
     * 删除AI模版
     */
    @PreAuthorize("@ss.hasPermi('ai:template:remove')")
    @Log(title = "AI模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiTemplateService.deleteAiTemplateByIds(ids));
    }
}
