Bläddra i källkod

对接接口方法:1.获取token2.更新案件状态3.上传文件4.推送案件附件信息

wangqiong 2 år sedan
förälder
incheckning
08f4aca27c

+ 69
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TestApiController.java Visa fil

@@ -0,0 +1,69 @@
1
+package com.ruoyi.web.controller.tool;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.alibaba.fastjson.JSONObject;
5
+import com.fasterxml.jackson.databind.ObjectMapper;
6
+import com.fasterxml.jackson.databind.node.ObjectNode;
7
+import com.ruoyi.common.annotation.Anonymous;
8
+import com.ruoyi.common.core.domain.AjaxResult;
9
+import com.ruoyi.common.enums.PushCaseStatusEnum;
10
+import com.ruoyi.system.service.impl.BeiMingInterfaceService;
11
+import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseStatusInfo;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.beans.factory.annotation.Value;
14
+import org.springframework.web.bind.annotation.GetMapping;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RestController;
17
+
18
+import java.io.File;
19
+
20
+import static com.ruoyi.common.utils.EncryptUtils.sm4Decrypt;
21
+import static com.ruoyi.common.utils.EncryptUtils.sm4Encrypt;
22
+
23
+@RestController
24
+@RequestMapping("/beiming/api")
25
+public class TestApiController {
26
+    @Autowired
27
+    BeiMingInterfaceService beiMingInterfaceService;
28
+    @Value("${beimingprivatekey}")
29
+    public String privateKey;
30
+
31
+    @GetMapping("/test")
32
+    @Anonymous
33
+    public AjaxResult selectCaseFlow() {
34
+        String token = beiMingInterfaceService.getApiToken("BWT_MEDIATION", "86251b190e3a40f3942v215d1762c663", System.currentTimeMillis());
35
+//         token = "f910e1441fc56e49d3f31396e8d9aa04228045815ee986a9587d7a5cb7312f9d11c7f80041745f38ec686ea1f819c8b8227f9c03196c6dd004f89215c4805c24355be4b57abeddb7b9d2cbda45fae74c49f4a83fb6496d84302ca8c07245786d682ecb68aed966fcbda3188b9c4d4376089471bb5aee371a62073b0ce15d72dccd6fbc8fd13957e2fb7aa018cb5937938bfc9773e570ac06ac633617cea8405759cf609c832074aaa03f972c0a6a93cde531da0d91d07770c037fdea1368ee5772941ba2a55ef155979d1ed8222faad92ed342530ef04f3746aa96499dee6ea4869ce46bd0dcfe7a69e7db49eb2aec388c47824c201b49825f24ffe82dde41b5";
36
+        System.out.println("toke:" + token);
37
+        //解密
38
+        if (token != null && !token.isEmpty()) {
39
+            JSONObject jsonObject = JSON.parseObject(token);
40
+            String tokenString = jsonObject.getString("data");
41
+            System.out.println("data信息:" + tokenString);
42
+            String tokenstr = sm4Decrypt(tokenString, privateKey);
43
+            System.out.println("解密后的字符串:" + tokenstr);
44
+            if (tokenstr != null && !tokenstr.isEmpty()) {
45
+                JSONObject tokenObject = JSON.parseObject(tokenstr);
46
+                String resultToken = tokenObject.getString("token");
47
+                MsCaseStatusInfo info = MsCaseStatusInfo.builder().caseNo("zc2024032700012").statusCode(PushCaseStatusEnum.MEDIATE.getCode()).caseClosureExplanation(PushCaseStatusEnum.MEDIATE.getName()).build();
48
+                JSONObject result = beiMingInterfaceService.submitCaseStatusInfo(resultToken, "zc2024032700012", "BWT_MEDIATION", info);
49
+                System.out.println("jieguo:" + result.toString());
50
+                if (result != null) {
51
+                    String data = result.getString("data");
52
+                    String datastr = sm4Decrypt(data, privateKey);
53
+                    System.out.println("最终解密后的字符串:" + datastr);
54
+                }
55
+            }
56
+        }
57
+        return AjaxResult.success();
58
+    }
59
+
60
+    @GetMapping("/testfile")
61
+    @Anonymous
62
+    public AjaxResult testfile() {
63
+//        File file = new File("D:/WorkDoc/TJ/File/证据1.png");
64
+        File file = new File("D:/WorkDoc/TJ/File/证据3.png");
65
+        JSONObject jsonObject1 = beiMingInterfaceService.pushAttachmentInfo("BWT_MEDIATION", "86251b190e3a40f3942v215d1762c663", file, "123abc", "BWT_MEDIATION", "zc2024032700012");
66
+        System.out.println("fanhui:" + jsonObject1.toString());
67
+        return AjaxResult.success();
68
+    }
69
+}

