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

/**
 * 预警设置Controller
 * 
 * @author goomood
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/fault/faultSetting")
public class FaultSettingController extends BaseController
{
    @Autowired
    private IFaultSettingService faultSettingService;

    /**
     * 查询预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('fault:faultSetting:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultSetting faultSetting)
    {
        startPage();
        List<FaultSetting> list = faultSettingService.selectFaultSettingList(faultSetting);
        return getDataTable(list);
    }

    /**
     * 导出预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('fault:faultSetting:export')")
    @Log(title = "预警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultSetting faultSetting)
    {
        List<FaultSetting> list = faultSettingService.selectFaultSettingList(faultSetting);
        ExcelUtil<FaultSetting> util = new ExcelUtil<FaultSetting>(FaultSetting.class);
        util.exportExcel(response, list, "预警设置数据");
    }

    /**
     * 获取预警设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('fault:faultSetting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultSettingService.selectFaultSettingById(id));
    }

    /**
     * 新增预警设置
     */
    @PreAuthorize("@ss.hasPermi('fault:faultSetting:add')")
    @Log(title = "预警设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultSetting faultSetting)
    {
        return toAjax(faultSettingService.insertFaultSetting(faultSetting));
    }

    /**
     * 修改预警设置
     */
    @PreAuthorize("@ss.hasPermi('fault:faultSetting:edit')")
    @Log(title = "预警设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultSetting faultSetting)
    {
        return toAjax(faultSettingService.updateFaultSetting(faultSetting));
    }

    /**
     * 删除预警设置
     */
    @PreAuthorize("@ss.hasPermi('fault:faultSetting:remove')")
    @Log(title = "预警设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faultSettingService.deleteFaultSettingByIds(ids));
    }
}
