package com.ruoyi.web.controller.system.system;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
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.TdTrain;
import com.ruoyi.system.service.ITdTrainService;
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 2024-04-11
 */
@Controller
@RequestMapping("/system/train")
public class TdTrainController extends BaseController
{
    private String prefix = "system/train";

    @Autowired
    private ITdTrainService tdTrainService;

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

    /**
     * 查询涉密人员培训列表
     */
    @RequiresPermissions("system:train:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdTrain tdTrain)
    {
        startPage();
        List<TdTrain> list = tdTrainService.selectTdTrainList(tdTrain);
        return getDataTable(list);
    }

    /**
     * 导出涉密人员培训列表
     */
    @RequiresPermissions("system:train:export")
    @Log(title = "涉密人员培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdTrain tdTrain)
    {
        List<TdTrain> list = tdTrainService.selectTdTrainList(tdTrain);
        ExcelUtil<TdTrain> util = new ExcelUtil<TdTrain>(TdTrain.class);
        return util.exportExcel(list, "涉密人员培训数据");
    }

    /**
     * 新增涉密人员培训
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存涉密人员培训
     */
    @RequiresPermissions("system:train:add")
    @Log(title = "涉密人员培训", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdTrain tdTrain)
    {
        tdTrain.setCreateStaffid(getLoginName());
        tdTrain.setCreateDate(new Date());
        tdTrain.setCreateDepartid(String.valueOf(getSysUser().getDeptId()));
        return toAjax(tdTrainService.insertTdTrain(tdTrain));
    }

    /**
     * 修改涉密人员培训
     */
    @RequiresPermissions("system:train:edit")
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {

        TdTrain tdTrain = tdTrainService.selectTdTrainByID(ID);
        mmap.put("tdTrain", tdTrain);
        return prefix + "/edit";
    }

    /**
     * 修改保存涉密人员培训
     */
    @RequiresPermissions("system:train:edit")
    @Log(title = "涉密人员培训", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdTrain tdTrain)
    {
        tdTrain.setUpdateStaffid(getLoginName());
        tdTrain.setUpdateDate(new Date());
        tdTrain.setUpdateDepartid(String.valueOf(getSysUser().getDeptId()));
        return toAjax(tdTrainService.updateTdTrain(tdTrain));
    }

    /**
     * 删除涉密人员培训
     */
    @RequiresPermissions("system:train:remove")
    @Log(title = "涉密人员培训", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tdTrainService.deleteTdTrainByIDs(ids));
    }

    /**
     * 培训记录详情
     */
    @RequiresPermissions("system:train:detail")
    @GetMapping("/detail/{ID}")
    public String detail(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        mmap.put("tdTrain", tdTrainService.selectTdTrainByID(ID));
        SysUser user = getSysUser();
        mmap.put("user", user);
        return prefix + "/detail";
    }

    /**
     * 审核涉密人员培训
     */
    @RequiresPermissions("system:train:examine")
    @GetMapping("/examine/{ID}")
    public String examine(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        TdTrain tdTrain = tdTrainService.selectTdTrainByID(ID);
        SysUser user = getSysUser();
        mmap.put("tdTrain", tdTrain);
        mmap.put("user", user);
        return prefix + "/examine";
    }

    /**
     * 修改保存涉密人员培训
     */
    @RequiresPermissions("system:train:examine")
    @Log(title = "涉密人员培训", businessType = BusinessType.EXAMINE)
    @PostMapping("/examine")
    @ResponseBody
    public AjaxResult examineSave(TdTrain tdTrain)
    {
        return toAjax(tdTrainService.updateTdTrain(tdTrain));
    }
}
