package com.ruoyi.web.controller.oa;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oa.domain.CmcTrain;
import com.ruoyi.oa.service.ICmcTrainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训记录Controller
 * 
 * @author cmc
 * @date 2024-09-25
 */
@RestController
@RequestMapping("/oa/train")
public class CmcTrainController extends BaseController
{
    @Autowired
    private ICmcTrainService cmcTrainService;

    /**
     * 查询培训记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcTrain cmcTrain)
    {
        startPage();
        List<CmcTrain> list = cmcTrainService.selectCmcTrainList(cmcTrain);
        return getDataTable(list);
    }

    /**
     * 导出培训记录列表
     */
    @Log(title = "培训记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcTrain cmcTrain)
    {
        List<CmcTrain> list = cmcTrainService.selectCmcTrainList(cmcTrain);
        ExcelUtil<CmcTrain> util = new ExcelUtil<CmcTrain>(CmcTrain.class);
        util.exportExcel(response, list, "培训记录数据");
    }

    /**
     * 获取培训记录详细信息
     */
    @GetMapping(value = "/{trainId}")
    public AjaxResult getInfo(@PathVariable("trainId") Integer trainId)
    {
        return success(cmcTrainService.selectCmcTrainByTrainId(trainId));
    }

    /**
     * 新增培训记录
     */
    @Log(title = "培训记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcTrain cmcTrain)
    {
        return toAjax(cmcTrainService.insertCmcTrain(cmcTrain));
    }

    /**
     * 修改培训记录
     */
    @Log(title = "培训记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcTrain cmcTrain)
    {
        return success(cmcTrainService.updateCmcTrain(cmcTrain));
    }

    /**
     * 删除培训记录
     */
    @Log(title = "培训记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trainIds}")
    public AjaxResult remove(@PathVariable Integer[] trainIds)
    {
        return success(cmcTrainService.deleteCmcTrainByTrainIds(trainIds));
    }
}
