package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.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.system.domain.SysAds;
import com.ruoyi.system.service.ISysAdsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页广告Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/system/ads")
public class SysAdsController extends BaseController
{
    @Autowired
    private ISysAdsService sysAdsService;

    /**
     * 查询首页广告列表
     */
    @PreAuthorize("@ss.hasPermi('system:ads:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAds sysAds)
    {
        startPage();
        List<SysAds> list = sysAdsService.selectSysAdsList(sysAds);
        return getDataTable(list);
    }

    /**
     * 导出首页广告列表
     */
    @PreAuthorize("@ss.hasPermi('system:ads:export')")
    @Log(title = "首页广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAds sysAds)
    {
        List<SysAds> list = sysAdsService.selectSysAdsList(sysAds);
        ExcelUtil<SysAds> util = new ExcelUtil<SysAds>(SysAds.class);
        util.exportExcel(response, list, "首页广告数据");
    }

    /**
     * 获取首页广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ads:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysAdsService.selectSysAdsById(id));
    }

    /**
     * 新增首页广告
     */
    @PreAuthorize("@ss.hasPermi('system:ads:add')")
    @Log(title = "首页广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAds sysAds)
    {
        return toAjax(sysAdsService.insertSysAds(sysAds));
    }

    /**
     * 修改首页广告
     */
    @PreAuthorize("@ss.hasPermi('system:ads:edit')")
    @Log(title = "首页广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAds sysAds)
    {
        return toAjax(sysAdsService.updateSysAds(sysAds));
    }

    /**
     * 删除首页广告
     */
    @PreAuthorize("@ss.hasPermi('system:ads:remove')")
    @Log(title = "首页广告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAdsService.deleteSysAdsByIds(ids));
    }
}
