package com.ruoyi.web.controller.school;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
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.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbMaterialDemo;
import com.ruoyi.system.service.ITbMaterialDemoService;
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;
import org.springframework.web.multipart.MultipartFile;

/**
 * 材料样例Controller
 * 
 * @author ruoyi
 * @date 2022-08-31
 */
@Controller
@RequestMapping("/system/demo")
public class TbMaterialDemoController extends BaseController
{
    private String prefix = "system/demo";

    @Autowired
    private ITbMaterialDemoService tbMaterialDemoService;

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

    @GetMapping("/queryAll")
    public List<TbMaterialDemo> queryAll(){
        return tbMaterialDemoService.queryAll();
    }

    /**
     * 查询材料样例列表
     */
    @RequiresPermissions("system:demo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbMaterialDemo tbMaterialDemo)
    {
        startPage();
        List<TbMaterialDemo> list = tbMaterialDemoService.selectTbMaterialDemoList(tbMaterialDemo);
        return getDataTable(list);
    }

    /**
     * 导出材料样例列表
     */
    @RequiresPermissions("system:demo:export")
    @Log(title = "材料样例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbMaterialDemo tbMaterialDemo)
    {
        List<TbMaterialDemo> list = tbMaterialDemoService.selectTbMaterialDemoList(tbMaterialDemo);
        ExcelUtil<TbMaterialDemo> util = new ExcelUtil<TbMaterialDemo>(TbMaterialDemo.class);
        return util.exportExcel(list, "材料样例数据");
    }

    /**
     * 新增材料样例
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存材料样例
     */
    @RequiresPermissions("system:demo:add")
    @Log(title = "材料样例", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbMaterialDemo tbMaterialDemo)
    {
        tbMaterialDemo.setCreator(getUserId());
        tbMaterialDemo.setCheckStatus(1);
        return toAjax(tbMaterialDemoService.insertTbMaterialDemo(tbMaterialDemo));
    }

    /**
     * 修改材料样例
     */
    @RequiresPermissions("system:demo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbMaterialDemo tbMaterialDemo = tbMaterialDemoService.selectTbMaterialDemoById(id);
        mmap.put("tbMaterialDemo", tbMaterialDemo);
        return prefix + "/edit";
    }

    /**
     * 修改保存材料样例
     */
    @RequiresPermissions("system:demo:edit")
    @Log(title = "材料样例", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbMaterialDemo tbMaterialDemo) {
        tbMaterialDemo.setModifiedBy(getUserId());
        return toAjax(tbMaterialDemoService.updateTbMaterialDemo(tbMaterialDemo));
    }

    /**
     * 删除材料样例
     */
    @RequiresPermissions("system:demo:remove")
    @Log(title = "材料样例", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbMaterialDemoService.deleteTbMaterialDemoByIds(ids));
    }
}