+ 14
- 11
ruoyi-admin/src/main/resources/application.yml Visa fil

@@ -90,7 +90,7 @@ spring:
90 90
         max-wait: -1ms
91 91
   web:
92 92
     resources:
93
-      static-locations:  file:/home/ruoyi/
93
+      static-locations: file:/home/ruoyi/
94 94
   mail:
95 95
     host: smtp.163.com
96 96
     port: 25
@@ -196,17 +196,20 @@ signSealCallbackConfig:
196 196
   url: http://121.40.189.20:7001/mssignSeal/signSeaalCaseApplicaCallback
197 197
 #  onlyOffice系统url配置
198 198
 onlyOfficeConfig:
199
-#  url: http://172.16.0.254:9090/files/upload
199
+  #  url: http://172.16.0.254:9090/files/upload
200 200
   url: http://121.40.189.20:9090/files/upload
201
-#jodconverter:
202
-#  local:
203
-#    host: 121.40.189.20
201
+    #jodconverter:
202
+    #  local:
203
+    #    host: 121.40.189.20
204 204
     #暂时关闭预览,启动时会有点慢
205
-#    enabled: true
205
+    #    enabled: true
206 206
     #设置libreoffice主目录 linux地址如:/usr/lib64/libreoffice
207
-#    office-home: /usr/lib64/libreoffice/
208
-#    office-home: D:\app\libreOffice\
209
-    #开启多个libreoffice进程,每个端口对应一个进程
210
-#    port-numbers: 8100
211
-    #libreoffice进程重启前的最大进程数
207
+    #    office-home: /usr/lib64/libreoffice/
208
+  #    office-home: D:\app\libreOffice\
209
+  #开启多个libreoffice进程,每个端口对应一个进程
210
+  #    port-numbers: 8100
211
+  #libreoffice进程重启前的最大进程数
212 212
 #    max-tasks-per-process: 100
213
+beimingapihost: https://zj.odrcloud.cn
214
+beimingapiprefix: /onestop/sync
215
+beimingprivatekey: d7724e72c4be93196a35203e8379ded5

+ 25
- 0
ruoyi-common/src/main/java/com/ruoyi/common/config/RestTemplateConfig.java Visa fil

@@ -0,0 +1,25 @@
1
+package com.ruoyi.common.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.http.client.ClientHttpRequestFactory;
6
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
7
+import org.springframework.web.client.RestTemplate;
8
+
9
+@Configuration
10
+public class RestTemplateConfig {
11
+
12
+    @Bean
13
+    public RestTemplate restTemplate(ClientHttpRequestFactory factory){
14
+        return new RestTemplate(factory);
15
+    }
16
+
17
+    @Bean
18
+    public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
19
+        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
20
+        factory.setReadTimeout(5000);//单位为ms
21
+        factory.setConnectTimeout(5000);//单位为ms
22
+        return factory;
23
+    }
24
+}
25
+

+ 15
- 0
ruoyi-common/src/main/java/com/ruoyi/common/enums/AttachmentOperateTypeEnum.java Visa fil

@@ -0,0 +1,15 @@
1
+package com.ruoyi.common.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+/**
7
+ * 案件附件操作类型
8
+ */
9
+@AllArgsConstructor
10
+@Getter
11
+public enum AttachmentOperateTypeEnum {
12
+    ADD("ADD", "新增"), DEL("DEL", "删除"), UPD("UPD", "修改");
13
+    private String code;
14
+    private String name;
15
+}

+ 13
- 0
ruoyi-common/src/main/java/com/ruoyi/common/enums/PushCaseStatusEnum.java Visa fil

@@ -0,0 +1,13 @@
1
+package com.ruoyi.common.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+@AllArgsConstructor
7
+@Getter
8
+public enum PushCaseStatusEnum {
9
+    MEDIATE("MEDIATE", "调解中", 1), SUCCESS("SUCCESS", "调解成功", 2), FAIL("FAIL", "调解失败", 3);
10
+    private String code;
11
+    private String name;
12
+    private Integer value;
13
+}

+ 121
- 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/EncryptUtils.java Visa fil

