package com.yunfeiyun.agmp.fms.controller;

import java.util.List;

import com.yunfeiyun.agmp.fms.domain.FmsWarn;
import com.yunfeiyun.agmp.fms.domain.reqvo.FmsWarnReqVo;
import com.yunfeiyun.agmp.fms.domain.reqvo.FmsWarnStatusReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.FmsWarnResVo;
import com.yunfeiyun.agmp.fms.util.DataAuthUtil;
import com.yunfeiyun.agmp.fms.service.IFmsWarnService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 预警Controller
 * 
 * @author 杨晓辉
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/fms/warn")
public class FmsWarnController extends BaseController
{
    @Autowired
    private IFmsWarnService fmsWarnService;
    @Resource
    private DataAuthUtil dataAuthUtil;

    /**
     * 查询预警列表
     */
    @PreAuthorize("@ss.hasPermi('fms:warn:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsWarnReqVo fmsWarnReqVo)
    {
        fmsWarnReqVo.setBlockIds(dataAuthUtil.blockList());
        fmsWarnReqVo.setDataFilter(dataAuthUtil.isValidate());
        startPage();
        List<FmsWarnResVo> list = fmsWarnService.selectFmsWarnList(fmsWarnReqVo);
        return getDataTable(list);
    }

    /**
     * 获取预警详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:warn:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("warnId") String warnId)
    {
        return success(fmsWarnService.selectFmsWarnByWarnId(warnId));
    }

    /**
     * 新增预警
     */
    @PreAuthorize("@ss.hasPermi('fms:warn:add')")
    @Log(title = "预警", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FmsWarn fmsWarn)
    {
        return toAjax(fmsWarnService.insertFmsWarn(fmsWarn));
    }

    /**
     * 修改预警状态为已知晓
     */
    @PreAuthorize("@ss.hasPermi('fms:warn:edit:read')")
    @Log(title = "预警", businessType = BusinessType.UPDATE)
    @PutMapping("/edit/read")
    public AjaxResult edit(@RequestBody FmsWarnStatusReqVo fmsWarnStatusReqVo)
    {
        return toAjax(fmsWarnService.updateFmsWarnByStatus(fmsWarnStatusReqVo));
    }

    /**
     * 删除预警
     */
    @PreAuthorize("@ss.hasPermi('fms:warn:delete')")
    @Log(title = "预警", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{warnIds}")
    public AjaxResult remove(@PathVariable String[] warnIds)
    {
        return toAjax(fmsWarnService.deleteFmsWarnByWarnIds(warnIds));
    }
}
