Commit 56af34af authored by 赵啸非's avatar 赵啸非

分组更新设备

parent 72793dc8
...@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; ...@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.BizLogPdu; import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.model.ErrorLogPdu; import com.mortals.framework.model.ErrorLogPdu;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IMessageProduceService; import com.mortals.framework.service.IMessageProduceService;
import com.mortals.xhx.common.code.*; import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.RedisKey; import com.mortals.xhx.common.key.RedisKey;
...@@ -66,139 +67,142 @@ public class CustomerKeyExpirationListener implements MessageListener { ...@@ -66,139 +67,142 @@ public class CustomerKeyExpirationListener implements MessageListener {
private ISmsSetFeign smsSetFeign; private ISmsSetFeign smsSetFeign;
@Autowired @Autowired
private IMessageProduceService messageProducer; private IMessageProduceService messageProducer;
@Autowired
private ICacheService cacheService;
@Override @Override
public void onMessage(Message message, byte[] bytes) { public void onMessage(Message message, byte[] bytes) {
String key = message.toString(); String key = message.toString();
String subStr = StrUtil.removePrefix(key, RedisKey.KEY_DEVICE_ONLINE_CACHE); //解决分布式系统 重复获取广播消息
if (!subStr.equals(key)) { boolean setnx = cacheService.setnx(key, 1, 10);
DeviceEntity deviceEntity = deviceService.getExtCache(subStr);
if (!ObjectUtils.isEmpty(deviceEntity)) { if (setnx) {
if (deviceEntity.getDeviceStatus() == DeviceStatusEnum.在线.getValue()) { String subStr = StrUtil.removePrefix(key, RedisKey.KEY_DEVICE_ONLINE_CACHE);
deviceEntity.setOfflineTime(new Date()); if (!subStr.equals(key)) {
deviceEntity.setDeviceStatus(DeviceStatusEnum.离线.getValue()); DeviceEntity deviceEntity = deviceService.getExtCache(subStr);
if (!ObjectUtils.isEmpty(deviceEntity)) {
DeviceEntity entity = new DeviceEntity(); if (deviceEntity.getDeviceStatus() == DeviceStatusEnum.在线.getValue()) {
entity.setOfflineTime(new Date()); deviceEntity.setOfflineTime(new Date());
entity.setUpdateTime(new Date()); deviceEntity.setDeviceStatus(DeviceStatusEnum.离线.getValue());
entity.setDeviceStatus(DeviceStatusEnum.离线.getValue());
DeviceEntity condition = new DeviceEntity(); DeviceEntity entity = new DeviceEntity();
condition.setId(deviceEntity.getId()); entity.setOfflineTime(new Date());
deviceService.getDeviceDao().update(entity, condition); entity.setUpdateTime(new Date());
deviceService.putCache(deviceEntity.getId().toString(), deviceEntity); entity.setDeviceStatus(DeviceStatusEnum.离线.getValue());
log.info("deviceCode:{},deviceName:{}==>离线", deviceEntity.getDeviceCode(), deviceEntity.getDeviceName()); DeviceEntity condition = new DeviceEntity();
// deviceService.update(deviceEntity); condition.setId(deviceEntity.getId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString()); deviceService.getDeviceDao().update(entity, condition);
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString()); deviceService.putCache(deviceEntity.getId().toString(), deviceEntity);
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) { log.info("deviceCode:{},deviceName:{}==>离线", deviceEntity.getDeviceCode(), deviceEntity.getDeviceName());
//通知第三方平台 // deviceService.update(deviceEntity);
deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.OFFLINE); PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
//保存业务消息为离线 ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
BizLogPdu bizLogPdu = new BizLogPdu(); if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
bizLogPdu.initAttrValue(); //通知第三方平台
//保存为产品名称 deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.OFFLINE);
bizLogPdu.setAppName(productEntity.getProductCode()); //保存业务消息为离线
bizLogPdu.setTraceID(IdUtil.objectId()); BizLogPdu bizLogPdu = new BizLogPdu();
bizLogPdu.setUserCode("system"); bizLogPdu.initAttrValue();
bizLogPdu.setDeviceCode(deviceEntity.getDeviceCode()); //保存为产品名称
bizLogPdu.setEventTopic("offline"); bizLogPdu.setAppName(productEntity.getProductCode());
bizLogPdu.setEventTopicName(LogTypeEnum.上报事件.name()); bizLogPdu.setTraceID(IdUtil.objectId());
bizLogPdu.setMsg(Base64.encode("设备下线")); bizLogPdu.setUserCode("system");
bizLogPdu.setLogLevel("INFO"); bizLogPdu.setDeviceCode(deviceEntity.getDeviceCode());
bizLogPdu.setLogTime(new Date()); bizLogPdu.setEventTopic("offline");
messageProducer.syncBizSend(bizLogPdu); bizLogPdu.setEventTopicName(LogTypeEnum.上报事件.name());
bizLogPdu.setMsg(Base64.encode("设备下线"));
ErrorLogPdu errorLogPdu = new ErrorLogPdu(); bizLogPdu.setLogLevel("INFO");
errorLogPdu.initAttrValue(); bizLogPdu.setLogTime(new Date());
errorLogPdu.setTraceID(IdUtil.objectId()); messageProducer.syncBizSend(bizLogPdu);
errorLogPdu.setAppName(productEntity.getProductCode());
errorLogPdu.setMessage(deviceEntity.getDeviceName()+deviceEntity.getDeviceCode()+"设备下线!"); ErrorLogPdu errorLogPdu = new ErrorLogPdu();
errorLogPdu.setPlatform("webos"); errorLogPdu.initAttrValue();
errorLogPdu.setCulprit(""); errorLogPdu.setTraceID(IdUtil.objectId());
errorLogPdu.setTags(""); errorLogPdu.setAppName(productEntity.getProductCode());
errorLogPdu.setLevel("INFO"); errorLogPdu.setMessage(deviceEntity.getDeviceName() + deviceEntity.getDeviceCode() + "设备下线!");
errorLogPdu.setEnvironment(""); errorLogPdu.setPlatform("webos");
errorLogPdu.setReleaseVersion(""); errorLogPdu.setCulprit("");
errorLogPdu.setFingerprint(LogTypeEnum.上报事件.name()); errorLogPdu.setTags("");
errorLogPdu.setThreadNo(Thread.currentThread().toString()); errorLogPdu.setLevel("INFO");
errorLogPdu.setErrorStack(Thread.currentThread()+deviceEntity.getDeviceName()+deviceEntity.getDeviceCode()+"设备下线!"); errorLogPdu.setEnvironment("");
errorLogPdu.setContext(""); errorLogPdu.setReleaseVersion("");
errorLogPdu.setExtra(""); errorLogPdu.setFingerprint(LogTypeEnum.上报事件.name());
errorLogPdu.setLogTime(new Date()); errorLogPdu.setThreadNo(Thread.currentThread().toString());
messageProducer.syncErrorSend(errorLogPdu); errorLogPdu.setErrorStack(Thread.currentThread() + deviceEntity.getDeviceName() + deviceEntity.getDeviceCode() + "设备下线!");
errorLogPdu.setContext("");
//生成异常日志 errorLogPdu.setExtra("");
} errorLogPdu.setLogTime(new Date());
messageProducer.syncErrorSend(errorLogPdu);
//生成异常日志
}
//保存离线告警消息 //保存离线告警消息
DeviceAlarmInfoEntity alarmInfoEntity = new DeviceAlarmInfoEntity(); DeviceAlarmInfoEntity alarmInfoEntity = new DeviceAlarmInfoEntity();
alarmInfoEntity.initAttrValue(); alarmInfoEntity.initAttrValue();
alarmInfoEntity.setAlarmDevice(deviceEntity.getId()); alarmInfoEntity.setAlarmDevice(deviceEntity.getId());
alarmInfoEntity.setSiteId(deviceEntity.getSiteId()); alarmInfoEntity.setSiteId(deviceEntity.getSiteId());
alarmInfoEntity.setAlarmTime(new Date()); alarmInfoEntity.setAlarmTime(new Date());
alarmInfoEntity.setDeviceName(deviceEntity.getDeviceName()); alarmInfoEntity.setDeviceName(deviceEntity.getDeviceName());
alarmInfoEntity.setDeviceCode(deviceEntity.getDeviceCode()); alarmInfoEntity.setDeviceCode(deviceEntity.getDeviceCode());
alarmInfoEntity.setAlarmContent(String.format("设备告警:%s设备:%s已离线,请注意检查!", productEntity.getProductName(), deviceEntity.getDeviceName() + ":" + deviceEntity.getDeviceName())); alarmInfoEntity.setAlarmContent(String.format("设备告警:%s设备:%s已离线,请注意检查!", productEntity.getProductName(), deviceEntity.getDeviceName() + ":" + deviceEntity.getDeviceName()));
alarmInfoEntity.setAlarmType(AlarmTypeEnum.离线.getValue()); alarmInfoEntity.setAlarmType(AlarmTypeEnum.离线.getValue());
alarmInfoEntity.setAlarmLevel(AlarmLevelEnum.一般.getValue()); alarmInfoEntity.setAlarmLevel(AlarmLevelEnum.一般.getValue());
alarmInfoEntity.setAlarmStatus(AlarmStatusEnum.未清除.getValue()); alarmInfoEntity.setAlarmStatus(AlarmStatusEnum.未清除.getValue());
alarmInfoEntity.setAlarmReceivePersonnel(deviceEntity.getLeadingOfficial()); alarmInfoEntity.setAlarmReceivePersonnel(deviceEntity.getLeadingOfficial());
alarmInfoEntity.setReceivePersonnelTelephone(deviceEntity.getLeadingOfficialTelephone()); alarmInfoEntity.setReceivePersonnelTelephone(deviceEntity.getLeadingOfficialTelephone());
alarmInfoEntity.setCreateTime(new Date()); alarmInfoEntity.setCreateTime(new Date());
alarmInfoEntity.setCreateUserId(1L); alarmInfoEntity.setCreateUserId(1L);
// TODO: 2022/6/23 告警信息保存与发送 // TODO: 2022/6/23 告警信息保存与发送
AlarmConfigEntity alarmConfigEntity = alarmConfigService.selectOne(new AlarmConfigQuery().productId(productEntity.getId())); AlarmConfigEntity alarmConfigEntity = alarmConfigService.selectOne(new AlarmConfigQuery().productId(productEntity.getId()));
if (!ObjectUtils.isEmpty(alarmConfigEntity)) { if (!ObjectUtils.isEmpty(alarmConfigEntity)) {
/* if (alarmConfigEntity.getAlarmPusW1ay() == AlarmPusW1ayEnum.站内信息.getValue()) { /* if (alarmConfigEntity.getAlarmPusW1ay() == AlarmPusW1ayEnum.站内信息.getValue()) {
}*/ }*/
if(EnabledEnum.启用.getValue()==alarmConfigEntity.getEnabled()){ if (EnabledEnum.启用.getValue() == alarmConfigEntity.getEnabled()) {
alarmInfoEntity.setProductId(productEntity.getId()); alarmInfoEntity.setProductId(productEntity.getId());
alarmInfoEntity.setProductCode(productEntity.getProductCode()); alarmInfoEntity.setProductCode(productEntity.getProductCode());
alarmInfoEntity.setProductName(productEntity.getProductName()); alarmInfoEntity.setProductName(productEntity.getProductName());
alarmInfoEntity.setPush(YesNoEnum.YES.getValue()); alarmInfoEntity.setPush(YesNoEnum.YES.getValue());
deviceAlarmInfoService.save(alarmInfoEntity); deviceAlarmInfoService.save(alarmInfoEntity);
} }
if (alarmConfigEntity.getAlarmPusW1ay() == AlarmPusW1ayEnum.短信.getValue()) {
// TODO: 2022/7/4 发送短信
Rest<RespData<List<SmsSetPdu>>> respDataRest = smsSetFeign.list(new SmsSetPdu().siteId(deviceEntity.getSiteId()));
if (respDataRest.getCode() == YesNoEnum.YES.getValue()) {
List<SmsSetPdu> data = respDataRest.getData().getData();
if (!ObjectUtils.isEmpty(data)) {
Integer messageoff = data.get(0).getMessageoff();
if (messageoff == YesNoEnum.YES.getValue()) {
// todo 发送短信
//短信使用模板,如 设备告警:{产品}设备:{设备名称加编码}已离线,请注意检查!
int count = deviceAlarmInfoService.count(new DeviceAlarmInfoQuery().alarmDevice(deviceEntity.getId()), null);
if (count > 0) {
AlarmSmsSendEntity alarmSmsSendEntity = new AlarmSmsSendEntity();
alarmSmsSendEntity.initAttrValue();
alarmSmsSendEntity.setId(IdUtil.getSnowflake().nextId());
alarmSmsSendEntity.setSiteId(deviceEntity.getSiteId());
alarmSmsSendEntity.setMobile(deviceEntity.getLeadingOfficial());
alarmSmsSendEntity.setReceiver(deviceEntity.getLeadingOfficialTelephone());
Map<String, String> map = new HashMap<>();
map.put("1", productEntity.getProductName());
map.put("2", deviceEntity.getDeviceName() + ":" + deviceEntity.getDeviceName());
alarmSmsSendEntity.setSendMess(JSON.toJSONString(map));
alarmSmsSendEntity.setSendStatus(SendStatusEnum.未发送.getValue());
alarmSmsSendService.save(alarmSmsSendEntity, null);
}
} else {
//推送站类
if (alarmConfigEntity.getAlarmPusW1ay() == AlarmPusW1ayEnum.短信.getValue()) {
// TODO: 2022/7/4 发送短信
Rest<RespData<List<SmsSetPdu>>> respDataRest = smsSetFeign.list(new SmsSetPdu().siteId(deviceEntity.getSiteId()));
if (respDataRest.getCode() == YesNoEnum.YES.getValue()) {
List<SmsSetPdu> data = respDataRest.getData().getData();
if (!ObjectUtils.isEmpty(data)) {
Integer messageoff = data.get(0).getMessageoff();
if (messageoff == YesNoEnum.YES.getValue()) {
// todo 发送短信
//短信使用模板,如 设备告警:{产品}设备:{设备名称加编码}已离线,请注意检查!
int count = deviceAlarmInfoService.count(new DeviceAlarmInfoQuery().alarmDevice(deviceEntity.getId()), null);
if (count > 0) {
AlarmSmsSendEntity alarmSmsSendEntity = new AlarmSmsSendEntity();
alarmSmsSendEntity.initAttrValue();
alarmSmsSendEntity.setId(IdUtil.getSnowflake().nextId());
alarmSmsSendEntity.setSiteId(deviceEntity.getSiteId());
alarmSmsSendEntity.setMobile(deviceEntity.getLeadingOfficial());
alarmSmsSendEntity.setReceiver(deviceEntity.getLeadingOfficialTelephone());
Map<String, String> map = new HashMap<>();
map.put("1", productEntity.getProductName());
map.put("2", deviceEntity.getDeviceName() + ":" + deviceEntity.getDeviceName());
alarmSmsSendEntity.setSendMess(JSON.toJSONString(map));
alarmSmsSendEntity.setSendStatus(SendStatusEnum.未发送.getValue());
alarmSmsSendService.save(alarmSmsSendEntity, null);
}
} else {
//推送站类
}
} }
} }
} }
} }
}
// deviceAlarmInfoService.save(alarmInfoEntity);
// deviceAlarmInfoService.save(alarmInfoEntity); }
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment