package com.ruoyi.sim.controller;

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

import com.ruoyi.sim.service.impl.RealExamCompRequestService;
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.RealExamCompRequest;
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-comp-request")
public class RealExamCompRequestController extends BaseController {
    @Autowired
    private RealExamCompRequestService realExamCompRequestService;

    /**
     * 查询考试更换件关联列表
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-comp-request:list')")
    @GetMapping("/list")
    public TableDataInfo list(RealExamCompRequest realExamCompRequest) {
        startPage();
        List<RealExamCompRequest> list = realExamCompRequestService.selectRealExamCompRequestList(realExamCompRequest);
        return getDataTable(list);
    }

    /**
     * 导出考试更换件关联列表
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-comp-request:export')")
    @Log(title = "考试更换件关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealExamCompRequest realExamCompRequest) {
        List<RealExamCompRequest> list = realExamCompRequestService.selectRealExamCompRequestList(realExamCompRequest);
        ExcelUtil<RealExamCompRequest> util = new ExcelUtil<RealExamCompRequest>(RealExamCompRequest.class);
        util.exportExcel(response, list, "考试更换件关联数据");
    }

    /**
     * 获取考试更换件关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-comp-request:query')")
    @GetMapping(value = "/{relId}")
    public AjaxResult getInfo(@PathVariable("relId") Long relId) {
        return success(realExamCompRequestService.selectRealExamCompRequestByRelId(relId));
    }

    /**
     * 新增考试更换件关联
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-comp-request:add')")
    @Log(title = "考试更换件关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RealExamCompRequest realExamCompRequest) {
        return toAjax(realExamCompRequestService.insertRealExamCompRequest(realExamCompRequest));
    }

    /**
     * 修改考试更换件关联
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-comp-request:edit')")
    @Log(title = "考试更换件关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RealExamCompRequest realExamCompRequest) {
        return toAjax(realExamCompRequestService.updateRealExamCompRequest(realExamCompRequest));
    }

    /**
     * 删除考试更换件关联
     */
    @PreAuthorize("@ss.hasPermi('sim:real-exam-comp-request:remove')")
    @Log(title = "考试更换件关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{relIds}")
    public AjaxResult remove(@PathVariable Long[] relIds) {
        return toAjax(realExamCompRequestService.deleteRealExamCompRequestByRelIds(relIds));
    }
}
