package com.ruoyi.web.controller.school;

import java.util.List;

import com.ruoyi.system.domain.TbSchool;
import com.ruoyi.system.domain.TbSchoolMajor;
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.TbEnrollmentTime;
import com.ruoyi.system.service.ITbEnrollmentTimeService;
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-09-05
 */
@Controller
@RequestMapping("/system/time")
public class TbEnrollmentTimeController extends BaseController
{
    private String prefix = "system/time";

    @Autowired
    private ITbEnrollmentTimeService tbEnrollmentTimeService;

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

    /**
     * 查询入学时间列表
     */
    @RequiresPermissions("system:time:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbEnrollmentTime tbEnrollmentTime)
    {
        startPage();
        List<TbEnrollmentTime> list = tbEnrollmentTimeService.selectTbEnrollmentTimeList(tbEnrollmentTime);
        return getDataTable(list);
    }

    /**
     * 查询入学时间列表
     */
    @RequiresPermissions("system:time:list")
    @PostMapping("/notPassList")
    @ResponseBody
    public TableDataInfo selectEnrollmentTimeNotPassList(TbEnrollmentTime tbEnrollmentTime)
    {
        startPage();
        List<TbEnrollmentTime> list = tbEnrollmentTimeService.selectEnrollmentTimeNotPassList(tbEnrollmentTime);
        return getDataTable(list);
    }

    /**
     * 导出入学时间列表
     */
    @RequiresPermissions("system:time:export")
    @Log(title = "入学时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbEnrollmentTime tbEnrollmentTime)
    {
        List<TbEnrollmentTime> list = tbEnrollmentTimeService.selectTbEnrollmentTimeList(tbEnrollmentTime);
        ExcelUtil<TbEnrollmentTime> util = new ExcelUtil<TbEnrollmentTime>(TbEnrollmentTime.class);
        return util.exportExcel(list, "入学时间数据");
    }

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

    /**
     * 新增保存入学时间
     */
    @RequiresPermissions("system:time:add")
    @Log(title = "入学时间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbEnrollmentTime tbEnrollmentTime)
    {
        tbEnrollmentTime.setCreator(getUserId());
        return toAjax(tbEnrollmentTimeService.insertTbEnrollmentTime(tbEnrollmentTime));
    }

    /**
     * 修改入学时间
     */
    @RequiresPermissions("system:time:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbEnrollmentTime tbEnrollmentTime = tbEnrollmentTimeService.selectTbEnrollmentTimeById(id);
        mmap.put("tbEnrollmentTime", tbEnrollmentTime);
        return prefix + "/edit";
    }

    /**
     * 修改保存入学时间
     */
    @RequiresPermissions("system:time:edit")
    @Log(title = "入学时间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbEnrollmentTime tbEnrollmentTime)
    {
        tbEnrollmentTime.setModifiedBy(getUserId());
        return toAjax(tbEnrollmentTimeService.updateTbEnrollmentTime(tbEnrollmentTime));
    }

    /**
     * 删除入学时间
     */
    @RequiresPermissions("system:time:remove")
    @Log(title = "入学时间", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbEnrollmentTimeService.deleteTbEnrollmentTimeByIds(ids));
    }

    /**
     * @Author : fanxiaolong
     * @Description :  根据学校id查询校区
     * @DateTime : 2022/9/7 10:51
     * @param : id
     * @return : java.util.List<java.lang.String>
     */
    @RequiresPermissions("system:time:list")
    @GetMapping("/selectSchool/{id}")
    @ResponseBody
    public List<TbSchool> selectSchoolCampusByID(@PathVariable Long id){

        return tbEnrollmentTimeService.selectSchoolCampusByID(id);
    }

    /**
     * @Author : fanxiaolong
     * @Description :  根据学校id查询专业信息
     * @DateTime : 2022/9/7 11:13
     * @param : id
     * @return : java.util.List<com.ruoyi.system.domain.TbSchoolMajor>
     */
    @RequiresPermissions("system:time:list")
    @GetMapping("/selectMajor/{id}")
    @ResponseBody
    public List<TbSchoolMajor> selectMajorBySchoolId(@PathVariable Long id){

        return tbEnrollmentTimeService.selectSchoolMajorBySchoolId(id);
    }

    @RequiresPermissions("system:time:list")
    @GetMapping("/selectDegree/{schoolId}/{majorCnName}")
    @ResponseBody
    public List<TbSchoolMajor> selectDegreeBySchooIdAndMajorName(@PathVariable String schoolId,@PathVariable String majorCnName){
        TbSchoolMajor tbSchoolMajor=new TbSchoolMajor();
        tbSchoolMajor.setSchoolId(schoolId);
        tbSchoolMajor.setMajorCnName(majorCnName);
        return tbEnrollmentTimeService.selectDegreeBySchooIdAndMajorName(tbSchoolMajor);
    }
}
