package com.ruoyi.ems.record.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ems.record.domain.EmsRecordAlarmData;
import com.ruoyi.ems.record.service.IEmsRecordAlarmDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异常数据记录Controller
 * 
 * @author Yinq
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/ems/record/recordAlarmData")
public class EmsRecordAlarmDataController extends BaseController
{
    @Autowired
    private IEmsRecordAlarmDataService emsRecordAlarmDataService;

    /**
     * 查询异常数据记录列表
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmData:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsRecordAlarmData emsRecordAlarmData)
    {
        startPage();
        List<EmsRecordAlarmData> list = emsRecordAlarmDataService.selectEmsRecordAlarmDataList(emsRecordAlarmData);
        return getDataTable(list);
    }

    /**
     * 导出异常数据记录列表
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmData:export')")
    @Log(title = "异常数据记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsRecordAlarmData emsRecordAlarmData)
    {
        List<EmsRecordAlarmData> list = emsRecordAlarmDataService.selectEmsRecordAlarmDataList(emsRecordAlarmData);
        ExcelUtil<EmsRecordAlarmData> util = new ExcelUtil<EmsRecordAlarmData>(EmsRecordAlarmData.class);
        util.exportExcel(response, list, "异常数据记录数据");
    }

    /**
     * 获取异常数据记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmData:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsRecordAlarmDataService.selectEmsRecordAlarmDataByObjId(objId));
    }

    /**
     * 新增异常数据记录
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmData:add')")
    @Log(title = "异常数据记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsRecordAlarmData emsRecordAlarmData)
    {
        emsRecordAlarmData.setCreateBy(getUsername());
        return toAjax(emsRecordAlarmDataService.insertEmsRecordAlarmData(emsRecordAlarmData));
    }

    /**
     * 修改异常数据记录
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmData:edit')")
    @Log(title = "异常数据记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsRecordAlarmData emsRecordAlarmData)
    {
        emsRecordAlarmData.setUpdateBy(getUsername());
        return toAjax(emsRecordAlarmDataService.updateEmsRecordAlarmData(emsRecordAlarmData));
    }

    /**
     * 删除异常数据记录
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmData:remove')")
    @Log(title = "异常数据记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsRecordAlarmDataService.deleteEmsRecordAlarmDataByObjIds(objIds));
    }

    /**
     * 处理异常数据
     * @param objIds
     * @return
     */
    @PostMapping("/handleExceptions/{objIds}")
    public AjaxResult handleExceptions(@PathVariable Long[] objIds)
    {
        return toAjax(emsRecordAlarmDataService.handleExceptionsAlarmData(objIds));
    }

}
