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.TbSchoolEntranceRequirements;
import com.ruoyi.system.service.ITbSchoolEntranceRequirementsService;
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-11
 */
@Controller
@RequestMapping("/system/requirements")
public class TbSchoolEntranceRequirementsController extends BaseController
{
    private String prefix = "system/requirements";

    @Autowired
    private ITbSchoolEntranceRequirementsService tbSchoolEntranceRequirementsService;

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

    /**
     * 查询入学要求列表
     */
    @RequiresPermissions("system:requirements:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        startPage();
        List<TbSchoolEntranceRequirements> list = tbSchoolEntranceRequirementsService.selectTbSchoolEntranceRequirementsList(tbSchoolEntranceRequirements);
        return getDataTable(list);
    }

    /**
     * 导出入学要求列表
     */
    @RequiresPermissions("system:requirements:export")
    @Log(title = "入学要求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        List<TbSchoolEntranceRequirements> list = tbSchoolEntranceRequirementsService.selectTbSchoolEntranceRequirementsList(tbSchoolEntranceRequirements);
        ExcelUtil<TbSchoolEntranceRequirements> util = new ExcelUtil<TbSchoolEntranceRequirements>(TbSchoolEntranceRequirements.class);
        return util.exportExcel(list, "入学要求数据");
    }

    /**
     * 新增入学要求
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入学要求
     */
    @RequiresPermissions("system:requirements:add")
    @Log(title = "入学要求", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        tbSchoolEntranceRequirements.setCreator(getUserId());
        return toAjax(tbSchoolEntranceRequirementsService.insertTbSchoolEntranceRequirements(tbSchoolEntranceRequirements));
    }

    /**
     * 修改入学要求
     */
    @RequiresPermissions("system:requirements:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbSchoolEntranceRequirements tbSchoolEntranceRequirements = tbSchoolEntranceRequirementsService.selectTbSchoolEntranceRequirementsById(id);
        mmap.put("tbSchoolEntranceRequirements", tbSchoolEntranceRequirements);
        return prefix + "/edit";
    }

    /**
     * 修改保存入学要求
     */
    @RequiresPermissions("system:requirements:edit")
    @Log(title = "入学要求", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        tbSchoolEntranceRequirements.setModifiedBy(getUserId());
        return toAjax(tbSchoolEntranceRequirementsService.updateTbSchoolEntranceRequirements(tbSchoolEntranceRequirements));
    }

    /**
     * 删除入学要求
     */
    @RequiresPermissions("system:requirements:remove")
    @Log(title = "入学要求", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbSchoolEntranceRequirementsService.deleteTbSchoolEntranceRequirementsByIds(ids));
    }
}
