|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+package com.ruoyi.wisdomarbitrate.service.mscase.impl;
|
|
|
2
|
+
|
|
|
3
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
4
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
5
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
6
|
+import com.google.gson.Gson;
|
|
|
7
|
+import com.google.gson.JsonObject;
|
|
|
8
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
9
|
+import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
|
|
|
10
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
11
|
+import com.ruoyi.common.exception.EsignDemoException;
|
|
|
12
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
13
|
+import com.ruoyi.common.utils.SmsUtils;
|
|
|
14
|
+import com.ruoyi.common.utils.file.SaaSAPIFileUtils;
|
|
|
15
|
+import com.ruoyi.wisdomarbitrate.domain.dto.dept.DeptIdentify;
|
|
|
16
|
+import com.ruoyi.wisdomarbitrate.domain.dto.dept.SealManage;
|
|
|
17
|
+import com.ruoyi.wisdomarbitrate.domain.dto.mscase.SealSignRecord;
|
|
|
18
|
+import com.ruoyi.wisdomarbitrate.domain.entity.dept.MsSealSignRecord;
|
|
|
19
|
+import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseAffiliate;
|
|
|
20
|
+import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseApplication;
|
|
|
21
|
+import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseAttach;
|
|
|
22
|
+import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseApplicationVO;
|
|
|
23
|
+import com.ruoyi.wisdomarbitrate.mapper.dept.DeptIdentifyMapper;
|
|
|
24
|
+import com.ruoyi.wisdomarbitrate.mapper.dept.MsSealSignRecordMapper;
|
|
|
25
|
+import com.ruoyi.wisdomarbitrate.mapper.dept.SealManageMapper;
|
|
|
26
|
+import com.ruoyi.wisdomarbitrate.mapper.mscase.MsCaseAffiliateMapper;
|
|
|
27
|
+import com.ruoyi.wisdomarbitrate.mapper.mscase.MsCaseApplicationMapper;
|
|
|
28
|
+import com.ruoyi.wisdomarbitrate.mapper.mscase.MsCaseAttachMapper;
|
|
|
29
|
+import com.ruoyi.wisdomarbitrate.service.mscase.MsSignSealService;
|
|
|
30
|
+import com.ruoyi.wisdomarbitrate.utils.SignAward;
|
|
|
31
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
32
|
+import org.springframework.stereotype.Service;
|
|
|
33
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
34
|
+
|
|
|
35
|
+import java.util.ArrayList;
|
|
|
36
|
+import java.util.List;
|
|
|
37
|
+
|
|
|
38
|
+@Service
|
|
|
39
|
+public class MsSignSealServiceImpl implements MsSignSealService {
|
|
|
40
|
+
|
|
|
41
|
+ @Autowired
|
|
|
42
|
+ MsCaseApplicationMapper msCaseApplicationMapper;
|
|
|
43
|
+ @Autowired
|
|
|
44
|
+ MsCaseAffiliateMapper msCaseAffiliateMapper;
|
|
|
45
|
+ @Autowired
|
|
|
46
|
+ MsCaseAttachMapper msCaseAttachMapper;
|
|
|
47
|
+ @Autowired
|
|
|
48
|
+ private DeptIdentifyMapper deptIdentifyMapper;
|
|
|
49
|
+ @Autowired
|
|
|
50
|
+ private SealManageMapper sealManageMapper;
|
|
|
51
|
+
|
|
|
52
|
+ @Autowired
|
|
|
53
|
+ private MsSealSignRecordMapper sealSignRecordMapper;
|
|
|
54
|
+
|
|
|
55
|
+
|
|
|
56
|
+ @Override
|
|
|
57
|
+ @Transactional
|
|
|
58
|
+ public AjaxResult sureMediationSeal(MsCaseApplicationVO caseApplicationVO) throws EsignDemoException, InterruptedException {
|
|
|
59
|
+ Long id = caseApplicationVO.getId();
|
|
|
60
|
+ MsCaseApplication caseApplication = msCaseApplicationMapper.selectByPrimaryKey(id);
|
|
|
61
|
+ // 查询案件相关人员
|
|
|
62
|
+ MsCaseAffiliate caseAffiliate = msCaseAffiliateMapper.selectByPrimaryKey(id);
|
|
|
63
|
+ // 查询附件
|
|
|
64
|
+ List<MsCaseAttach> caseAttachList = msCaseAttachMapper.queryAnnexPathByCaseId(id);
|
|
|
65
|
+ if (caseAttachList != null && caseAttachList.size() > 0) {
|
|
|
66
|
+ for (MsCaseAttach caseAttach : caseAttachList) {
|
|
|
67
|
+ if (caseAttach.getAnnexType() == 3) {
|
|
|
68
|
+ String annexPath = caseAttach.getAnnexPath();
|
|
|
69
|
+ String path = "/home/ruoyi" + annexPath;
|
|
|
70
|
+
|
|
|
71
|
+ //获取文件上传地址
|
|
|
72
|
+ EsignHttpResponse response = SaaSAPIFileUtils.getUploadUrl(path);
|
|
|
73
|
+ String body = response.getBody();
|
|
|
74
|
+ if (body != null) {
|
|
|
75
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
76
|
+ String fileId = jsonObject.getJSONObject("data").getString("fileId");
|
|
|
77
|
+ String fileUploadUrl = jsonObject.getJSONObject("data").getString("fileUploadUrl");
|
|
|
78
|
+ //上传文件流
|
|
|
79
|
+ EsignHttpResponse response1 = SaaSAPIFileUtils.uploadFile(fileUploadUrl, path);
|
|
|
80
|
+ JSONObject jsonObject1 = JSONObject.parseObject(response1.getBody());
|
|
|
81
|
+ if (jsonObject1.getIntValue("errCode") == 0) {
|
|
|
82
|
+ //查看文件上传状态
|
|
|
83
|
+ Thread.sleep(1000);
|
|
|
84
|
+ EsignHttpResponse response2 = SaaSAPIFileUtils.getFileStatus(fileId);
|
|
|
85
|
+ JSONObject jsonObject2 = JSONObject.parseObject(response2.getBody());
|
|
|
86
|
+ JSONObject data = jsonObject2.getJSONObject("data");
|
|
|
87
|
+ int fileStatus = data.getIntValue("fileStatus");
|
|
|
88
|
+ if (fileStatus == 2 || fileStatus == 5) {
|
|
|
89
|
+ String fileName = data.getString("fileName");
|
|
|
90
|
+ //上传成功,获取文件签名印章位置
|
|
|
91
|
+ SealSignRecord sealSignRecord = new SealSignRecord();
|
|
|
92
|
+ sealSignRecord.setFileid(fileId);
|
|
|
93
|
+ EsignHttpResponse positions = SignAward.getPositionsMediation(sealSignRecord);
|
|
|
94
|
+ Gson gson = new Gson();
|
|
|
95
|
+ JsonObject positionsJsonObject = gson.fromJson(positions.getBody(), JsonObject.class);
|
|
|
96
|
+ JsonObject positionsData = positionsJsonObject.getAsJsonObject("data");
|
|
|
97
|
+ String keywordPositions = positionsData.get("keywordPositions").toString();
|
|
|
98
|
+ //发起签署
|
|
|
99
|
+ sealSignRecord.setFilename(fileName);
|
|
|
100
|
+
|
|
|
101
|
+ sealSignRecord.setPensonAccount(caseAffiliate.getContactTelphoneAgent());
|
|
|
102
|
+ sealSignRecord.setPensonName(caseAffiliate.getNameAgent());
|
|
|
103
|
+ sealSignRecord.setPensonAccountRes(caseAffiliate.getRespondentPhone());
|
|
|
104
|
+ sealSignRecord.setPensonNameRes(caseAffiliate.getRespondentName());
|
|
|
105
|
+
|
|
|
106
|
+ DeptIdentify deptIdentify = new DeptIdentify();
|
|
|
107
|
+ deptIdentify.setIsUse(1);
|
|
|
108
|
+ DeptIdentify deptIdentifyselect = new DeptIdentify();
|
|
|
109
|
+ List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
|
|
|
110
|
+ if (deptIdentifysnew != null && deptIdentifysnew.size() > 0) {
|
|
|
111
|
+ deptIdentifyselect = deptIdentifysnew.get(0);
|
|
|
112
|
+ sealSignRecord.setOrgnizeName(deptIdentifyselect.getIdentifyName());
|
|
|
113
|
+ sealSignRecord.setOrgnizeNamePsnAccount(deptIdentifyselect.getOperPhone());
|
|
|
114
|
+ sealSignRecord.setOrgnizeNamepsnName(deptIdentifyselect.getOperName());
|
|
|
115
|
+ } else {
|
|
|
116
|
+ return AjaxResult.error("没有用印时的机构名称及经办人信息");
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ //解析文件签名印章位置
|
|
|
120
|
+ JSONArray jsonArray = JSONArray.parseArray(keywordPositions);
|
|
|
121
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
122
|
+ JSONObject jsonObject3 = jsonArray.getJSONObject(i);
|
|
|
123
|
+ String keyword = jsonObject3.getString("keyword");
|
|
|
124
|
+ if (keyword.equals("申请人:")) {
|
|
|
125
|
+ //签名
|
|
|
126
|
+ JSONArray positionsArray = jsonObject3.getJSONArray("positions");
|
|
|
127
|
+ // 遍历 positionsArray 中的每个元素
|
|
|
128
|
+ for (int j = 0; j < positionsArray.size(); j++) {
|
|
|
129
|
+ JSONObject positionObj = positionsArray.getJSONObject(j);
|
|
|
130
|
+ int pageNum = positionObj.getIntValue("pageNum");
|
|
|
131
|
+ sealSignRecord.setPositionPagepsn(String.valueOf(pageNum));
|
|
|
132
|
+ JSONArray coordinatesArray = positionObj.getJSONArray("coordinates");
|
|
|
133
|
+ JSONObject coordinateObj = coordinatesArray.getJSONObject(0);
|
|
|
134
|
+ double positionX = coordinateObj.getDoubleValue("positionX");
|
|
|
135
|
+ double positionY = coordinateObj.getDoubleValue("positionY");
|
|
|
136
|
+ sealSignRecord.setPositionXpsn(positionX + 90);
|
|
|
137
|
+ sealSignRecord.setPositionYpsn(positionY);
|
|
|
138
|
+ }
|
|
|
139
|
+ }else if (keyword.equals("被申请人:")) {
|
|
|
140
|
+ //签名
|
|
|
141
|
+ JSONArray positionsArray = jsonObject3.getJSONArray("positions");
|
|
|
142
|
+ // 遍历 positionsArray 中的每个元素
|
|
|
143
|
+ for (int j = 0; j < positionsArray.size(); j++) {
|
|
|
144
|
+ JSONObject positionObj = positionsArray.getJSONObject(j);
|
|
|
145
|
+ int pageNum = positionObj.getIntValue("pageNum");
|
|
|
146
|
+ sealSignRecord.setPositionPagepsnRes(String.valueOf(pageNum));
|
|
|
147
|
+ JSONArray coordinatesArray = positionObj.getJSONArray("coordinates");
|
|
|
148
|
+ JSONObject coordinateObj = coordinatesArray.getJSONObject(0);
|
|
|
149
|
+ double positionX = coordinateObj.getDoubleValue("positionX");
|
|
|
150
|
+ double positionY = coordinateObj.getDoubleValue("positionY");
|
|
|
151
|
+ sealSignRecord.setPositionXpsnRes(positionX + 90);
|
|
|
152
|
+ sealSignRecord.setPositionYpsnRes(positionY);
|
|
|
153
|
+ }
|
|
|
154
|
+ }else {
|
|
|
155
|
+ //用印
|
|
|
156
|
+ JSONArray positionsArray = jsonObject3.getJSONArray("positions");
|
|
|
157
|
+ // 遍历 positionsArray 中的每个元素
|
|
|
158
|
+ for (int j = 0; j < positionsArray.size(); j++) {
|
|
|
159
|
+ JSONObject positionObj = positionsArray.getJSONObject(j);
|
|
|
160
|
+ int pageNum = positionObj.getIntValue("pageNum");
|
|
|
161
|
+ sealSignRecord.setPositionPageorg(String.valueOf(pageNum));
|
|
|
162
|
+ JSONArray coordinatesArray = positionObj.getJSONArray("coordinates");
|
|
|
163
|
+ JSONObject coordinateObj = coordinatesArray.getJSONObject(0);
|
|
|
164
|
+ double positionX = coordinateObj.getDoubleValue("positionX");
|
|
|
165
|
+ double positionY = coordinateObj.getDoubleValue("positionY");
|
|
|
166
|
+ sealSignRecord.setPositionXorg(positionX + 90);
|
|
|
167
|
+ sealSignRecord.setPositionYorg(positionY);
|
|
|
168
|
+ }
|
|
|
169
|
+ }
|
|
|
170
|
+ }
|
|
|
171
|
+ /*DeptIdentify deptIdentify1 = new DeptIdentify();
|
|
|
172
|
+ deptIdentify1.setSealStatus(1); // 印章状态为启用
|
|
|
173
|
+ //根据机构名称查询部门id
|
|
|
174
|
+ SysDept sysDept = new SysDept();
|
|
|
175
|
+ sysDept.setDeptName(sealSignRecord.getOrgnizeName());
|
|
|
176
|
+ List<SysDept> sysDepts = deptMapper.selectDeptList(sysDept);
|
|
|
177
|
+ if (sysDepts != null && sysDepts.size() > 0) {
|
|
|
178
|
+ Long deptId = sysDepts.get(0).getDeptId();
|
|
|
179
|
+ deptIdentify1.setDeptId(deptId);
|
|
|
180
|
+ }
|
|
|
181
|
+ List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentifylistother(deptIdentify1);
|
|
|
182
|
+ List<String> sealIds = new ArrayList<>();
|
|
|
183
|
+ if (deptIdentifies != null && deptIdentifies.size() > 0) {
|
|
|
184
|
+ for (DeptIdentify identify : deptIdentifies) {
|
|
|
185
|
+ String sealId = identify.getSealId();
|
|
|
186
|
+ sealIds.add(sealId);
|
|
|
187
|
+ }
|
|
|
188
|
+ }*/
|
|
|
189
|
+ String orgnizeName = sealSignRecord.getOrgnizeName(); //机构名称
|
|
|
190
|
+ String orgnizeNamepsnName = sealSignRecord.getOrgnizeNamepsnName(); //机构经办人姓名
|
|
|
191
|
+ String orgnizeNamePsnAccount = sealSignRecord.getOrgnizeNamePsnAccount(); //机构经办人联系方式
|
|
|
192
|
+ //查询机构信息
|
|
|
193
|
+ DeptIdentify deptIdentify1 = new DeptIdentify();
|
|
|
194
|
+ deptIdentify1.setIdentifyName(orgnizeName);
|
|
|
195
|
+ deptIdentify1.setOperName(orgnizeNamepsnName);
|
|
|
196
|
+ deptIdentify1.setOperPhone(orgnizeNamePsnAccount);
|
|
|
197
|
+ List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentify(deptIdentify1);
|
|
|
198
|
+ if (deptIdentifies != null && deptIdentifies.size() > 0) {
|
|
|
199
|
+ Long iddeptIdent = deptIdentifies.get(0).getId();
|
|
|
200
|
+ SealManage sealManage = new SealManage();
|
|
|
201
|
+ sealManage.setIdentifyId(iddeptIdent);
|
|
|
202
|
+ List<String> sealIdList = new ArrayList<>();
|
|
|
203
|
+ List<SealManage> selectSealList = sealManageMapper.selectSealList(sealManage);
|
|
|
204
|
+ if (selectSealList != null && selectSealList.size() > 0) {
|
|
|
205
|
+ for (SealManage manage : selectSealList) {
|
|
|
206
|
+ Integer sealStatus = manage.getSealStatus();
|
|
|
207
|
+ Integer isUse = manage.getIsUse();
|
|
|
208
|
+ if (sealStatus == 1 && isUse ==1) {
|
|
|
209
|
+ sealIdList.add(manage.getSealId());
|
|
|
210
|
+ }
|
|
|
211
|
+ }
|
|
|
212
|
+ EsignHttpResponse response3 = SignAward.createByFileMediation(sealSignRecord, sealIdList);
|
|
|
213
|
+
|
|
|
214
|
+ JSONObject jsonObject3 = JSONObject.parseObject(response3.getBody());
|
|
|
215
|
+ if (jsonObject3 != null) {
|
|
|
216
|
+ if (jsonObject3.getIntValue("code") == 0) {
|
|
|
217
|
+ //获取签署流程ID
|
|
|
218
|
+ JSONObject data1 = jsonObject3.getJSONObject("data");
|
|
|
219
|
+ String signFlowId = data1.getString("signFlowId");
|
|
|
220
|
+ //保存案件id,文件id,文件名称.流程id到签署用印记录表里
|
|
|
221
|
+ sealSignRecord.setCaseAppliId(caseApplication.getId());
|
|
|
222
|
+ sealSignRecord.setSignFlowid(signFlowId);
|
|
|
223
|
+ sealSignRecord.setSignFlowStatus(1);//待签名
|
|
|
224
|
+ MsSealSignRecord msSealSignRecord = new MsSealSignRecord();
|
|
|
225
|
+ BeanUtil.copyProperties(sealSignRecord, msSealSignRecord);
|
|
|
226
|
+ msSealSignRecord.setFileId(sealSignRecord.getFileid());
|
|
|
227
|
+ msSealSignRecord.setFileName(sealSignRecord.getFilename());
|
|
|
228
|
+ msSealSignRecord.setSignFlowId(sealSignRecord.getSignFlowid());
|
|
|
229
|
+ msSealSignRecord.setOrgnNamePsnAcc(sealSignRecord.getOrgnizeNamePsnAccount());
|
|
|
230
|
+ msSealSignRecord.setOrgnNamePsnName(sealSignRecord.getOrgnizeNamepsnName());
|
|
|
231
|
+ sealSignRecordMapper.insert(msSealSignRecord);
|
|
|
232
|
+
|
|
|
233
|
+ SealSignRecord sealSignRecordapply = new SealSignRecord();
|
|
|
234
|
+ sealSignRecordapply.setSignFlowid(signFlowId);
|
|
|
235
|
+ sealSignRecordapply.setPensonAccount(caseAffiliate.getContactTelphoneAgent());
|
|
|
236
|
+ EsignHttpResponse signUrl = SignAward.signUrlMediation(sealSignRecordapply);
|
|
|
237
|
+ JsonObject signUrlJsonObject = gson.fromJson(signUrl.getBody(), JsonObject.class);
|
|
|
238
|
+ JsonObject signUrlData = signUrlJsonObject.getAsJsonObject("data");
|
|
|
239
|
+ String urlapply = signUrlData.get("shortUrl").getAsString();
|
|
|
240
|
+ String urlapplynew = urlapply.substring(urlapply.lastIndexOf("/")+1);
|
|
|
241
|
+
|
|
|
242
|
+ //发送签名链接短信,尊敬的{1}用户,您的{2}调解案件,签名链接{3},请点击链接签名,如非本人操作,请忽略本短信
|
|
|
243
|
+ SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
|
|
|
244
|
+ request.setTemplateId("2047719");
|
|
|
245
|
+ request.setPhone(caseAffiliate.getContactTelphoneAgent());
|
|
|
246
|
+ request.setTemplateParamSet(new String[]{caseAffiliate.getNameAgent(), caseApplication.getCaseNum(),urlapplynew});
|
|
|
247
|
+ Boolean aBoolean = SmsUtils.sendSms(request);
|
|
|
248
|
+
|
|
|
249
|
+ SealSignRecord sealSignRecordRespon = new SealSignRecord();
|
|
|
250
|
+ sealSignRecordRespon.setSignFlowid(signFlowId);
|
|
|
251
|
+ sealSignRecordRespon.setPensonAccount(caseAffiliate.getRespondentPhone());
|
|
|
252
|
+ EsignHttpResponse signUrlRespon = SignAward.signUrlMediation(sealSignRecordRespon);
|
|
|
253
|
+ JsonObject signUrlJsonObjectRespon = gson.fromJson(signUrlRespon.getBody(), JsonObject.class);
|
|
|
254
|
+ JsonObject signUrlDataRespon = signUrlJsonObjectRespon.getAsJsonObject("data");
|
|
|
255
|
+ String urlRespon = signUrlDataRespon.get("shortUrl").getAsString();
|
|
|
256
|
+ String urlResponnew = urlRespon.substring(urlRespon.lastIndexOf("/")+1);
|
|
|
257
|
+
|
|
|
258
|
+ SmsUtils.SendSmsRequest request1 = new SmsUtils.SendSmsRequest();
|
|
|
259
|
+ request1.setTemplateId("2047719");
|
|
|
260
|
+ request1.setPhone(caseAffiliate.getRespondentPhone());
|
|
|
261
|
+ request1.setTemplateParamSet(new String[]{caseAffiliate.getNameAgent(), caseApplication.getCaseNum(),urlResponnew});
|
|
|
262
|
+ Boolean aBoolean1 = SmsUtils.sendSms(request1);
|
|
|
263
|
+
|
|
|
264
|
+
|
|
|
265
|
+ } else {
|
|
|
266
|
+ throw new ServiceException(jsonObject3.getString("message"));
|
|
|
267
|
+ }
|
|
|
268
|
+ } else {
|
|
|
269
|
+ return AjaxResult.error();
|
|
|
270
|
+ }
|
|
|
271
|
+
|
|
|
272
|
+ }
|
|
|
273
|
+
|
|
|
274
|
+
|
|
|
275
|
+ } else {
|
|
|
276
|
+ return AjaxResult.error();
|
|
|
277
|
+ }
|
|
|
278
|
+ }
|
|
|
279
|
+ }
|
|
|
280
|
+ }
|
|
|
281
|
+ break;
|
|
|
282
|
+ }
|
|
|
283
|
+
|
|
|
284
|
+ }
|
|
|
285
|
+
|
|
|
286
|
+ }
|
|
|
287
|
+ return AjaxResult.success();
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+
|
|
|
291
|
+
|
|
|
292
|
+
|
|
|
293
|
+}
|