@@ -0,0 +1,121 @@
1
+package com.ruoyi.common.utils;
2
+
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import com.fasterxml.jackson.databind.node.ObjectNode;
5
+import java.nio.charset.StandardCharsets;
6
+import java.security.InvalidKeyException;
7
+import java.security.Key;
8
+import java.security.NoSuchAlgorithmException;
9
+import java.security.SecureRandom;
10
+import java.security.Security;
11
+import java.util.UUID;
12
+import javax.crypto.Cipher;
13
+import javax.crypto.KeyGenerator;
14
+import javax.crypto.Mac;
15
+import javax.crypto.SecretKey;
16
+import javax.crypto.spec.SecretKeySpec;
17
+import lombok.extern.slf4j.Slf4j;
18
+import org.apache.commons.lang3.StringUtils;
19
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
20
+import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
21
+
22
+@Slf4j
23
+public class EncryptUtils {
24
+  static {
25
+    Security.addProvider(new BouncyCastleProvider());
26
+  }
27
+
28
+  /**
29
+   * sm4加密
30
+   * @explain 加密模式:ECB 密文长度不固定,会随着被加密字符串长度的变化而变化
31
+   * @param paramStr 待加密字符串
32
+   * @return 返回16进制的加密字符串
33
+   * @throws Exception
34
+   */
35
+  public static String sm4Encrypt(String paramStr, String secretKey) {
36
+    if (StringUtils.isBlank(paramStr)) {
37
+      return null;
38
+    }
39
+    try {
40
+      // 16进制字符串-->byte[]
41
+      byte[] keyData = ByteUtils.fromHexString(secretKey);
42
+      // String-->byte[]
43
+      byte[] srcData = paramStr.getBytes(StandardCharsets.UTF_8);
44
+      // 加密后的数组
45
+      Cipher cipher = Cipher.getInstance("SM4/ECB/PKCS5Padding", BouncyCastleProvider.PROVIDER_NAME);
46
+      Key sm4Key = new SecretKeySpec(keyData, "SM4");
47
+      cipher.init(Cipher.ENCRYPT_MODE, sm4Key);
48
+      byte[] cipherArray = cipher.doFinal(srcData);
49
+      // byte[]-->hexString
50
+      return ByteUtils.toHexString(cipherArray);
51
+    } catch (Exception e) {
52
+      log.error("sm4加密失败:{}", paramStr, e);
53
+    }
54
+    return null;
55
+    
56
+  }
57
+  
58
+  /**
59
+   * sm4解密
60
+   * @explain 解密模式:采用ECB
61
+   * @param cipherText 16进制的加密字符串(忽略大小写)
62
+   * @return 解密后的字符串
63
+   * @throws Exception
64
+   */
65
+  public static String sm4Decrypt(String cipherText, String secretKey) {
66
+    if (StringUtils.isBlank(cipherText)) {
67
+      return null;
68
+    }
69
+    try {
70
+      // hexString-->byte[]
71
+      byte[] keyData = ByteUtils.fromHexString(secretKey);
72
+      // hexString-->byte[]
73
+      byte[] cipherData = ByteUtils.fromHexString(cipherText);
74
+      // 解密
75
+      Cipher cipher = Cipher.getInstance("SM4/ECB/PKCS5Padding", BouncyCastleProvider.PROVIDER_NAME);
76
+      Key sm4Key = new SecretKeySpec(keyData, "SM4");
77
+      cipher.init(Cipher.DECRYPT_MODE, sm4Key);
78
+      byte[] cipherArray = cipher.doFinal(cipherData);
79
+      // byte[]-->String
80
+      return new String(cipherArray, StandardCharsets.UTF_8);
81
+    } catch (Exception e) {
82
+      log.error("sm4解密失败:{}", cipherText, e);
83
+    }
84
+    return null;
85
+  }
86
+
87
+  /**
88
+   * @description: 初始化 HmacMD5 密钥
89
+   */
90
+  public static String initHmacMD5Key() throws NoSuchAlgorithmException {
91
+    //Init KeyGenerator.
92
+    KeyGenerator generator = KeyGenerator.getInstance("HmacSHA224");
93
+    //Generate key.
94
+    SecretKey secretKey = generator.generateKey();
95
+    return ByteUtils.toHexString(secretKey.getEncoded());
96
+  }
97
+
98
+  /**
99
+   * @description: HmacMD5 消息摘要
100
+   */
101
+  public static String encodeHmacMD5(String data, String key) throws NoSuchAlgorithmException, InvalidKeyException {
102
+    //Restore key.
103
+    SecretKey secretKey = new SecretKeySpec(ByteUtils.fromHexString(key), "HmacSHA224");
104
+    //Instantiate Mac.
105
+    Mac mac = Mac.getInstance(secretKey.getAlgorithm());
106
+    //Init Mac.
107
+    mac.init(secretKey);
108
+    //Execute.
109
+    return ByteUtils.toHexString(mac.doFinal(ByteUtils.fromHexString(data)));
110
+  }
111
+
112
+  public static void main(String[] args) {
113
+    String privateKey = "936df5fd9aba3b86adc3c1a1c52dcde1";
114
+    ObjectNode param = new ObjectMapper().createObjectNode();
115
+    param.put("name", "姓名");
116
+    String encryptString = sm4Encrypt(param.toString(), privateKey);
117
+    System.out.println("加密后的字符串:" + encryptString);
118
+    System.out.println("解密后的字符串:" + sm4Decrypt(encryptString, privateKey));
119
+  }
120
+
121
+}

