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.TbMaterialDemo;
import com.ruoyi.system.service.ITbMaterialDemoService;
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-31
 */
@Controller
@RequestMapping("/system/checkDemo")
public class MaterialDemoCheckController extends BaseController
{
    private String prefix = "system/demo";

    @Autowired
    private ITbMaterialDemoService tbMaterialDemoService;

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

    @GetMapping("/queryAll")
    public List<TbMaterialDemo> queryAll(){
        return tbMaterialDemoService.queryAll();
    }

    /**
     * 查询材料样例列表
     */
    @RequiresPermissions("system:checkDemo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbMaterialDemo tbMaterialDemo)
    {
        startPage();
        List<TbMaterialDemo> list = tbMaterialDemoService.selectMaterialDemoNotPassList(tbMaterialDemo);
        return getDataTable(list);
    }

    /**
     * 修改材料样例
     */
    @RequiresPermissions("system:checkDemo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbMaterialDemo tbMaterialDemo = tbMaterialDemoService.selectTbMaterialDemoById(id);
        mmap.put("tbMaterialDemo", tbMaterialDemo);
        return prefix + "/editCheckStatus";
    }

    /**
     * 修改保存材料样例
     */
    @RequiresPermissions("system:checkDemo:edit")
    @Log(title = "材料样例", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbMaterialDemo tbMaterialDemo)
    {
        tbMaterialDemo.setChecker(getUserId());
        return toAjax(tbMaterialDemoService.updateCheckStatus(tbMaterialDemo));
    }

}
