Commit 3c53240d5813a091aa7657422d5872b9f5064e97

Authored by zhangmeiyang
1 parent ff9c90b3

金蝶对接模型创建

etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/demarcate/AbstractBusinessHandler.java
1 package com.diligrp.etrade.thirdparty.demarcate; 1 package com.diligrp.etrade.thirdparty.demarcate;
2 2
3 -import com.diligrp.etrade.thirdparty.type.BusinessEnum; 3 +import com.diligrp.etrade.core.util.JsonUtils;
  4 +import com.fasterxml.jackson.core.type.TypeReference;
4 5
5 -public abstract class AbstractBusinessHandler<T> { 6 +public abstract class AbstractBusinessHandler<T> implements TypeMarketInterface{
6 public void handle(String json){ 7 public void handle(String json){
7 - T t = this.covertData(json);  
8 - this.handle(t); 8 + this.handle(this.covertData(json));
  9 + }
  10 + protected T covertData(String json){
  11 + return JsonUtils.fromJsonString(json,new TypeReference<>() {});
9 } 12 }
10 13
11 protected abstract void handle(T t); 14 protected abstract void handle(T t);
12 -  
13 - protected abstract T covertData(String json);  
14 -  
15 - public abstract BusinessEnum getType();  
16 } 15 }
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/demarcate/ErrorHandler.java
1 package com.diligrp.etrade.thirdparty.demarcate; 1 package com.diligrp.etrade.thirdparty.demarcate;
2 2
3 -import com.diligrp.etrade.thirdparty.type.BusinessEnum;  
4 -  
5 -public interface ErrorHandler {  
6 - void saveAndRecordError(String json,String errorMessage);  
7 - BusinessEnum getBusinessType();  
8 - 3 +public interface ErrorHandler extends TypeMarketInterface {
  4 + void saveAndRecordError(String json, String errorMessage);
9 } 5 }
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/demarcate/TypeMarketInterface.java 0 → 100644
  1 +package com.diligrp.etrade.thirdparty.demarcate;
  2 +
  3 +import com.diligrp.etrade.thirdparty.type.BusinessEnum;
  4 +
  5 +public interface TypeMarketInterface {
  6 + BusinessEnum getType();
  7 +}
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/exec/ZrHolder.java
@@ -31,8 +31,8 @@ public class ZrHolder implements InitializingBean, DisposableBean { @@ -31,8 +31,8 @@ public class ZrHolder implements InitializingBean, DisposableBean {
31 31
32 @Override 32 @Override
33 public void afterPropertiesSet() throws Exception { 33 public void afterPropertiesSet() throws Exception {
34 - businessHandlers.forEach(e-> CONTEXT.put(e.getType(), e));  
35 - errorHandlers.forEach(e-> ERROR_HANDLER_CONTEXT.put(e.getBusinessType(), e)); 34 + businessHandlers.forEach(e -> CONTEXT.put(e.getType(), e));
  35 + errorHandlers.forEach(e -> ERROR_HANDLER_CONTEXT.put(e.getType(), e));
36 } 36 }
37 37
38 @Override 38 @Override
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/handler/ErrorBusinessHandler.java
1 package com.diligrp.etrade.thirdparty.handler; 1 package com.diligrp.etrade.thirdparty.handler;
2 2
3 -import com.diligrp.etrade.core.util.JsonUtils;  
4 import com.diligrp.etrade.thirdparty.co.ErrorMessageCo; 3 import com.diligrp.etrade.thirdparty.co.ErrorMessageCo;
5 import com.diligrp.etrade.thirdparty.demarcate.AbstractBusinessHandler; 4 import com.diligrp.etrade.thirdparty.demarcate.AbstractBusinessHandler;
6 import com.diligrp.etrade.thirdparty.exec.ZrHolder; 5 import com.diligrp.etrade.thirdparty.exec.ZrHolder;
@@ -18,10 +17,6 @@ public class ErrorBusinessHandler extends AbstractBusinessHandler&lt;ErrorMessageCo @@ -18,10 +17,6 @@ public class ErrorBusinessHandler extends AbstractBusinessHandler&lt;ErrorMessageCo
18 protected void handle(ErrorMessageCo co) { 17 protected void handle(ErrorMessageCo co) {
19 ZrHolder.ERROR_HANDLER_CONTEXT.get(co.getBusiness()).saveAndRecordError(co.getContent(),co.getErrorMessage()); 18 ZrHolder.ERROR_HANDLER_CONTEXT.get(co.getBusiness()).saveAndRecordError(co.getContent(),co.getErrorMessage());
20 } 19 }
21 - @Override  
22 - protected ErrorMessageCo covertData(String json) {  
23 - return JsonUtils.fromJsonString(json, ErrorMessageCo.class);  
24 - }  
25 20
26 @Override 21 @Override
27 public BusinessEnum getType() { 22 public BusinessEnum getType() {
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/handler/TestBusinessHandler.java
1 package com.diligrp.etrade.thirdparty.handler; 1 package com.diligrp.etrade.thirdparty.handler;
2 2
3 -import com.diligrp.etrade.core.util.JsonUtils;  
4 import com.diligrp.etrade.thirdparty.co.TestCo; 3 import com.diligrp.etrade.thirdparty.co.TestCo;
5 import com.diligrp.etrade.thirdparty.demarcate.AbstractBusinessHandler; 4 import com.diligrp.etrade.thirdparty.demarcate.AbstractBusinessHandler;
6 import com.diligrp.etrade.thirdparty.demarcate.ErrorHandler; 5 import com.diligrp.etrade.thirdparty.demarcate.ErrorHandler;
@@ -18,20 +17,11 @@ public class TestBusinessHandler extends AbstractBusinessHandler&lt;TestCo&gt; impleme @@ -18,20 +17,11 @@ public class TestBusinessHandler extends AbstractBusinessHandler&lt;TestCo&gt; impleme
18 protected void handle(TestCo t) { 17 protected void handle(TestCo t) {
19 var s = 1/0; 18 var s = 1/0;
20 } 19 }
21 - @Override  
22 - protected TestCo covertData(String json) {  
23 - return JsonUtils.fromJsonString(json, TestCo.class);  
24 - }  
25 20
26 @Override 21 @Override
27 public BusinessEnum getType() { 22 public BusinessEnum getType() {
28 return BusinessEnum.TEST; 23 return BusinessEnum.TEST;
29 } 24 }
30 -  
31 - @Override  
32 - public BusinessEnum getBusinessType() {  
33 - return BusinessEnum.TEST;  
34 - }  
35 @Override 25 @Override
36 public void saveAndRecordError(String json,String errorMessage) { 26 public void saveAndRecordError(String json,String errorMessage) {
37 System.out.println(json); 27 System.out.println(json);