Browse Source

集中监控告警消息处理结构调整

zhongwei
tyty 1 year ago
parent
commit
dbe6b830c5
  1. 58
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/ConditionAlarmVo.java
  2. 0
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmConfigDetailMapper.xml
  3. 0
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmConfigMapper.xml
  4. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmHistoryMapper.java
  5. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmHistoryMapper.xml
  6. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmMapper.java
  7. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmMapper.xml
  8. 33
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/task/fdpAlarmTask.java
  9. 13
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java
  10. 7
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java
  11. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/ConditionAlarmService.java
  12. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/FdpAlarmService.java
  13. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/LevelAlarmService.java
  14. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/SystemAlarmService.java
  15. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHistoryServiceImpl.java
  16. 42
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java
  17. 47
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/ConditionAlarmServiceImpl.java
  18. 47
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/FdpAlarmServiceImpl.java
  19. 41
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/LevelAlarmServiceImpl.java
  20. 7
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/MessageServiceImpl.java
  21. 43
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/SystemAlarmServiceImpl.java
  22. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/condition/ConditionAlarmRegular.java
  23. 26
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/condition/ConditionAlarmWebSocket.java
  24. 5
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/fdp/FdpAlarmRegular.java
  25. 24
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/fdp/FdpAlarmWebSocket.java
  26. 3
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/hz3000/SystemAlarmRegular.java
  27. 24
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/hz3000/SystemAlarmWebSocket.java
  28. 15
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java

58
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/ConditionAlarmVo.java

@ -0,0 +1,58 @@
package com.hnac.hzims.alarm.vo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.Date;
/**
* @author ty
*/
@Data
@ApiModel(value = "条件预警对象", description = "条件预警对象")
public class ConditionAlarmVo {
//todo
private static final long serialVersionUID = 1L;
/**
* 故障ID
*/
private String faultId;
/**
* 故障站点
*/
private String station;
/**
* 故障名称
*/
private String name;
/**
* 位置
*/
private String ord;
/**
* 故障状态
*/
private Float status;
/**
* 故障的附属信息
*/
private String info;
/**
* 报警类型
*/
private String ftype;
/**
* 报警内容
*/
private String finfo;
/**
* 报警内容
*/
private Object[] children;
/**
* 创建时间
*/
private Date createTime;
}

0
hzims-service/hzims-alarm/src/main/resources/mapper/AlarmConfigDetatilMapper.xml → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmConfigDetailMapper.xml

0
hzims-service/hzims-alarm/src/main/resources/mapper/AlarmConfigMapper.xml → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmConfigMapper.xml

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHistoryMapper.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmHistoryMapper.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.show.mapper;
package com.hnac.hzims.alarm.config.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.alarm.entity.AlarmHistoryEntity;

2
hzims-service/hzims-alarm/src/main/resources/mapper/AlarmHistoryMapper.xml → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmHistoryMapper.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.alarm.show.mapper.AlarmHistoryMapper">
<mapper namespace="com.hnac.hzims.alarm.config.mapper.AlarmHistoryMapper">
</mapper>

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmMapper.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmMapper.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.show.mapper;
package com.hnac.hzims.alarm.config.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.alarm.entity.AlarmEntity;

2
hzims-service/hzims-alarm/src/main/resources/mapper/AlarmMapper.xml → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/mapper/AlarmMapper.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.alarm.show.mapper.AlarmMapper">
<mapper namespace="com.hnac.hzims.alarm.config.mapper.AlarmMapper">
</mapper>

33
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/task/fdpAlarmTask.java

