|
|
|
package com.zhonglai.luhui.admin.controller.iot;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
import com.ruoyi.system.domain.IotAlert;
|
|
|
|
import com.ruoyi.system.service.IIotAlertService;
|
|
|
|
import com.zhonglai.luhui.admin.dto.AlarmActionConfig;
|
|
|
|
import com.zhonglai.luhui.admin.dto.AlarmTriggersConfig;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
...
|
...
|
@@ -18,6 +23,7 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设备告警Controller
|
|
...
|
...
|
@@ -80,6 +86,14 @@ public class IotAlertController extends BaseController |
|
|
|
@PostMapping
|
|
|
|
public AjaxResult add(@RequestBody IotAlert alert)
|
|
|
|
{
|
|
|
|
if (checkTriggers(alert))
|
|
|
|
{
|
|
|
|
return AjaxResult.error("触发器参数必填");
|
|
|
|
}
|
|
|
|
if (checkActions(alert))
|
|
|
|
{
|
|
|
|
return AjaxResult.error("执行动作参数必填");
|
|
|
|
}
|
|
|
|
return toAjax(alertService.insertAlert(alert));
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -92,6 +106,14 @@ public class IotAlertController extends BaseController |
|
|
|
@PutMapping
|
|
|
|
public AjaxResult edit(@RequestBody IotAlert alert)
|
|
|
|
{
|
|
|
|
if (checkTriggers(alert))
|
|
|
|
{
|
|
|
|
return AjaxResult.error("触发器参数必填");
|
|
|
|
}
|
|
|
|
if (checkActions(alert))
|
|
|
|
{
|
|
|
|
return AjaxResult.error("执行动作参数必填");
|
|
|
|
}
|
|
|
|
return toAjax(alertService.updateAlert(alert));
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -106,4 +128,34 @@ public class IotAlertController extends BaseController |
|
|
|
{
|
|
|
|
return toAjax(alertService.deleteAlertByAlertIds(alertIds));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 检验触发器
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean checkTriggers(IotAlert alert)
|
|
|
|
{
|
|
|
|
String triggers = Optional.ofNullable(alert).orElse(new IotAlert()).getTriggers();
|
|
|
|
if(StringUtils.isNotEmpty(triggers))
|
|
|
|
{
|
|
|
|
AlarmTriggersConfig alarmTriggersConfig = JSONObject.parseObject(triggers, AlarmTriggersConfig.class);
|
|
|
|
return BeanUtil.hasNullField(alarmTriggersConfig,"cron");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 检验执行动作
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean checkActions(IotAlert alert)
|
|
|
|
{
|
|
|
|
String actions = Optional.ofNullable(alert).orElse(new IotAlert()).getActions();
|
|
|
|
if(StringUtils.isNotEmpty(actions))
|
|
|
|
{
|
|
|
|
AlarmActionConfig alarmActionConfig = JSONObject.parseObject(actions, AlarmActionConfig.class);
|
|
|
|
return BeanUtil.hasNullField(alarmActionConfig);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|