Authored by mali

上链迁移

... ... @@ -38,6 +38,9 @@ import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Created by li.ma on 2020/3/31.
... ... @@ -63,6 +66,8 @@ public class ProductChainService {
@Value("${urltrainblock.url}")
private String urltrainblockUrl;
private ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 1, TimeUnit.HOURS, new ArrayBlockingQueue<>(10000));
// curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v
public void postQuery(Long chainId, String tagid) {
// (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout)
... ... @@ -92,24 +97,47 @@ public class ProductChainService {
}
private class SynChainThread implements Runnable {
public SynChainThread(){}
public SynChainThread(Map<String, Object> request, Long id, String sign) {
this.request = request;
this.id = id;
this.sign = sign;
}
public void postChainInfo(Map<String, Object> request, Long id, String sign) {
private Map<String, Object> request;
HttpHeaders headers = getHttpHeaders(sign);
HttpEntity<String> formEntity = getStringHttpEntity(request, headers);
ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/info", formEntity, String.class);
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
String errorMsg = jsonObject.getString("errorMsg");
String result = jsonObject.getString("result");
private Long id;
private String sign;
@Override
public void run() {
postChainInfo(request, id, sign);
}
public void postChainInfo(Map<String, Object> request, Long id, String sign) {
HttpHeaders headers = getHttpHeaders(sign);
HttpEntity<String> formEntity = getStringHttpEntity(request, headers);
ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/info", formEntity, String.class);
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
String errorMsg = jsonObject.getString("errorMsg");
String result = jsonObject.getString("result");
logger.info("postChainInfo success. bo is {}, id is {}, errorMsg is {}, result is {}", request, id, errorMsg, result);
logger.info("postChainInfo success. bo is {}, id is {}, errorMsg is {}, result is {}", request, id, errorMsg, result);
if ("Y".equals(result) || "ID字段重复".equals(errorMsg)) {
updateIsupload(id, 1); // 如果更新成功,则更新数据库字段
if ("Y".equals(result) || "ID字段重复".equals(errorMsg)) {
updateIsupload(id, 1); // 如果更新成功,则更新数据库字段
}
}
}
public void aSynPostChainInfo(Map<String, Object> request, Long id, String sign) {
executor.submit(new SynChainThread(request, id, sign));
}
// SELECT * FROM ${TABLE_PRODUCT_CHAIN} WHERE transaction_id IS NULL
public List<ProductChain> queryProductChain() {
return productChainMapper.selectProductChain();
... ...