@ -0,0 +1,33 @@
package com.hnac.hzims.alarm.config.task;
//
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class fdpAlarmTask {
//
// private final IUserClient userClient;
//
// private final IStationClient stationClient;
// @Value("${url.getAutoFault}")
// public String autoFaultPath;
//
// @XxlJob(PERSONAL_MONTH_REPORT)
// public ReturnT<String> execute(String param) throws IOException {
// log.info("----FDP智能预警查询----",param);
// R<List<StationEntity>> listAll = stationClient.getListAll();
// if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){
// log.error("FDP智能预警查询失败:无站点数据",listAll);
// }
// List<StationEntity> stations = listAll.getData();
// Map<String, Object> paramMap = new HashMap<>();
// paramMap.put("stationIds",stations);
// String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST");
// if (StringUtil.isBlank(result)){
// return null;
// }
// JSONObject.parseObject(result).get("data").toString();
// log.info("----FDP智能预警查询----",param);
// return new ReturnT<>("SUCCESS");
// }
//}

13
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.SystemAlarmService;
import com.hnac.hzims.alarm.vo.AlarmCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -15,6 +16,7 @@ import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -31,7 +33,9 @@ import java.util.Map;
@Api(value = "告警配置", tags = "告警配置")
public class ShowAlarmController extends BladeController {
private final AlarmService alarmService;
@Autowired
private AlarmService alarmService;
private SystemAlarmService systemAlarmService;
@PostMapping("/alarms")
@ApiOperationSupport(order = 1)
@ -87,6 +91,13 @@ public class ShowAlarmController extends BladeController {
AlarmEntity detail = alarmService.getOne(Condition.getQueryWrapper(entity));
return R.data(detail);
}
@PostMapping("/test")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "详情", notes = "传入em_model_param")
public R<AlarmEntity> test(@RequestBody String param) {
systemAlarmService.receiveMessage(param);
return R.success("结束");
}
}

7
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java

@ -15,4 +15,11 @@ public interface AlarmService extends BaseService<AlarmEntity> {
IPage<AlarmEntity> alarms(AlarmEntity alarm, IPage<AlarmEntity> page);
List<AlarmCountVo> counts();
/**
* websocket 消息推送保存
* @param param
*/
void dealAlarmEntities(List<AlarmEntity> param);
}

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/ConditionAlarmService.java

