diff --git a/Test/TestChain/pom.xml b/Test/TestChain/pom.xml
index d8170cd1..3a5f47c1 100644
--- a/Test/TestChain/pom.xml
+++ b/Test/TestChain/pom.xml
@@ -20,110 +20,127 @@
audit-sdk
system
1.5.4
-
- ${project.basedir}/src/main/resources/lib/audit-sdk-1.5.4-jar-with-dependencies.jar
+ ${project.basedir}/src/main/resources/lib/audit-sdk-1.6.0.jar
+
+
+
+ io.netty
+ netty-tcnative-openssl-static
+ system
+ 2.0.39.Final
+ ${project.basedir}/src/main/resources/lib/netty-tcnative-openssl-static-2.0.39.Final.jar
+
+
+
+ org.chainmaker.sdk
+ shanghai
+ system
+ 1.0.0
+ ${project.basedir}/src/main/resources/lib/chainmaker-sdk-2.3.2.jar
+
+
org.bouncycastle
bcpkix-jdk15on
1.60
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ ch.qos.logback
+ logback-classic
+ 1.2.3
+
+
+
+ org.apache.commons
+ commons-pool2
+ 2.11.1
+
+
+
+ org.yaml
+ snakeyaml
+ 1.33
+
+
+
+
+ commons-collections
+ commons-collections
+ 3.2.2
+
+
+ io.netty
+ netty-handler
+ 4.1.53.Final
+
+
+ io.grpc
+ grpc-api
+ 1.40.1
+
+
+ io.grpc
+ grpc-netty
+ 1.40.1
+
+
+ io.grpc
+ grpc-stub
+ 1.40.1
+
+
+ io.grpc
+ grpc-protobuf
+ 1.40.1
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.14.0
+
+
+
+ cn.hutool
+ hutool-core
+ 5.8.18
+
+
+
+ com.alibaba
+ fastjson
+ 2.0.32
+
+
+
+
+ com.github.houbb
+ sensitive-word
+ 0.16.1
+
+
+
+ com.googlecode.aviator
+ aviator
+ 5.4.1
+
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.5.14
+
+
+
+ org.web3j
+ abi
+ 5.0.0
+
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
\ No newline at end of file
diff --git a/Test/TestChain/src/main/java/com/renchao/Demo01.java b/Test/TestChain/src/main/java/com/renchao/Demo01.java
index 684a8c30..b40daa79 100644
--- a/Test/TestChain/src/main/java/com/renchao/Demo01.java
+++ b/Test/TestChain/src/main/java/com/renchao/Demo01.java
@@ -5,109 +5,162 @@ import cn.dreamdt.audit.domain.ChainMessage;
import cn.dreamdt.audit.domain.MessageBean;
import cn.dreamdt.audit.main.DataAudit;
import cn.dreamdt.audit.maker.chain.ChainConsumer;
-import cn.dreamdt.audit.util.AuditUtil;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import io.netty.handler.ssl.OpenSsl;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.net.MalformedURLException;
import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.security.Security;
-import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+
/**
* @author ren_chao
*/
public class Demo01 {
// uniTrust.clientDid
private static final String CLIENT_DID = "did:unitrust:6r5eR9TPcSNRCGYjfEsDxbXjm9Cm";
+
public static void main(String[] args) {
+
+ // setParent(Demo01.class.getClassLoader());
+
+
DataAudit dataAudit = DataAudit.create(AuditConfig.builder()
.appCode("jtktph").appKey("240710105317v53eyAsWrsQRXYYAMWm").serverUrl("https://116.128.191.6:2031/DreamWeb")
.logFilePath("C:\\Users\\RENCHAO\\Desktop\\temp-sss\\log").chainConsumer(new MyChainConsumerImpl()).build());
+ dataAudit.subscribeChain(null,null,null);
// 数据上链 测试数据
JSONObject bizData = new JSONObject();
- bizData.put("behaviorId", "00570000000000000000121");
+ bizData.put("behaviorId", "20240701798445635972400");
bizData.put("platformCid", "did:unitrust:6r5eR9TPcSNRCGYjfEsDxbXjm9Cm");
bizData.put("ccid", "did:unitrust:7CXMdXzSmNrGk3mWPe9jpsHg2HmU");
bizData.put("sceneCode", "77");
bizData.put("startTime", "2024-07-05 16:43:52");
- bizData.put("endTime", "2024-07-05 16:43:52");
+ // bizData.put("endTime", "2024-07-05 16:43:52");
+ // bizData.put("endTime", "");
bizData.put("tripDistance", "5544.000");
bizData.put("hashData", "5f89452b52a9df1fe0060c8ac3de5b6ffea3e6855cf307db31ac0359d67d7888");
- bizData.put("state", "1");
+ bizData.put("state", 1);
//调用合约
MessageBean messageBean = dataAudit.invoke("CAMC", "saveAssetData", bizData,"00570000000000000000121");
- System.out.println("=========================\n");
- System.out.println(messageBean);
- System.out.println("\n=========================");
-
System.out.println("=============json============\n");
System.out.println(JSON.toJSONString(messageBean));
System.out.println("\n=========================");
Map map = new HashMap<>();
- map.put("behaviorId", "00570000000000000000121");
+ map.put("behaviorId", "20240701798445635972400"); // 失败的
+ // map.put("behaviorId", "00571000000000000000126"); // 成功d
MessageBean query = dataAudit.query("CAMC", "findAssetData", map);
+ // MessageBean query = dataAudit.query("CAMC", "findAssetData", "17e38900edca0112ca9f2132c60492a758760b1099c8451dbcdf8d666cf447ba");
System.out.println("=============query============\n");
System.out.println(query);
System.out.println("\n=========================");
// 数据批量上链 测试数据
- JSONArray bizDataArray = new JSONArray();
- JSONObject bizData1 = new JSONObject();
- bizData1.put("behaviorId", "00470000000000000000171");
- bizData1.put("platformCid", "did:unitrust:6r5eR9TPcSNRCGYjfEsDxbXjm9Cm");
- bizData1.put("ccid", "did:unitrust:7CXMdXzSmNrGk3mWPe9jpsHg2HmU");
- bizData1.put("sceneCode", "77");
- bizData1.put("startTime", "2024-07-05 16:43:52");
- bizData1.put("endTime", "2024-07-05 16:43:52");
- bizData1.put("tripDistance", "5544.000");
- bizData1.put("hashData", "099513e015663a8b1d9183a8beae1ccb286893092e597669ca015dee9a8a89ee");
- bizData1.put("state", "1");
- bizDataArray.add(bizData1);
-
-
- JSONObject bizData2 = new JSONObject();
- bizData2.put("behaviorId", "00470000000000000000125");
- bizData2.put("platformCid", "did:unitrust:6r5eR9TPcSNRCGYjfEsDxbXjm9Cm");
- bizData2.put("ccid", "did:unitrust:7CXMdXzSmNrGk3mWPe9jpsHg2HmU");
- bizData2.put("sceneCode", "77");
- bizData2.put("startTime", "2024-07-05 16:43:52");
- bizData2.put("endTime", "2024-07-05 16:43:52");
- bizData2.put("tripDistance", "5544.000");
- bizData2.put("hashData", "fd238cf96c983d68684e17c867d01192355df3f12bb69a954300b4ed608b61cf");
- bizData2.put("state", "1");
- bizDataArray.add(bizData2);
+ // JSONArray bizDataArray = new JSONArray();
+ // JSONObject bizData1 = new JSONObject();
+ // bizData1.put("behaviorId", "00470000000000000000171");
+ // bizData1.put("platformCid", "did:unitrust:6r5eR9TPcSNRCGYjfEsDxbXjm9Cm");
+ // bizData1.put("ccid", "did:unitrust:7CXMdXzSmNrGk3mWPe9jpsHg2HmU");
+ // bizData1.put("sceneCode", "77");
+ // bizData1.put("startTime", "2024-07-05 16:43:52");
+ // bizData1.put("endTime", "2024-07-05 16:43:52");
+ // bizData1.put("tripDistance", "5544.000");
+ // bizData1.put("hashData", "099513e015663a8b1d9183a8beae1ccb286893092e597669ca015dee9a8a89ee");
+ // bizData1.put("state", "1");
+ // bizDataArray.add(bizData1);
+ //
+ //
+ // JSONObject bizData2 = new JSONObject();
+ // bizData2.put("behaviorId", "00470000000000000000125");
+ // bizData2.put("platformCid", "did:unitrust:6r5eR9TPcSNRCGYjfEsDxbXjm9Cm");
+ // bizData2.put("ccid", "did:unitrust:7CXMdXzSmNrGk3mWPe9jpsHg2HmU");
+ // bizData2.put("sceneCode", "77");
+ // bizData2.put("startTime", "2024-07-05 16:43:52");
+ // bizData2.put("endTime", "2024-07-05 16:43:52");
+ // bizData2.put("tripDistance", "5544.000");
+ // bizData2.put("hashData", "fd238cf96c983d68684e17c867d01192355df3f12bb69a954300b4ed608b61cf");
+ // bizData2.put("state", "1");
+ // bizDataArray.add(bizData2);
+ //
+ // //调用合约
+ // ArrayList bizIndexList = new ArrayList<>();
+ // bizIndexList.add("00470000000000000000171");
+ // bizIndexList.add("00470000000000000000125");
+ //
+ // MessageBean messageBean2 = dataAudit.batchInvoke("CAMC", "findAssetData", bizDataArray, bizIndexList);
+
+ while (true) {
+ System.out.println("====================");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
- //调用合约
- ArrayList bizIndexList = new ArrayList<>();
- bizIndexList.add("00470000000000000000171");
- bizIndexList.add("00470000000000000000125");
- MessageBean messageBean2 = dataAudit.batchInvoke("CAMC", "findAssetData", bizDataArray, bizIndexList);
+ }
+
+ private static void setParent(ClassLoader classLoader) {
+ try {
+ Field parent = ClassLoader.class.getDeclaredField("parent");
+ parent.setAccessible(true);
+ CustomClassLoader loader = new CustomClassLoader(classLoader.getParent());
+ parent.set(classLoader,loader);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+
+ public static class CustomClassLoader extends ClassLoader {
+
+ public CustomClassLoader(ClassLoader parent) {
+ super(parent);
+ }
+
+ @Override
+ public URL getResource(String name) {
+
+ try {
+ if (name.endsWith("sdk_config.yml")
+ || name.endsWith("crypto.yml")
+ || name.endsWith("OrgSignCert.crt")
+ || name.endsWith("SignCert.crt")
+ || name.endsWith("SignKey.key")
+ || name.endsWith("TlsCert.crt")
+ || name.endsWith("TlsKey.key")) {
+ return new URL("file:C:/Users/RENCHAO/Desktop/temp-sss/cc/" + name);
+ }
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return getParent().getResource(name);
+ }
+
+
+ @Override
+ public Class> loadClass(String name) throws ClassNotFoundException {
+ return getParent().loadClass(name);
+ }
}
static class MyChainConsumerImpl implements ChainConsumer {
@Override
public void onMessage(ChainMessage chainMessage) {
- System.out.println("============回掉结果=============\n\n");
- System.out.println(chainMessage);
- System.out.println("\n\n=========================");
- System.out.println("============回掉结果json=============\n\n");
+ System.out.println("============回调结果json=============\n");
System.out.println(JSON.toJSONString(chainMessage));
- System.out.println("\n\n=========================");
+ System.out.println("\n=========================");
}
}
diff --git a/Test/TestChain/src/main/java/com/renchao/Demo02.java b/Test/TestChain/src/main/java/com/renchao/Demo02.java
new file mode 100644
index 00000000..63e22e76
--- /dev/null
+++ b/Test/TestChain/src/main/java/com/renchao/Demo02.java
@@ -0,0 +1,77 @@
+package com.renchao;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * @author ren_chao
+ */
+public class Demo02 {
+ public static void main(String[] args) throws IOException {
+ String root = "./abc/dd/";
+ String file = "tt.txt";
+
+ Path path = Paths.get(root, file);
+ System.out.println(path.toString());
+
+
+ // setParent(Demo02.class.getClassLoader());
+ //
+ //
+ // URL resource = Demo02.class.getClassLoader().getResource("crypto.yml");
+ //
+ //
+ // try(InputStream inputStream = resource.openStream();
+ // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
+ // String line;
+ // while ((line = br.readLine()) != null) {
+ // System.out.println(line);
+ // }
+ //
+ // }
+ // System.out.println(resource);
+ }
+
+
+ private static void setParent(ClassLoader classLoader) {
+
+ try {
+ Field parent = ClassLoader.class.getDeclaredField("parent");
+ parent.setAccessible(true);
+ CustomClassLoader loader = new CustomClassLoader(classLoader.getParent());
+ parent.set(classLoader,loader);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static class CustomClassLoader extends ClassLoader {
+
+ public CustomClassLoader(ClassLoader parent) {
+ super(parent);
+ }
+
+ @Override
+ public URL getResource(String name) {
+ try {
+ if ("crypto.yml".equals(name)) {
+ return new URL("file:C:/Users/RENCHAO/Desktop/temp-sss/bb/" + name);
+ }
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return super.getResource(name);
+ }
+
+ }
+}
diff --git a/Test/TestChain/src/main/resources/cert/zxzj/org/OrgSignCert.crt b/Test/TestChain/src/main/resources/cert/org/OrgSignCert.crt
similarity index 100%
rename from Test/TestChain/src/main/resources/cert/zxzj/org/OrgSignCert.crt
rename to Test/TestChain/src/main/resources/cert/org/OrgSignCert.crt
diff --git a/Test/TestChain/src/main/resources/cert/user/EncTlsCert.crt b/Test/TestChain/src/main/resources/cert/user/EncTlsCert.crt
new file mode 100644
index 00000000..df13d09b
--- /dev/null
+++ b/Test/TestChain/src/main/resources/cert/user/EncTlsCert.crt
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDbzCCAxagAwIBAgIQWKQdbIzXXGI0HyTMVQqaSDAKBggqgRzPVQGDdTCBhzEL
+MAkGA1UEBhMCQ04xMzAxBgNVBAoMKuW4guWkp+aVsOaNruS4reW/gy3nm5HnrqHp
+k74uY20tMzl1cWhoazloMzELMAkGA1UECwwCY2ExNjA0BgNVBAMMLWNhLuW4guWk
+p+aVsOaNruS4reW/gy3nm5HnrqHpk74uY20tMzl1cWhoazloMzAeFw0yNDA0MDMw
+NTIxNTRaFw0yOTA0MDIwNTIxNTRaMIHCMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG
+5LiK5rW3MQ8wDQYDVQQHDAbkuIrmtbcxMzAxBgNVBAoMKuW4guWkp+aVsOaNruS4
+reW/gy3nm5HnrqHpk74uY20tMzl1cWhoazloMzEOMAwGA1UECxMFYWRtaW4xTDBK
+BgNVBAMMQ+Wkp+aVsOaNruS4reW/g+euoeeQhuWRmC3luILlpKfmlbDmja7kuK3l
+v4Mt55uR566h6ZO+LmNtLTM5dXFoaGs5aDMwWTATBgcqhkjOPQIBBggqgRzPVQGC
+LQNCAARRDwc9DKv7hy24Zn6tdnaK7vJjFSHK7Y/OZW6jx8RoE5E/AzcxtmBYtHMr
+B10cuTs/aEnqtI7sIO5bnkLFzEx0o4IBJTCCASEwHQYDVR0OBBYEFAVn3B0+DHsp
+6b4mPtaqOjbzNZk9MA4GA1UdDwEB/wQEAwIDODAJBgNVHRMEAjAAMB8GA1UdIwQY
+MBaAFJSwbf0W4Y1mITjqfSm22chUqkK0MEEGCCsGAQUFBwEBBDUwMzAxBggrBgEF
+BQcwAYYlaHR0cDovL29zY3AxLmJsb2NrY2hhaW4uc2guY2Vnbi5jbi92MTA+BgNV
+HR8ENzA1MDOgMaAvhi1odHRwOi8vbGRhcDEuYmxvY2tjaGFpbi5zaC5jZWduLmNu
+L3YxL2FsbC5jcmwwQQYDVR0gBDowODA2BggqgRyG7zqBFTAqMCgGCCsGAQUFBwIB
+FhxodHRwOi8vd3d3LnNoZWNhLmNvbS9wb2xpY3kvMAoGCCqBHM9VAYN1A0cAMEQC
+ID2SIp0MsD7ImramHmazo6gjQdLxq5hUILVsFRUMz8+pAiAHCdZ6OwASFamka0Bn
+rdfj97z29ERgrsJ6gSnL2D9Meg==
+-----END CERTIFICATE-----
diff --git a/Test/TestChain/src/main/resources/cert/user/EncTlsKey.key b/Test/TestChain/src/main/resources/cert/user/EncTlsKey.key
new file mode 100644
index 00000000..269c01df
--- /dev/null
+++ b/Test/TestChain/src/main/resources/cert/user/EncTlsKey.key
@@ -0,0 +1,6 @@
+-----BEGIN PRIVATE KEY-----
+MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQg2e6nVOJwcfqXZO20
+OK+4SAbLlIqoivBGTGHUuge9FaagCgYIKoEcz1UBgi2hRANCAARRDwc9DKv7hy24
+Zn6tdnaK7vJjFSHK7Y/OZW6jx8RoE5E/AzcxtmBYtHMrB10cuTs/aEnqtI7sIO5b
+nkLFzEx0
+-----END PRIVATE KEY-----
\ No newline at end of file
diff --git a/Test/TestChain/src/main/resources/cert/zxzj/user/SignCert.crt b/Test/TestChain/src/main/resources/cert/user/SignCert.crt
similarity index 100%
rename from Test/TestChain/src/main/resources/cert/zxzj/user/SignCert.crt
rename to Test/TestChain/src/main/resources/cert/user/SignCert.crt
diff --git a/Test/TestChain/src/main/resources/cert/zxzj/user/SignKey.key b/Test/TestChain/src/main/resources/cert/user/SignKey.key
similarity index 100%
rename from Test/TestChain/src/main/resources/cert/zxzj/user/SignKey.key
rename to Test/TestChain/src/main/resources/cert/user/SignKey.key
diff --git a/Test/TestChain/src/main/resources/cert/zxzj/user/TlsCert.crt b/Test/TestChain/src/main/resources/cert/user/TlsCert.crt
similarity index 100%
rename from Test/TestChain/src/main/resources/cert/zxzj/user/TlsCert.crt
rename to Test/TestChain/src/main/resources/cert/user/TlsCert.crt
diff --git a/Test/TestChain/src/main/resources/cert/zxzj/user/TlsKey.key b/Test/TestChain/src/main/resources/cert/user/TlsKey.key
similarity index 100%
rename from Test/TestChain/src/main/resources/cert/zxzj/user/TlsKey.key
rename to Test/TestChain/src/main/resources/cert/user/TlsKey.key
diff --git a/Test/TestChain/src/main/resources/lib/chainmaker-sdk-java-2.3.2.jar00 b/Test/TestChain/src/main/resources/lib/chainmaker-sdk-java-2.3.2.jar00
new file mode 100644
index 00000000..ed8e7a28
Binary files /dev/null and b/Test/TestChain/src/main/resources/lib/chainmaker-sdk-java-2.3.2.jar00 differ
diff --git a/Test/TestChain/src/main/resources/lib/chainmaker-sdk-java-2.3.2.jar44 b/Test/TestChain/src/main/resources/lib/chainmaker-sdk-java-2.3.2.jar44
new file mode 100644
index 00000000..e2a2e1d5
Binary files /dev/null and b/Test/TestChain/src/main/resources/lib/chainmaker-sdk-java-2.3.2.jar44 differ
diff --git a/Test/TestChain/src/main/resources/sdk_config.yml b/Test/TestChain/src/main/resources/sdk_config.yml
index 2ab47fb6..f3bfcb39 100644
--- a/Test/TestChain/src/main/resources/sdk_config.yml
+++ b/Test/TestChain/src/main/resources/sdk_config.yml
@@ -1,20 +1,24 @@
enableRemoteConfig: false #是否启用远程配置
logLevel: fine #日志级别 info error
+version: v2
chainConfigList:
- # 链ID
chainId: "ZW_C8458AD_002"
# 组织ID
orgId: "测试514-碳普惠测试链2.cm-l7wv90h523"
#组织证书路径
- orgCrtPath: "cert/zxzj/org/OrgSignCert.crt"
+ orgCrtPath: "cert/org/OrgSignCert.crt"
# 客户端用户交易私钥路径
- userTlsKeyPath: "cert/zxzj/user/TlsKey.key"
+ userTlsKeyPath: "cert/user/TlsKey.key"
# 客户端用户交易证书路径
- userTlsCrtPath: "cert/zxzj/user/TlsCert.crt"
+ userTlsCrtPath: "cert/user/TlsCert.crt"
# 客户端用户交易签名私钥路径(若未设置,将使用user_key_file_path)
- userSignKeyPath: "cert/zxzj/user/SignKey.key"
+ userSignKeyPath: "cert/user/SignKey.key"
# 客户端用户交易签名证书路径(若未设置,将使用user_crt_file_path)
- userSignCrtPath: "cert/zxzj/user/SignCert.crt"
+ userSignCrtPath: "cert/user/SignCert.crt"
+
+ userEncTlsKeyPath: "cert/user/EncTlsKey.key"
+ userEncTlsCrtPath: "cert/user/EncTlsCert.crt"
# grpc客户端最大接受容量(MB)
rpcMaxReceiveMessageSize: 32
# 交易结果是否订阅获取
@@ -24,11 +28,13 @@ chainConfigList:
caConfigPath: "crypto.yml"
nodeList:
- # 节点地址,格式为:IP:端口:连接数,有两个端口,使用rpc的端口
- addr: "116.128.190.190:9020"
+ addr: "116.128.191.6:2032"
+# addr: "116.128.190.190:9020"
# 节点连接数
connectCount: 10
# RPC连接是否启用双向TLS认证
enableTls: true
# TLS hostname
tlsHostName: "consensus1-69vkhheorg.cm-l7wv90h523"
+ chainTlsHostName: "consensus1-69vkhheorg.cm-l7wv90h523"
diff --git a/agile-bacth/agile-batch-service/pom.xml b/agile-bacth/agile-batch-service/pom.xml
index 1978510f..38338404 100644
--- a/agile-bacth/agile-batch-service/pom.xml
+++ b/agile-bacth/agile-batch-service/pom.xml
@@ -194,7 +194,6 @@
false
-
src/main/resources/libx
BOOT-INF/lib/
diff --git a/carbon-dataprocess/carbon-dataprocess-api/pom.xml b/carbon-dataprocess/carbon-dataprocess-api/pom.xml
index 0f7cd754..f0c40629 100644
--- a/carbon-dataprocess/carbon-dataprocess-api/pom.xml
+++ b/carbon-dataprocess/carbon-dataprocess-api/pom.xml
@@ -3,7 +3,7 @@
com.jiuyv.sptcc
carbon-dataprocess
- 0.4.2-SNAPSHOT
+ 0.4.4-SNAPSHOT
carbon-dataprocess-api
diff --git a/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/api/CarbonDataApi.java b/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/api/CarbonDataApi.java
index 5487419b..c3906cc5 100644
--- a/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/api/CarbonDataApi.java
+++ b/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/api/CarbonDataApi.java
@@ -1,5 +1,6 @@
package com.jiuyv.sptcc.carbon.dataprocess.api;
+import com.jiuyv.sptcc.carbon.dataprocess.dto.ReqChainResultDTO;
import com.jiuyv.sptcc.carbon.dataprocess.dto.ReqSignResultDTO;
import com.jiuyv.sptcc.carbon.dataprocess.dto.ResultDTO;
import org.springframework.web.bind.annotation.PostMapping;
@@ -19,4 +20,10 @@ public interface CarbonDataApi {
*/
@PostMapping(PREFIX + "/sign")
ResultDTO signResult(@RequestBody ReqSignResultDTO signResultDTO);
+
+ /**
+ * 上链结果回调
+ */
+ @PostMapping(PREFIX + "/chainResult")
+ ResultDTO chainResultCallback(@RequestBody ReqChainResultDTO chainResultDTO);
}
diff --git a/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/dto/ReqChainResultDTO.java b/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/dto/ReqChainResultDTO.java
new file mode 100644
index 00000000..31c5ce8a
--- /dev/null
+++ b/carbon-dataprocess/carbon-dataprocess-api/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/dto/ReqChainResultDTO.java
@@ -0,0 +1,19 @@
+package com.jiuyv.sptcc.carbon.dataprocess.dto;
+
+import java.io.Serializable;
+
+/**
+ * @author ren_chao
+ */
+public class ReqChainResultDTO implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private String txId;
+
+ public String getTxId() {
+ return txId;
+ }
+
+ public void setTxId(String txId) {
+ this.txId = txId;
+ }
+}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/pom.xml b/carbon-dataprocess/carbon-dataprocess-service/pom.xml
index 681aa99e..a94d85e7 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/pom.xml
+++ b/carbon-dataprocess/carbon-dataprocess-service/pom.xml
@@ -4,7 +4,7 @@
com.jiuyv.sptcc
carbon-dataprocess
- 0.4.2-SNAPSHOT
+ 0.4.4-SNAPSHOT
carbon-dataprocess-service
@@ -87,15 +87,6 @@
spring-boot-starter-security
-
- org.springframework.boot
- spring-boot-starter-cache
-
-
- com.github.ben-manes.caffeine
- caffeine
-
-
org.springframework.boot
spring-boot-configuration-processor
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/DataProcessProperties.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/DataProcessProperties.java
new file mode 100644
index 00000000..d67e78bf
--- /dev/null
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/DataProcessProperties.java
@@ -0,0 +1,24 @@
+package com.jiuyv.sptcc.carbon.dataprocess.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author ren_chao
+ */
+@Component
+@ConfigurationProperties(prefix = "carbon-data-process")
+public class DataProcessProperties {
+ /**
+ * 是否开启上链
+ */
+ private boolean enableUpChain = true;
+
+ public boolean getEnableUpChain() {
+ return enableUpChain;
+ }
+
+ public void setEnableUpChain(boolean enableUpChain) {
+ this.enableUpChain = enableUpChain;
+ }
+}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/FeignConfiguration.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/FeignConfiguration.java
index cb74c87d..7a0daef9 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/FeignConfiguration.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/FeignConfiguration.java
@@ -1,19 +1,27 @@
package com.jiuyv.sptcc.carbon.dataprocess.config;
import com.jiuyv.sptcc.carbon.dataprocess.exception.ServiceException;
-import feign.Logger;
import feign.codec.ErrorDecoder;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
/**
* @author ren_chao
*/
@Configuration
public class FeignConfiguration {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FeignConfiguration.class);
+
+
@Bean
- Logger.Level feignLoggerLevel() {
- return Logger.Level.FULL;
+ feign.Logger.Level feignLoggerLevel() {
+ return feign.Logger.Level.FULL;
}
@@ -23,6 +31,16 @@ public class FeignConfiguration {
*/
@Bean
public ErrorDecoder errorDecoder() {
- return (methodKey, response) -> new ServiceException("系统服务调用异常");
+ return (methodKey, response) -> {
+ String res;
+ try {
+ res = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8));
+ } catch (IOException e) {
+ LOGGER.info("读取服务调用异常body出错", e);
+ res = "";
+ }
+ LOGGER.info("Feign服务{}调用异常:{}", methodKey, res);
+ return new ServiceException("系统服务调用异常:" + res);
+ };
}
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/SmsProperties.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/SmsProperties.java
new file mode 100644
index 00000000..feb0860d
--- /dev/null
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/config/SmsProperties.java
@@ -0,0 +1,41 @@
+package com.jiuyv.sptcc.carbon.dataprocess.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @author ren_chao
+ */
+@Component
+@ConfigurationProperties(prefix = "sms")
+public class SmsProperties {
+ private boolean enable = false;
+ private String sendUrl;
+ private List phoneList;
+
+ public boolean isEnable() {
+ return enable;
+ }
+
+ public void setEnable(boolean enable) {
+ this.enable = enable;
+ }
+
+ public String getSendUrl() {
+ return sendUrl;
+ }
+
+ public void setSendUrl(String sendUrl) {
+ this.sendUrl = sendUrl;
+ }
+
+ public List getPhoneList() {
+ return phoneList;
+ }
+
+ public void setPhoneList(List phoneList) {
+ this.phoneList = phoneList;
+ }
+}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/CarbonDataController.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/CarbonDataController.java
index c9b66662..82c00288 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/CarbonDataController.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/CarbonDataController.java
@@ -3,8 +3,10 @@ package com.jiuyv.sptcc.carbon.dataprocess.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jiuyv.sptcc.carbon.dataprocess.api.CarbonDataApi;
+import com.jiuyv.sptcc.carbon.dataprocess.dto.ReqChainResultDTO;
import com.jiuyv.sptcc.carbon.dataprocess.dto.ReqSignResultDTO;
import com.jiuyv.sptcc.carbon.dataprocess.dto.ResultDTO;
+import com.jiuyv.sptcc.carbon.dataprocess.service.IDataAuditService;
import com.jiuyv.sptcc.carbon.dataprocess.service.ISignResultService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,11 +23,15 @@ public class CarbonDataController implements CarbonDataApi {
private static final Logger LOGGER = LoggerFactory.getLogger(CarbonDataController.class);
private final ISignResultService signResultService;
+ private final IDataAuditService dataAuditService;
private final ObjectMapper objectMapper;
- public CarbonDataController(ISignResultService signResultService, ObjectMapper objectMapper) {
+ public CarbonDataController(ISignResultService signResultService,
+ IDataAuditService dataAuditService,
+ ObjectMapper objectMapper) {
this.signResultService = signResultService;
+ this.dataAuditService = dataAuditService;
this.objectMapper = objectMapper;
}
@@ -40,6 +46,15 @@ public class CarbonDataController implements CarbonDataApi {
return ResultDTO.success();
}
+ /**
+ * 上链结果回调
+ */
+ @Override
+ public ResultDTO chainResultCallback(ReqChainResultDTO chainResultDTO) {
+ dataAuditService.callback(chainResultDTO.getTxId());
+ return ResultDTO.success();
+ }
+
private String objectToString(Object o) {
try {
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/TestController.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/TestController.java
index 0afc7e72..4c124543 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/TestController.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/controller/TestController.java
@@ -1,67 +1,29 @@
package com.jiuyv.sptcc.carbon.dataprocess.controller;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jiuyv.sptcc.carbon.dataprocess.domain.BcCalcFactor;
import com.jiuyv.sptcc.carbon.dataprocess.exception.ServiceException;
+import com.jiuyv.sptcc.carbon.dataprocess.feign.SmsSendFeign;
import com.jiuyv.sptcc.carbon.dataprocess.service.ICalculateReductionService;
+import com.jiuyv.sptcc.carbon.dataprocess.service.IDataAuditService;
import com.jiuyv.sptcc.carbon.dataprocess.service.IPushReductionService;
import com.jiuyv.sptcc.carbon.dataprocess.service.IReadFileService;
import com.jiuyv.sptcc.carbon.dataprocess.service.ISignResultService;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufAllocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
+import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
+import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import sun.net.www.protocol.https.Handler;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import javax.validation.Constraint;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.Payload;
-import javax.validation.constraints.Email;
-import javax.validation.constraints.Max;
-import javax.validation.constraints.Min;
-import javax.validation.constraints.NotBlank;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
+
+import java.lang.reflect.Field;
import java.text.DecimalFormat;
-import java.util.Arrays;
-import java.util.Base64;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
-import java.util.stream.Collectors;
-
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.ElementType.TYPE_USE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashMap;
+import java.util.Map;
/**
* @author ren_chao
@@ -83,14 +45,12 @@ public class TestController {
private ISignResultService signResultService;
@Autowired
- private ObjectMapper objectMapper;
-
+ private IDataAuditService dataAuditService;
+ @Autowired
+ private SmsSendFeign smsSendFeign;
- @GetMapping("test000")
- public String test000(@RequestParam("date") String date) {
- // readFileService.readFileAndInsertDatabase(date);
- return "OK!!!";
- }
+ @Autowired
+ private ApplicationContext applicationContext;
@GetMapping("test00")
public String test00(@RequestParam("date") String date) {
@@ -123,117 +83,58 @@ public class TestController {
}
- @PostMapping("/test44")
- public String test44(@Validated(GroupA.class) @RequestBody User user) {
-
- return "GroupA OK!!!";
- }
-
-
- @PostMapping("/test55")
- public String test55(@Validated(GroupB.class) @RequestBody User user) {
-
- return "GroupB OK!!!";
- }
-
@GetMapping("/test66")
public String test66() {
-
+ dataAuditService.upChain();
return "OK OK OK!!!";
}
- public static class User {
-
- @NotBlank(message = "名称不能为空", groups = GroupA.class)
- private String name;
-
- @Email(message = "email格式不正确", groups = GroupB.class)
- private String email;
-
- @Max(message = "年龄必须小于100", value = 100)
- @Min(message = "年龄必须大于5", value = 5)
- private Integer age;
-
- @ListValue(message = "请输入0或1", values = {0, 1}, groups = {GroupA.class, GroupB.class})
- private Integer sex;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public Integer getAge() {
- return age;
- }
-
- public void setAge(Integer age) {
- this.age = age;
- }
-
- public Integer getSex() {
- return sex;
- }
-
- public void setSex(Integer sex) {
- this.sex = sex;
- }
+ @GetMapping("/test77")
+ public String test77() {
+ dataAuditService.queryUpChainResult();
+ return "OK OK OK!!!";
}
+ @GetMapping("/test888")
+ public String test888(@RequestParam("sms") String sms, @RequestParam("code") String code, @RequestParam("phoneNo") String phoneNo) {
+ System.out.println("=================================");
+ System.out.println(sms);
+ System.out.println(code);
+ System.out.println(phoneNo);
+ System.out.println("=================================");
- @Documented
- // 指定校验器
- @Constraint(validatedBy = {ListValueConstraintValidator.class})
- @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
- @Retention(RUNTIME)
- public @interface ListValue {
- String message() default "请输入指定的值!";
-
- Class>[] groups() default {};
-
- Class extends Payload>[] payload() default {};
+ return smsSendFeign.send(phoneNo, sms, code);
- int[] values() default {};
}
- public static class ListValueConstraintValidator implements ConstraintValidator {
- private final Set set = new HashSet<>();
- // 初始化方法
- @Override
- public void initialize(ListValue constraintAnnotation) {
- set.addAll(Arrays.stream(constraintAnnotation.values()).boxed().collect(Collectors.toList()));
- }
+ public static void main(String[] args) {
+ BcCalcFactor calcFactor = new BcCalcFactor();
+ calcFactor.setEnd(LocalDateTime.parse("20240801000000", REQ_SDF));
+ calcFactor.setStart(LocalDateTime.parse("20240820000000", REQ_SDF));
- // 校验逻辑,value就是需要校验的值
- @Override
- public boolean isValid(Integer value, ConstraintValidatorContext context) {
- return set.contains(value);
+ long l = System.currentTimeMillis();
+ for (int i = 0; i < 20000; i++) {
+ getCalcFactor("20240809000000", calcFactor);
}
- }
+ System.out.println(":::" + (System.currentTimeMillis() - l));
- interface GroupA {
}
- interface GroupB {
- }
+ private static final DateTimeFormatter REQ_SDF = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+ private static BcCalcFactor getCalcFactor(String intoTransTime, BcCalcFactor calcFactor) {
- public static void main(String[] args) throws InterruptedException {
- final Base64.Decoder decoder = Base64.getDecoder();
- final byte[] aa = decoder.decode("dW5tYXJzaGFsIGFyZ3MgZXJyb3I6IGludmFsaWQgY2hhcmFjdGVyICciJyBhZnRlciBhcnJheSBlbGVtZW50");
- System.out.println(new String(aa));
+ LocalDateTime time = LocalDateTime.parse(intoTransTime, REQ_SDF);
+ if (calcFactor == null || time.isAfter(calcFactor.getEnd()) || time.isBefore(calcFactor.getStart())) {
+ if (calcFactor == null) {
+ LOGGER.error("未查询到排放因子数据:{}", intoTransTime);
+ throw new ServiceException("未查询到排放因子数据");
+ }
+ }
+ return calcFactor;
}
+
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcCalcFactor.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcCalcFactor.java
index c230fc52..c7e66f21 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcCalcFactor.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcCalcFactor.java
@@ -1,6 +1,7 @@
package com.jiuyv.sptcc.carbon.dataprocess.domain;
import java.io.Serializable;
+import java.time.LocalDateTime;
/**
*
@@ -41,16 +42,13 @@ public class BcCalcFactor implements Serializable {
*/
private String factor;
- /**
- *
- */
private String startTime;
- /**
- *
- */
private String endTime;
+ private LocalDateTime start;
+ private LocalDateTime end;
+
public Long getFactorId() {
return factorId;
}
@@ -122,4 +120,20 @@ public class BcCalcFactor implements Serializable {
public void setEndTime(String endTime) {
this.endTime = endTime;
}
+
+ public LocalDateTime getStart() {
+ return start;
+ }
+
+ public void setStart(LocalDateTime start) {
+ this.start = start;
+ }
+
+ public LocalDateTime getEnd() {
+ return end;
+ }
+
+ public void setEnd(LocalDateTime end) {
+ this.end = end;
+ }
}
\ No newline at end of file
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcTravelNotice.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcTravelNotice.java
index 24982544..a3cb8c76 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcTravelNotice.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/domain/BcTravelNotice.java
@@ -152,14 +152,15 @@ public class BcTravelNotice implements Serializable {
/**
* 上链状态
* INIT:提交上链,
- * AUDIT_FAILED:稽核规则校验失败,
- * UP_CHAIN_FAILED:上链失败失败,
- * SUCCESS:上链成功
+ * AUDIT_SUCCESS("调用合约成功"),
+ * AUDIT_FAILED("调用合约失败"),
+ * CHAIN_SUCCESS("上链成功"),
+ * CHAIN_FAILED("上链失败");
*/
private String chainStatus;
/**
- * 上链ID
+ * 上链事务ID
*/
private String chainTxId;
@@ -215,7 +216,7 @@ public class BcTravelNotice implements Serializable {
private Integer sendCount;
/**
- * 签发结果,-1:抽检不通过,1:已签发,2: ?动签发不通过,3:??签发不通过
+ * 签发结果,-1:抽检不通过,1:已签发,2: 自动签发不通过,3:人工签发不通过
*/
private Integer signStatus;
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/enums/ChainStatusEnum.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/enums/ChainStatusEnum.java
index f7aff50e..fe4a0ad2 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/enums/ChainStatusEnum.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/enums/ChainStatusEnum.java
@@ -6,10 +6,11 @@ package com.jiuyv.sptcc.carbon.dataprocess.enums;
* @author ren_chao
*/
public enum ChainStatusEnum {
- INIT("提交上链"),
- AUDIT_FAILED("稽核规则校验失败"),
- UP_CHAIN_FAILED("上链失败失败"),
- SUCCESS("上链成功");
+ INIT("初始化"),
+ AUDIT_SUCCESS("调用合约成功"),
+ AUDIT_FAILED("调用合约失败"),
+ CHAIN_SUCCESS("上链成功"),
+ CHAIN_FAILED("上链失败");
private final String msg;
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/feign/SmsSendFeign.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/feign/SmsSendFeign.java
new file mode 100644
index 00000000..c45731c5
--- /dev/null
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/feign/SmsSendFeign.java
@@ -0,0 +1,16 @@
+package com.jiuyv.sptcc.carbon.dataprocess.feign;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * 短信发送
+ *
+ * @author ren_chao
+ */
+@FeignClient(url = "${sms.sendUrl}", name = "msgSendFeign")
+public interface SmsSendFeign {
+ @GetMapping
+ String send(@RequestParam("phoneNo") String phoneNo, @RequestParam("sms") String sms, @RequestParam("code") String code);
+}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/mapper/BcTravelNoticeMapper.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/mapper/BcTravelNoticeMapper.java
index f9f8e5b2..61a45ad9 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/mapper/BcTravelNoticeMapper.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/mapper/BcTravelNoticeMapper.java
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* 针对表【TBL_BC_TRAVEL_NOTICE】的数据库操作Mapper
@@ -15,16 +16,14 @@ import java.util.Map;
@Mapper
public interface BcTravelNoticeMapper {
- int insert(BcTravelNotice record);
+ int updateBySeqNo(BcTravelNotice travelNotice);
- BcTravelNotice selectBySeqNo(@Param("seqNo") Long seqNo);
+ List selectPageByStatus(@Param("status") String status,
+ @Param("chainStatus") String chainStatus,
+ @Param("start") Integer start,
+ @Param("end") Integer end);
- int updateBySeqNo(BcTravelNotice record);
-
- List selectPageByStatus(@Param("status") String status, @Param("start") Integer start,
- @Param("count") Integer count);
-
- Integer selectCountByStatus(@Param("status") String status);
+ Integer selectCountByStatus(@Param("status") String status, @Param("chainStatus") String chainStatus);
List selectListByBatchNo(@Param("batchNo") String batchNo);
@@ -33,7 +32,28 @@ public interface BcTravelNoticeMapper {
List selectPageBySignStatus(@Param("signStatus") Integer signStatus, @Param("start") Integer start,
@Param("count") Integer count);
- Long selectCountByFileName(@Param("fileName") String fileName);
+ List selectTravelNoticeList(Map queryMap);
+
+ int selectCountByFileName(@Param("fileName") String fileName);
+
+ void updateChainStatusByTxId(@Param("chainStatus") String chainStatus, @Param("txId") String txId);
+
+ int updateChainStatusByTravelNos(@Param("list") List list,
+ @Param("chainStatus") String chainStatus,
+ @Param("txId") String txId);
+
+ int updateStatusBySeqNos(@Param("list") List list,
+ @Param("status") String status,
+ @Param("batchNo") String batchNo);
+
+ Integer selectTxIdCountByChainStatus(@Param("chainStatus") String chainStatus);
+
+ List selectTxIdLimitByChainStatus(@Param("chainStatus") String chainStatus,
+ @Param("count") Integer count);
+
+ void batchInsert(List list);
+
+ Set selectTravelNoListByTravelNoList(@Param("list") List list);
- List selectTravelNoticePage(Map queryMap);
+ void updateBatchBySeqNo(@Param("list") List list);
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/quartz/CarbonDataTask.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/quartz/CarbonDataTask.java
index 66da0a20..87bc9448 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/quartz/CarbonDataTask.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/quartz/CarbonDataTask.java
@@ -1,7 +1,10 @@
package com.jiuyv.sptcc.carbon.dataprocess.quartz;
+import com.jiuyv.sptcc.carbon.dataprocess.config.SmsProperties;
import com.jiuyv.sptcc.carbon.dataprocess.exception.ServiceException;
+import com.jiuyv.sptcc.carbon.dataprocess.feign.SmsSendFeign;
import com.jiuyv.sptcc.carbon.dataprocess.service.ICalculateReductionService;
+import com.jiuyv.sptcc.carbon.dataprocess.service.IDataAuditService;
import com.jiuyv.sptcc.carbon.dataprocess.service.IPushReductionService;
import com.jiuyv.sptcc.carbon.dataprocess.service.IReadFileService;
import com.jiuyv.sptcc.carbon.dataprocess.service.ISignResultService;
@@ -10,6 +13,9 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
/**
* xxl任务调度入口
@@ -18,20 +24,31 @@ import org.springframework.stereotype.Component;
@Component
public class CarbonDataTask {
private static final Logger LOGGER = LoggerFactory.getLogger(CarbonDataTask.class);
+ private static final String CODE = "utf-8";
private final IReadFileService readFileService;
private final ICalculateReductionService calculateReductionService;
private final IPushReductionService pushReductionService;
private final ISignResultService signResultService;
+ private final IDataAuditService dataAuditService;
+
+ private final SmsSendFeign smsSendFeign;
+ private final SmsProperties smsProperties;
public CarbonDataTask(IReadFileService readFileService,
ICalculateReductionService calculateReductionService,
IPushReductionService pushReductionService,
- ISignResultService signResultService) {
+ ISignResultService signResultService,
+ IDataAuditService dataAuditService,
+ SmsSendFeign smsSendFeign,
+ SmsProperties smsProperties) {
this.readFileService = readFileService;
this.calculateReductionService = calculateReductionService;
this.pushReductionService = pushReductionService;
this.signResultService = signResultService;
+ this.dataAuditService = dataAuditService;
+ this.smsSendFeign = smsSendFeign;
+ this.smsProperties = smsProperties;
}
/**
@@ -56,12 +73,15 @@ public class CarbonDataTask {
@XxlJob(value = "readFileTask")
public void readFileTask() {
try {
- readFileService.readFileAndInsertDatabase(XxlJobHelper.getJobParam());
+ int count = readFileService.readFileAndInsertDatabase(XxlJobHelper.getJobParam());
+ smsSend("中台数据读取成功,记录数:" + count);
} catch (ServiceException e) {
LOGGER.error(e.getMessage(), e);
+ smsSend("中台数据读取异常:" + e.getMessage());
throw e;
} catch (Exception e) {
LOGGER.error("未知异常", e);
+ smsSend("中台数据读取异常:" + e.getMessage());
throw e;
}
}
@@ -115,4 +135,50 @@ public class CarbonDataTask {
}
}
+ /**
+ * 上链
+ */
+ @XxlJob(value = "upChainTask")
+ public void upChainTask() {
+ try {
+ dataAuditService.upChain();
+ } catch (ServiceException e) {
+ LOGGER.error(e.getMessage(), e);
+ throw e;
+ } catch (Exception e) {
+ LOGGER.error("未知异常", e);
+ throw e;
+ }
+ }
+
+ /**
+ * 上链结果查询
+ */
+ @XxlJob(value = "queryUpChainResultTask")
+ public void queryUpChainResultTask() {
+ try {
+ dataAuditService.queryUpChainResult();
+ } catch (ServiceException e) {
+ LOGGER.error(e.getMessage(), e);
+ throw e;
+ } catch (Exception e) {
+ LOGGER.error("未知异常", e);
+ throw e;
+ }
+ }
+
+ private void smsSend(String sms) {
+ List phoneList = smsProperties.getPhoneList();
+ if (smsProperties.isEnable() && !CollectionUtils.isEmpty(phoneList)) {
+ for (String phone : phoneList) {
+ String res = smsSendFeign.send(phone, sms, CODE);
+ if ("success".equals(res)) {
+ LOGGER.info("短信发送成功,手机[{}],消息[{}]", phone, sms);
+ } else {
+ LOGGER.error("短信发送失败:[{}]", res);
+ }
+ }
+ }
+ }
+
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/ICalculateReductionService.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/ICalculateReductionService.java
index ecc61d57..9fa63d4d 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/ICalculateReductionService.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/ICalculateReductionService.java
@@ -1,8 +1,5 @@
package com.jiuyv.sptcc.carbon.dataprocess.service;
-import com.jiuyv.sptcc.carbon.pushgate.dto.GResultDTO;
-import com.jiuyv.sptcc.carbon.pushgate.dto.reduction.ResBatchComputationDTO;
-
/**
* 计算碳减排量
*
@@ -15,8 +12,4 @@ public interface ICalculateReductionService {
*/
void calculate();
- /**
- * 更新
- */
- void updateReduction(GResultDTO resultDTO);
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IDataAuditService.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IDataAuditService.java
index d373213d..38e46351 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IDataAuditService.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IDataAuditService.java
@@ -1,9 +1,7 @@
package com.jiuyv.sptcc.carbon.dataprocess.service;
-import com.jiuyv.sptcc.carbon.pushgate.dto.GResultDTO;
-import com.jiuyv.sptcc.carbon.pushgate.dto.chain.ChainInfoDTO;
-
import java.util.List;
+import java.util.Map;
/**
* @author ren_chao
@@ -18,13 +16,11 @@ public interface IDataAuditService {
/**
* 接收区块链系统回调 更新上链结果
*/
- void callback();
+ void callback(String txId);
/**
* 主动查询一直没有回调的数据
*/
void queryUpChainResult();
-
- void updateReduction(GResultDTO> resultDTO);
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IPushReductionService.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IPushReductionService.java
index af91837b..47018bf8 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IPushReductionService.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IPushReductionService.java
@@ -17,8 +17,4 @@ public interface IPushReductionService {
*/
void escalation();
- /**
- * 更新状态
- */
- void updateStatus(List bcTravelNoticeList, String status, String currentTime, String batchNo);
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IReadFileService.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IReadFileService.java
index f87da693..6926e710 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IReadFileService.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/IReadFileService.java
@@ -9,10 +9,11 @@ public interface IReadFileService {
/**
* 读取文件并插入数据库
*/
- void readFileAndInsertDatabase(String dateStr);
+ int readFileAndInsertDatabase(String dateStr);
/**
* 获取里程数据
*/
void getDictionary();
+
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/CalculateReductionServiceImpl.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/CalculateReductionServiceImpl.java
index 588b3305..0bbd982f 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/CalculateReductionServiceImpl.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/CalculateReductionServiceImpl.java
@@ -1,7 +1,14 @@
package com.jiuyv.sptcc.carbon.dataprocess.service.impl;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.jiuyv.sptcc.carbon.dataprocess.domain.BcTravelNotice;
+import com.jiuyv.sptcc.carbon.dataprocess.domain.BusSpotCheck;
+import com.jiuyv.sptcc.carbon.dataprocess.domain.SubwaySpotCheck;
import com.jiuyv.sptcc.carbon.dataprocess.enums.CarbonDataEnum;
+import com.jiuyv.sptcc.carbon.dataprocess.enums.ChainStatusEnum;
+import com.jiuyv.sptcc.carbon.dataprocess.enums.IndustryCodeEnum;
import com.jiuyv.sptcc.carbon.dataprocess.exception.ServiceException;
import com.jiuyv.sptcc.carbon.dataprocess.feign.CarbonDataProcessFeign;
import com.jiuyv.sptcc.carbon.dataprocess.mapper.BcTravelNoticeMapper;
@@ -12,13 +19,16 @@ import com.jiuyv.sptcc.carbon.pushgate.dto.GResultDTO;
import com.jiuyv.sptcc.carbon.pushgate.dto.reduction.BatchComputationReqVo;
import com.jiuyv.sptcc.carbon.pushgate.dto.reduction.ResBatchComputationDTO;
import com.jiuyv.sptcc.carbon.pushgate.dto.reduction.ResComputationDTO;
+import org.bouncycastle.crypto.digests.SM3Digest;
+import org.bouncycastle.util.encoders.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import java.nio.charset.StandardCharsets;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -36,16 +46,20 @@ public class CalculateReductionServiceImpl implements ICalculateReductionService
private final CarbonDataProcessFeign carbonDataProcessFeign;
- private final ICalculateReductionService calculateReductionService;
+ /**
+ * 单独给 原始数据使用,如果需要特殊配置,直接配置这个objectMapper
+ */
+ private final ObjectMapper objectMapper;
public CalculateReductionServiceImpl(BcTravelNoticeMapper travelNoticeMapper,
SysDateMapper sysDateMapper,
- CarbonDataProcessFeign carbonDataProcessFeign,
- @Lazy ICalculateReductionService calculateReductionService) {
+ CarbonDataProcessFeign carbonDataProcessFeign) {
this.travelNoticeMapper = travelNoticeMapper;
this.sysDateMapper = sysDateMapper;
this.carbonDataProcessFeign = carbonDataProcessFeign;
- this.calculateReductionService = calculateReductionService;
+ this.objectMapper = new ObjectMapper();
+ objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@@ -54,13 +68,22 @@ public class CalculateReductionServiceImpl implements ICalculateReductionService
*/
@Override
public synchronized void calculate() {
- Integer count = travelNoticeMapper.selectCountByStatus(CarbonDataEnum.PROCESSING.getCode());
+ Integer count = travelNoticeMapper.selectCountByStatus(CarbonDataEnum.PROCESSING.getCode(), null);
LOGGER.info(">>>> 开始计算碳减排量,总记录数:{}", count);
+ if (count == 0) {
+ return;
+ }
long startTime = System.currentTimeMillis();
- for (int i = 0; i < count; i += PAGE_COUNT) {
- LOGGER.info(">>>> 计算第{}页,{}-{}", i / PAGE_COUNT + 1, i + 1, i + PAGE_COUNT);
+ int pageCount = count / PAGE_COUNT + 1;
+ for (int i = 1; i <= pageCount; i++) {
+ LOGGER.info(">>>> 计算第{}页", i);
List bcTravelNoticeList = travelNoticeMapper
- .selectPageByStatus(CarbonDataEnum.PROCESSING.getCode(), i, PAGE_COUNT);
+ .selectPageByStatus(CarbonDataEnum.PROCESSING.getCode(), null, 1, PAGE_COUNT);
+ if (CollectionUtils.isEmpty(bcTravelNoticeList)) {
+ break;
+ }
+ // 计算hash
+ bcTravelNoticeList.forEach(this::spotCheckHash);
List collect = bcTravelNoticeList.stream().map(bcTravelNotice -> {
BatchComputationReqVo.RawData rawData = new BatchComputationReqVo.RawData();
rawData.setBaseFactor(bcTravelNotice.getBaseFactor());
@@ -79,29 +102,75 @@ public class CalculateReductionServiceImpl implements ICalculateReductionService
throw new ServiceException("计算错误");
}
- // 更新计算结果
- calculateReductionService.updateReduction(resultDTO);
+ Map hashDataMap = bcTravelNoticeList.stream()
+ .collect(Collectors.toMap(BcTravelNotice::getSeqNo, BcTravelNotice::getHashData));
+
+ List tnList = getUpdateTravelNoticeList(resultDTO.getContent().getEmissionReductions(), hashDataMap);
+
+ travelNoticeMapper.updateBatchBySeqNo(tnList);
}
LOGGER.info(">>>> 计算完成,耗时:{}秒", (System.currentTimeMillis() - startTime) / 1000);
}
+ private List getUpdateTravelNoticeList(List ers, Map hashDataMap) {
+ String currentTime = sysDateMapper.currentTime();
+ return ers.stream().map(res -> {
+ BcTravelNotice tn = new BcTravelNotice();
+ String seqNo = res.getDataId();
+ tn.setSeqNo(seqNo);
+ tn.setHashData(hashDataMap.get(seqNo));
+ tn.setCarbonFootprint(res.getEmissionReduction());
+ tn.setReductionCalculateTime(currentTime);
+ tn.setStatus(CarbonDataEnum.WAIT_FOR_SEND.getCode());
+ tn.setChainStatus(ChainStatusEnum.INIT.toString());
+ return tn;
+ }).collect(Collectors.toList());
+ }
+
/**
- * 更新
+ * 抽检字段hash
*/
- @Transactional
- @Override
- public void updateReduction(GResultDTO resultDTO) {
- List emissionReductions = resultDTO.getContent().getEmissionReductions();
- String currentTime = sysDateMapper.currentTime();
- emissionReductions.forEach(res -> {
- BcTravelNotice bcTravelNotice = new BcTravelNotice();
- bcTravelNotice.setSeqNo(res.getDataId());
- bcTravelNotice.setCarbonFootprint(res.getEmissionReduction());
- bcTravelNotice.setReductionCalculateTime(currentTime);
- bcTravelNotice.setStatus(CarbonDataEnum.WAIT_FOR_SEND.getCode());
- travelNoticeMapper.updateBySeqNo(bcTravelNotice);
- });
+ private void spotCheckHash(BcTravelNotice travelNotice) {
+ if (IndustryCodeEnum.SUBWAY.getCode().equals(travelNotice.getIndustryCode())) {
+ SubwaySpotCheck spotCheck = new SubwaySpotCheck();
+ spotCheck.setTravelNo(travelNotice.getTravelNo());
+ spotCheck.setIntoTransTime(travelNotice.getIntoTransTime());
+ spotCheck.setInDeviceNo(travelNotice.getInDeviceNo());
+ spotCheck.setInStationName(travelNotice.getInStationName());
+ spotCheck.setOutTransTime(travelNotice.getOutTransTime());
+ spotCheck.setOutDeviceNo(travelNotice.getOutDeviceNo());
+ spotCheck.setOutStationName(travelNotice.getOutStationName());
+ spotCheck.setMileage(travelNotice.getMileage());
+ travelNotice.setHashData(sm3Hash(spotCheck));
+ } else {
+ BusSpotCheck spotCheck = new BusSpotCheck();
+ spotCheck.setTravelNo(travelNotice.getTravelNo());
+ spotCheck.setIntoTransTime(travelNotice.getIntoTransTime());
+ spotCheck.setLineNo(travelNotice.getLineNo());
+ spotCheck.setMileage(travelNotice.getMileage());
+ travelNotice.setHashData(sm3Hash(spotCheck));
+ }
}
+ private String sm3Hash(Object data) {
+ byte[] bytes = convertToJson(data).getBytes(StandardCharsets.UTF_8);
+ SM3Digest digest = new SM3Digest();
+ digest.update(bytes, 0, bytes.length);
+ byte[] output = new byte[digest.getDigestSize()];
+ digest.doFinal(output, 0);
+ return Hex.toHexString(output);
+ }
+
+
+ private String convertToJson(Object o) {
+ try {
+ return objectMapper.writeValueAsString(o);
+ } catch (Exception e) {
+ LOGGER.error("原始数据序列化错误", e);
+ throw new ServiceException("原始数据序列化错误");
+ }
+ }
+
+
}
diff --git a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/DataAuditServiceImpl.java b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/DataAuditServiceImpl.java
index 3d3d20ba..675a256c 100644
--- a/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/DataAuditServiceImpl.java
+++ b/carbon-dataprocess/carbon-dataprocess-service/src/main/java/com/jiuyv/sptcc/carbon/dataprocess/service/impl/DataAuditServiceImpl.java
@@ -1,24 +1,25 @@
package com.jiuyv.sptcc.carbon.dataprocess.service.impl;
import com.jiuyv.sptcc.carbon.dataprocess.domain.BcTravelNotice;
-import com.jiuyv.sptcc.carbon.dataprocess.enums.CarbonDataEnum;
import com.jiuyv.sptcc.carbon.dataprocess.enums.ChainStatusEnum;
+import com.jiuyv.sptcc.carbon.dataprocess.enums.IndustryCodeEnum;
import com.jiuyv.sptcc.carbon.dataprocess.exception.ServiceException;
import com.jiuyv.sptcc.carbon.dataprocess.feign.DataAuditFeign;
import com.jiuyv.sptcc.carbon.dataprocess.mapper.BcTravelNoticeMapper;
import com.jiuyv.sptcc.carbon.dataprocess.service.IDataAuditService;
+import com.jiuyv.sptcc.carbon.pushgate.api.DataAuditApi;
+import com.jiuyv.sptcc.carbon.pushgate.dto.chain.ChainResultDTO;
import com.jiuyv.sptcc.carbon.pushgate.common.ResultCode;
import com.jiuyv.sptcc.carbon.pushgate.dto.GResultDTO;
import com.jiuyv.sptcc.carbon.pushgate.dto.chain.AssetDataVo;
import com.jiuyv.sptcc.carbon.pushgate.dto.chain.BatchAssetDataVo;
-import com.jiuyv.sptcc.carbon.pushgate.dto.chain.ChainInfoDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -30,16 +31,13 @@ import java.util.stream.Collectors;
public class DataAuditServiceImpl implements IDataAuditService {
private static final Logger LOGGER = LoggerFactory.getLogger(DataAuditServiceImpl.class);
- private static final Integer PAGE_COUNT = 500;
+ private static final Integer PAGE_COUNT = 1000;
private final BcTravelNoticeMapper travelNoticeMapper;
private final DataAuditFeign dataAuditFeign;
- private final IDataAuditService dataAuditService;
- public DataAuditServiceImpl(BcTravelNoticeMapper travelNoticeMapper, DataAuditFeign dataAuditFeign,
- @Lazy IDataAuditService dataAuditService) {
+ public DataAuditServiceImpl(BcTravelNoticeMapper travelNoticeMapper, DataAuditFeign dataAuditFeign) {
this.travelNoticeMapper = travelNoticeMapper;
this.dataAuditFeign = dataAuditFeign;
- this.dataAuditService = dataAuditService;
}
/**
@@ -47,47 +45,51 @@ public class DataAuditServiceImpl implements IDataAuditService {
*/
@Override
public void upChain() {
- Integer count = travelNoticeMapper.selectCountByStatus(CarbonDataEnum.PROCESSING.getCode());
- LOGGER.info(">>>> 开始上链,总记录数:{}", count);
+ Integer count = travelNoticeMapper.selectCountByStatus(null, ChainStatusEnum.INIT.toString());
+ LOGGER.info(">>>> 开始调用合约,总记录数:{}", count);
+ if (count == 0) {
+ return;
+ }
long startTime = System.currentTimeMillis();
- for (int i = 0; i < count; i += PAGE_COUNT) {
- LOGGER.info(">>>> 上链第{}页,{}-{}", i / PAGE_COUNT + 1, i + 1, i + PAGE_COUNT);
+ int pageCount = count / PAGE_COUNT + 1;
+ for (int i = 1; i <= pageCount; i++) {
+ LOGGER.info(">>>> 调用合约第{}页", i);
List bcTravelNoticeList = travelNoticeMapper
- .selectPageByStatus(CarbonDataEnum.PROCESSING.getCode(), i, PAGE_COUNT);
+ .selectPageByStatus(null, ChainStatusEnum.INIT.toString(), 1, PAGE_COUNT);
+ if (CollectionUtils.isEmpty(bcTravelNoticeList)) {
+ break;
+ }
List collect = bcTravelNoticeList.stream().map(bcTravelNotice -> {
AssetDataVo rawData = new AssetDataVo();
rawData.setBehaviorId(bcTravelNotice.getTravelNo());
- // TODO 确定所属场景方cid
- rawData.setPlatformId("???");
rawData.setCcid(bcTravelNotice.getCcid());
rawData.setSceneCode(bcTravelNotice.getIndustryCode());
-
- // TODO 时间转换 如果缺少进站时间或出站时间?
rawData.setStartTime(bcTravelNotice.getIntoTransTime());
- rawData.setEndTime(bcTravelNotice.getOutTransTime());
-
- rawData.setTripDistance(Double.valueOf(bcTravelNotice.getMileage()));
+ if (IndustryCodeEnum.SUBWAY.getCode().equals(bcTravelNotice.getIndustryCode())) {
+ rawData.setEndTime(bcTravelNotice.getOutTransTime());
+ }
+ rawData.setTripDistance(bcTravelNotice.getMileage());
rawData.setHashData(bcTravelNotice.getHashData());
-
- // TODO 确定状态
- rawData.setState(0);
+ rawData.setState(1);
return rawData;
}).collect(Collectors.toList());
BatchAssetDataVo batchAssetDataVo = new BatchAssetDataVo();
batchAssetDataVo.setAssetDataVoList(collect);
- GResultDTO> resultDTO = dataAuditFeign.batchUpChain(batchAssetDataVo);
-
+ GResultDTO