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.TbSchool;
import com.ruoyi.system.service.ITbSchoolService;
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-08-29
 */
@Controller
@RequestMapping("/system/schoolCheck")
public class SchoolContentCheckController extends BaseController
{
    private String prefix = "system/school";

    @Autowired
    private ITbSchoolService tbSchoolService;

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

    /**
     * @Author : fanxiaolong
     * @Description :  分页查询所有未通过审核或待审核的学校信息
     * @DateTime : 2022/9/2 17:09
     * @param : tbSchool
     * @return : com.ruoyi.common.core.page.TableDataInfo
     */
    @RequiresPermissions("system:schoolCheck:list")
    @PostMapping("/notPassList")
    @ResponseBody
    public TableDataInfo selectTbSchoolNotPassList(TbSchool tbSchool){

        startPage();
        List<TbSchool> list = tbSchoolService.selectTbSchoolNotPassList(tbSchool);
        return getDataTable(list);
    }

    /**
     * 查询学校信息列表
     */
    @RequiresPermissions("system:schoolCheck:list")
    @GetMapping("/getList")
    @ResponseBody
    public List<TbSchool> getList()
    {
        List<TbSchool> list = tbSchoolService.selectAllTbSchoolList();
        return list;
    }

    /**
     * 修改学校信息
     */
    @RequiresPermissions("system:schoolCheck:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbSchool tbSchool = tbSchoolService.selectTbSchoolById(id);
        mmap.put("tbSchool", tbSchool);
        return prefix + "/editCheckStatus";
    }

    /**
     * @Author : fanxiaolong
     * @Description :  修改审核状态，审核结果
     * @DateTime : 2022/9/5 9:59
     * @param : tbSchool
     * @return : com.ruoyi.common.core.domain.AjaxResult
     */
    @RequiresPermissions("system:schoolCheck:edit")
    @Log(title = "学校信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editCheckStatus")
    @ResponseBody
    public AjaxResult updateCheckStatus(TbSchool tbSchool){

        tbSchool.setChecker(getUserId());
        return toAjax(tbSchoolService.updateCheckStatus(tbSchool));
    }

}
