Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
yang_shj 1 year ago
parent
commit
333e1c3b4a
  1. 2
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmConstants.java
  2. 21
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/FdpAlarmVo.java
  3. 1
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java
  4. 4
      hzims-service/hzims-alarm/pom.xml
  5. 53
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/fdpMqttConfig.java
  6. 40
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/fdpMqttConsumer.java
  7. 16
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/VideoAlarmService.java
  8. 35
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java
  9. 7
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/ConditionAlarmServiceImpl.java
  10. 21
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/FdpAlarmServiceImpl.java
  11. 104
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/VideoAlarmServiceImpl.java
  12. 37
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/task/VideoScheduledTask.java
  13. 3
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/fdp/FdpAlarmWebSocket.java
  14. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/hz3000/SystemAlarmRegular.java
  15. 1
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/hz3000/SystemAlarmWebSocket.java
  16. 1
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java

2
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmConstants.java

@ -52,5 +52,5 @@ public interface AlarmConstants {
List<Integer> LEVEL_ALARAM = Arrays.asList(ONE_LEVEL,TWO_LEVEL,THREE_LEVEL);
Integer EARLY = 30;
Integer CONDITION = 40;
String VIDEO_SCHEDULED_TASK= "VideoScheduledTask";
}

21
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/FdpAlarmVo.java

