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.TbSchoolMajor;
import com.ruoyi.system.service.ITbSchoolMajorService;
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.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 学校专业Controller
 * 
 * @author ruoyi
 * @date 2022-08-29
 */
@Controller
@RequestMapping("/system/majorCheck")
public class SchoolMajorContentCheckController extends BaseController
{
    private String prefix = "system/major";

    @Autowired
    private ITbSchoolMajorService tbSchoolMajorService;

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

    /**
     * 查询学校专业列表
     */
    @RequiresPermissions("system:majorCheck:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbSchoolMajor tbSchoolMajor)
    {
        startPage();
        List<TbSchoolMajor> list = tbSchoolMajorService.selectTbSchoolMajorNotPassList(tbSchoolMajor);
        return getDataTable(list);
    }

    /**
     * 修改学校专业
     */
    @RequiresPermissions("system:majorCheck:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbSchoolMajor tbSchoolMajor = tbSchoolMajorService.selectTbSchoolMajorById(id);
        mmap.put("tbSchoolMajor", tbSchoolMajor);
        List<Long> checkedList=new ArrayList<>();
        Arrays.asList(tbSchoolMajor.getNeedMaterial().split(",")).stream().forEach(s -> {
            checkedList.add(Long.parseLong(s));
        });
        mmap.put("checkedList",checkedList);
        return prefix + "/editCheckStatus";
    }

    /**
     * 修改保存学校专业
     */
    @RequiresPermissions("system:majorCheck:edit")
    @Log(title = "学校专业", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbSchoolMajor tbSchoolMajor)
    {
        tbSchoolMajor.setChecker(getUserId());
        return toAjax(tbSchoolMajorService.updateTbSchoolMajorCheckResult(tbSchoolMajor));
    }

}