+ 77
- 0
ruoyi-system/src/main/java/com/ruoyi/system/service/BeiMingInterface.java Visa fil

@@ -0,0 +1,77 @@
1
+package com.ruoyi.system.service;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.ruoyi.wisdomarbitrate.domain.entity.casestatus.MsCaseStatus;
5
+import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseFileInfo;
6
+import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseStatusInfo;
7
+import org.apache.ibatis.annotations.Case;
8
+import org.apache.poi.hmef.Attachment;
9
+import org.springframework.web.multipart.MultipartFile;
10
+
11
+import java.io.File;
12
+
13
+public interface BeiMingInterface {
14
+    /**
15
+     * 1.获取北明接口令牌token
16
+     *
17
+     * @param userName
18
+     * @param password
19
+     * @param times
20
+     * @return
21
+     */
22
+    String getApiToken(String userName, String password, Long times);
23
+
24
+
25
+    /**
26
+     * 2.提交案件状态信息
27
+     *
28
+     * @param token            令牌
29
+     * @param abutmentId       第三方平台案件唯一标识
30
+     * @param msCaseStatusInfo 案件状态信息
31
+     * @return
32
+     */
33
+    JSONObject submitCaseStatusInfo(String token, String abutmentId, String syncSource, MsCaseStatusInfo msCaseStatusInfo);
34
+
35
+    /**
36
+     * 3.上传附件
37
+     *
38
+     * @param file
39
+     * @return
40
+     */
41
+    JSONObject uploadFile(File file, String token, String syncSource);
42
+
43
+    /**
44
+     * 4.同步附件信息
45
+     *
46
+     * @param action
47
+     * @param caseNo
48
+     * @param msCaseFileInfo
49
+     * @return
50
+     */
51
+    JSONObject syncAttachmentInfo(String token, String syncSource, String action, String caseNo, MsCaseFileInfo msCaseFileInfo);
52
+
53
+    /**
54
+     * 推送案件状态信息(调解系统推送案件状态时调用)
55
+     *
56
+     * @param username               用户名
57
+     * @param password               密码
58
+     * @param caseNo                 案件编号
59
+     * @param statusCode             案件状态编码
60
+     * @param caseClosureExplanation 案件状态描述(或结案信息)
61
+     * @return
62
+     */
63
+    JSONObject pushCaseStatusInfo(String username, String password, String caseNo, String statusCode, String caseClosureExplanation);
64
+
65
+    /**
66
+     * 推送案件附件信息(调解系统推送案件附件信息时调用)
67
+     *
68
+     * @param username   用户名
69
+     * @param password   密码
70
+     * @param file       文件
71
+     * @param abutmentId 调解系统文件Id
72
+     * @param syncSource 用户名
73
+     * @param caseNo     案件编号
74
+     * @return
75
+     */
76
+    JSONObject pushAttachmentInfo(String username, String password, File file, String abutmentId, String syncSource, String caseNo);
77
+}

+ 316
- 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BeiMingInterfaceService.java Visa fil

