package com.ruoyi.project.system.controller;

import java.util.Date;
import java.util.List;

import org.quartz.SchedulerException;
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.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.TAlarmtype;
import com.ruoyi.project.system.service.ITAlarmtypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 报警配置管理Controller
 *
 * @author ruoyi
 * @date 2020-12-30
 */
@RestController
@RequestMapping("/system/alarmtype")
public class TAlarmtypeController extends BaseController
{
    @Autowired
    private ITAlarmtypeService tAlarmtypeService;

    /**
     * 查询报警配置管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAlarmtype tAlarmtype)
    {
        startPage();
        List<TAlarmtype> list = tAlarmtypeService.selectTAlarmtypeList(tAlarmtype);
        return getDataTable(list);
    }

    /**
     * 导出报警配置管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:export')")
    @Log(title = "报警配置管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TAlarmtype tAlarmtype)
    {
        List<TAlarmtype> list = tAlarmtypeService.selectTAlarmtypeList(tAlarmtype);
        ExcelUtil<TAlarmtype> util = new ExcelUtil<TAlarmtype>(TAlarmtype.class);
        return util.exportExcel(list, "alarmtype");
    }

    /**
     * 获取报警配置管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tAlarmtypeService.selectTAlarmtypeById(id));
    }

    /**
     * 新增报警配置管理
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:add')")
    @Log(title = "报警配置管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAlarmtype tAlarmtype)
    {
        tAlarmtype.setCreaterCode(getUserId().toString());
        return toAjax(tAlarmtypeService.insertTAlarmtype(tAlarmtype));
    }

    /**
     * 修改报警配置管理
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:edit')")
    @Log(title = "报警配置管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAlarmtype tAlarmtype)
    {
        tAlarmtype.setUpdaterCode(getUserId().toString());
        tAlarmtype.setUpdatedate(new Date());
        return toAjax(tAlarmtypeService.updateTAlarmtype(tAlarmtype));
    }

    /**
     * 修改报警开启状态
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:edit')")
    @Log(title = "报警配置管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeAlarmStatus")
    public AjaxResult changeAlarmStatus(@RequestBody TAlarmtype tAlarmtype)
    {
//        TAlarmtype alarmtype = tAlarmtypeService.selectTAlarmtypeById(tAlarmtype.getId());
//        alarmtype.setIsOpen(tAlarmtype.getIsOpen());
        return toAjax(tAlarmtypeService.updateIsOpen(tAlarmtype));
    }

    /**
     * 删除报警配置管理
     */
    @PreAuthorize("@ss.hasPermi('system:alarmtype:remove')")
    @Log(title = "报警配置管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAlarmtypeService.deleteTAlarmtypeByIds(ids));
    }
}
