package com.ruoyi.web.controller.school;

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.system.domain.TbSchoolUploadMaterial;
import com.ruoyi.system.service.ITbSchoolUploadMaterialService;
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 2022-10-10
 */
@Controller
@RequestMapping("/system/material")
public class TbSchoolUploadMaterialController extends BaseController
{
    private String prefix = "system/material";

    @Autowired
    private ITbSchoolUploadMaterialService tbSchoolUploadMaterialService;

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

    /**
     * 查询学校上传的材料列表
     */
    @RequiresPermissions("system:material:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbSchoolUploadMaterial tbSchoolUploadMaterial)
    {
        startPage();
        List<TbSchoolUploadMaterial> list = tbSchoolUploadMaterialService.selectTbSchoolUploadMaterialList(tbSchoolUploadMaterial);
        return getDataTable(list);
    }

    /**
     * 导出学校上传的材料列表
     */
    @RequiresPermissions("system:material:export")
    @Log(title = "学校上传的材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbSchoolUploadMaterial tbSchoolUploadMaterial)
    {
        List<TbSchoolUploadMaterial> list = tbSchoolUploadMaterialService.selectTbSchoolUploadMaterialList(tbSchoolUploadMaterial);
        ExcelUtil<TbSchoolUploadMaterial> util = new ExcelUtil<TbSchoolUploadMaterial>(TbSchoolUploadMaterial.class);
        return util.exportExcel(list, "学校上传的材料数据");
    }

    /**
     * 新增学校上传的材料
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学校上传的材料
     */
    @RequiresPermissions("system:material:add")
    @Log(title = "学校上传的材料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbSchoolUploadMaterial tbSchoolUploadMaterial)
    {
        tbSchoolUploadMaterial.setCreator(getUserId());
        return toAjax(tbSchoolUploadMaterialService.insertTbSchoolUploadMaterial(tbSchoolUploadMaterial));
    }

    /**
     * 修改学校上传的材料
     */
    @RequiresPermissions("system:material:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbSchoolUploadMaterial tbSchoolUploadMaterial = tbSchoolUploadMaterialService.selectTbSchoolUploadMaterialById(id);
        mmap.put("tbSchoolUploadMaterial", tbSchoolUploadMaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存学校上传的材料
     */
    @RequiresPermissions("system:material:edit")
    @Log(title = "学校上传的材料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbSchoolUploadMaterial tbSchoolUploadMaterial)
    {
        tbSchoolUploadMaterial.setModifiedBy(getUserId());
        return toAjax(tbSchoolUploadMaterialService.updateTbSchoolUploadMaterial(tbSchoolUploadMaterial));
    }

    /**
     * 删除学校上传的材料
     */
    @RequiresPermissions("system:material:remove")
    @Log(title = "学校上传的材料", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbSchoolUploadMaterialService.deleteTbSchoolUploadMaterialByIds(ids));
    }
}
