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.FaultCase;
import com.phm.manage.service.IFaultCaseService;
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/faultCase")
public class FaultCaseController extends BaseController {
    @Autowired
    private IFaultCaseService faultCaseService;

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

    /**
     * 导出故障案例信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage: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('manage:faultCase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(faultCaseService.selectFaultCaseById(id));
    }

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

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

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