package com.ruoyi.web.controller.staffTrainTime;

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.staffTrainTime.StaffTrainTime;
import com.ruoyi.system.service.IStaffTrainTimeService;
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-21
 */
@RestController
@RequestMapping("/wuYe/staffTrainTime")
public class StaffTrainTimeController extends BaseController {
    @Autowired
    private IStaffTrainTimeService staffTrainTimeService;

    /**
     * 查询员工培训时长列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staffTrainTime:list')")
    @GetMapping("/list")
    public TableDataInfo list(StaffTrainTime staffTrainTime) {
        List<StaffTrainTime> list = staffTrainTimeService.selectStaffTrainTimeList(staffTrainTime);
        return getDataTable(list);
    }

    /**
     * 导出员工培训时长列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staffTrainTime:export')")
    @Log(title = "员工培训时长", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StaffTrainTime staffTrainTime) {
        List<StaffTrainTime> list = staffTrainTimeService.selectStaffTrainTimeList(staffTrainTime);
        ExcelUtil<StaffTrainTime> util = new ExcelUtil<StaffTrainTime>(StaffTrainTime.class);
        util.exportExcel(response, list, "员工培训时长数据");
    }

    /**
     * 获取员工培训时长详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staffTrainTime:query')")
    @GetMapping(value = "/{trainTimeId}")
    public AjaxResult getInfo(@PathVariable("trainTimeId") Long trainTimeId) {
        return success(staffTrainTimeService.selectStaffTrainTimeByTrainTimeId(trainTimeId));
    }

    /**
     * 新增员工培训时长
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staffTrainTime:add')")
    @Log(title = "员工培训时长", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StaffTrainTime staffTrainTime) {
        return toAjax(staffTrainTimeService.insertStaffTrainTime(staffTrainTime));
    }

    /**
     * 修改员工培训时长
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staffTrainTime:edit')")
    @Log(title = "员工培训时长", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody StaffTrainTime staffTrainTime) {
        return toAjax(staffTrainTimeService.updateStaffTrainTime(staffTrainTime));
    }

    /**
     * 删除员工培训时长
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staffTrainTime:remove')")
    @Log(title = "员工培训时长", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{trainTimeIds}")
    public AjaxResult remove(@PathVariable Long[] trainTimeIds) {
        return toAjax(staffTrainTimeService.deleteStaffTrainTimeByTrainTimeIds(trainTimeIds));
    }
}