@ -1,5 +1,9 @@
package com.hnac.hzims.alarm.show.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import java.util.List;
/**
* 等级处理接口
* @author ysj
@ -8,5 +12,5 @@ public interface ConditionAlarmService {
String message();
void receive(String message);
List<AlarmEntity> receiveMessage(String message);
}

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/FdpAlarmService.java

@ -1,5 +1,9 @@
package com.hnac.hzims.alarm.show.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import java.util.List;
/**
* 告警处理接口
* @author ysj
@ -8,5 +12,5 @@ public interface FdpAlarmService {
String sendMessage();
void receiveMessage(String message);
List<AlarmEntity> receiveMessage(String message);
}

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/LevelAlarmService.java

@ -1,5 +1,9 @@
package com.hnac.hzims.alarm.show.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import java.util.List;
/**
* 等级处理接口
* @author ysj
@ -8,5 +12,5 @@ public interface LevelAlarmService {
String message();
void receive(String message);
List<AlarmEntity> receiveMessage(String message);
}

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/SystemAlarmService.java

@ -1,5 +1,9 @@
package com.hnac.hzims.alarm.show.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import java.util.List;
/**
* 告警处理接口
* @author ysj
@ -8,5 +12,5 @@ public interface SystemAlarmService {
String sendMessage();
void receiveMessage(String message);
List<AlarmEntity> receiveMessage(String message);
}

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHistoryServiceImpl.java

@ -1,7 +1,7 @@
package com.hnac.hzims.alarm.show.service.impl;
import com.hnac.hzims.alarm.entity.AlarmHistoryEntity;
import com.hnac.hzims.alarm.show.mapper.AlarmHistoryMapper;
import com.hnac.hzims.alarm.config.mapper.AlarmHistoryMapper;
import com.hnac.hzims.alarm.show.service.AlarmHistoryService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

42
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java

@ -2,23 +2,28 @@ package com.hnac.hzims.alarm.show.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.alarm.config.mapper.AlarmMapper;
import com.hnac.hzims.alarm.config.service.AlarmConfigService;
import com.hnac.hzims.alarm.constants.AlarmConstants;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.mapper.AlarmMapper;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.MessageService;
import com.hnac.hzims.alarm.vo.AlarmCountVo;
import com.hnac.hzims.alarm.vo.ChildAlarmCountVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
@ -30,6 +35,7 @@ import java.util.stream.Collectors;
public class AlarmServiceImpl extends BaseServiceImpl<AlarmMapper, AlarmEntity> implements AlarmService {
private final AlarmConfigService configService;
private final MessageService messageService;
/**
* 查询告警列表
@ -90,6 +96,40 @@ public class AlarmServiceImpl extends BaseServiceImpl<AlarmMapper, AlarmEntity>
}).collect(Collectors.toList());
}
/**
* websocket 消息推送保存
* @param param
*/
@Override
public void dealAlarmEntities(List<AlarmEntity> param) {
if (CollectionUtil.isNotEmpty(param)) {
// 查询当天已经记录的告警
List<AlarmEntity> historys = this.list(Wrappers.<AlarmEntity>lambdaQuery().
ge(AlarmEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00")
.eq(AlarmEntity::getAlarmSource, param.get(0).getAlarmSource()));
// 数据过滤
List<AlarmEntity> entitys = param.stream()
.filter(alarm -> CollectionUtil.isNotEmpty(historys) || !historys.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(alarm.getAlarmId()))
.map(item -> {
//消息推送
// 短信
CompletableFuture.runAsync(() -> messageService.message(item));
// web/app消息推送
CompletableFuture.runAsync(() -> messageService.webAppMessage(item));
// 微信公众号推送
CompletableFuture.runAsync(() -> messageService.weChatMessage(item));
return item;
}).collect(Collectors.toList());
if (CollectionUtil.isEmpty(entitys)) {
return;
}
// 批量保存
this.saveBatch(entitys);
}
}
/**
* 子类型数量集合

47
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/ConditionAlarmServiceImpl.java

@ -1,15 +1,29 @@
package com.hnac.hzims.alarm.show.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.ConditionAlarmService;
import com.hnac.hzims.alarm.show.service.MessageService;
import com.hnac.hzims.alarm.vo.ConditionAlarmVo;
import com.hnac.hzims.equipment.feign.IEmInfoClient;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static com.hnac.hzims.alarm.constants.AlarmConstants.EARLY;
import static com.hnac.hzims.alarm.constants.AlarmConstants.EARLY_WARNING;
/**
* 等级告警实现类
* @author ysj
@ -40,11 +54,40 @@ public class ConditionAlarmServiceImpl implements ConditionAlarmService {
return "";
}
/**
* 处理websocket消息
* 转换接收服务推送消息
* @param message
*/
@Override
public void receive(String message) {
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<ConditionAlarmVo> alarms = JSONObject.parseArray(message, ConditionAlarmVo.class);
if (CollectionUtil.isEmpty(alarms)) {
return new ArrayList<>();
}
List<AlarmEntity> res = alarms.stream().map(s -> {
AlarmEntity entity = getAlarmEntity(s);
return entity;
}).collect(Collectors.toList());
return res;
}
private AlarmEntity getAlarmEntity(ConditionAlarmVo item) {
AlarmEntity entity = new AlarmEntity();
entity.setAlarmId(item.getFaultId());
entity.setAlarmTime(item.getCreateTime());
entity.setAlarmContext(item.getFinfo());
entity.setAlarmType(EARLY);
entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus())));
entity.setStationId(item.getStation());
entity.setAlarmStatus(EARLY_WARNING);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){
entity.setCreateDept(stationByCode.getData().getCreateDept());
entity.setStationName(stationByCode.getData().getName());
}
return entity;
}
}

47
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/FdpAlarmServiceImpl.java

