Commit 7a0859a9 authored by 赵啸非's avatar 赵啸非

修改设备通知刷新消息

parent 4d43ac55
......@@ -48,7 +48,7 @@ public class MessageProducer implements IMessageProduceService, RabbitMessageSer
@Override
public void syncOperSend(OperateLogPdu operLogPdu) {
log.info("send poerate log ==>{}", JSON.toJSONString(operLogPdu));
log.info("send operate log ==>{}", JSON.toJSONString(operLogPdu));
String send = JSON.toJSONString(operLogPdu);
rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.OPERATION_LOG_QUEUE, send);
}
......
......@@ -38,6 +38,7 @@ import com.mortals.xhx.common.utils.EncryptUtil;
import com.mortals.xhx.common.utils.SendTaskThreadPool;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.firm.model.FirmEntity;
......@@ -823,7 +824,7 @@ public class DeviceApiController {
if (ObjectUtils.isEmpty(req.getDeviceCode())) {
throw new AppException(DEVICE_CODE_IS_EMPTY, DEVICE_CODE_IS_EMPTY_CONTENT);
}
DeviceEntity deviceEntity = deviceService.getExtCache(req.getDeviceCode());
DeviceEntity deviceEntity = deviceService.selectOne(new DeviceQuery().deviceCode(req.getDeviceCode()));
if (ObjectUtils.isEmpty(deviceEntity)) {
//初始化新增基础设备,后续在线完善信息后再行注册添加
deviceEntity = new DeviceEntity();
......
package com.mortals.xhx.busiz.web;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.busiz.req.UploadDeviceReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.queue.DefaultTbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static com.mortals.xhx.common.key.Constant.MESSAGETYPE_NOTIFY_REFRESH;
@RestController
@Slf4j
@RequestMapping("/notify")
public class DeviceSendMsgController {
@Autowired
private DeviceService deviceService;
@Autowired
private MessageProducer messageProducer;
@PostMapping("refreshMessage")
public String refreshMessage(@RequestBody UploadDeviceReq req) {
log.info("【设备通知刷新数据】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<String> rsp = new ApiResp<>();
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
try {
//查询站点设备并通知每个设备
List<DeviceEntity> deviceList = deviceService.find(new DeviceQuery().siteId(req.getSiteId()));
for (DeviceEntity deviceEntity : deviceList) {
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, MESSAGETYPE_NOTIFY_REFRESH);
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "==", header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE,Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(),JSON.toJSONString(queueMsg));
}
} catch (Exception e) {
log.error("接收数据失败", e);
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
}
log.debug("响应【设备通知刷新数据】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp);
}
}
......@@ -108,6 +108,11 @@ public final class Constant {
*/
public static final String MESSAGETYPE_HEARTBEAT = "HEART_BEAT";
/**
* 消息类型(通知更新)
*/
public static final String MESSAGETYPE_NOTIFY_REFRESH = "NOTIFY_REFRESH";
/**
* 消息类型(upgread)
*/
......
......@@ -13,14 +13,11 @@ import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceLogEntity;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.platform.model.PlatformEntity;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.queue.DefaultTbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import com.mortals.xhx.queue.TopicPartitionInfo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
......@@ -57,7 +54,7 @@ public class DownMsgTask implements Runnable {
DeviceEntity deviceEntity = deviceService.getExtCache(item.getDeviceCode());
if (!ObjectUtils.isEmpty(deviceEntity)) {
//将上报信息转发到mq中
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
/* PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
if (ObjectUtils.isEmpty(platformEntity)) {
log.error("当前设备未配置所属系统平台,请在后台配置后再激活!");
return;
......@@ -66,9 +63,9 @@ public class DownMsgTask implements Runnable {
if (ObjectUtils.isEmpty(productEntity)) {
log.error("当前设备未配置所属产品,请在后台配置后再激活!");
return;
}
String exchangeName = platformEntity.getPlatformSn() + Constant.EXCHANGE_SPLIT + productEntity.getProductCode();
TopicPartitionInfo info = TopicPartitionInfo.builder().exchangeName(exchangeName).topic(Constant.DOWN_TOPIC + deviceEntity.getDeviceMac()).build();
}*/
// String exchangeName = platformEntity.getPlatformSn() + Constant.EXCHANGE_SPLIT + productEntity.getProductCode();
// TopicPartitionInfo info = TopicPartitionInfo.builder().exchangeName(exchangeName).topic(Constant.DOWN_TOPIC + deviceEntity.getDeviceMac()).build();
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, item.getMessageType());
header.put(MessageHeader.DEVICECODE, item.getDeviceCode());
......
......@@ -668,7 +668,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
protected void updateBefore(DeviceEntity entity, Context context) throws AppException {
super.updateBefore(entity, context);
ProductEntity productEntity = productService.get(entity.getProductId(), context);
entity.setProductCode(productEntity.getProductCode());
entity.setProductCode(productEntity==null?"":productEntity.getProductCode());
updateDeviceHomeUrl(entity);
}
......
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