|
|
@@ -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
|
+}
|