package com.ruoyi.web.controller.contentCheck;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbEnrollmentTime;
import com.ruoyi.system.domain.TbSchoolMajor;
import com.ruoyi.system.service.ITbEnrollmentTimeService;
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.*;

import java.util.List;

/**
 * 入学时间Controller
 * 
 * @author ruoyi
 * @date 2022-09-05
 */
@Controller
@RequestMapping("/system/checkTime")
public class EnrollmentTimeCheckController extends BaseController
{
    private String prefix = "system/time";

    @Autowired
    private ITbEnrollmentTimeService tbEnrollmentTimeService;

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

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

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

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

    /**
     * @Author : fanxiaolong
     * @Description :  根据学校id查询专业
     * @DateTime : 2022/9/7 10:51
     * @param : id
     * @return : java.util.List<java.lang.String>
     */
    @RequiresPermissions("system:checkTime:list")
    @GetMapping("/selectMajor/{id}")
    @ResponseBody
    public List<TbSchoolMajor> selectSchoolMajorBySchoolId(@PathVariable Long id){

        return tbEnrollmentTimeService.selectSchoolMajorBySchoolId(id);
    }

    @RequiresPermissions("system:checkTime: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);
    }
}