@@ -0,0 +1,316 @@
1
+package com.ruoyi.system.service.impl;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.alibaba.fastjson.JSONObject;
5
+import com.fasterxml.jackson.databind.ObjectMapper;
6
+import com.fasterxml.jackson.databind.node.ObjectNode;
7
+import com.ruoyi.common.enums.AttachmentOperateTypeEnum;
8
+import com.ruoyi.system.service.BeiMingInterface;
9
+import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseFileInfo;
10
+import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseStatusInfo;
11
+import com.ruoyi.wisdomarbitrate.utils.CommonInputStreamResource;
12
+import lombok.extern.slf4j.Slf4j;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.beans.factory.annotation.Value;
15
+import org.springframework.http.HttpEntity;
16
+import org.springframework.http.HttpHeaders;
17
+import org.springframework.stereotype.Service;
18
+import org.springframework.util.LinkedMultiValueMap;
19
+import org.springframework.util.MultiValueMap;
20
+import org.springframework.web.client.RestClientException;
21
+import org.springframework.web.client.RestTemplate;
22
+
23
+import java.io.File;
24
+import java.io.FileInputStream;
25
+
26
+import static com.ruoyi.common.utils.EncryptUtils.sm4Decrypt;
27
+import static com.ruoyi.common.utils.EncryptUtils.sm4Encrypt;
28
+
29
+/**
30
+ * @author ym
31
+ */
32
+@Slf4j
33
+@Service
34
+public class BeiMingInterfaceService implements BeiMingInterface {
35
+    @Autowired
36
+    RestTemplate restTemplate;
37
+    /**
38
+     * 接口地址
39
+     */
40
+    @Value("${beimingapihost}")
41
+    public String apihost;
42
+    /**
43
+     * 接口路径前缀
44
+     */
45
+    @Value("${beimingapiprefix}")
46
+    public String apiprefix;
47
+    @Value("${beimingprivatekey}")
48
+    public String privateKey;
49
+
50
+    /**
51
+     * 1.获取北明接口令牌token
52
+     *
53
+     * @param userName
54
+     * @param password
55
+     * @param times
56
+     */
57
+    @Override
58
+    public String getApiToken(String userName, String password, Long times) {
59
+        JSONObject result = new JSONObject();
60
+        try {
61
+            //设置请求头
62
+            HttpHeaders httpHeaders = new HttpHeaders();
63
+            //传递请求体时必须设置传递参数的格式,为Content-Type : application/json
64
+            httpHeaders.add("Content-Type", "application/json;charset=UTF-8");
65
+            httpHeaders.add("syncSource", userName);
66
+            // 2.请求头 & 请求体
67
+            HttpEntity<JSON> fromEntity = new HttpEntity(httpHeaders);
68
+            JSONObject body = new JSONObject();
69
+//            body.put("account", userName);
70
+//            body.put("password", password);
71
+//            body.put("timestamp", times);
72
+            //对整体请求进行加密
73
+            ObjectNode param = new ObjectMapper().createObjectNode();
74
+            param.put("account", userName);
75
+            param.put("password", password);
76
+            param.put("timestamp", times);
77
+            String encryptString = sm4Encrypt(param.toString(), privateKey);
78
+            body.put("encryptString", encryptString);
79
+            System.out.println("encryptString:" + encryptString);
80
+            fromEntity = new HttpEntity(body, httpHeaders);
81
+            String url = apihost + apiprefix + "/getToken";
82
+            result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
83
+        } catch (RestClientException e) {
84
+            e.printStackTrace();
85
+        }
86
+        return result.toString();
87
+    }
88
+
89
+    /**
90
+     * 解析加密后端token
91
+     *
92
+     * @param token
93
+     * @return
94
+     */
95
+    public String analysisResultToken(String token) {
96
+        String resultToken = null;
97
+        if (token != null && !token.isEmpty()) {
98
+            JSONObject jsonObject = JSON.parseObject(token);
99
+            String tokenString = jsonObject.getString("data");
100
+            System.out.println("data信息:" + tokenString);
101
+            String tokenstr = sm4Decrypt(tokenString, privateKey);
102
+            System.out.println("解密后的字符串:" + tokenstr);
103
+            if (tokenstr != null && !tokenstr.isEmpty()) {
104
+                JSONObject tokenObject = JSON.parseObject(tokenstr);
105
+                resultToken = tokenObject.getString("token");
106
+            }
107
+        }
108
+        return resultToken;
109
+    }
110
+
111
+    /**
112
+     * 2.推送案件状态信息
113
+     *
114
+     * @param token            令牌
115
+     * @param abutmentId       第三方平台案件唯一标识
116
+     * @param msCaseStatusInfo 案件状态信息
117
+     * @param syncSource       同步来源(账户名)
118
+     * @return
119
+     */
120
+    @Override
121
+    public JSONObject submitCaseStatusInfo(String token, String abutmentId, String syncSource, MsCaseStatusInfo msCaseStatusInfo) {
122
+        JSONObject result = new JSONObject();
123
+        try {
124
+            //设置请求头
125
+            HttpHeaders httpHeaders = new HttpHeaders();
126
+            //传递请求体时必须设置传递参数的格式,为Content-Type : application/json
127
+            httpHeaders.add("Content-Type", "application/json;charset=UTF-8");
128
+            httpHeaders.add("token", token);
129
+            httpHeaders.add("syncSource", syncSource);
130
+            //对整体请求进行加密
131
+            ObjectNode param = new ObjectMapper().createObjectNode();
132
+            param.put("abutmentId", abutmentId);
133
+            param.put("caseNo", msCaseStatusInfo.getCaseNo());
134
+            param.put("statusCode", msCaseStatusInfo.getStatusCode());
135
+            param.put("caseClosureExplanation", msCaseStatusInfo.getCaseClosureExplanation());
136
+            String encryptString = sm4Encrypt(param.toString(), privateKey);
137
+            // 2.请求头 & 请求体
138
+            HttpEntity<JSON> fromEntity = new HttpEntity(httpHeaders);
139
+            JSONObject body = new JSONObject();
140
+//            body.put("abutmentId", Encrypt("abutmentId",abutmentId));
141
+//            body.put("caseNo", Encrypt("caseNo", msCaseStatusInfo.getCaseNo()));
142
+//            body.put("statusCode",  Encrypt("statusCode",msCaseStatusInfo.getStatusCode()));
143
+//            body.put("caseClosureExplanation", Encrypt("caseClosureExplanation", msCaseStatusInfo.getCaseClosureExplanation()));
144
+            //对整体请求进行加密
145
+            body.put("encryptString", encryptString);
146
+            fromEntity = new HttpEntity(body, httpHeaders);
147
+
148
+            String url = apihost + apiprefix + "/caseMediation/status";
149
+            result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
150
+        } catch (RestClientException e) {
151
+            e.printStackTrace();
152
+        }
153
+        return result;
154
+
155
+    }
156
+
157
+    /**
158
+     * 3.上传附件
159
+     *
160
+     * @param file
161
+     * @return
162
+     */
163
+    @Override
164
+    public JSONObject uploadFile(File file, String token, String syncSource) {
165
+        System.out.println("文件:" + file.getName());
166
+        System.out.println("文件:" + file.toString());
167
+        JSONObject result = new JSONObject();
168
+        try {
169
+            //设置请求头
170
+            HttpHeaders httpHeaders = new HttpHeaders();
171
+            //传递请求体时必须设置传递参数的格式,为Content-Type : application/json
172
+            httpHeaders.add("Content-Type", "multipart/form-data");
173
+            httpHeaders.add("token", token);
174
+            httpHeaders.add("syncSource", syncSource);
175
+            // 构建请求体
176
+            MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
177
+            CommonInputStreamResource commonInputStreamResource = null;
178
+            try {
179
+                FileInputStream fileInputStream = new FileInputStream(file);
180
+                commonInputStreamResource = new CommonInputStreamResource(fileInputStream, file.length(), file.getName());
181
+            } catch (Exception e) {
182
+                log.error("文件输入流转换错误", e);
183
+            }
184
+            requestBody.add("file", commonInputStreamResource);
185
+            HttpEntity<MultiValueMap> fromEntity = new HttpEntity<MultiValueMap>(requestBody, httpHeaders);
186
+            String url = apihost + apiprefix + "/uploadFile";
187
+            result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
188
+        } catch (RestClientException e) {
189
+            e.printStackTrace();
190
+        }
191
+        return result;
192
+    }
193
+
194
+    /**
195
+     * 4.同步附件信息
196
+     *
197
+     * @param token
198
+     * @param syncSource     用户名
199
+     * @param action         附件操作类型
200
+     * @param caseNo         案件编号
201
+     * @param msCaseFileInfo 案件附件信息
202
+     * @return
203
+     */
204
+    @Override
205
+    public JSONObject syncAttachmentInfo(String token, String syncSource, String action, String caseNo, MsCaseFileInfo msCaseFileInfo) {
206
+        JSONObject result = new JSONObject();
207
+        try {
208
+            //设置请求头
209
+            HttpHeaders httpHeaders = new HttpHeaders();
210
+            //传递请求体时必须设置传递参数的格式,为Content-Type : application/json
211
+            httpHeaders.add("Content-Type", "application/json;charset=UTF-8");
212
+            httpHeaders.add("token", token);
213
+            httpHeaders.add("syncSource", syncSource);
214
+            //对整体请求进行加密
215
+            ObjectNode param = new ObjectMapper().createObjectNode();
216
+            param.put("caseNo", caseNo);
217
+            param.put("action", action);
218
+            param.put("abutmentId", msCaseFileInfo.getAbutmentId());
219
+            param.put("abutmentCaseId", msCaseFileInfo.getAbutmentCaseId());
220
+            param.put("documentSubject", msCaseFileInfo.getDocumentSubject());
221
+            param.put("documentType", msCaseFileInfo.getDocumentType());
222
+            param.put("fileName", msCaseFileInfo.getFileName());
223
+            param.put("fileId", msCaseFileInfo.getFileId());
224
+            if (msCaseFileInfo.getOwnerType() != null) {
225
+                param.put("ownerType", msCaseFileInfo.getOwnerType());
226
+            }
227
+            if (msCaseFileInfo.getOwnerId() != null) {
228
+                param.put("ownerId", msCaseFileInfo.getOwnerId());
229
+            }
230
+            if (msCaseFileInfo.getOwnerName() != null) {
231
+                param.put("ownerName", msCaseFileInfo.getOwnerName());
232
+            }
233
+            String encryptString = sm4Encrypt(param.toString(), privateKey);
234
+            // 2.请求体
235
+            HttpEntity<JSON> fromEntity = new HttpEntity(httpHeaders);
236
+            JSONObject body = new JSONObject();
237
+            //对整体请求进行加密
238
+            body.put("encryptString", encryptString);
239
+            fromEntity = new HttpEntity(body, httpHeaders);
240
+            String url = apihost + apiprefix + "/caseMediation/attachment/accept";
241
+            result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
242
+        } catch (RestClientException e) {
243
+            e.printStackTrace();
244
+        }
245
+        return result;
246
+    }
247
+
248
+    /**
249
+     * 推送案件状态信息
250
+     */
251
+    @Override
252
+    public JSONObject pushCaseStatusInfo(String username, String password, String caseNo, String statusCode, String caseClosureExplanation) {
253
+        JSONObject result = new JSONObject();
254
+        String token = getApiToken(username, password, System.currentTimeMillis());
255
+        token = analysisResultToken(token);
256
+        if (token != null && !token.isEmpty()) {
257
+            MsCaseStatusInfo info = MsCaseStatusInfo.builder().caseNo(caseNo).statusCode(statusCode).caseClosureExplanation(caseClosureExplanation).build();
258
+            result = submitCaseStatusInfo(token, caseNo, username, info);
259
+            System.out.println("jieguo:" + result.toString());
260
+            if (result != null) {
261
+                String data = result.getString("data");
262
+                String datastr = sm4Decrypt(data, privateKey);
263
+                System.out.println("最终解密后的字符串:" + datastr);
264
+            }
265
+        }
266
+        return result;
267
+    }
268
+
269
+    /**
270
+     * 推送案件附件信息
271
+     */
272
+    @Override
273
+    public JSONObject pushAttachmentInfo(String username, String password, File file, String abutmentId, String syncSource, String caseNo) {
274
+        JSONObject result = new JSONObject();
275
+        //1.获取token
276
+        String token = getApiToken(username, password, System.currentTimeMillis());
277
+        token = analysisResultToken(token);
278
+        if (token != null && !token.isEmpty()) {
279
+            //2.上传文件
280
+            JSONObject fileResult = uploadFile(file, token, syncSource);
281
+            if (fileResult != null) {
282
+                String data = fileResult.getString("data");
283
+                String datastr = sm4Decrypt(data, privateKey);
284
+                System.out.println("最终解密后的字符串:" + datastr);
285
+                if (datastr != null) {
286
+                    JSONObject parse = JSON.parseObject(datastr);
287
+                    if (parse != null) {
288
+                        String fileId = parse.getString("fileId");
289
+                        System.out.println("fileId====:" + fileId);
290
+                        if (fileId != null) {
291
+                            //3.同步附件更新信息
292
+                            MsCaseFileInfo fileInfo = MsCaseFileInfo.builder().fileId(fileId).fileName(file.getName()).abutmentId(abutmentId).abutmentCaseId(caseNo).documentSubject("EVEDENT").documentType("EVEDENT_METERIAL").build();
293
+                            result = syncAttachmentInfo(token, username, AttachmentOperateTypeEnum.ADD.getCode(), caseNo, fileInfo);
294
+                            result = syncAttachmentInfo(token, username, AttachmentOperateTypeEnum.UPD.getCode(), caseNo, fileInfo);
295
+                            result = syncAttachmentInfo(token, username, AttachmentOperateTypeEnum.DEL.getCode(), caseNo, fileInfo);
296
+                        }
297
+                    }
298
+                }
299
+            }
300
+        }
301
+        return result;
302
+    }
303
+
304
+    /**
305
+     * 对字段值进行加密
306
+     *
307
+     * @return
308
+     */
309
+    private String Encrypt(String filed, String filedValue) {
310
+        ObjectNode param = new ObjectMapper().createObjectNode();
311
+        param.put(filed, filedValue);
312
+        String encryptString = sm4Encrypt(param.toString(), privateKey);
313
+        return encryptString;
314
+    }
315
+
316
+}

