package com.ruoyi.asset.controller;

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.asset.domain.TbFaultReport;
import com.ruoyi.asset.service.ITbFaultReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障报备Controller
 * 
 * @author 原动力
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/asset/fault")
public class TbFaultReportController extends BaseController
{
    @Autowired
    private ITbFaultReportService tbFaultReportService;

    /**
     * 查询故障报备列表
     */
    @PreAuthorize("@ss.hasPermi('asset:fault:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbFaultReport tbFaultReport)
    {
        startPage();
        List<TbFaultReport> list = tbFaultReportService.selectTbFaultReportList(tbFaultReport);
        return getDataTable(list);
    }

    /**
     * 导出故障报备列表
     */
    @PreAuthorize("@ss.hasPermi('asset:fault:export')")
    @Log(title = "故障报备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbFaultReport tbFaultReport)
    {
        List<TbFaultReport> list = tbFaultReportService.selectTbFaultReportList(tbFaultReport);
        ExcelUtil<TbFaultReport> util = new ExcelUtil<TbFaultReport>(TbFaultReport.class);
        util.exportExcel(response, list, "故障报备数据");
    }

    /**
     * 获取故障报备详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:fault:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbFaultReportService.selectTbFaultReportById(id));
    }

    /**
     * 新增故障报备
     */
    @PreAuthorize("@ss.hasPermi('asset:fault:add')")
    @Log(title = "故障报备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbFaultReport tbFaultReport)
    {
        return toAjax(tbFaultReportService.insertTbFaultReport(tbFaultReport));
    }

    /**
     * 修改故障报备
     */
    @PreAuthorize("@ss.hasPermi('asset:fault:edit')")
    @Log(title = "故障报备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbFaultReport tbFaultReport)
    {
        return toAjax(tbFaultReportService.updateTbFaultReport(tbFaultReport));
    }

    /**
     * 删除故障报备
     */
    @PreAuthorize("@ss.hasPermi('asset:fault:remove')")
    @Log(title = "故障报备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbFaultReportService.deleteTbFaultReportByIds(ids));
    }
}
