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.TbSchoolAtlas;
import com.ruoyi.system.service.ITbSchoolAtlasService;
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-08
 */
@Controller
@RequestMapping("/system/atlas")
public class TbSchoolAtlasController extends BaseController
{
    private String prefix = "system/atlas";

    @Autowired
    private ITbSchoolAtlasService tbSchoolAtlasService;

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

    /**
     * 查询学校图册列表
     */
    @RequiresPermissions("system:atlas:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbSchoolAtlas tbSchoolAtlas)
    {
        startPage();
        List<TbSchoolAtlas> list = tbSchoolAtlasService.selectTbSchoolAtlasList(tbSchoolAtlas);
        return getDataTable(list);
    }

    /**
     * 导出学校图册列表
     */
    @RequiresPermissions("system:atlas:export")
    @Log(title = "学校图册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbSchoolAtlas tbSchoolAtlas)
    {
        List<TbSchoolAtlas> list = tbSchoolAtlasService.selectTbSchoolAtlasList(tbSchoolAtlas);
        ExcelUtil<TbSchoolAtlas> util = new ExcelUtil<TbSchoolAtlas>(TbSchoolAtlas.class);
        return util.exportExcel(list, "学校图册数据");
    }

    /**
     * 新增学校图册
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学校图册
     */
    @RequiresPermissions("system:atlas:add")
    @Log(title = "学校图册", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbSchoolAtlas tbSchoolAtlas)
    {
        tbSchoolAtlas.setCreator(getUserId());
        return toAjax(tbSchoolAtlasService.insertTbSchoolAtlas(tbSchoolAtlas));
    }

    /**
     * 修改学校图册
     */
    @RequiresPermissions("system:atlas:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbSchoolAtlas tbSchoolAtlas = tbSchoolAtlasService.selectTbSchoolAtlasById(id);
        mmap.put("tbSchoolAtlas", tbSchoolAtlas);
        return prefix + "/edit";
    }

    /**
     * 修改保存学校图册
     */
    @RequiresPermissions("system:atlas:edit")
    @Log(title = "学校图册", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbSchoolAtlas tbSchoolAtlas)
    {
        tbSchoolAtlas.setModifiedBy(getUserId());
        return toAjax(tbSchoolAtlasService.updateTbSchoolAtlas(tbSchoolAtlas));
    }

    /**
     * 删除学校图册
     */
    @RequiresPermissions("system:atlas:remove")
    @Log(title = "学校图册", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbSchoolAtlasService.deleteTbSchoolAtlasByIds(ids));
    }
}
