package com.ruoyi.web.controller.system;

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

import io.swagger.annotations.Api;
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.WyPlatformBanner;
import com.ruoyi.system.service.IWyPlatformBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * platFormBannerController
 * 
 * @author ruoyi
 * @date 2025-01-05
 */
@Api(tags = "平台banner管理")
@RestController
@RequestMapping("/system/platFormBanner")
public class WyPlatformBannerController extends BaseController
{
    @Autowired
    private IWyPlatformBannerService wyPlatformBannerService;

    /**
     * 查询platFormBanner列表
     */
    @PreAuthorize("@ss.hasPermi('system:platFormBanner:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyPlatformBanner wyPlatformBanner)
    {
        startPage();
        List<WyPlatformBanner> list = wyPlatformBannerService.selectWyPlatformBannerList(wyPlatformBanner);
        return getDataTable(list);
    }

    /**
     * 导出platFormBanner列表
     */
    @PreAuthorize("@ss.hasPermi('system:platFormBanner:export')")
    @Log(title = "platFormBanner", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyPlatformBanner wyPlatformBanner)
    {
        List<WyPlatformBanner> list = wyPlatformBannerService.selectWyPlatformBannerList(wyPlatformBanner);
        ExcelUtil<WyPlatformBanner> util = new ExcelUtil<WyPlatformBanner>(WyPlatformBanner.class);
        util.exportExcel(response, list, "platFormBanner数据");
    }

    /**
     * 获取platFormBanner详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:platFormBanner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyPlatformBannerService.selectWyPlatformBannerById(id));
    }

    /**
     * 新增platFormBanner
     */
    @PreAuthorize("@ss.hasPermi('system:platFormBanner:add')")
    @Log(title = "platFormBanner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyPlatformBanner wyPlatformBanner)
    {
        if(wyPlatformBanner.getBannerType() == null || wyPlatformBanner.getBannerType().equals("")){
            return error("轮播图类型不能为空");
        }
        return toAjax(wyPlatformBannerService.insertWyPlatformBanner(wyPlatformBanner));
    }

    /**
     * 修改platFormBanner
     */
    @PreAuthorize("@ss.hasPermi('system:platFormBanner:edit')")
    @Log(title = "platFormBanner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyPlatformBanner wyPlatformBanner)
    {
        return toAjax(wyPlatformBannerService.updateWyPlatformBanner(wyPlatformBanner));
    }

    /**
     * 删除platFormBanner
     */
    @PreAuthorize("@ss.hasPermi('system:platFormBanner:remove')")
    @Log(title = "platFormBanner", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyPlatformBannerService.deleteWyPlatformBannerByIds(ids));
    }
}
