package com.ruoyi.model.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.model.domain.Examination;
import com.ruoyi.model.service.IExaminationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/model/examination")
public class ExaminationController extends BaseController
{
    @Autowired
    private IExaminationService examinationService;

    /**
     * 查询考核列表
     */
    @PreAuthorize("@ss.hasPermi('model:examination:list')")
    @GetMapping("/list")
    public TableDataInfo list(Examination examination)
    {
        startPage();
        List<Examination> list = examinationService.selectExaminationList(examination);
        return getDataTable(list);
    }

    /**
     * 导出考核列表
     */
    @PreAuthorize("@ss.hasPermi('model:examination:export')")
    @Log(title = "考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Examination examination) throws IOException {
        List<Examination> list = examinationService.selectExaminationList(examination);
        ExcelUtil<Examination> util = new ExcelUtil<Examination>(Examination.class);
        util.exportExcel(response, list, "考核数据");
    }

    /**
     * 获取考核详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:examination:query')")
    @GetMapping(value = "/{examinationId}")
    public AjaxResult getInfo(@PathVariable("examinationId") Long examinationId)
    {
        return success(examinationService.selectExaminationByExaminationId(examinationId));
    }

    /**
     * 新增考核
     */
    @PreAuthorize("@ss.hasPermi('model:examination:add')")
    @Log(title = "考核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Examination examination)
    {
        return toAjax(examinationService.insertExamination(examination));
    }

    /**
     * 修改考核
     */
    @PreAuthorize("@ss.hasPermi('model:examination:edit')")
    @Log(title = "考核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Examination examination)
    {
        return toAjax(examinationService.updateExamination(examination));
    }

    /**
     * 删除考核
     */
    @PreAuthorize("@ss.hasPermi('model:examination:remove')")
    @Log(title = "考核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examinationIds}")
    public AjaxResult remove(@PathVariable Long[] examinationIds)
    {
        return toAjax(examinationService.deleteExaminationByExaminationIds(examinationIds));
    }
}
