作者 钟来

告警系统功能完善

正在显示 18 个修改的文件 包含 461 行增加27 行删除
... ... @@ -37,8 +37,6 @@ public abstract class JwtAuthenticationTokenFilter extends OncePerRequestFilter
UsernamePasswordAuthenticationToken authenticationToken = getUsernamePasswordAuthenticationToken(loginUser);
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}else {
throw new ServiceException("token验证失败");
}
chain.doFilter(request, response);
... ...
... ... @@ -16,7 +16,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
* app接口安全策略. 没有{@link Order}注解优先级比上面低
*/
@Configuration
@Order(1)
public class AdminConfigurerAdapter extends DefaultSecurityConfig {
@Autowired
... ...
package com.zhonglai.luhui.alarm.clas;
import com.zhonglai.luhui.alarm.dto.IotAlertNoticeChannel;
import com.zhonglai.luhui.alarm.dto.IotAlertUserNotice;
import java.io.Serializable;
import java.lang.reflect.Field;
import static com.zhonglai.luhui.alarm.config.CachAlarmConfig.user_alarm_config;
import static com.zhonglai.luhui.alarm.config.CachAlarmConfig.user_alarm_notice_channel;
/**
* 告警通知渠道配置
*/
public class IotAlertNoticeChannelUpCach extends UpAlarmFactory<IotAlertNoticeChannel> implements Serializable {
public IotAlertNoticeChannelUpCach(IotAlertNoticeChannel beforeupAlarmDb, IotAlertNoticeChannel afterupAlarmDb) {
super(beforeupAlarmDb, afterupAlarmDb);
}
@Override
void deleteGenerateAlarm() {
user_alarm_notice_channel.remove(beforeupAlarmDb.getId());
}
@Override
void insertGenerateAlarm() {
user_alarm_notice_channel.put(afterupAlarmDb.getId(),afterupAlarmDb);
}
@Override
void updateGenerateAlarm() {
Integer key = beforeupAlarmDb.getId();
IotAlertNoticeChannel iotAlertNoticeChannel = user_alarm_notice_channel.get(key);
if(null == iotAlertNoticeChannel)
{
insertGenerateAlarm();
}else {
Field[] fields = afterupAlarmDb.getClass().getDeclaredFields();
for (Field field:fields)
{
field.setAccessible(true);
Object value = null;
try {
value = field.get(afterupAlarmDb);
if (value!= null) {
field.set(iotAlertNoticeChannel, value);
}
} catch (IllegalAccessException e) {
logger.info("告警通知缓存更新失败【{}】,【{}】",afterupAlarmDb,beforeupAlarmDb);
logger.error("告警通知缓存更新失败",e);
return;
}
}
}
user_alarm_notice_channel.put(key,iotAlertNoticeChannel);
}
@Override
Object getNowValue(Object model_name, Integer type) {
return null;
}
}
... ...
package com.zhonglai.luhui.alarm.clas;
import com.zhonglai.luhui.alarm.dto.IotAlertNoticeChannel;
import com.zhonglai.luhui.alarm.dto.IotAlertUserNotice;
import java.io.Serializable;
import java.lang.reflect.Field;
import static com.zhonglai.luhui.alarm.config.CachAlarmConfig.user_alarm_config;
public class IotAlertUserNoticeUpCack extends UpAlarmFactory<IotAlertUserNotice> implements Serializable {
public IotAlertUserNoticeUpCack(IotAlertUserNotice beforeupAlarmDb, IotAlertUserNotice afterupAlarmDb) {
super(beforeupAlarmDb, afterupAlarmDb);
}
@Override
void deleteGenerateAlarm() {
String key = beforeupAlarmDb.getUser_id()+"|"+beforeupAlarmDb.getType();
user_alarm_config.remove(key);
}
@Override
void insertGenerateAlarm() {
String key = afterupAlarmDb.getUser_id()+"|"+afterupAlarmDb.getType();
user_alarm_config.put(key,afterupAlarmDb);
}
@Override
void updateGenerateAlarm() {
String key = beforeupAlarmDb.getUser_id()+"|"+beforeupAlarmDb.getType();
IotAlertUserNotice iotAlertUserNotice = user_alarm_config.get(key);
if(null == iotAlertUserNotice)
{
insertGenerateAlarm();
}else {
Field[] fields = afterupAlarmDb.getClass().getDeclaredFields();
for (Field field:fields)
{
field.setAccessible(true);
Object value = null;
try {
value = field.get(afterupAlarmDb);
if (value!= null) {
field.set(iotAlertUserNotice, value);
}
} catch (IllegalAccessException e) {
logger.info("告警通知缓存更新失败【{}】,【{}】",afterupAlarmDb,beforeupAlarmDb);
logger.error("告警通知缓存更新失败",e);
return;
}
}
}
user_alarm_config.remove(key);
key = afterupAlarmDb.getUser_id()+"|"+afterupAlarmDb.getType();
user_alarm_config.put(key,iotAlertUserNotice);
}
@Override
Object getNowValue(Object model_name, Integer type) {
return null;
}
}
... ...
... ... @@ -19,7 +19,7 @@ import java.util.List;
* 告警工厂
*/
public abstract class UpAlarmFactory<T> {
private static final Logger logger = LoggerFactory.getLogger(UpAlarmFactory.class);
protected static final Logger logger = LoggerFactory.getLogger(UpAlarmFactory.class);
protected List<IotAlertLog> list = new ArrayList<>();
protected T beforeupAlarmDb;
... ... @@ -46,6 +46,13 @@ public abstract class UpAlarmFactory<T> {
return new IotTerminalAlarm(IotTerminal.instantiate(beforecolumns),IotTerminal.instantiate(aftercolumns));
case "mqtt_broker.iot_alert":
return new IotAlertAlarm(IotAlert.instantiate(beforecolumns),IotAlert.instantiate(aftercolumns));
case "mqtt_broker.iot_alert_notice_channel":
return new IotAlertNoticeChannelUpCach(IotAlertNoticeChannel.instantiate(beforecolumns),IotAlertNoticeChannel.instantiate(aftercolumns));
case "mqtt_broker.iot_alert_user_notice":
return new IotAlertUserNoticeUpCack(IotAlertUserNotice.instantiate(beforecolumns),IotAlertUserNotice.instantiate(aftercolumns));
case "mqtt_broker.user_openid":
return new UserOpenidUpCach(UserOpenid.instantiate(beforecolumns),UserOpenid.instantiate(aftercolumns));
}
return null;
}
... ... @@ -75,6 +82,10 @@ public abstract class UpAlarmFactory<T> {
protected void valueUp(String client_id,Integer product_id,String oldvalue,String newValue,Integer user_id,String device_name)
{
if ("864814074929612".equals(client_id))
{
System.out.println(client_id);
}
if(StringUtils.isNotEmpty(newValue))
{
JSONObject oldjson = null==oldvalue?new JSONObject():JSONObject.parseObject(oldvalue);
... ... @@ -129,7 +140,7 @@ public abstract class UpAlarmFactory<T> {
String alrmname = attributeTriggers.getValueMapName().get(newValue);
if(StringUtils.isNotEmpty(alrmname))
{
IotAlertLog iotAlertLog = new IotAlertLog(iotAlert.getAlertId(),alrmname,iotAlert.getAlertLevel().intValue(),2,client_id,System.currentTimeMillis(),1,iotAlert.getUser_id() ,device_name,null==iotAlert.getUser_id()?1:2);
IotAlertLog iotAlertLog = new IotAlertLog(iotAlert.getAlertId(),alrmname,iotAlert.getAlertLevel().intValue(),2,client_id,System.currentTimeMillis(),1,user_id ,device_name,null==iotAlert.getUser_id()?1:2);
list.add(iotAlertLog);
}
}
... ... @@ -145,11 +156,11 @@ public abstract class UpAlarmFactory<T> {
continue;
}
List<TriggerTriggers> attributeTriggersList = JSON.parseArray(iotAlert.getTriggers(),TriggerTriggers.class);
alarmTriggerTriggers(attributeTriggersList,newValue,iotAlert.getAlertId(),iotAlert.getAlertName(),iotAlert.getAlertLevel().intValue(),client_id,iotAlert.getUser_id(),device_name);
alarmTriggerTriggers(attributeTriggersList,newValue,iotAlert.getAlertId(),iotAlert.getAlertName(),iotAlert.getAlertLevel().intValue(),client_id,user_id,device_name,null==iotAlert.getUser_id()?1:2);
}
}
public void alarmTriggerTriggers( List<TriggerTriggers> attributeTriggersList,Object newValue,Long alert_id, String alert_name, Integer alert_level, String device_id,Integer userId,String device_name )
public void alarmTriggerTriggers( List<TriggerTriggers> attributeTriggersList,Object newValue,Long alert_id, String alert_name, Integer alert_level, String device_id,Integer userId,String device_name,Integer alert_config_type)
{
if(null != attributeTriggersList && attributeTriggersList.size() != 0)
{
... ... @@ -188,7 +199,7 @@ public abstract class UpAlarmFactory<T> {
if(jieguo)
{
IotAlertLog iotAlertLog = new IotAlertLog(alert_id,alert_name,alert_level,2,device_id,System.currentTimeMillis(),1,userId,device_name,null==userId?1:2);
IotAlertLog iotAlertLog = new IotAlertLog(alert_id,alert_name,alert_level,2,device_id,System.currentTimeMillis(),1,userId,device_name,alert_config_type);
list.add(iotAlertLog);
}
}
... ...
package com.zhonglai.luhui.alarm.clas;
import com.zhonglai.luhui.alarm.dto.IotAlertNoticeChannel;
import com.zhonglai.luhui.alarm.dto.IotAlertUserNotice;
import com.zhonglai.luhui.alarm.dto.UserOpenid;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static com.zhonglai.luhui.alarm.config.CachAlarmConfig.user_alarm_notice_channel;
import static com.zhonglai.luhui.alarm.config.CachAlarmConfig.xcx_user_openid;
public class UserOpenidUpCach extends UpAlarmFactory<UserOpenid> implements Serializable {
public UserOpenidUpCach(UserOpenid beforeupAlarmDb, UserOpenid afterupAlarmDb) {
super(beforeupAlarmDb, afterupAlarmDb);
}
@Override
void deleteGenerateAlarm() {
Map<Integer, Set<String>> mapset = xcx_user_openid.get(beforeupAlarmDb.getXcx_config_id());
if(null != mapset)
{
Set<String> set = mapset.get(beforeupAlarmDb.getUser_id());
if(null != set)
{
set.remove(beforeupAlarmDb.getOpenid());
}
}
}
@Override
void insertGenerateAlarm() {
if(null != afterupAlarmDb.getXcx_config_id())
{
Map<Integer, Set<String>> mapset = xcx_user_openid.get(afterupAlarmDb.getXcx_config_id());
if(null == mapset)
{
mapset = new HashMap<>();
xcx_user_openid.put(afterupAlarmDb.getXcx_config_id(),mapset);
}
if(null != afterupAlarmDb.getUser_id())
{
Set<String> set = mapset.get(afterupAlarmDb.getUser_id());
if(null == set)
{
set = new HashSet<>();
mapset.put(afterupAlarmDb.getUser_id(),set);
}
if(null != afterupAlarmDb.getOpenid())
{
set.add(afterupAlarmDb.getOpenid());
}
}
}
}
@Override
void updateGenerateAlarm() {
if(null != beforeupAlarmDb.getXcx_config_id())
{
Map<Integer, Set<String>> mapset = xcx_user_openid.get(beforeupAlarmDb.getXcx_config_id());
if(null == mapset)
{
insertGenerateAlarm();
}else {
if(null != beforeupAlarmDb.getUser_id())
{
Set<String> set = mapset.get(beforeupAlarmDb.getUser_id());
if(null != set )
{
set.remove(beforeupAlarmDb.getOpenid());
}
}
}
insertGenerateAlarm();
}
}
@Override
Object getNowValue(Object model_name, Integer type) {
return null;
}
}
... ...
... ... @@ -20,26 +20,29 @@ public class CachAlarmConfig {
/** 属性告警路由 */
private static Map<Integer, Map<String, String>> product_attribute_route = new HashMap<>();
public static Map<Integer, Map<String, String>> product_attribute_route = new HashMap<>();
/** 触发告警路由 */
private static Map<Integer, Map<String, String>> product_trigger_route = new HashMap<>();
public static Map<Integer, Map<String, String>> product_trigger_route = new HashMap<>();
/** 告警配置 */
private static Map<Long, IotAlert> alarmConfig = new HashMap<>();
public static Map<Long, IotAlert> alarmConfig = new HashMap<>();
/** 告警配置 */
private static Map<String, Integer> device_product = new HashMap<>();
public static Map<String, Integer> device_product = new HashMap<>();
/** 用户告警通知配置 */
private static Map<String, IotAlertUserNotice> user_alarm_config = new HashMap<>();
public static Map<String, IotAlertUserNotice> user_alarm_config = new HashMap<>();
/** 用户告警通知渠道 */
private static Map<Integer, IotAlertNoticeChannel> user_alarm_notice_channel = new HashMap<>();
public static Map<Integer, IotAlertNoticeChannel> user_alarm_notice_channel = new HashMap<>();
/** 用户微信小程序关系 */
private static Map<Integer, Map<Integer, Set<String>>> xcx_user_openid = new HashMap<>();
public static Map<Integer, Map<Integer, Set<String>>> xcx_user_openid = new HashMap<>();
/** 用户设备关系 */
public static Map<String, Integer> dervice_user = new HashMap<>();
public static void loadConfig()
{
... ... @@ -63,6 +66,9 @@ public class CachAlarmConfig {
//加载用户微信小程序关系
loadXcxUserOpenid();
//加载设备用户
loadDeviceUser();
}
/**
... ... @@ -205,6 +211,31 @@ public class CachAlarmConfig {
}
/**
* 加载设备用户
*/
private static void loadDeviceUser()
{
List<IotTerminal> list = DbOperateUtil.getDeviceUserList();
if(null != list && list.size() != 0)
{
for (IotTerminal iotTerminal:list)
{
dervice_user.put(iotTerminal.getId(),iotTerminal.getUser_info_id());
}
}
}
public static void addDeviceUser(String derviceInfoid,Integer userInfoId)
{
dervice_user.put(derviceInfoid,userInfoId);
}
public static Integer getDeviceUser(String derviceInfoid)
{
return dervice_user.get(derviceInfoid);
}
/**
* 添加属性告警路由
* @param iotAlert
*/
... ...
... ... @@ -75,4 +75,9 @@ public class DbOperateUtil {
{
return baseDao.findBysql("SELECT * FROM `user_openid`",UserOpenid.class);
}
public static List<IotTerminal> getDeviceUserList()
{
return baseDao.findBysql("SELECT user_info_id,id FROM `iot_terminal` WHERE user_info_id IS NOT NULL",IotTerminal.class);
}
}
... ...
... ... @@ -13,7 +13,7 @@ public class IotAlertLog
private Long alert_log_id; // bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
private Long alert_id; // bigint DEFAULT NULL COMMENT '告警ID',
private String alert_name; // varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '告警名称',
private Integer alert_level; // int NOT NULL COMMENT '告警级别(1=轻微问题,2=提醒通知,3=严重警告)',
private Integer alert_level; // int NOT NULL COMMENT '告警级别(1=提醒通知,2=轻微问题,3=严重警告)',
private Integer status; // int NOT NULL COMMENT '处理状态(1=不需要处理,2=未处理,3=已处理)',
private String device_id; // varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '设备ID',
private Long create_time; // datetime DEFAULT NULL COMMENT '创建时间',
... ...
package com.zhonglai.luhui.alarm.dto;
import com.alibaba.otter.canal.protocol.CanalEntry;
import java.util.List;
/**
* 告警通知渠道
*/
... ... @@ -9,6 +13,32 @@ public class IotAlertNoticeChannel {
private String config; // json NOT NULL COMMENT '渠道配置',
private String name; // varchar(50) NOT NULL COMMENT '名称',
public static IotAlertNoticeChannel instantiate(List<CanalEntry.Column> columns) {
if (null == columns || columns.size() ==0)
{
return null;
}
IotAlertNoticeChannel iotAlertNoticeChannel = new IotAlertNoticeChannel();
for (CanalEntry.Column column : columns)
{
switch (column.getName())
{
case "id":
iotAlertNoticeChannel.setId(Integer.parseInt(column.getValue()));
break;
case "type":
iotAlertNoticeChannel.setType(Integer.parseInt(column.getValue()));
break;
case "config":
iotAlertNoticeChannel.setConfig(column.getValue());
break;
case "name":
iotAlertNoticeChannel.setName(column.getValue());
break;
}
}
return iotAlertNoticeChannel;
}
public Integer getId() {
return id;
}
... ...
package com.zhonglai.luhui.alarm.dto;
import com.alibaba.otter.canal.protocol.CanalEntry;
import java.util.List;
/**
* 用户告警通知配置
*/
... ... @@ -10,6 +14,32 @@ public class IotAlertUserNotice {
private String alert_ids; // varchar(100) DEFAULT '*' COMMENT '告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)',
private Integer user_id; // int DEFAULT NULL COMMENT '用户id'
public static IotAlertUserNotice instantiate(List<CanalEntry.Column> columns) {
if (null == columns || columns.size() == 0) {
return null;
}
IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice();
for (CanalEntry.Column column : columns) {
switch (column.getName()) {
case "id":
iotAlertUserNotice.setId(Integer.parseInt(column.getValue()));
break;
case "type":
iotAlertUserNotice.setType(Integer.parseInt(column.getValue()));
break;
case "channels":
iotAlertUserNotice.setChannels(column.getValue());
break;
case "alert_ids":
iotAlertUserNotice.setAlert_ids(column.getValue());
break;
case "user_id":
iotAlertUserNotice.setUser_id(Integer.parseInt(column.getValue()));
break;
}
}
return iotAlertUserNotice;
}
public Integer getId() {
return id;
}
... ...
package com.zhonglai.luhui.alarm.dto;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.otter.canal.protocol.CanalEntry;
import com.zhonglai.luhui.alarm.clas.UpAlarmFactory;
import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
import java.util.List;
... ... @@ -117,6 +119,16 @@ public class IotTerminal {
{
return null;
}
if(iotTerminal.getId().startsWith("864814074929612"))
{
System.out.println(iotTerminal.getUser_info_id());
}
if(null != iotTerminal.getUser_info_id())
{
CachAlarmConfig.addDeviceUser(iotTerminal.getId(),iotTerminal.getUser_info_id());
}else {
iotTerminal.setUser_info_id(CachAlarmConfig.getDeviceUser(iotTerminal.getId()));
}
return iotTerminal;
}
}
... ...
package com.zhonglai.luhui.alarm.dto;
import com.alibaba.otter.canal.protocol.CanalEntry;
import java.util.List;
public class UserOpenid {
private Integer user_id; // int DEFAULT NULL COMMENT '用户id',
private String openid; // varchar(50) DEFAULT NULL COMMENT '微信用户的唯一标识',
private Integer xcx_config_id; // int DEFAULT NULL COMMENT '微信平台的配置参数表id',
public static UserOpenid instantiate(List<CanalEntry.Column> columns) {
if (null == columns || columns.size() ==0)
{
return null;
}
UserOpenid userOpenid = new UserOpenid();
for (CanalEntry.Column column : columns)
{
switch (column.getName())
{
case "user_id":
userOpenid.setUser_id(Integer.parseInt(column.getValue()));
break;
case "openid":
userOpenid.setOpenid(column.getValue());
break;
case "xcx_config_id":
userOpenid.setXcx_config_id(Integer.parseInt(column.getValue()));
break;
}
}
return userOpenid;
}
public Integer getUser_id() {
return user_id;
}
... ...
... ... @@ -3,6 +3,7 @@ package com.zhonglai.luhui.alarm.handle;
import com.alibaba.fastjson.JSON;
import com.zhonglai.luhui.alarm.clas.IotAlertAlarm;
import com.zhonglai.luhui.alarm.clas.IotTerminalAlarm;
import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
import com.zhonglai.luhui.alarm.dao.DbOperateUtil;
import com.zhonglai.luhui.alarm.dto.*;
import com.zhonglai.luhui.service.dao.util.StringUtils;
... ... @@ -27,18 +28,17 @@ public class TimerAlarmJob implements Job {
List<TriggerTriggers> triggersList = timerTriggers.getTriggersList();
String alertName = iotAlert.getAlertName();
Long productId = iotAlert.getProductId();
Integer user_id = iotAlert.getUser_id();
String terminalids = timerTriggers.getTerminalids();
List<IotAlertLog> list = new ArrayList<>();
List<IotTerminal> iotTerminallist = DbOperateUtil.getTimerAlarmIotTerminal(productId,terminalids,user_id);
List<IotTerminal> iotTerminallist = DbOperateUtil.getTimerAlarmIotTerminal(productId,terminalids,iotAlert.getUser_id());
if (null != iotTerminallist && iotTerminallist.size() != 0 )
{
for (IotTerminal iotTerminal:iotTerminallist)
{
IotTerminalAlarm iotTerminalAlarm = new IotTerminalAlarm(iotTerminal,iotTerminal);
iotTerminalAlarm.alarmTriggerTriggers(triggersList,iotTerminal.getThings_model_value(),iotAlert.getAlertId(),alertName,iotAlert.getAlertLevel().intValue(),iotTerminal.getId(),iotAlert.getUser_id(), iotTerminal.getName());
iotTerminalAlarm.alarmTriggerTriggers(triggersList,iotTerminal.getThings_model_value(),iotAlert.getAlertId(),alertName,iotAlert.getAlertLevel().intValue(),iotTerminal.getId(),CachAlarmConfig.getDeviceUser(iotTerminal.getId()), iotTerminal.getName(),null==iotAlert.getUser_id()?1:2);
List<IotAlertLog> serviceDtolist = iotTerminalAlarm.getList();
if(null != serviceDtolist && serviceDtolist.size()!=0)
{
... ...
... ... @@ -46,10 +46,7 @@ public class SendAlarmService {
}
switch (iotAlertLog.getAlert_level())
{
case 1: //轻微问题
notids.add(iotAlertLog.getAlert_log_id());
break;
case 2: //提醒通知
case 1: //提醒通知
if(NoticeFactory.notice(iotAlertLog))
{
ids.add(iotAlertLog.getAlert_log_id());
... ... @@ -57,6 +54,9 @@ public class SendAlarmService {
notids.add(iotAlertLog.getAlert_log_id());
}
break;
case 2: //轻微问题
notids.add(iotAlertLog.getAlert_log_id());
break;
case 3: //严重警告
if(NoticeFactory.request(iotAlertLog))
... ...
... ... @@ -63,19 +63,19 @@ public class TriggerAlarmService {
// 连接到Canal服务器
connector.connect();
// 订阅指定的表(这里以database.table为例)
connector.subscribe("mqtt_broker\\.(iot_device|iot_terminal|iot_alert)");
connector.subscribe("mqtt_broker\\.(iot_device|iot_terminal|iot_alert|iot_alert_notice_channel|iot_alert_user_notice|user_openid)");
}
private static void handle() throws InterruptedException {
while (ThreadPoolUtil.executor.getPoolSize()-ThreadPoolUtil.executor.getActiveCount()>0)
{
logger.info("总线程数{},已使用线程数{},剩下线程数{}",ThreadPoolUtil.executor.getPoolSize(),ThreadPoolUtil.executor.getActiveCount(),ThreadPoolUtil.executor.getPoolSize()-ThreadPoolUtil.executor.getActiveCount());
// logger.info("总线程数{},已使用线程数{},剩下线程数{}",ThreadPoolUtil.executor.getPoolSize(),ThreadPoolUtil.executor.getActiveCount(),ThreadPoolUtil.executor.getPoolSize()-ThreadPoolUtil.executor.getActiveCount());
// 获取指定数量的数据
Message message = connector.getWithoutAck(100);
long batchId = message.getId();
int size = message.getEntries().size();
logger.info("拉取的数据库同步数据量{}",size);
// logger.info("拉取的数据库同步数据量{}",size);
if (batchId != -1 && size > 0) {
ThreadPoolUtil.executor.schedule(() -> {
try {
... ...
package com.zhonglai.luhui.api.controller.iot;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.zhonglai.luhui.action.BaseController;
import com.zhonglai.luhui.device.domain.IotAlertLog;
import com.zhonglai.luhui.device.service.IIotAlertLogService;
import com.zhonglai.luhui.security.utils.SecurityUtils;
import com.zhonglai.luhui.sys.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 设备告警Controller
*
* @author kerwincui
* @date 2022-01-13
*/
@Api(tags = "设备告警日志")
@RestController
@RequestMapping("/iot/alertLog")
public class IotAlertLogController extends BaseController
{
@Autowired
private IIotAlertLogService alertLogService;
@ApiOperation(value = "查询设备告警列表",notes = "参数说明:" +
"params.beginTime 开始时间" +
"params.endTime 结束时间" +
"alertName 告警名称为模糊匹配")
@GetMapping("/list")
public TableDataInfo list(IotAlertLog alertLog)
{
alertLog.setUser_id(SecurityUtils.getUserId().intValue());
startPage();
List<IotAlertLog> list = alertLogService.selectAlertLogList(alertLog);
return getDataTable(list);
}
/**
* 导出设备告警列表
*/
@ApiOperation("导出设备告警列表")
@Log(title = "设备告警", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, IotAlertLog alertLog)
{
alertLog.setUser_id(SecurityUtils.getUserId().intValue());
List<IotAlertLog> list = alertLogService.selectAlertLogList(alertLog);
ExcelUtil<IotAlertLog> util = new ExcelUtil<IotAlertLog>(IotAlertLog.class);
util.exportExcel(response, list, "设备告警数据");
}
/**
* 获取设备告警详细信息
*/
@ApiOperation("获取设备告警详细信息")
@GetMapping(value = "/{alertLogId}")
public AjaxResult getInfo(@PathVariable("alertLogId") Long alertLogId)
{
return AjaxResult.success(alertLogService.selectAlertLogByAlertLogId(alertLogId));
}
}
... ...
# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 18080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login/ApiLogin/*,/content/**,/test/**,/fish/FishPriceCollection/* # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1
\ No newline at end of file
# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 18080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn com.zhonglai.luhui: debug # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login/ApiLogin/*,/content/**,/test/**,/fish/FishPriceCollection/* # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1
\ No newline at end of file
... ...