package com.ruoyi.sim.controller;

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

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

/**
 * 任务故障关联Controller
 *
 * @author tom
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/sim/task-fault")
public class TaskFaultController extends BaseController {
    @Autowired
    private TaskFaultService taskFaultService;

    /**
     * 查询任务故障关联列表
     */
    @PreAuthorize("@ss.hasPermi('sim:task-fault:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskFault taskFault) {
        startPage();
        List<TaskFault> list = taskFaultService.selectTaskFaultList(taskFault);
        return getDataTable(list);
    }

    /**
     * 导出任务故障关联列表
     */
    @PreAuthorize("@ss.hasPermi('sim:task-fault:export')")
    @Log(title = "任务故障关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskFault taskFault) {
        List<TaskFault> list = taskFaultService.selectTaskFaultList(taskFault);
        ExcelUtil<TaskFault> util = new ExcelUtil<TaskFault>(TaskFault.class);
        util.exportExcel(response, list, "任务故障关联数据");
    }

    /**
     * 获取任务故障关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('sim:task-fault:query')")
    @GetMapping(value = "/{relId}")
    public AjaxResult getInfo(@PathVariable("relId") Long relId) {
        return success(taskFaultService.selectTaskFaultByRelId(relId));
    }

    /**
     * 新增任务故障关联
     */
    @PreAuthorize("@ss.hasPermi('sim:task-fault:add')")
    @Log(title = "任务故障关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskFault taskFault) {
        return toAjax(taskFaultService.insertTaskFault(taskFault));
    }

    /**
     * 修改任务故障关联
     */
    @PreAuthorize("@ss.hasPermi('sim:task-fault:edit')")
    @Log(title = "任务故障关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskFault taskFault) {
        return toAjax(taskFaultService.updateTaskFault(taskFault));
    }

    /**
     * 删除任务故障关联
     */
    @PreAuthorize("@ss.hasPermi('sim:task-fault:remove')")
    @Log(title = "任务故障关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{relIds}")
    public AjaxResult remove(@PathVariable Long[] relIds) {
        return toAjax(taskFaultService.deleteTaskFaultByRelIds(relIds));
    }
}
