package com.aidex.web.controller.system;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.framework.cache.DictUtils;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.system.domain.SysAlarm;
import com.aidex.system.service.SysAlarmService;

/**
 * 报警信息Controller
 * @author ChenSir
 * @email 914769835
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/system/sysAlarm")
public class SysAlarmController extends BaseController {

    @Autowired
    private SysAlarmService sysAlarmService;

    /**
     * 查询报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysAlarm:list')")
    @GetMapping("/list")
    public R<PageInfo> list(SysAlarm sysAlarm, HttpServletRequest request, HttpServletResponse response) {
        sysAlarm.setPage(new PageDomain(request, response));
        return R.data(sysAlarmService.findPage(sysAlarm));
    }

    /**
     * 获取报警信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysAlarm:query')")
    @GetMapping(value = "/{id}")
    public R<SysAlarm> detail(@PathVariable("id") String id) {
        return R.data(sysAlarmService.get(id));
    }

    /**
     * 新增报警信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysAlarm:add')")
    @Log(title = "报警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  SysAlarm sysAlarm) {
        return R.status(sysAlarmService.save(sysAlarm));
    }

    /**
     * 修改报警信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysAlarm:edit')")
    @Log(title = "报警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SysAlarm sysAlarm) {
        return R.status(sysAlarmService.save(sysAlarm));
    }

    /**
     * 删除报警信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysAlarm:remove')")
    @Log(title = "报警信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(sysAlarmService.deleteSysAlarmByIds(ids));
    }


    /**
     * 导出报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysAlarm:export')")
    @Log(title = "报警信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SysAlarm sysAlarm) {
        List<SysAlarm> list = sysAlarmService.findList(sysAlarm);
        ExcelUtil<SysAlarm> util = new ExcelUtil<SysAlarm>(SysAlarm.class);
        return util.exportExcel(list, "报警信息数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
