package com.ruoyi.web.controller.ai;

import com.ruoyi.ai.domain.AiBanner;
import com.ruoyi.ai.service.IAiBannerService;
import com.ruoyi.common.annotation.Anonymous;
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 io.swagger.annotations.ApiOperation;
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;

/**
 * banner管理Controller
 * 
 * @author shi
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/ai/banner")
public class AiBannerController extends BaseController
{
    @Autowired
    private IAiBannerService aiBannerService;

    /**
     * 查询banner管理列表
     */
    @PreAuthorize("@ss.hasPermi('ai:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiBanner aiBanner)
    {
        startPage();
        List<AiBanner> list = aiBannerService.selectAiBannerList(aiBanner);
        return getDataTable(list);
    }


    /**
     * 导出banner管理列表
     */
    @PreAuthorize("@ss.hasPermi('ai:banner:export')")
    @Log(title = "banner管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiBanner aiBanner)
    {
        List<AiBanner> list = aiBannerService.selectAiBannerList(aiBanner);
        ExcelUtil<AiBanner> util = new ExcelUtil<AiBanner>(AiBanner.class);
        util.exportExcel(response, list, "banner管理数据");
    }

    /**
     * 获取banner管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiBannerService.selectAiBannerById(id));
    }

    /**
     * 新增banner管理
     */
    @PreAuthorize("@ss.hasPermi('ai:banner:add')")
    @Log(title = "banner管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiBanner aiBanner)
    {
        return toAjax(aiBannerService.insertAiBanner(aiBanner));
    }

    /**
     * 修改banner管理
     */
    @PreAuthorize("@ss.hasPermi('ai:banner:edit')")
    @Log(title = "banner管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiBanner aiBanner)
    {
        return toAjax(aiBannerService.updateAiBanner(aiBanner));
    }

    /**
     * 删除banner管理
     */
    @PreAuthorize("@ss.hasPermi('ai:banner:remove')")
    @Log(title = "banner管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiBannerService.deleteAiBannerByIds(ids));
    }
}