+ 54
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/mscase/MsCaseFileInfo.java Visa fil

@@ -0,0 +1,54 @@
1
+package com.ruoyi.wisdomarbitrate.domain.vo.mscase;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Builder;
5
+import lombok.Data;
6
+import lombok.NoArgsConstructor;
7
+
8
+/**
9
+ * 北明接口案件附件信息入参
10
+ */
11
+@Data
12
+@NoArgsConstructor
13
+@AllArgsConstructor
14
+@Builder
15
+public class MsCaseFileInfo {
16
+
17
+    /**
18
+     * 第三方文件唯一标识
19
+     */
20
+    private String abutmentId;
21
+    /**
22
+     * 第三方平台案件唯一标识
23
+     */
24
+    private String abutmentCaseId;
25
+    /**
26
+     * 第一级文件类型
27
+     */
28
+    private String documentSubject;
29
+    /**
30
+     * 第二级文件类型
31
+     */
32
+    private String documentType;
33
+    /**
34
+     * 所属人类型(可不传)
35
+     */
36
+    private String ownerType;
37
+    /**
38
+     * 文件所属人第三方平台对应的人员唯一标识(可不传)
39
+     */
40
+    private String ownerId;
41
+    /**
42
+     * 文件所属人名称(可不传)
43
+     */
44
+    private String ownerName;
45
+    /**
46
+     * 文件名称
47
+     */
48
+    private String fileName;
49
+    /**
50
+     * 一站式平台返回的文件ID
51
+     */
52
+    private String fileId;
53
+
54
+}

