package com.ruoyi.traceability.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.traceability.domain.BaseAlarminfo;
import com.ruoyi.traceability.service.IBaseAlarminfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 报警信息Controller
 * 
 * @author wenjy
 * @date 2023-01-01
 */
@Controller
@RequestMapping("/traceability/alarminfo")
public class BaseAlarminfoController extends BaseController
{
    private String prefix = "traceability/alarminfo";

    @Autowired
    private IBaseAlarminfoService baseAlarminfoService;

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

    /**
     * 查询报警信息列表
     */
    @RequiresPermissions("traceability:alarminfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseAlarminfo baseAlarminfo)
    {
        startPage();
        List<BaseAlarminfo> list = baseAlarminfoService.selectBaseAlarminfoList(baseAlarminfo);
        return getDataTable(list);
    }

    /**
     * 导出报警信息列表
     */
    @RequiresPermissions("traceability:alarminfo:export")
    @Log(title = "报警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseAlarminfo baseAlarminfo)
    {
        List<BaseAlarminfo> list = baseAlarminfoService.selectBaseAlarminfoList(baseAlarminfo);
        ExcelUtil<BaseAlarminfo> util = new ExcelUtil<BaseAlarminfo>(BaseAlarminfo.class);
        return util.exportExcel(list, "报警信息数据");
    }

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

    /**
     * 新增保存报警信息
     */
    @RequiresPermissions("traceability:alarminfo:add")
    @Log(title = "报警信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseAlarminfo baseAlarminfo)
    {
        return toAjax(baseAlarminfoService.insertBaseAlarminfo(baseAlarminfo));
    }

    /**
     * 修改报警信息
     */
    @RequiresPermissions("traceability:alarminfo:edit")
    @GetMapping("/edit/{objId}")
    public String edit(@PathVariable("objId") Long objId, ModelMap mmap)
    {
        BaseAlarminfo baseAlarminfo = baseAlarminfoService.selectBaseAlarminfoByObjId(objId);
        mmap.put("baseAlarminfo", baseAlarminfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警信息
     */
    @RequiresPermissions("traceability:alarminfo:edit")
    @Log(title = "报警信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseAlarminfo baseAlarminfo)
    {
        return toAjax(baseAlarminfoService.updateBaseAlarminfo(baseAlarminfo));
    }

    /**
     * 删除报警信息
     */
    @RequiresPermissions("traceability:alarminfo:remove")
    @Log(title = "报警信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseAlarminfoService.deleteBaseAlarminfoByObjIds(ids));
    }

    @Log(title = "报警信息", businessType = BusinessType.IMPORT)
    @RequiresPermissions("traceability:alarminfo:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BaseAlarminfo> util = new ExcelUtil<BaseAlarminfo>(BaseAlarminfo.class);
        List<BaseAlarminfo> alarminfoList = util.importExcel(file.getInputStream());
        String message = baseAlarminfoService.importAlarmInfo(alarminfoList, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @RequiresPermissions("traceability:alarminfo:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<BaseAlarminfo> util = new ExcelUtil<BaseAlarminfo>(BaseAlarminfo.class);
        return util.importTemplateExcel("报警信息");
    }
}
