zhaoyk 3 年之前
父節點
當前提交
a413a4d4bd

+ 1 - 1
src/main/java/com/persagy/bdtp/adm/aop/ExceptionAspect.java

@@ -21,7 +21,7 @@ public class ExceptionAspect {
     @Around("handle()")
     public Object aroundInvoke(ProceedingJoinPoint point) throws Throwable {
         try{
-            return point.proceed(point.getArgs());
+            return point.proceed();
         } catch (CallException e) {
             return e.getErrorResult();
         }

+ 16 - 0
src/main/java/com/persagy/bdtp/adm/config/AdmCommonConfig.java

@@ -0,0 +1,16 @@
+package com.persagy.bdtp.adm.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.bdtp.adm.datatx.ObjectMapper4Tx;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class AdmCommonConfig {
+
+	@Bean(name = "mapper4Tx")
+	public ObjectMapper4Tx getObjectMapper4Tx(){
+		return new ObjectMapper4Tx(new ObjectMapper());
+	}
+
+}

+ 0 - 38
src/main/java/com/persagy/bdtp/adm/controller/TestController.java

@@ -1,38 +0,0 @@
-package com.persagy.bdtp.adm.controller;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.persagy.bdtp.adm.common.AdmMessageConst;
-import com.persagy.bdtp.adm.common.AdmRequest;
-import com.persagy.bdtp.adm.common.AdmResult;
-import com.persagy.bdtp.adm.dao.AdmObjectMapper;
-import com.persagy.bdtp.adm.entity.AdmObject;
-import com.persagy.bdtp.adm.entity.D2mMessage;
-import com.persagy.bdtp.adm.service.ISyncModel;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.Arrays;
-
-@RestController
-@RequestMapping("/test")
-public class TestController {
-
-	@Autowired
-	private ISyncModel syncModel;
-
-	@Autowired
-	private AdmObjectMapper admObjectMapper;
-
-	@RequestMapping("/testMq")
-	public AdmResult<Object> testMq(@RequestBody AdmRequest req){
-		AdmObject obj = admObjectMapper.selectOne(new QueryWrapper<AdmObject>().eq("id", "Eq00022200023a8d5a59a7fb49a89dfa6ae746518bc2"));
-		obj.getInfos().put("comp_type", "FFFAAL-声光报警器");
-		D2mMessage msg = new D2mMessage();
-		msg.setAddItems(Arrays.asList(obj));
-		syncModel.sendMessageToModel(msg);
-		return AdmResult.success(null);
-	}
-
-}

+ 8 - 0
src/main/java/com/persagy/bdtp/adm/datatx/ObjectForTx.java

@@ -0,0 +1,8 @@
+package com.persagy.bdtp.adm.datatx;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties({"grouping", "groupCode", "projectId", "buildingId", "uploadFlag", "clientDevice", "clientId", "d2mState", "deliveryState"})
+public interface ObjectForTx {
+
+}

+ 40 - 0
src/main/java/com/persagy/bdtp/adm/datatx/ObjectMapper4Tx.java

@@ -0,0 +1,40 @@
+package com.persagy.bdtp.adm.datatx;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.bdtp.adm.entity.AdmObject;
+
+/**
+ * 针对数据传输的ObjectMapper,过滤字段
+ */
+public class ObjectMapper4Tx {
+
+	private ObjectMapper mapper;
+
+	public ObjectMapper4Tx(ObjectMapper mapper) {
+		this.mapper = mapper;
+		configMapper();
+	}
+
+	private void configMapper(){
+		mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+
+		//设置实体的传输字段
+		mapper.addMixIn(AdmObject.class, ObjectForTx.class);
+
+	}
+
+	public ObjectMapper mapper() {
+		return mapper;
+	}
+
+	public String toJson(Object obj){
+		try{
+			return mapper.writeValueAsString(obj);
+		}catch (JsonProcessingException e){
+			throw new RuntimeException(e);
+		}
+	}
+
+}