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.FaultDescription;
import com.goomood.phm.service.IFaultDescriptionService;
import com.goomood.common.utils.poi.ExcelUtil;
import com.goomood.common.core.page.TableDataInfo;

/**
 * 故障缺陷Controller
 * 
 * @author goomood
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/system/faultDescription")
public class FaultDescriptionController extends BaseController
{
    @Autowired
    private IFaultDescriptionService faultDescriptionService;

    /**
     * 查询故障缺陷列表
     */
    @PreAuthorize("@ss.hasPermi('system:faultDescription:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultDescription faultDescription)
    {
        startPage();
        List<FaultDescription> list = faultDescriptionService.selectFaultDescriptionList(faultDescription);
        return getDataTable(list);
    }

    /**
     * 导出故障缺陷列表
     */
    @PreAuthorize("@ss.hasPermi('system:faultDescription:export')")
    @Log(title = "故障缺陷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultDescription faultDescription)
    {
        List<FaultDescription> list = faultDescriptionService.selectFaultDescriptionList(faultDescription);
        ExcelUtil<FaultDescription> util = new ExcelUtil<FaultDescription>(FaultDescription.class);
        util.exportExcel(response, list, "故障缺陷数据");
    }

    /**
     * 获取故障缺陷详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:faultDescription:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultDescriptionService.selectFaultDescriptionById(id));
    }

    /**
     * 新增故障缺陷
     */
    @PreAuthorize("@ss.hasPermi('system:faultDescription:add')")
    @Log(title = "故障缺陷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultDescription faultDescription)
    {
        return toAjax(faultDescriptionService.insertFaultDescription(faultDescription));
    }

    /**
     * 修改故障缺陷
     */
    @PreAuthorize("@ss.hasPermi('system:faultDescription:edit')")
    @Log(title = "故障缺陷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultDescription faultDescription)
    {
        return toAjax(faultDescriptionService.updateFaultDescription(faultDescription));
    }

    /**
     * 删除故障缺陷
     */
    @PreAuthorize("@ss.hasPermi('system:faultDescription:remove')")
    @Log(title = "故障缺陷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faultDescriptionService.deleteFaultDescriptionByIds(ids));
    }
}
