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.TbSchoolPartners;
import com.ruoyi.system.service.ITbSchoolPartnersService;
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-13
 */
@Controller
@RequestMapping("/system/partners")
public class TbSchoolPartnersController extends BaseController
{
    private String prefix = "system/partners";

    @Autowired
    private ITbSchoolPartnersService tbSchoolPartnersService;

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

    /**
     * 查询合作院校列表
     */
    @RequiresPermissions("system:partners:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbSchoolPartners tbSchoolPartners)
    {
        startPage();
        List<TbSchoolPartners> list = tbSchoolPartnersService.selectTbSchoolPartnersList(tbSchoolPartners);
        return getDataTable(list);
    }

    /**
     * 导出合作院校列表
     */
    @RequiresPermissions("system:partners:export")
    @Log(title = "合作院校", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbSchoolPartners tbSchoolPartners)
    {
        List<TbSchoolPartners> list = tbSchoolPartnersService.selectTbSchoolPartnersList(tbSchoolPartners);
        ExcelUtil<TbSchoolPartners> util = new ExcelUtil<TbSchoolPartners>(TbSchoolPartners.class);
        return util.exportExcel(list, "合作院校数据");
    }

    /**
     * 新增合作院校
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合作院校
     */
    @RequiresPermissions("system:partners:add")
    @Log(title = "合作院校", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbSchoolPartners tbSchoolPartners)
    {
        tbSchoolPartners.setCreator(getUserId());
        return toAjax(tbSchoolPartnersService.insertTbSchoolPartners(tbSchoolPartners));
    }

    /**
     * 修改合作院校
     */
    @RequiresPermissions("system:partners:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbSchoolPartners tbSchoolPartners = tbSchoolPartnersService.selectTbSchoolPartnersById(id);
        mmap.put("tbSchoolPartners", tbSchoolPartners);
        return prefix + "/edit";
    }

    /**
     * 修改保存合作院校
     */
    @RequiresPermissions("system:partners:edit")
    @Log(title = "合作院校", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbSchoolPartners tbSchoolPartners)
    {
        tbSchoolPartners.setModifiedBy(getUserId());
        return toAjax(tbSchoolPartnersService.updateTbSchoolPartners(tbSchoolPartners));
    }

    /**
     * 删除合作院校
     */
    @RequiresPermissions("system:partners:remove")
    @Log(title = "合作院校", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbSchoolPartnersService.deleteTbSchoolPartnersByIds(ids));
    }
}
