package beilv.web.controller.carousel;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import beilv.common.annotation.Log;
import beilv.common.enums.BusinessType;
import beilv.carousel.domain.BeilvCarousel;
import beilv.carousel.service.IBeilvCarouselService;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.utils.poi.ExcelUtil;
import beilv.common.core.page.TableDataInfo;

/**
 * 轮播Controller
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@Controller
@RequestMapping("/carousel")
public class CarouselController extends BaseController {
    private String prefix = "carousel";

    @Autowired
    private IBeilvCarouselService beilvCarouselService;

    @GetMapping()
    public String carousel() {
        return prefix + "/carousel";
    }

    /**
     * 查询轮播列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BeilvCarousel beilvCarousel) {
        startPage();
        List<BeilvCarousel> list = beilvCarouselService.selectBeilvCarouselList(beilvCarousel);
        return getDataTable(list);
    }

    /**
     * 导出轮播列表
     */
    @Log(title = "轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BeilvCarousel beilvCarousel) {
        List<BeilvCarousel> list = beilvCarouselService.selectBeilvCarouselList(beilvCarousel);
        ExcelUtil<BeilvCarousel> util = new ExcelUtil<BeilvCarousel>(BeilvCarousel.class);
        return util.exportExcel(list, "轮播数据");
    }

    /**
     * 新增轮播
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存轮播
     */
    @Log(title = "轮播", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BeilvCarousel beilvCarousel) {
        return toAjax(beilvCarouselService.insertBeilvCarousel(beilvCarousel));
    }

    /**
     * 修改轮播
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BeilvCarousel beilvCarousel = beilvCarouselService.selectBeilvCarouselById(id);
        mmap.put("beilvCarousel", beilvCarousel);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播
     */
    @Log(title = "轮播", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BeilvCarousel beilvCarousel) {
        return toAjax(beilvCarouselService.updateBeilvCarousel(beilvCarousel));
    }

    /**
     * 删除轮播
     */
    @Log(title = "轮播", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(beilvCarouselService.deleteBeilvCarouselByIds(ids));
    }
}
