Forráskód Böngészése

对象、关系发生变化后,记录变更历史-接口调整

linhuili 3 éve
szülő
commit
0daa1bfaf9

+ 4 - 3
dmp-business/dmp-rwd-plus/src/main/java/com/persagy/dmp/rwd/version/controller/ObjectDigitalHistoryController.java

@@ -9,6 +9,7 @@ import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.common.utils.ResultHelper;
 import com.persagy.dmp.digital.entity.ObjectDigital;
+import com.persagy.dmp.mybatis.utils.ConditionUtil;
 import com.persagy.dmp.rwd.version.entity.ObjectDigitalHistory;
 import com.persagy.dmp.rwd.version.service.IObjectDigitalHistoryService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,8 +44,11 @@ public class ObjectDigitalHistoryController {
             throw new BusinessException(ResponseCode.A0400.getCode(), ResponseCode.A0400.getDesc());
         }
         QueryWrapper<ObjectDigitalHistory> wrapper = new QueryWrapper<>();
+        // 添加所属项目条件
+        ConditionUtil.ensureProjectCriteria(wrapper);
         // 转换查询条件
         QueryCriteriaHelper.toWrapper(wrapper, criteria, ObjectDigitalHistory.class);
+
         Page page = QueryCriteriaHelper.toPage(criteria);
         if(criteria.isOnlyCount()) {
             Integer total = service.queryCount(wrapper);
@@ -62,7 +66,6 @@ public class ObjectDigitalHistoryController {
      */
     @PostMapping("/create")
     public CommonResult<ObjectDigitalHistory> create(@Valid @RequestBody ObjectDigital vo) throws Exception{
-        //新增信息点
         ObjectDigitalHistory insert = service.insert(vo);
         return ResultHelper.single(insert);
     }
@@ -74,7 +77,6 @@ public class ObjectDigitalHistoryController {
      */
     @PostMapping("/update")
     public CommonResult<ObjectDigitalHistory> update(@Valid @RequestBody ObjectDigital vo) throws Exception{
-        //修改信息点
         ObjectDigitalHistory update = service.update(vo);
         return ResultHelper.single(update);
     }
@@ -85,7 +87,6 @@ public class ObjectDigitalHistoryController {
      */
     @PostMapping("/delete")
     public CommonResult<ObjectDigitalHistory> delete(@Valid @RequestBody ObjectDigital vo) throws Exception{
-        //修改信息点
         ObjectDigitalHistory objHistory = service.delete(vo);
         return ResultHelper.single(objHistory);
     }

+ 3 - 3
dmp-business/dmp-rwd-plus/src/main/java/com/persagy/dmp/rwd/version/controller/ObjectRelationHistoryController.java

@@ -9,6 +9,7 @@ import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.common.utils.ResultHelper;
 import com.persagy.dmp.digital.entity.ObjectRelation;
+import com.persagy.dmp.mybatis.utils.ConditionUtil;
 import com.persagy.dmp.rwd.version.entity.ObjectRelationHistory;
 import com.persagy.dmp.rwd.version.service.IObjectRelationHistoryService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +44,8 @@ public class ObjectRelationHistoryController {
             throw new BusinessException(ResponseCode.A0400.getCode(), ResponseCode.A0400.getDesc());
         }
         QueryWrapper<ObjectRelationHistory> wrapper = new QueryWrapper<>();
+        // 添加所属项目条件
+        ConditionUtil.ensureProjectCriteria(wrapper);
         // 转换查询条件
         QueryCriteriaHelper.toWrapper(wrapper, criteria, ObjectRelationHistory.class);
         Page page = QueryCriteriaHelper.toPage(criteria);
@@ -62,7 +65,6 @@ public class ObjectRelationHistoryController {
      */
     @PostMapping("/create")
     public CommonResult<ObjectRelationHistory> create(@Valid @RequestBody ObjectRelation vo) throws Exception{
-        //新增信息点
         ObjectRelationHistory insert = service.insert(vo);
         return ResultHelper.single(insert);
     }
@@ -74,7 +76,6 @@ public class ObjectRelationHistoryController {
      */
     @PostMapping("/update")
     public CommonResult<ObjectRelationHistory> update(@Valid @RequestBody ObjectRelation vo) throws Exception{
-        //修改信息点
         ObjectRelationHistory update = service.update(vo);
         return ResultHelper.single(update);
     }
@@ -85,7 +86,6 @@ public class ObjectRelationHistoryController {
      */
     @PostMapping("/delete")
     public CommonResult<ObjectRelationHistory> delete(@Valid @RequestBody ObjectRelation vo) throws Exception{
-        //修改信息点
         ObjectRelationHistory objHistory = service.delete(vo);
         return ResultHelper.single(objHistory);
     }

+ 50 - 3
dmp-business/dmp-rwd-plus/src/main/java/com/persagy/dmp/rwd/version/handler/ObjectDigitalHistoryMessageHandler.java

@@ -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);

+ 8 - 7
dmp-business/dmp-rwd-plus/src/main/java/com/persagy/dmp/rwd/version/handler/ObjectRelationHistoryMessageHandler.java

@@ -7,9 +7,7 @@ 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.common.exception.BusinessException;
-import com.persagy.dmp.digital.entity.ObjectDigital;
 import com.persagy.dmp.digital.entity.ObjectRelation;
-import com.persagy.dmp.rwd.version.service.IObjectDigitalHistoryService;
 import com.persagy.dmp.rwd.version.service.IObjectRelationHistoryService;
 import com.rabbitmq.client.Channel;
 import lombok.extern.slf4j.Slf4j;
@@ -39,24 +37,27 @@ public class ObjectRelationHistoryMessageHandler extends AbstractRabbitHandlerTe
     @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 objectRelation = messageVO.getNewObj();
             if(objectRelation == null || StrUtil.isEmpty(messageVO.getOperatorType())){
                 log.info("对象关系消息格式有误:{}"+ messageVO);
             }
-            ObjectRelation objectRelationVO = objectMapper.readValue((DataInput) objectRelation, ObjectRelation.class);
+            if(!ObjectRelation.class.getSimpleName().equals(messageVO.getOperatorObj())){
+                return;
+            }
+            ObjectRelation objectRelationVO = objectMapper.readValue(objectRelation.toString(), ObjectRelation.class);
             //新增对象关系,历史记录
-            if(DigitalMessageConstant.OPERATE_REL_AFTER_INSERT.equals(messageVO.getOperatorType())){
+            if(DigitalMessageConstant.OPERATE_AFTER_INSERT.equals(messageVO.getOperatorType())){
                 objectRelationHisService.insert(objectRelationVO);
             }
             //修改对象关系,历史记录
-            if(DigitalMessageConstant.OPERATE_REL_AFTER_INSERT.equals(messageVO.getOperatorType())){
+            if(DigitalMessageConstant.OPERATE_AFTER_INSERT.equals(messageVO.getOperatorType())){
                 objectRelationHisService.update(objectRelationVO);
             }
             //删除对象关系,历史记录
-            if(DigitalMessageConstant.OPERATE_REL_AFTER_INSERT.equals(messageVO.getOperatorType())){
+            if(DigitalMessageConstant.OPERATE_AFTER_INSERT.equals(messageVO.getOperatorType())){
                 objectRelationHisService.delete(objectRelationVO);
             }
         } catch (Exception e) {

+ 3 - 3
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/ObjectRelationServiceImpl.java

@@ -75,7 +75,7 @@ public class ObjectRelationServiceImpl extends ServiceImpl<ObjectRelationMapper,
         iService.saveOrUpdateBatch(voList);
         //发送新增消息
         voList.forEach(vo->{
-            messageSender.sendMessage(DigitalMessageConstant.OPERATE_REL_AFTER_INSERT, null, vo, false);
+            messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_INSERT, null, vo, false);
         });
         return voList;
     }
@@ -152,7 +152,7 @@ public class ObjectRelationServiceImpl extends ServiceImpl<ObjectRelationMapper,
         iService.saveOrUpdateBatch(voList);
         //发送修改消息
         voList.forEach(vo->{
-            messageSender.sendMessage(DigitalMessageConstant.OPERATE_REL_AFTER_UPDATE, null, vo, false);
+            messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_UPDATE, null, vo, false);
         });
         return voList;
     }
@@ -177,7 +177,7 @@ public class ObjectRelationServiceImpl extends ServiceImpl<ObjectRelationMapper,
         iService.saveOrUpdateBatch(list);
         //发送删除消息
         list.forEach(vo->{
-            messageSender.sendMessage(DigitalMessageConstant.OPERATE_REL_AFTER_DELETE, null, vo, false);
+            messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_DELETE, null, vo, false);
         });
         return list;
     }

+ 0 - 7
dmp-comp/dmp-digital-starter/src/main/java/com/persagy/dmp/basic/constant/DigitalMessageConstant.java

@@ -24,11 +24,4 @@ public interface DigitalMessageConstant {
     String OPERATE_AFTER_UPDATE = "AfterUpdate";
     /** 删除后 */
     String OPERATE_AFTER_DELETE = "AfterDelete";
-
-    /** 新增关系数据 */
-    String OPERATE_REL_AFTER_INSERT = "RelAfterInsert";
-    /** 修改关系后 */
-    String OPERATE_REL_AFTER_UPDATE = "RelAfterUpdate";
-    /** 删除关系后 */
-    String OPERATE_REL_AFTER_DELETE = "RelAfterDelete";
 }