package com.ruoyi.sim.controller;

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

import com.ruoyi.sim.service.impl.RealExamFaultService;
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.sim.domain.RealExamFault;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考试故障关联Controller
 *
 * @author tom
 * @date 2024-12-15
 */
@RestController
@RequestMapping("/sim/real-exam-fault")
public class RealExamFaultController extends BaseController {
    @Autowired
    private RealExamFaultService realExamFaultService;

    /**
     * 查询考试故障关联列表
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-fault:list')")
    @GetMapping("/list")
    public TableDataInfo list(RealExamFault realExamFault) {
        startPage();
        List<RealExamFault> list = realExamFaultService.selectRealExamFaultList(realExamFault);
        return getDataTable(list);
    }

    /**
     * 导出考试故障关联列表
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-fault:export')")
    @Log(title = "考试故障关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealExamFault realExamFault) {
        List<RealExamFault> list = realExamFaultService.selectRealExamFaultList(realExamFault);
        ExcelUtil<RealExamFault> util = new ExcelUtil<RealExamFault>(RealExamFault.class);
        util.exportExcel(response, list, "考试故障关联数据");
    }

    /**
     * 获取考试故障关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-fault:query')")
    @GetMapping(value = "/{refId}")
    public AjaxResult getInfo(@PathVariable("refId") Long refId) {
        return success(realExamFaultService.selectRealExamFaultByRefId(refId));
    }

    /**
     * 新增考试故障关联
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-fault:add')")
    @Log(title = "考试故障关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RealExamFault realExamFault) {
        return toAjax(realExamFaultService.insertRealExamFault(realExamFault));
    }

    /**
     * 修改考试故障关联
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-fault:edit')")
    @Log(title = "考试故障关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RealExamFault realExamFault) {
        return toAjax(realExamFaultService.updateRealExamFault(realExamFault));
    }

    /**
     * 删除考试故障关联
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-fault:remove')")
    @Log(title = "考试故障关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{refIds}")
    public AjaxResult remove(@PathVariable Long[] refIds) {
        return toAjax(realExamFaultService.deleteRealExamFaultByRefIds(refIds));
    }
}
