Showing
1 changed file
with
38 additions
and
10 deletions
@@ -38,6 +38,9 @@ import java.nio.charset.StandardCharsets; | @@ -38,6 +38,9 @@ import java.nio.charset.StandardCharsets; | ||
38 | import java.security.*; | 38 | import java.security.*; |
39 | import java.security.spec.PKCS8EncodedKeySpec; | 39 | import java.security.spec.PKCS8EncodedKeySpec; |
40 | import java.util.*; | 40 | import java.util.*; |
41 | +import java.util.concurrent.ArrayBlockingQueue; | ||
42 | +import java.util.concurrent.ThreadPoolExecutor; | ||
43 | +import java.util.concurrent.TimeUnit; | ||
41 | 44 | ||
42 | /** | 45 | /** |
43 | * Created by li.ma on 2020/3/31. | 46 | * Created by li.ma on 2020/3/31. |
@@ -63,6 +66,8 @@ public class ProductChainService { | @@ -63,6 +66,8 @@ public class ProductChainService { | ||
63 | @Value("${urltrainblock.url}") | 66 | @Value("${urltrainblock.url}") |
64 | private String urltrainblockUrl; | 67 | private String urltrainblockUrl; |
65 | 68 | ||
69 | + private ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 1, TimeUnit.HOURS, new ArrayBlockingQueue<>(10000)); | ||
70 | + | ||
66 | // curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v | 71 | // curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v |
67 | public void postQuery(Long chainId, String tagid) { | 72 | public void postQuery(Long chainId, String tagid) { |
68 | // (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout) | 73 | // (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout) |
@@ -92,24 +97,47 @@ public class ProductChainService { | @@ -92,24 +97,47 @@ public class ProductChainService { | ||
92 | } | 97 | } |
93 | 98 | ||
94 | 99 | ||
100 | + private class SynChainThread implements Runnable { | ||
101 | + public SynChainThread(){} | ||
95 | 102 | ||
103 | + public SynChainThread(Map<String, Object> request, Long id, String sign) { | ||
104 | + this.request = request; | ||
105 | + this.id = id; | ||
106 | + this.sign = sign; | ||
107 | + } | ||
96 | 108 | ||
97 | - public void postChainInfo(Map<String, Object> request, Long id, String sign) { | 109 | + private Map<String, Object> request; |
98 | 110 | ||
99 | - HttpHeaders headers = getHttpHeaders(sign); | ||
100 | - HttpEntity<String> formEntity = getStringHttpEntity(request, headers); | ||
101 | - ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/info", formEntity, String.class); | ||
102 | - JSONObject jsonObject = JSONObject.parseObject(response.getBody()); | ||
103 | - String errorMsg = jsonObject.getString("errorMsg"); | ||
104 | - String result = jsonObject.getString("result"); | 111 | + private Long id; |
112 | + | ||
113 | + private String sign; | ||
114 | + | ||
115 | + @Override | ||
116 | + public void run() { | ||
117 | + postChainInfo(request, id, sign); | ||
118 | + } | ||
119 | + | ||
120 | + public void postChainInfo(Map<String, Object> request, Long id, String sign) { | ||
121 | + HttpHeaders headers = getHttpHeaders(sign); | ||
122 | + HttpEntity<String> formEntity = getStringHttpEntity(request, headers); | ||
123 | + ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/info", formEntity, String.class); | ||
124 | + JSONObject jsonObject = JSONObject.parseObject(response.getBody()); | ||
125 | + String errorMsg = jsonObject.getString("errorMsg"); | ||
126 | + String result = jsonObject.getString("result"); | ||
105 | 127 | ||
106 | - logger.info("postChainInfo success. bo is {}, id is {}, errorMsg is {}, result is {}", request, id, errorMsg, result); | 128 | + logger.info("postChainInfo success. bo is {}, id is {}, errorMsg is {}, result is {}", request, id, errorMsg, result); |
107 | 129 | ||
108 | - if ("Y".equals(result) || "ID字段重复".equals(errorMsg)) { | ||
109 | - updateIsupload(id, 1); // 如果更新成功,则更新数据库字段 | 130 | + if ("Y".equals(result) || "ID字段重复".equals(errorMsg)) { |
131 | + updateIsupload(id, 1); // 如果更新成功,则更新数据库字段 | ||
132 | + } | ||
110 | } | 133 | } |
111 | } | 134 | } |
112 | 135 | ||
136 | + | ||
137 | + public void aSynPostChainInfo(Map<String, Object> request, Long id, String sign) { | ||
138 | + executor.submit(new SynChainThread(request, id, sign)); | ||
139 | + } | ||
140 | + | ||
113 | // SELECT * FROM ${TABLE_PRODUCT_CHAIN} WHERE transaction_id IS NULL | 141 | // SELECT * FROM ${TABLE_PRODUCT_CHAIN} WHERE transaction_id IS NULL |
114 | public List<ProductChain> queryProductChain() { | 142 | public List<ProductChain> queryProductChain() { |
115 | return productChainMapper.selectProductChain(); | 143 | return productChainMapper.selectProductChain(); |
-
Please register or login to post a comment