package com.ruoyi.index.controller;

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.index.domain.IndexS;
import com.ruoyi.index.service.IIndexSService;
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 ruoyi
 * @date 2021-12-28
 */
@Controller
@RequestMapping("/index/s")
public class IndexSController extends BaseController
{
    private String prefix = "index/s";

    @Autowired
    private IIndexSService indexSService;

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

    /**
     * 查询基础指标列表
     */
    @RequiresPermissions("index:s:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IndexS indexS)
    {
        startPage();
        List<IndexS> list = indexSService.selectIndexSList(indexS);
        return getDataTable(list);
    }

    /**
     * 导出基础指标列表
     */
    @RequiresPermissions("index:s:export")
    @Log(title = "基础指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IndexS indexS)
    {
        List<IndexS> list = indexSService.selectIndexSList(indexS);
        ExcelUtil<IndexS> util = new ExcelUtil<IndexS>(IndexS.class);
        return util.exportExcel(list, "基础指标数据");
    }

    /**
     * 新增基础指标
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存基础指标
     */
    @RequiresPermissions("index:s:add")
    @Log(title = "基础指标", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IndexS indexS)
    {
        return toAjax(indexSService.insertIndexS(indexS));
    }

    /**
     * 修改基础指标
     */
    @RequiresPermissions("index:s:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IndexS indexS = indexSService.selectIndexSById(id);
        mmap.put("indexS", indexS);
        return prefix + "/edit";
    }

    /**
     * 修改保存基础指标
     */
    @RequiresPermissions("index:s:edit")
    @Log(title = "基础指标", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IndexS indexS)
    {
        return toAjax(indexSService.updateIndexS(indexS));
    }

    /**
     * 删除基础指标
     */
    @RequiresPermissions("index:s:remove")
    @Log(title = "基础指标", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(indexSService.deleteIndexSByIds(ids));
    }
}
