package com.ruoyi.web.controller.staffTrain;

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.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.staffTrain.StaffTrainManual;
import com.ruoyi.system.service.IStaffTrainManualService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 员工培训手册Controller
 *
 * @author boman
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/wuYe/manual")
public class StaffTrainManualController extends BaseController {
    @Autowired
    private IStaffTrainManualService staffTrainManualService;

    /**
     * 查询员工培训手册列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:list')")
    @GetMapping("/list")
    public TableDataInfo list(StaffTrainManual staffTrainManual) {
        startPage();
        List<StaffTrainManual> list = staffTrainManualService.selectStaffTrainManualList(staffTrainManual);
        return getDataTable(list);
    }


    /**
     * 导出员工培训手册列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:export')")
    @Log(title = "员工培训手册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StaffTrainManual staffTrainManual) {
        List<StaffTrainManual> list = staffTrainManualService.selectStaffTrainManualList(staffTrainManual);
        ExcelUtil<StaffTrainManual> util = new ExcelUtil<StaffTrainManual>(StaffTrainManual.class);
        util.exportExcel(response, list, "员工培训手册数据");
    }

    /**
     * 获取员工培训手册详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:query')")
    @GetMapping(value = "/{manualId}")
    public AjaxResult getInfo(@PathVariable("manualId") Long manualId) {
        return success(staffTrainManualService.selectStaffTrainManualByManualId(manualId));
    }


    /**
     * 获取已读人员名单
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:getRead')")
    @PostMapping(value = "/getRead")
    public AjaxResult getRead(@RequestBody StaffTrainManual staffTrainManual) {
        return staffTrainManualService.getRead(staffTrainManual);
    }

    /**
     * 新增员工培训手册
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:add')")
    @Log(title = "员工培训手册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StaffTrainManual staffTrainManual) {
        return toAjax(staffTrainManualService.insertStaffTrainManual(staffTrainManual));
    }

    /**
     * 修改员工培训手册
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:edit')")
    @Log(title = "员工培训手册", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody StaffTrainManual staffTrainManual) {
        return toAjax(staffTrainManualService.updateStaffTrainManual(staffTrainManual));
    }

    /**
     * 删除员工培训手册
     */
    @PreAuthorize("@ss.hasPermi('wuYe:manual:remove')")
    @Log(title = "员工培训手册", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{manualIds}")
    public AjaxResult remove(@PathVariable Long[] manualIds) {
        return toAjax(staffTrainManualService.deleteStaffTrainManualByManualIds(manualIds));
    }
}