@ -2,7 +2,6 @@ package com.hnac.hzims.alarm.show.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.FdpAlarmService;
@ -16,15 +15,13 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@ -64,47 +61,22 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
return JSONObject.toJSONString(map);
}
/**
* 接收服务推送消息
* 转换接收服务推送消息
* @param message
*/
@Override
public void receiveMessage(String message) {
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<FdpAlarmVo> alarms = JSONObject.parseArray(message, FdpAlarmVo.class);
if(CollectionUtil.isEmpty(alarms)){
return;
if (CollectionUtil.isEmpty(alarms)) {
return new ArrayList<>();
}
// R<List<StationEntity>> listAll = stationClient.getListAll();
// if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){
// throw new ServiceException("FdpAlarm send message is null");
// }
// List<StationEntity> stations = listAll.getData();
// 查询当天已经记录的告警
List<AlarmEntity> historys = alarmService.list(Wrappers.<AlarmEntity>lambdaQuery().
ge(AlarmEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00")
.eq(AlarmEntity::getAlarmSource, EARLY_WARNING));
// 数据过滤
List<AlarmEntity> entitys = alarms.stream()
.filter(alarm -> CollectionUtil.isNotEmpty(historys) || !historys.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(alarm.getFaultId()))
.map(item->{
//转换对象
AlarmEntity entity = getAlarmEntity(item);
// 短信
CompletableFuture.runAsync(() -> messageService.message(entity));
// web/app消息推送
CompletableFuture.runAsync(() -> messageService.webAppMessage(entity));
// 微信公众号推送
CompletableFuture.runAsync(() -> messageService.weChatMessage(entity));
List<AlarmEntity> res = alarms.stream().map(s -> {
AlarmEntity entity = getAlarmEntity(s);
return entity;
}).collect(Collectors.toList());
if(CollectionUtil.isEmpty(entitys)){
return;
}
// 批量保存
alarmService.saveBatch(entitys);
return res;
}
private AlarmEntity getAlarmEntity(FdpAlarmVo item) {
@ -116,10 +88,13 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus())));
entity.setStationId(item.getStation());
entity.setAlarmStatus(EARLY_WARNING);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){
entity.setCreateDept(stationByCode.getData().getCreateDept());
entity.setStationName(stationByCode.getData().getName());
}
return entity;
}
}

41
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/LevelAlarmServiceImpl.java

@ -2,7 +2,6 @@ package com.hnac.hzims.alarm.show.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.alarm.constants.AlarmConstants;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
@ -22,9 +21,9 @@ import org.springblade.core.tool.utils.DateUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
@ -70,26 +69,25 @@ public class LevelAlarmServiceImpl implements LevelAlarmService {
}
/**
* 处理websocket消息
* 转换接收服务推送消息
* @param message
*/
@Override
public void receive(String message) {
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<LevelVo> levels = JSONObject.parseArray(message,LevelVo.class);
if(CollectionUtil.isEmpty(levels)){
return;
List<LevelVo> alarms = JSONObject.parseArray(message, LevelVo.class);
if (CollectionUtil.isEmpty(alarms)) {
return new ArrayList<>();
}
// 设备
List<AlarmEntity> res = alarms.stream().map(s -> {
AlarmEntity entity = getAlarmEntity(s);
return entity;
}).collect(Collectors.toList());
return res;
}
private AlarmEntity getAlarmEntity(LevelVo level) {
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(),new TypeReference<List<EminfoAndEmParamVo>>() {});
// 查询已经保存等级告警数据
List<AlarmEntity> records = alarmService.list(Wrappers.<AlarmEntity>lambdaQuery()
.ge(AlarmEntity::getAlarmSource,AlarmConstants.LEVEL_ALARM)
.in(AlarmEntity::getAlarmId,levels.stream().map(LevelVo::getId).collect(Collectors.toList()))
);
// 遍历等级告警数据
levels.stream().filter(o-> CollectionUtil.isEmpty(records) || !records.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(o.getId())).
forEach(level->{
AlarmEntity entity = new AlarmEntity();
entity.setAlarmSource(AlarmConstants.LEVEL_ALARM);
entity.setAlarmId(level.getId());
@ -105,13 +103,8 @@ public class LevelAlarmServiceImpl implements LevelAlarmService {
entity.setStationId(ems.get(0).getStationCode());
entity.setDeviceName(ems.get(0).getStationName());
}
this.alarmService.save(entity);
// 短信
CompletableFuture.runAsync(() -> this.messageService.message(entity));
// web/app消息推送
CompletableFuture.runAsync(() -> this.messageService.webAppMessage(entity));
// 微信公众号推送
CompletableFuture.runAsync(() -> this.messageService.weChatMessage(entity));
});
return entity;
}
}

7
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/MessageServiceImpl.java

@ -10,7 +10,7 @@ import com.hnac.hzims.message.dto.BusinessMessageDTO;
import com.hnac.hzims.message.fegin.IMessageClient;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import lombok.RequiredArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
@ -28,7 +28,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
@Service
@RequiredArgsConstructor
@AllArgsConstructor
public class MessageServiceImpl implements MessageService {
private final ISysClient sysClient;
private final IStationClient stationClient;
@ -68,7 +68,8 @@ public class MessageServiceImpl implements MessageService {
message.setBusinessClassify("warning");
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey());
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription());
message.setTaskId(entity.getId());
// todo
// message.setTaskId(entity.getAlarmId());
message.setTenantId("200000");
message.setContent(entity.getAlarmContext());
message.setDeptId(dept);

