Commit f800ac00 authored by 赵啸非's avatar 赵啸非

添加设备上线和下线的业务日志记录

parent b2b6f9fb
......@@ -3,7 +3,9 @@ package com.mortals.xhx.base.framework.listener;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IMessageProduceService;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.key.RedisKey;
......@@ -53,6 +55,8 @@ public class DirectDynamicListener implements MessageListener {
private SendTaskThreadPool sendTaskThreadPool;
@Autowired
private ICacheService cacheService;
@Autowired
private IMessageProduceService messageProducer;
@Override
......@@ -91,6 +95,20 @@ public class DirectDynamicListener implements MessageListener {
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台
deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.ONLINE);
//保存业务消息为离线
BizLogPdu bizLogPdu = new BizLogPdu();
bizLogPdu.initAttrValue();
//保存为产品名称
bizLogPdu.setAppName(productEntity.getProductName());
bizLogPdu.setTraceID(IdUtil.objectId());
bizLogPdu.setUserCode("system");
bizLogPdu.setDeviceCode(deviceEntity.getDeviceCode());
bizLogPdu.setEventTopic("online");
bizLogPdu.setEventTopicName(LogTypeEnum.上报事件.name());
bizLogPdu.setMsg("设备上线");
bizLogPdu.setLogLevel("INFO");
bizLogPdu.setLogTime(new Date());
messageProducer.syncBizSend(bizLogPdu);
}
log.info("id:{},deviceCode:{} deviceStatus:{}==>上线 ", deviceEntity.getId(), deviceEntity.getDeviceCode(), deviceEntity.getDeviceStatus());
}
......
package com.mortals.xhx.daemon.task;
import cn.hutool.core.util.IdUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IMessageProduceService;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.common.code.DeviceMethodEnum;
import com.mortals.xhx.common.code.DeviceStatusEnum;
import com.mortals.xhx.common.code.LogTypeEnum;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
......@@ -38,6 +42,8 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
private ProductService productService;
@Autowired
private PlatformService platformService;
@Autowired
private IMessageProduceService messageProducer;
@Override
public void excuteTask(ITask task) throws AppException {
......@@ -45,17 +51,12 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
List<DeviceEntity> waitDeviceInfos = new ArrayList<>();
while (true) {
DeviceEntity deviceEntity = cacheService.lpop(RedisKey.KEY_DEVICE_ONLINE_QUEUE, DeviceEntity.class);
log.info("deviceEntity:{}",deviceEntity==null);
if (ObjectUtils.isEmpty(deviceEntity)) {
log.info("deviceEntity:{}",deviceEntity==null);
break;
} else {
waitDeviceInfos.add(deviceEntity);
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
log.error("线程休眠异常",e);
}
}
log.info("waitDeviceInfos size:{}", waitDeviceInfos.size());
......@@ -85,6 +86,22 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//通知第三方平台
deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.OFFLINE);
//保存业务消息为离线
BizLogPdu bizLogPdu = new BizLogPdu();
bizLogPdu.initAttrValue();
//保存为产品名称
bizLogPdu.setAppName(productEntity.getProductName());
bizLogPdu.setTraceID(IdUtil.objectId());
bizLogPdu.setUserCode("system");
bizLogPdu.setDeviceCode(deviceEntity.getDeviceCode());
bizLogPdu.setEventTopic("offline");
bizLogPdu.setEventTopicName(LogTypeEnum.上报事件.name());
bizLogPdu.setMsg("设备离线");
bizLogPdu.setLogLevel("INFO");
bizLogPdu.setLogTime(new Date());
messageProducer.syncBizSend(bizLogPdu);
}
});
}
......
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