@ -23,6 +23,10 @@ public class FdpAlarmVo {
*/
private String station;
/**
* 故障状态
*/
private String status;
/**
* 故障名称
*/
private String name;
@ -30,10 +34,7 @@ public class FdpAlarmVo {
* 位置
*/
private String ord;
/**
* 故障状态
*/
private Float status;
/**
* 故障的附属信息
*/
@ -47,9 +48,17 @@ public class FdpAlarmVo {
*/
private String finfo;
/**
* 报警内容
* 内容
*/
private String content;
/**
* 设备名称
*/
private Object[] children;
private String deviceName;
// /**
// * 报警内容
// */
// private Object[] children;
/**
* 创建时间
*/

1
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java

@ -64,6 +64,7 @@ public class MessageConstants {
OVERHAUL_PLAN("overhaul-plan","检修计划"),
OVERHAUL_TASK("overhaul-task","检修任务"),
;
@Getter
private String key;

4
hzims-service/hzims-alarm/pom.xml

@ -138,6 +138,10 @@
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
</dependency>
</dependencies>
<build>

53
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/fdpMqttConfig.java

@ -0,0 +1,53 @@
package com.hnac.hzims.alarm.mqtt;
import com.hnac.hzinfo.subscribe.AnalysisSubscribe;
import com.hnac.hzinfo.subscribe.MqttConfig;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Collections;
/**
* @Author: ty
*/
@Component
public class fdpMqttConfig {
@Autowired
fdpMqttConsumer fdpMqttConsumer;
@Value("${hzims.mqtt.fdp-url}")
private String mqtt_fdp_url;
@Value("${hzims.mqtt.fdp-group}")
private String mqtt_fdp_group;
@Value("${hzims.mqtt.fdp-password}")
private String mqtt_fdp_password;
@Value("${hzims.mqtt.fdp-username}")
private String mqtt_fdp_username;
@Value("${hzims.mqtt.fdp-topname}")
private String mqtt_fdp_topname;
@PostConstruct
public void registerMqtt(){
try {
MqttConfig mqttConfig = new MqttConfig();
mqttConfig.setUrl("tcp://175.6.40.68:1883");
mqttConfig.setGroup("hzims-alarm");
mqttConfig.setPassword("hz123456");
mqttConfig.setUsername("hzinfo");
// mqttConfig.setUrl(mqtt_fdp_url);
// mqttConfig.setGroup(mqtt_fdp_group);
// mqttConfig.setPassword(mqtt_fdp_password);
// mqttConfig.setUsername(mqtt_fdp_username);
AnalysisSubscribe analysisSubscribe = new AnalysisSubscribe();
analysisSubscribe.subscribe(mqttConfig, Collections.singletonList("iot/sync/analytics/#"), fdpMqttConsumer);
// analysisSubscribe.subscribe(mqttConfig, mqtt_fdp_topname, fdpMqttConsumer);
}catch (MqttException e){
e.printStackTrace();
}
}
}

40
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/fdpMqttConsumer.java

@ -0,0 +1,40 @@
package com.hnac.hzims.alarm.mqtt;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.FdpAlarmService;
import com.hnac.hzinfo.subscribe.SubscribeCallBack;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
*
* @Author: ty
*/
@Service
public class fdpMqttConsumer implements SubscribeCallBack {
@Autowired
private FdpAlarmService fdpAlarmService;
@Autowired
private AlarmService alarmService;
@Override
public void onMessage(Map<String, Object> data) {
System.out.println("监听到消息"+data.toString());
String s = JSONObject.toJSONString(data);
//消费代码
List<AlarmEntity> alarmEntities = fdpAlarmService.receiveMessage(s);
//统一数据处理
try {
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错(FdpAlarm):"+e);
}
}
}

16
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/VideoAlarmService.java

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

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

@ -11,12 +11,17 @@ 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 com.hnac.hzims.message.dto.MailMessageDTO;
import com.hnac.hzims.message.fegin.IMessageClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -36,6 +41,8 @@ public class AlarmServiceImpl extends BaseServiceImpl<AlarmMapper, AlarmEntity>
private final AlarmConfigService configService;
private final MessageService messageService;
private final IMessageClient messageClient;
private final IUserClient userClient;
/**
* 查询告警列表
@ -185,4 +192,32 @@ public class AlarmServiceImpl extends BaseServiceImpl<AlarmMapper, AlarmEntity>
}
return new ArrayList<>();
}
/**
* websocket断联发送邮件
* @return
*/
public void sendMailByNum(Integer num,Integer maxConnent,String name) {
if (num>=maxConnent){
MailMessageDTO mailMessageDTO = new MailMessageDTO();
mailMessageDTO.setDeptId(200000L);
mailMessageDTO.setDeptName("华自科技");
mailMessageDTO.setBusinessClassify("system");
mailMessageDTO.setBusinessKey("Mail");
mailMessageDTO.setSubject("邮件发送");
mailMessageDTO.setContent(name+"websocket链接失败;"+"链接失败次数:"+num);
R<List<User>> res = userClient.userListByRoleAlias("200000", "sendMail");
if (!res.isSuccess()||CollectionUtil.isEmpty(res.getData())){
log.error("消息发送失败:无对应用户");
}
String userIds = res.getData().stream().map(s -> s.getId().toString()).collect(Collectors.joining(","));
mailMessageDTO.setUserIds(userIds);
mailMessageDTO.setIsHtml(false);
R<Boolean> booleanR = messageClient.sendMailMsgByUsers(mailMessageDTO);
if (!booleanR.isSuccess()){
log.error("消息发送失败:"+mailMessageDTO.getUserIds()+"--->"+booleanR.getMsg());
}
}
}
}

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

@ -21,8 +21,7 @@ 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;
import static com.hnac.hzims.alarm.constants.AlarmConstants.*;
/**
* 等级告警实现类
@ -78,10 +77,10 @@ public class ConditionAlarmServiceImpl implements ConditionAlarmService {
entity.setAlarmId(item.getFaultId());
entity.setAlarmTime(item.getCreateTime());
entity.setAlarmContext(item.getFinfo());
entity.setAlarmType(EARLY);
entity.setAlarmType(CONDITION);
entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus())));
entity.setStationId(item.getStation());
entity.setAlarmStatus(EARLY_WARNING);
entity.setAlarmSource(CONDITION_ALARM);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){

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

@ -20,6 +20,7 @@ import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -68,15 +69,16 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
@Override
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<FdpAlarmVo> alarms = JSONObject.parseArray(message, FdpAlarmVo.class);
if (CollectionUtil.isEmpty(alarms)) {
FdpAlarmVo alarms = JSONObject.parseObject(message, FdpAlarmVo.class);
if (ObjectUtils.isEmpty(alarms)) {
return new ArrayList<>();
}
List<AlarmEntity> res = alarms.stream().map(s -> {
AlarmEntity entity = getAlarmEntity(s);
return entity;
}).collect(Collectors.toList());
return res;
AlarmEntity entity = getAlarmEntity(alarms);
// List<AlarmEntity> res = alarms.stream().map(s -> {
// AlarmEntity entity = getAlarmEntity(s);
// return entity;
// }).collect(Collectors.toList());
return Collections.singletonList(entity);
}
private AlarmEntity getAlarmEntity(FdpAlarmVo item) {
@ -85,9 +87,10 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
entity.setAlarmTime(item.getCreateTime());
entity.setAlarmContext(item.getFinfo());
entity.setAlarmType(EARLY);
entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus())));
entity.setDeviceName(item.getDeviceName());
entity.setAlarmStatus(Integer.valueOf(item.getStatus()));
entity.setStationId(item.getStation());
entity.setAlarmStatus(EARLY_WARNING);
entity.setAlarmSource(EARLY_WARNING);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){

104
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/VideoAlarmServiceImpl.java

@ -0,0 +1,104 @@
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.constants.AlarmConstants;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.show.service.VideoAlarmService;
import com.hnac.hzims.alarm.vo.SystemAlarmVo;
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.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.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 华自3000告警实现类
*
* @author ty
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class VideoAlarmServiceImpl implements VideoAlarmService {
private final IUserClient userClient;
private final ISysClient sysClient;
private final IMessageClient messageClient;
private final AlarmService alarmService;
private final IStationClient stationClient;
/**
* 定时查询告警信息
* @return String
*/
@Override
public List<AlarmEntity> sendMessage() {
R<List<StationEntity>> listAll = stationClient.getListAll();
if (!listAll.isSuccess() || CollectionUtil.isEmpty(listAll.getData())) {
throw new ServiceException("暂无站点信息");
}
List<StationEntity> stations = listAll.getData();
List<String> collect = stations.stream().map(StationEntity::getCode).collect(Collectors.toList());
// em_infoService
// collect
//
//
//
// map.put("soe_type", AbnormalAlarmConstant.SYSTEM_TYPE_LIST);
// return JSONObject.toJSONString(map);
return new ArrayList<>();
}
/**
* 转换接收服务推送消息
* @param message
*/
@Override
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<SystemAlarmVo> alarms = JSONObject.parseArray(message, SystemAlarmVo.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(SystemAlarmVo item) {
AlarmEntity entity = new AlarmEntity();
entity.setAlarmId(item.getId());
entity.setAlarmTime(DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s"));
entity.setAlarmContext(item.getSoeExplain());
entity.setAlarmType(item.getSoeAlarmType());
entity.setAlarmStatus(item.getSoeStatus());
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;
}
}

37
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/task/VideoScheduledTask.java

@ -0,0 +1,37 @@
package com.hnac.hzims.alarm.task;
import com.hnac.hzims.alarm.show.service.VideoAlarmService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static com.hnac.hzims.alarm.constants.AlarmConstants.VIDEO_SCHEDULED_TASK;
/**
* 各厂站实时/指标数据 定时任务
* @author ysj
*/
@Slf4j
@Component
public class VideoScheduledTask {
@Autowired
private VideoAlarmService service;
/**
* 设备信息缓存
* @return
* @throws Exception
*/
@XxlJob(VIDEO_SCHEDULED_TASK)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> loadEmInfo(String param) {
service.sendMessage();
return new ReturnT<>("SUCCESS");
}
}

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

@ -57,12 +57,11 @@ public class FdpAlarmWebSocket extends WebSocketClient {
List<AlarmEntity> alarmEntities = fdpAlarmService.receiveMessage(message);
//统一数据处理
try {
//websocket 消息推送保存
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错(FdpAlarm):"+e);
}
// 等级告警数据处理
fdpAlarmService.receiveMessage(message);
}
}

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

@ -28,6 +28,7 @@ public class SystemAlarmRegular {
@Autowired
private SystemAlarmService systemAlarmService;
int count=0;
// 定时发送消息
@Scheduled(cron = "0 0/30 * * * ?")
private void regular(){
@ -35,9 +36,14 @@ public class SystemAlarmRegular {
if(ObjectUtil.isNotEmpty(client) && client.isOpen()){
client.send(systemAlarmService.sendMessage());
System.out.println("systemAlarm:存活");
count=0;
}else {
System.out.println("systemAlarm:链接失败");
this.createClient();
count++;
if (count>=3){
}
}
}

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

@ -57,6 +57,7 @@ public class SystemAlarmWebSocket extends WebSocketClient {
List<AlarmEntity> alarmEntities = systemAlarmService.receiveMessage(message);
//统一数据处理
try {
//websocket 消息推送保存
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错:"+e);

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

@ -58,6 +58,7 @@ public class LevelAlarmWebSocket extends WebSocketClient {
List<AlarmEntity> alarmEntities = levelService.receiveMessage(message);
// 等级告警数据处理
try {
//websocket 消息推送保存
alarmService.dealAlarmEntities(alarmEntities);
}catch (Exception e){
throw new ServiceException("集中监控告警数据处理报错(levelAlarm):"+e);

Loading…
Cancel
Save