43
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/SystemAlarmServiceImpl.java

@ -2,7 +2,6 @@ package com.hnac.hzims.alarm.show.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.alarm.constants.AlarmConstants;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
@ -23,10 +22,9 @@ import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@ -69,46 +67,21 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
/**
* 接收服务推送消息
* 转换接收服务推送消息
* @param message
*/
@Override
public void receiveMessage(String message) {
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<SystemAlarmVo> alarms = JSONObject.parseArray(message, SystemAlarmVo.class);
if (CollectionUtil.isEmpty(alarms)) {
return;
}
//
// R<List<StationEntity>> listAll = stationClient.getListAll();
// if (!listAll.isSuccess() || CollectionUtil.isEmpty(listAll.getData())) {
// throw new ServiceException("systemAlarm send message is null");
// }
// List<StationEntity> stations = listAll.getData();
// 查询当天已经记录的告警
List<AlarmEntity> historys = alarmService.list(Wrappers.<AlarmEntity>lambdaQuery().
ge(AlarmEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00")
.eq(AlarmEntity::getAlarmSource, AlarmConstants.HZ3000_ALARM));
// 数据过滤
List<AlarmEntity> entitys = alarms.stream()
.filter(alarm -> CollectionUtil.isNotEmpty(historys) || !historys.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(alarm.getId()))
.map(item -> {
AlarmEntity entity = getAlarmEntity(item);
if (ObjectUtils.isNotEmpty(entity)){
// 短信
CompletableFuture.runAsync(() -> messageService.message(entity));
// web/app消息推送
CompletableFuture.runAsync(() -> messageService.webAppMessage(entity));
// 微信公众号推送
CompletableFuture.runAsync(() -> messageService.weChatMessage(entity));
return new ArrayList<>();
}
List<AlarmEntity> res = alarms.stream().map(s -> {
AlarmEntity entity = getAlarmEntity(s);
return entity;
}).collect(Collectors.toList());
if (CollectionUtil.isEmpty(entitys)) {
return;
}
// 批量保存
alarmService.saveBatch(entitys);
return res;
}
private AlarmEntity getAlarmEntity(SystemAlarmVo item) {
@ -121,9 +94,11 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
entity.setAlarmValue(item.getOptionvals());
entity.setStationId(item.getStation());
entity.setAlarmSource(AlarmConstants.HZ3000_ALARM);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess() && ObjectUtils.isNotEmpty(stationByCode.getData())) {
entity.setCreateDept(stationByCode.getData().getCreateDept());
entity.setStationName(stationByCode.getData().getName());
}
return entity;
}

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/condition/ConditionAlarmRegular.java

@ -42,9 +42,9 @@ public class ConditionAlarmRegular {
socket.send(message);
}
}
log.error("level websocket survival check : {}","重新建立链接");
log.error("conditionAlarm survival check : {}","重新建立链接");
}else{
log.error("level websocket survival check : {}","存活");
log.error("conditionAlarm survival check : {}","存活");
}
}
@ -54,7 +54,7 @@ public class ConditionAlarmRegular {
socket = new LevelAlarmWebSocket(new URI(condition_wss_url));
socket.connectBlocking();
}catch (Exception e){
log.error("level create error : {}",e.getMessage());
log.error("conditionAlarm create error : {}",e.getMessage());
}
}
}

26
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/condition/ConditionAlarmWebSocket.java

