package com.agri.system.controller;

import com.agri.common.annotation.Log;
import com.agri.common.core.controller.BaseController;
import com.agri.common.core.domain.AjaxResult;
import com.agri.common.core.page.TableDataInfo;
import com.agri.common.enums.BusinessType;
import com.agri.common.utils.poi.ExcelUtil;
import com.agri.system.domain.SysAgriAlarmRelation;
import com.agri.system.service.ISysAgriAlarmRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 告警方式设置Controller
 * 
 * @author agri
 * @date 2026-01-08
 */
@RestController
@RequestMapping("/assets/alarm")
public class SysAgriAlarmRelationController extends BaseController
{
    @Autowired
    private ISysAgriAlarmRelationService sysAgriAlarmRelationService;

    /**
     * 查询告警方式设置列表
     */
    @PreAuthorize("@ss.hasPermi('assets:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAgriAlarmRelation sysAgriAlarmRelation)
    {
        startPage();
        List<SysAgriAlarmRelation> list = sysAgriAlarmRelationService.selectSysAgriAlarmRelationList(sysAgriAlarmRelation);
        return getDataTable(list);
    }

    /**
     * 导出告警方式设置列表
     */
    @PreAuthorize("@ss.hasPermi('assets:alarm:export')")
    @Log(title = "告警方式设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAgriAlarmRelation sysAgriAlarmRelation)
    {
        List<SysAgriAlarmRelation> list = sysAgriAlarmRelationService.selectSysAgriAlarmRelationList(sysAgriAlarmRelation);
        ExcelUtil<SysAgriAlarmRelation> util = new ExcelUtil<SysAgriAlarmRelation>(SysAgriAlarmRelation.class);
        util.exportExcel(response, list, "告警方式设置数据");
    }

    /**
     * 获取告警方式设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:alarm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysAgriAlarmRelationService.selectSysAgriAlarmRelationById(id));
    }

    /**
     * 新增告警方式设置
     */
    @PreAuthorize("@ss.hasPermi('assets:alarm:add')")
    @Log(title = "告警方式设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAgriAlarmRelation sysAgriAlarmRelation)
    {
        return toAjax(sysAgriAlarmRelationService.insertSysAgriAlarmRelation(sysAgriAlarmRelation));
    }

    /**
     * 修改告警方式设置
     */
    @PreAuthorize("@ss.hasPermi('assets:alarm:edit')")
    @Log(title = "告警方式设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAgriAlarmRelation sysAgriAlarmRelation)
    {
        return toAjax(sysAgriAlarmRelationService.updateSysAgriAlarmRelation(sysAgriAlarmRelation));
    }

    /**
     * 删除告警方式设置
     */
    @PreAuthorize("@ss.hasPermi('assets:alarm:remove')")
    @Log(title = "告警方式设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAgriAlarmRelationService.deleteSysAgriAlarmRelationByIds(ids));
    }
}