+ 35
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/mscase/MsCaseStatusInfo.java Visa fil

@@ -0,0 +1,35 @@
1
+package com.ruoyi.wisdomarbitrate.domain.vo.mscase;
2
+
3
+import lombok.*;
4
+
5
+import javax.persistence.Column;
6
+import javax.persistence.GeneratedValue;
7
+import javax.persistence.Id;
8
+import javax.persistence.Table;
9
+
10
+/**
11
+ * 北明接口案件状态入参
12
+ */
13
+@Data
14
+@NoArgsConstructor
15
+@AllArgsConstructor
16
+@Builder
17
+public class MsCaseStatusInfo {
18
+    /**
19
+     * 案号
20
+     * 案件状态编码
21
+     * 结案说明
22
+     */
23
+    private String  caseNo;
24
+
25
+    /**
26
+     * 案件状态编码
27
+     */
28
+    private String statusCode;
29
+
30
+    /**
31
+     * 结案说明
32
+     */
33
+    private String caseClosureExplanation;
34
+
35
+}

+ 42
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/CommonInputStreamResource.java Visa fil

@@ -0,0 +1,42 @@
1
+package com.ruoyi.wisdomarbitrate.utils;
2
+
3
+import org.springframework.core.io.InputStreamResource;
4
+import java.io.InputStream;
5
+public class CommonInputStreamResource extends InputStreamResource {
6
+    private long length;
7
+    private String fileName;
8
+    public CommonInputStreamResource(InputStream inputStream, long length, String fileName) {
9
+        super(inputStream);
10
+        this.length = length;
11
+        this.fileName = fileName;
12
+    }
13
+
14
+    /**
15
+     * 覆写父类方法
16
+     * 如果不重写这个方法,并且文件有一定大小,那么服务端会出现异常
17
+     * {@code The multi-part request contained parameter data (excluding uploaded files) that exceeded}
18
+     */
19
+    @Override
20
+    public String getFilename() {
21
+        return fileName;
22
+    }
23
+
24
+    /**
25
+     * 覆写父类 contentLength 方法
26
+     * 因为 {@link org.springframework.core.io.AbstractResource#contentLength()}方法会重新读取一遍文件,
27
+     * 而上传文件时,restTemplate 会通过这个方法获取大小。然后当真正需要读取内容的时候,发现已经读完,会报如下错误。
28
+     */
29
+    @Override
30
+    public long contentLength() {
31
+        long estimate = length;
32
+        return estimate == 0 ? 1 : estimate;
33
+    }
34
+
35
+    public void setLength(long length) {
36
+        this.length = length;
37
+    }
38
+
39
+    public void setFileName(String fileName) {
40
+        this.fileName = fileName;
41
+    }
42
+}