Commit 17783e2e authored by 赵啸非's avatar 赵啸非

修改设备通知刷新消息

parent d8e3734b
......@@ -14,6 +14,9 @@ public class DeviceMsgReq implements Serializable {
* 设备编码
*/
private String deviceCode;
private String productCode;
/**
* 消息类型
*/
......
......@@ -568,6 +568,49 @@ public class DeviceApiController {
}
/**
* 第三方回调产品
*
* @param
* @return
*/
@PostMapping("callbackByProduct")
@UnAuth
public String callbackByProduct(@RequestBody DeviceMsgReq deviceMsgReq) {
log.info("【设备数据消息接收】【请求体】--> " + JSONObject.toJSONString(deviceMsgReq));
ApiResp<String> rsp = new ApiResp<>();
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
try {
ProductEntity productEntity = productService.selectOne(new ProductQuery().productCode(deviceMsgReq.getProductCode()));
if(!ObjectUtils.isEmpty(productEntity)){
List<DeviceEntity> deviceEntities = deviceService.find(new DeviceQuery().productId(productEntity.getId()));
List<DeviceMsgReq> list = deviceEntities.stream().map(item -> {
DeviceMsgReq msgReq = new DeviceMsgReq();
BeanUtils.copyProperties(deviceMsgReq,msgReq,BeanUtil.getNullPropertyNames(deviceMsgReq));
msgReq.setDeviceCode(item.getDeviceCode());
return msgReq;
}).collect(Collectors.toList());
DownMsgTask downMsgTask = new DownMsgTask(list, platformService, productService, deviceService, deviceLogService, messageProducer);
sendTaskThreadPool.execute(downMsgTask);
}
} catch (AppException e) {
log.error("接收数据失败", e);
rsp.setCode(e.getCode());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
} 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);
}
/**
* 设备数据上报
*
......
......@@ -38,6 +38,8 @@ public class DeviceSendMsgController {
@Autowired
private MessageProducer messageProducer;
@PostMapping("refreshMessage")
public String refreshMessage(@RequestBody UploadDeviceReq req) {
log.info("【设备通知刷新数据】【请求体】--> " + JSONObject.toJSONString(req));
......
......@@ -85,10 +85,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
private AlarmSmsSendService alarmSmsSendService;
@Autowired
private MessageProducer messageProducer;
@Autowired
private DirectMessageListenerContainer container;
@Autowired
private MessageService messageService;
......
......@@ -7,12 +7,15 @@ import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.common.code.LogTypeEnum;
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.DeviceLogEntity;
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.product.dao.ProductVersionDao;
import com.mortals.xhx.module.product.model.ProductEntity;
......@@ -26,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import static com.mortals.xhx.common.key.Constant.MESSAGETYPE_UPGREAD;
......@@ -46,6 +50,8 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
private DeviceService deviceService;
@Autowired
private MessageProducer messageProducer;
@Autowired
private DeviceLogService deviceLogService;
@Override
......@@ -62,9 +68,7 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
@Override
protected void saveAfter(ProductVersionEntity entity, Context context) throws AppException {
//推送消息
if (!ObjectUtils.isEmpty(entity.getProductId())) {
ProductEntity productEntity = productService.get(entity.getProductId(), context);
if (!ObjectUtils.isEmpty(productEntity)) {
......@@ -77,6 +81,21 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "==", header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg));
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue();
deviceLogEntity.setTraceID(IdUtil.fastSimpleUUID());
deviceLogEntity.setSiteId(deviceEntity.getSiteId());
deviceLogEntity.setDeviceId(deviceEntity.getId());
deviceLogEntity.setDeviceName(deviceEntity.getDeviceName());
deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode());
deviceLogEntity.setMessageHead(MESSAGETYPE_UPGREAD);
deviceLogEntity.setContent("==");
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity,null);
}
}
......
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