package com.ruoyi.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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 com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.SChart;
import com.ruoyi.business.service.ISChartService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/chart")
public class SChartController extends BaseController
{
    private String prefix = "business/chart";

    @Autowired
    private ISChartService sChartService;

    @RequiresPermissions("business:chart:view")
    @GetMapping()
    public String chart()
    {
        return prefix + "/chart";
    }

    /**
     * 查询轮播图列表
     */
    @RequiresPermissions("business:chart:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SChart sChart)
    {
        startPage();
        List<SChart> list = sChartService.selectSChartList(sChart);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @RequiresPermissions("business:chart:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SChart sChart)
    {
        List<SChart> list = sChartService.selectSChartList(sChart);
        ExcelUtil<SChart> util = new ExcelUtil<SChart>(SChart.class);
        return util.exportExcel(list, "轮播图数据");
    }

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

    /**
     * 新增保存轮播图
     */
    @RequiresPermissions("business:chart:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SChart sChart)
    {
        return toAjax(sChartService.insertSChart(sChart));
    }

    /**
     * 修改轮播图
     */
    @RequiresPermissions("business:chart:edit")
    @GetMapping("/edit/{chartId}")
    public String edit(@PathVariable("chartId") Integer chartId, ModelMap mmap)
    {
        SChart sChart = sChartService.selectSChartByChartId(chartId);
        mmap.put("sChart", sChart);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播图
     */
    @RequiresPermissions("business:chart:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SChart sChart)
    {
        return toAjax(sChartService.updateSChart(sChart));
    }

    /**
     * 删除轮播图
     */
    @RequiresPermissions("business:chart:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sChartService.deleteSChartByChartIds(ids));
    }
}
