yang_shj
1 year ago
16 changed files with 330 additions and 22 deletions
@ -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(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
@ -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"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue