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

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.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TdTrain;
import com.ruoyi.system.service.ITdTrainService;
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
@RequestMapping("/system/trainnum")
public class SysTrainnumController extends BaseController {
    private String prefix = "system/trainnum";
    @Autowired
    private ITdTrainService tdTrainService;

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

    /**
     * 培训列表
     * @param tdTrain
     * @return
     */
    @RequiresPermissions("system:trainnum:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdTrain tdTrain)
    {
        startPage();
        List<TdTrain> list = tdTrainService.selectTdTrainList(tdTrain);
        return getDataTable(list);
    }

    /**
     * 导出培训数据
     * @param tdTrain
     * @return
     */
    @Log(title = "培训统计", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:trainnum: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, "培训统计数据");
    }

    /**
     * 详细
     */
    @RequiresPermissions("system:trainnum: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";
    }

}
