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.AiWork;
import com.ruoyi.ai.service.IAiWorkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ai作品Controller
 * 
 * @author shi
 * @date 2025-11-25
 */
@RestController
@RequestMapping("/ai/work")
public class AiWorkController extends BaseController
{
    @Autowired
    private IAiWorkService aiWorkService;

    /**
     * 查询ai作品列表
     */
    @PreAuthorize("@ss.hasPermi('ai:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiWork aiWork)
    {
        startPage();
        List<AiWork> list = aiWorkService.selectAiWorkList(aiWork);
        return getDataTable(list);
    }

    /**
     * 导出ai作品列表
     */
    @PreAuthorize("@ss.hasPermi('ai:work:export')")
    @Log(title = "ai作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiWork aiWork)
    {
        List<AiWork> list = aiWorkService.selectAiWorkList(aiWork);
        ExcelUtil<AiWork> util = new ExcelUtil<AiWork>(AiWork.class);
        util.exportExcel(response, list, "ai作品数据");
    }

    /**
     * 获取ai作品详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiWorkService.selectAiWorkById(id));
    }

    /**
     * 新增ai作品
     */
    @PreAuthorize("@ss.hasPermi('ai:work:add')")
    @Log(title = "ai作品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiWork aiWork)
    {
        return toAjax(aiWorkService.insertAiWork(aiWork));
    }

    /**
     * 修改ai作品
     */
    @PreAuthorize("@ss.hasPermi('ai:work:edit')")
    @Log(title = "ai作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiWork aiWork)
    {
        return toAjax(aiWorkService.updateAiWork(aiWork));
    }

    /**
     * 删除ai作品
     */
    @PreAuthorize("@ss.hasPermi('ai:work:remove')")
    @Log(title = "ai作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiWorkService.deleteAiWorkByIds(ids));
    }
}
