package com.ztmap.project.zhny.alarm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ztmap.framework.aspectj.lang.annotation.Log;
import com.ztmap.framework.aspectj.lang.enums.BusinessType;
import com.ztmap.project.zhny.alarm.domain.TAlarm;
import com.ztmap.project.zhny.alarm.service.ITAlarmService;
import com.ztmap.framework.web.controller.BaseController;
import com.ztmap.framework.web.domain.AjaxResult;
import com.ztmap.common.utils.poi.ExcelUtil;
import com.ztmap.framework.web.page.TableDataInfo;

/**
 * 告警Controller
 * 
 * @author ztmap
 * @date 2023-11-16
 */
@Controller
@RequestMapping("/zhny/alarm")
public class TAlarmController extends BaseController
{
    private String prefix = "zhny/alarm";

    @Autowired
    private ITAlarmService tAlarmService;

    @RequiresPermissions("zhny:alarm:view")
    @GetMapping()
    public String alarm()
    {
        return prefix + "/alarm";
    }

    /**
     * 查询告警列表
     */
    @RequiresPermissions("zhny:alarm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TAlarm tAlarm)
    {
        startPage();
        List<TAlarm> list = tAlarmService.selectTAlarmList(tAlarm);
        return getDataTable(list);
    }

    /**
     * 导出告警列表
     */
    @RequiresPermissions("zhny:alarm:export")
    @Log(title = "告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TAlarm tAlarm)
    {
        List<TAlarm> list = tAlarmService.selectTAlarmList(tAlarm);
        ExcelUtil<TAlarm> util = new ExcelUtil<TAlarm>(TAlarm.class);
        return util.exportExcel(list, "告警数据");
    }

    /**
     * 新增告警
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存告警
     */
    @RequiresPermissions("zhny:alarm:add")
    @Log(title = "告警", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TAlarm tAlarm)
    {
        return toAjax(tAlarmService.insertTAlarm(tAlarm));
    }

    /**
     * 修改告警
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TAlarm tAlarm = tAlarmService.selectTAlarmById(id);
        mmap.put("tAlarm", tAlarm);
        return prefix + "/edit";
    }

    /**
     * 修改保存告警
     */
    @RequiresPermissions("zhny:alarm:edit")
    @Log(title = "告警", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAlarm tAlarm)
    {
        return toAjax(tAlarmService.updateTAlarm(tAlarm));
    }

    /**
     * 删除告警
     */
    @RequiresPermissions("zhny:alarm:remove")
    @Log(title = "告警", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tAlarmService.deleteTAlarmByIds(ids));
    }
}
