package com.leromro.core.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.leromro.common.core.domain.R;
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.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.Slideshow;
import com.leromro.core.service.ILSlideshowService;
import com.leromro.common.utils.poi.ExcelUtil;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 主页轮播图或后续其他广告图片Controller
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@RestController
@Api(tags = "主页轮播图或后续其他广告图片")
@RequestMapping("/web/core/slideshow")
public class LSlideshowController extends BaseController
{
    @Autowired
    private ILSlideshowService lSlideshowService;

    /**
     * 查询主页轮播图或后续其他广告图片列表
     */
    @ApiOperation("web查询图片列表")
  //  @PreAuthorize("@ss.hasPermi('core:slideshow:list')")
    @GetMapping("/list")
    public TableDataInfo<Slideshow> list(Slideshow slideshow)
    {
        startPage();
        List<Slideshow> list = lSlideshowService.selectLSlideshowList(slideshow);
        return getDataTable(list);
    }

    /**
     * 导出主页轮播图或后续其他广告图片列表
     */
    @ApiOperation("导出主页轮播图或后续其他广告图片列表")
  //  @PreAuthorize("@ss.hasPermi('core:slideshow:export')")
    @Log(title = "主页轮播图或后续其他广告图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Slideshow slideshow)
    {
        List<Slideshow> list = lSlideshowService.selectLSlideshowList(slideshow);
        ExcelUtil<Slideshow> util = new ExcelUtil<Slideshow>(Slideshow.class);
        util.exportExcel(response, list, "主页轮播图或后续其他广告图片数据");
    }

    /**
     * 获取主页轮播图或后续其他广告图片详细信息
     */
    @ApiOperation("小程序端根据轮播图id查询")
 //   @PreAuthorize("@ss.hasPermi('core:slideshow:query')")
    @GetMapping(value = "/{slideshowId}")
    public R<Slideshow> getInfo(@PathVariable("slideshowId") Long slideshowId)
    {
        return R.ok(lSlideshowService.selectLSlideshowBySlideshowId(slideshowId));
    }

    /**
     * 新增主页轮播图或后续其他广告图片
     */
    @ApiOperation("web新增主页轮播图图片，传入图片 前端分割")
    /*@PreAuthorize("@ss.hasPermi('core:slideshow:add')")*/
    @Log(title = "主页轮播图或后续其他广告图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Slideshow slideshow)
    {
        return toAjax(lSlideshowService.save(slideshow));
    }

    /**
     * 修改主页轮播图或后续其他广告图片
     */
    @ApiOperation("web修改主页轮播图或后续其他广告图片")
  //  @PreAuthorize("@ss.hasPermi('core:slideshow:edit')")
    @Log(title = "主页轮播图或后续其他广告图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Slideshow slideshow)
    {
        return toAjax(lSlideshowService.updateLSlideshow(slideshow));
    }

    /**
     * 删除主页轮播图或后续其他广告图片
     */
    @ApiOperation("删除主页轮播图或后续其他广告图片")
 //   @PreAuthorize("@ss.hasPermi('core:slideshow:remove')")
    @Log(title = "主页轮播图或后续其他广告图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{slideshowIds}")
    public R<Integer> remove(@PathVariable Long[] slideshowIds)
    {
        return R.ok(lSlideshowService.deleteLSlideshowBySlideshowIds(slideshowIds));
    }
}