@ -1,10 +1,12 @@
package com.hnac.hzims.alarm.ws.condition;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.ConditionAlarmService;
import com.hnac.hzims.alarm.show.service.LevelAlarmService;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
@ -15,6 +17,7 @@ import java.net.Socket;
import java.net.URI;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Optional;
/**
@ -25,6 +28,7 @@ public class ConditionAlarmWebSocket extends WebSocketClient {
private final ConditionAlarmService conditionService;
private AlarmService alarmService;
/**
* 构造等级告警websocket
@ -39,30 +43,36 @@ public class ConditionAlarmWebSocket extends WebSocketClient {
// 链接到服务器回调接口
@Override
public void onOpen(ServerHandshake handshakedata) {
log.error("systemAlarm websocket open");
log.error("conditionAlarm websocket open");
}
// 接收到服务器消息回调接口
@Override
public void onMessage(String message) {
if(StringUtil.isEmpty(message)){
log.error("level alarm on message is null");
log.error("conditionAlarm on message is null");
}else{
// 告警数据转化
List<AlarmEntity> alarmEntities = conditionService.receiveMessage(message);
// 等级告警数据处理
conditionService.receive(message);
try {
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错(conditionAlarm):"+e);
}
}
}
// 与服务器链接中断回调接口
@Override
public void onClose(int code, String reason, boolean remote) {
log.error("level alarm websocket close");
log.error("conditionAlarm websocket close");
}
// 与服务器通讯异常触发
@Override
public void onError(Exception e) {
log.error("level alarm websocket error : {}",e.getMessage());
log.error("conditionAlarm websocket error : {}",e.getMessage());
}
/**
@ -89,7 +99,7 @@ public class ConditionAlarmWebSocket extends WebSocketClient {
try{
socket = context.getSocketFactory().createSocket();
}catch (Exception e){
log.error("level alarm socket create error : {}",e.getMessage());
log.error("conditionAlarm socket create error : {}",e.getMessage());
}
return socket;
}
@ -118,7 +128,7 @@ public class ConditionAlarmWebSocket extends WebSocketClient {
}
}}, new SecureRandom());
}catch (Exception e){
log.error("level alarm SSL init error : {}",e.getMessage());
log.error("conditionAlarm SSL init error : {}",e.getMessage());
}
return SSL;
}

5
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/fdp/FdpAlarmRegular.java

@ -31,11 +31,15 @@ public class FdpAlarmRegular {
// 定时发送消息
@Scheduled(cron = "0 0/30 * * * ?")
private void regular(){
System.out.println("系统告警链接检查");
// 检查链接存活状态
if(ObjectUtil.isNotEmpty(client) && client.isOpen()){
client.send(fdpAlarmService.sendMessage());
System.out.println("FdpAlarm:链接成功");
}else {
System.out.println("FdpAlarm:链接失败");
this.createClient();
System.out.println("FdpAlarm:重新链接");
}
}
@ -44,6 +48,7 @@ public class FdpAlarmRegular {
try{
client = new FdpAlarmWebSocket(new URI(fdp_alarm_url));
client.connectBlocking();
System.out.println("FdpAlarm create success");
}catch (Exception e){
log.error("FdpAlarm create error : {}",e.getMessage());
}

24
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/fdp/FdpAlarmWebSocket.java

@ -1,11 +1,15 @@
package com.hnac.hzims.alarm.ws.fdp;
import com.hnac.hzims.alarm.show.service.SystemAlarmService;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.FdpAlarmService;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@ -14,6 +18,7 @@ import java.net.Socket;
import java.net.URI;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Optional;
/**
@ -22,8 +27,9 @@ import java.util.Optional;
*/
@Slf4j
public class FdpAlarmWebSocket extends WebSocketClient {
private final SystemAlarmService systemAlarmService;
@Autowired
private FdpAlarmService fdpAlarmService;
private AlarmService alarmService;
/**
* 构造等级告警websocket
@ -31,7 +37,7 @@ public class FdpAlarmWebSocket extends WebSocketClient {
*/
public FdpAlarmWebSocket(URI uri) {
super(uri);
systemAlarmService = SpringUtil.getBean(SystemAlarmService.class);
fdpAlarmService = SpringUtil.getBean(FdpAlarmService.class);
connection(this);
}
@ -47,8 +53,16 @@ public class FdpAlarmWebSocket extends WebSocketClient {
if(StringUtil.isEmpty(message)){
log.error("FdpAlarm on message is null");
}else{
// 告警数据转化
List<AlarmEntity> alarmEntities = fdpAlarmService.receiveMessage(message);
//统一数据处理
try {
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错(FdpAlarm):"+e);
}
// 等级告警数据处理
systemAlarmService.receiveMessage(message);
fdpAlarmService.receiveMessage(message);
}
}

3
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/hz3000/SystemAlarmRegular.java

@ -34,7 +34,9 @@ public class SystemAlarmRegular {
// 检查链接存活状态
if(ObjectUtil.isNotEmpty(client) && client.isOpen()){
client.send(systemAlarmService.sendMessage());
System.out.println("systemAlarm:存活");
}else {
System.out.println("systemAlarm:链接失败");
this.createClient();
}
}
@ -44,6 +46,7 @@ public class SystemAlarmRegular {
try{
client = new SystemAlarmWebSocket(new URI(system_wss_url));
client.connectBlocking();
System.out.println("systemAlarm create success");
}catch (Exception e){
log.error("systemAlarm create error : {}",e.getMessage());
}

24
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/hz3000/SystemAlarmWebSocket.java

@ -1,9 +1,12 @@
package com.hnac.hzims.alarm.ws.hz3000;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.SystemAlarmService;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
@ -14,6 +17,7 @@ import java.net.Socket;
import java.net.URI;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Optional;
/**
@ -25,6 +29,8 @@ public class SystemAlarmWebSocket extends WebSocketClient {
private final SystemAlarmService systemAlarmService;
private AlarmService alarmService;
/**
* 构造等级告警websocket
* @param uri
@ -38,7 +44,7 @@ public class SystemAlarmWebSocket extends WebSocketClient {
// 链接到服务器回调接口
@Override
public void onOpen(ServerHandshake handshakedata) {
log.error("systemAlarm websocket open");
log.error("SystemAlarmWebSocket链接到服务器回调接口");
}
// 接收到服务器消息回调接口
@ -47,15 +53,22 @@ public class SystemAlarmWebSocket extends WebSocketClient {
if(StringUtil.isEmpty(message)){
log.error("systemAlarm on message is null");
}else{
// 等级告警数据处理
systemAlarmService.receiveMessage(message);
// 华自3000告警数据转化
List<AlarmEntity> alarmEntities = systemAlarmService.receiveMessage(message);
//统一数据处理
try {
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错:"+e);
}
log.error("华自3000告警数据处理");
}
}
// 与服务器链接中断回调接口
@Override
public void onClose(int code, String reason, boolean remote) {
log.error("systemAlarm websocket close");
log.error("SystemAlarmWebSocket与服务器链接中断回调接口 ");
}
// 与服务器通讯异常触发
@ -76,6 +89,7 @@ public class SystemAlarmWebSocket extends WebSocketClient {
webSocket.setSocket(socket);
}
}
System.out.println("systemAlarm create success");
}
/**
@ -87,6 +101,7 @@ public class SystemAlarmWebSocket extends WebSocketClient {
Socket socket = null;
try{
socket = context.getSocketFactory().createSocket();
log.error("SystemAlarmWebSocket链接创建成功");
}catch (Exception e){
log.error("systemAlarm socket create error : {}",e.getMessage());
}
@ -116,6 +131,7 @@ public class SystemAlarmWebSocket extends WebSocketClient {
return new X509Certificate[0];
}
}}, new SecureRandom());
log.error("SystemAlarmWebSocket初始化成功");
}catch (Exception e){
log.error("systemAlarm SSL init error : {}",e.getMessage());
}

15
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java

@ -1,9 +1,12 @@
package com.hnac.hzims.alarm.ws.level;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.LevelAlarmService;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
@ -14,6 +17,7 @@ import java.net.Socket;
import java.net.URI;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Optional;
/**
@ -25,6 +29,8 @@ public class LevelAlarmWebSocket extends WebSocketClient {
private final LevelAlarmService levelService;
private AlarmService alarmService;
/**
* 构造等级告警websocket
* @param uri
@ -47,8 +53,15 @@ public class LevelAlarmWebSocket extends WebSocketClient {
if(StringUtil.isEmpty(message)){
log.error("level alarm on message is null");
}else{
// 告警数据转化
List<AlarmEntity> alarmEntities = levelService.receiveMessage(message);
// 等级告警数据处理
levelService.receive(message);
try {
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错(levelAlarm):"+e);
}
}
}

Loading…
Cancel
Save