package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.FaultAnalyzeResult;
import com.phm.manage.service.IFaultAnalyzeResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 故障分析结果Controller
 *
 * @author phm
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/manage/faultAnalyzeResult")
public class FaultAnalyzeResultController extends BaseController {
    @Autowired
    private IFaultAnalyzeResultService faultAnalyzeResultService;

    /**
     * 查询故障分析结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:faultAnalyzeResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultAnalyzeResult faultAnalyzeResult) {
        startPage();
        List<FaultAnalyzeResult> list = faultAnalyzeResultService.selectFaultAnalyzeResultList(faultAnalyzeResult);
        return getDataTable(list);
    }

    /**
     * 导出故障分析结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:faultAnalyzeResult:export')")
    @Log(title = "故障分析结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultAnalyzeResult faultAnalyzeResult) {
        List<FaultAnalyzeResult> list = faultAnalyzeResultService.selectFaultAnalyzeResultList(faultAnalyzeResult);
        ExcelUtil<FaultAnalyzeResult> util = new ExcelUtil<FaultAnalyzeResult>(FaultAnalyzeResult.class);
        util.exportExcel(response, list, "故障分析结果数据");
    }

    /**
     * 获取故障分析结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:faultAnalyzeResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(faultAnalyzeResultService.selectFaultAnalyzeResultById(id));
    }

    /**
     * 新增故障分析结果
     */
    @PreAuthorize("@ss.hasPermi('manage:faultAnalyzeResult:add')")
    @Log(title = "故障分析结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultAnalyzeResult faultAnalyzeResult) {
        return toAjax(faultAnalyzeResultService.insertFaultAnalyzeResult(faultAnalyzeResult));
    }

    /**
     * 修改故障分析结果
     */
    @PreAuthorize("@ss.hasPermi('manage:faultAnalyzeResult:edit')")
    @Log(title = "故障分析结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultAnalyzeResult faultAnalyzeResult) {
        return toAjax(faultAnalyzeResultService.updateFaultAnalyzeResult(faultAnalyzeResult));
    }

    /**
     * 删除故障分析结果
     */
    @PreAuthorize("@ss.hasPermi('manage:faultAnalyzeResult:remove')")
    @Log(title = "故障分析结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(faultAnalyzeResultService.deleteFaultAnalyzeResultByIds(ids));
    }
}
