package com.goomood.phm.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.goomood.common.annotation.Log;
import com.goomood.common.core.controller.BaseController;
import com.goomood.common.core.domain.AjaxResult;
import com.goomood.common.enums.BusinessType;
import com.goomood.phm.domain.FaultCase;
import com.goomood.phm.service.IFaultCaseService;
import com.goomood.common.utils.poi.ExcelUtil;
import com.goomood.common.core.page.TableDataInfo;

/**
 * 故障案例Controller
 * 
 * @author goomood
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/fault/faultCase")
public class FaultCaseController extends BaseController
{
    @Autowired
    private IFaultCaseService faultCaseService;

    /**
     * 查询故障案例列表
     */
    @PreAuthorize("@ss.hasPermi('fault:faultCase:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultCase faultCase)
    {
        startPage();
        List<FaultCase> list = faultCaseService.selectFaultCaseList(faultCase);
        return getDataTable(list);
    }

    /**
     * 导出故障案例列表
     */
    @PreAuthorize("@ss.hasPermi('fault:faultCase:export')")
    @Log(title = "故障案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultCase faultCase)
    {
        List<FaultCase> list = faultCaseService.selectFaultCaseList(faultCase);
        ExcelUtil<FaultCase> util = new ExcelUtil<FaultCase>(FaultCase.class);
        util.exportExcel(response, list, "故障案例数据");
    }

    /**
     * 获取故障案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('fault:faultCase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultCaseService.selectFaultCaseById(id));
    }

    /**
     * 新增故障案例
     */
    @PreAuthorize("@ss.hasPermi('fault:faultCase:add')")
    @Log(title = "故障案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultCase faultCase)
    {
        return toAjax(faultCaseService.insertFaultCase(faultCase));
    }

    /**
     * 修改故障案例
     */
    @PreAuthorize("@ss.hasPermi('fault:faultCase:edit')")
    @Log(title = "故障案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultCase faultCase)
    {
        return toAjax(faultCaseService.updateFaultCase(faultCase));
    }

    /**
     * 删除故障案例
     */
    @PreAuthorize("@ss.hasPermi('fault:faultCase:remove')")
    @Log(title = "故障案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faultCaseService.deleteFaultCaseByIds(ids));
    }
}
