|
@@ -1,10 +1,13 @@
|
|
package com.persagy.dmp.rwd.basic.utils;
|
|
package com.persagy.dmp.rwd.basic.utils;
|
|
|
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
|
-import com.persagy.dmp.common.model.entity.BaseEntity;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.persagy.dmp.amqp.handler.RabbitMessageSender;
|
|
import com.persagy.dmp.amqp.handler.RabbitMessageSender;
|
|
-import com.persagy.dmp.rwd.basic.constant.DigitalMessageConstant;
|
|
|
|
import com.persagy.dmp.basic.model.DigitalManageMessage;
|
|
import com.persagy.dmp.basic.model.DigitalManageMessage;
|
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
|
+import com.persagy.dmp.common.model.entity.BaseEntity;
|
|
|
|
+import com.persagy.dmp.rwd.basic.constant.DigitalMessageConstant;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -14,10 +17,13 @@ import org.springframework.stereotype.Component;
|
|
* @date 2021-06-25
|
|
* @date 2021-06-25
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
|
|
+@Slf4j
|
|
public class DigitalMessageHelper {
|
|
public class DigitalMessageHelper {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RabbitMessageSender messageSender;
|
|
private RabbitMessageSender messageSender;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 发送消息
|
|
* 发送消息
|
|
@@ -33,15 +39,20 @@ public class DigitalMessageHelper {
|
|
message.setOldObj(oldVO);
|
|
message.setOldObj(oldVO);
|
|
message.setNewObj(newVO);
|
|
message.setNewObj(newVO);
|
|
// 同步消息
|
|
// 同步消息
|
|
- if(syncFlag) {
|
|
|
|
- messageSender.sendAndReceive(DigitalMessageConstant.MESSAGE_EXCHANGE,
|
|
|
|
- DigitalMessageConstant.MESSAGE_ROUTING,
|
|
|
|
- JSONUtil.toJsonStr(message));
|
|
|
|
- } else {
|
|
|
|
- // 异步消息
|
|
|
|
- messageSender.send(DigitalMessageConstant.MESSAGE_EXCHANGE,
|
|
|
|
- DigitalMessageConstant.MESSAGE_ROUTING,
|
|
|
|
- JSONUtil.toJsonStr(message));
|
|
|
|
|
|
+ try {
|
|
|
|
+ if(syncFlag) {
|
|
|
|
+ messageSender.sendAndReceive(DigitalMessageConstant.MESSAGE_EXCHANGE,
|
|
|
|
+ DigitalMessageConstant.MESSAGE_ROUTING,
|
|
|
|
+ objectMapper.writeValueAsString(message));
|
|
|
|
+ } else {
|
|
|
|
+ // 异步消息
|
|
|
|
+ messageSender.send(DigitalMessageConstant.MESSAGE_EXCHANGE,
|
|
|
|
+ DigitalMessageConstant.MESSAGE_ROUTING,
|
|
|
|
+ objectMapper.writeValueAsString(message));
|
|
|
|
+ }
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
|
+ throw new BusinessException("消息格式有误!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|