|
@@ -1,12 +1,16 @@
|
|
|
package com.persagy.dmp.rwd.version.handler;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.amqp.handler.AbstractRabbitHandlerTemplate;
|
|
|
import com.persagy.dmp.basic.constant.DigitalMessageConstant;
|
|
|
import com.persagy.dmp.basic.model.DigitalManageMessage;
|
|
|
+import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
+import com.persagy.dmp.digital.client.DigitalObjectFacade;
|
|
|
import com.persagy.dmp.digital.entity.ObjectDigital;
|
|
|
import com.persagy.dmp.rwd.version.service.IObjectDigitalHistoryService;
|
|
|
import com.rabbitmq.client.Channel;
|
|
@@ -15,6 +19,9 @@ import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.io.DataInput;
|
|
|
|
|
@@ -26,6 +33,8 @@ import java.io.DataInput;
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@RabbitListener
|
|
|
+@RestController
|
|
|
+@RequestMapping("object")
|
|
|
public class ObjectDigitalHistoryMessageHandler extends AbstractRabbitHandlerTemplate {
|
|
|
|
|
|
@Autowired
|
|
@@ -37,14 +46,52 @@ public class ObjectDigitalHistoryMessageHandler extends AbstractRabbitHandlerTem
|
|
|
@Override
|
|
|
protected void handler(String message, Channel channel, Message vo) {
|
|
|
try {
|
|
|
- log.info("接收对象消息:{}", message);
|
|
|
+ log.info("对象历史记录-接收对象消息:{}", message);
|
|
|
//接收对象消息
|
|
|
DigitalManageMessage messageVO = objectMapper.readValue(message, DigitalManageMessage.class);
|
|
|
ObjectNode objectDigital = messageVO.getNewObj();
|
|
|
- if(objectDigital == null || StrUtil.isEmpty(messageVO.getOperatorType())){
|
|
|
+ if(objectDigital == null || StrUtil.isEmpty(messageVO.getOperatorType()) || StrUtil.isEmpty(messageVO.getOperatorObj())){
|
|
|
log.info("对象消息格式有误:{}"+ messageVO);
|
|
|
+ return;
|
|
|
}
|
|
|
- ObjectDigital objectDigitalVO = objectMapper.readValue((DataInput) objectDigital, ObjectDigital.class);
|
|
|
+ if(!ObjectDigital.class.getSimpleName().equals(messageVO.getOperatorObj())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ObjectDigital objectDigitalVO = objectMapper.readValue(objectDigital.toString(), ObjectDigital.class);
|
|
|
+ //新增对象,历史记录
|
|
|
+ if(DigitalMessageConstant.OPERATE_AFTER_INSERT.equals(messageVO.getOperatorType())){
|
|
|
+ objectDigitalHisService.insert(objectDigitalVO);
|
|
|
+ }
|
|
|
+ //修改对象,历史记录
|
|
|
+ if(DigitalMessageConstant.OPERATE_AFTER_UPDATE.equals(messageVO.getOperatorType())){
|
|
|
+ objectDigitalHisService.update(objectDigitalVO);
|
|
|
+ }
|
|
|
+ //删除对象,历史记录
|
|
|
+ if(DigitalMessageConstant.OPERATE_AFTER_DELETE.equals(messageVO.getOperatorType())){
|
|
|
+ objectDigitalHisService.delete(objectDigitalVO);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ throw new BusinessException(e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/test")
|
|
|
+ public void handler2(@RequestBody String message) {
|
|
|
+ try {
|
|
|
+ log.info("对象历史记录-接收对象消息:{}", message);
|
|
|
+ //接收对象消息
|
|
|
+ DigitalManageMessage messageVO = objectMapper.readValue(message, DigitalManageMessage.class);
|
|
|
+ ObjectNode objectDigital = messageVO.getNewObj();
|
|
|
+ if(objectDigital == null || StrUtil.isEmpty(messageVO.getOperatorType()) || StrUtil.isEmpty(messageVO.getOperatorObj())){
|
|
|
+ log.info("对象消息格式有误:{}"+ messageVO);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(!ObjectDigital.class.getSimpleName().equals(messageVO.getOperatorObj())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ObjectDigital objectDigitalVO = objectMapper.readValue(objectDigital.toString(), ObjectDigital.class);
|
|
|
//新增对象,历史记录
|
|
|
if(DigitalMessageConstant.OPERATE_AFTER_INSERT.equals(messageVO.getOperatorType())){
|
|
|
objectDigitalHisService.insert(objectDigitalVO);
|