|
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+package com.ruoyi.wisdomarbitrate.service.impl;
|
|
|
2
|
+
|
|
|
3
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
4
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
5
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
6
|
+import cn.hutool.core.util.StrUtil;
|
|
|
7
|
+import com.ruoyi.common.constant.CaseApplicationConstants;
|
|
|
8
|
+import com.ruoyi.common.constant.Constants;
|
|
|
9
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
10
|
+import com.ruoyi.common.core.domain.entity.SysRole;
|
|
|
11
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
12
|
+import com.ruoyi.common.enums.UpdateSubmitStatus;
|
|
|
13
|
+import com.ruoyi.common.utils.*;
|
|
|
14
|
+import com.ruoyi.common.config.RuoYiConfig;
|
|
|
15
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
16
|
+import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
17
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
18
|
+import com.ruoyi.common.utils.file.FileUtils;
|
|
|
19
|
+import com.ruoyi.common.utils.thread.MultipleThreadListParam;
|
|
|
20
|
+import com.ruoyi.common.utils.thread.MultipleThreadWorkUtil;
|
|
|
21
|
+import com.ruoyi.system.domain.SysUserRole;
|
|
|
22
|
+import com.ruoyi.system.mapper.*;
|
|
|
23
|
+import com.ruoyi.wisdomarbitrate.domain.CaseAffiliate;
|
|
|
24
|
+import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
|
|
|
25
|
+import com.ruoyi.wisdomarbitrate.domain.CaseAttach;
|
|
|
26
|
+import com.ruoyi.wisdomarbitrate.domain.FatchRule;
|
|
|
27
|
+import com.ruoyi.wisdomarbitrate.domain.vo.ColumnValue;
|
|
|
28
|
+import com.ruoyi.wisdomarbitrate.mapper.*;
|
|
|
29
|
+import com.ruoyi.wisdomarbitrate.utils.OCRUtils;
|
|
|
30
|
+import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
|
|
|
31
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
32
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
33
|
+import org.springframework.stereotype.Service;
|
|
|
34
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
35
|
+
|
|
|
36
|
+import java.io.*;
|
|
|
37
|
+import java.math.BigDecimal;
|
|
|
38
|
+import java.text.SimpleDateFormat;
|
|
|
39
|
+import java.util.*;
|
|
|
40
|
+import java.util.function.Function;
|
|
|
41
|
+import java.util.regex.Matcher;
|
|
|
42
|
+import java.util.regex.Pattern;
|
|
|
43
|
+import java.util.stream.Collectors;
|
|
|
44
|
+
|
|
|
45
|
+import static com.ruoyi.common.core.domain.AjaxResult.error;
|
|
|
46
|
+import static com.ruoyi.common.core.domain.AjaxResult.success;
|
|
|
47
|
+import static com.ruoyi.common.utils.SecurityUtils.getUsername;
|
|
|
48
|
+
|
|
|
49
|
+/**
|
|
|
50
|
+ * @author wangqiong
|
|
|
51
|
+ * @description 案件压缩包导入
|
|
|
52
|
+ * @date 2023-12-11 11:45
|
|
|
53
|
+ */
|
|
|
54
|
+@Service
|
|
|
55
|
+public class CaseZipImportImpl {
|
|
|
56
|
+ @Autowired
|
|
|
57
|
+ private CaseApplicationServiceImpl caseApplicationService;
|
|
|
58
|
+ @Autowired
|
|
|
59
|
+ private FatchRuleMapper fatchRuleMapper;
|
|
|
60
|
+ @Autowired
|
|
|
61
|
+ private SysDictDataMapper dictDataMapper;
|
|
|
62
|
+ @Autowired
|
|
|
63
|
+ private CaseApplicationMapper caseApplicationMapper;
|
|
|
64
|
+ @Autowired
|
|
|
65
|
+ private SysDeptMapper sysDeptMapper;
|
|
|
66
|
+ @Autowired
|
|
|
67
|
+ private SysRoleMapper roleMapper;
|
|
|
68
|
+ @Autowired
|
|
|
69
|
+ private SysUserMapper userMapper;
|
|
|
70
|
+ @Autowired
|
|
|
71
|
+ private SysUserRoleMapper userRoleMapper;
|
|
|
72
|
+ @Autowired
|
|
|
73
|
+ private CaseApplicationLogMapper caseApplicationLogMapper;
|
|
|
74
|
+ @Autowired
|
|
|
75
|
+ private CaseAffiliateLogMapper caseAffiliateLogMapper;
|
|
|
76
|
+ @Autowired
|
|
|
77
|
+ private CaseAttachLogMapper caseAttachLogMapper;
|
|
|
78
|
+ @Autowired
|
|
|
79
|
+ private SmsRecordMapper smsRecordMapper;
|
|
|
80
|
+ @Autowired
|
|
|
81
|
+ private CaseAttachMapper caseAttachMapper;
|
|
|
82
|
+ @Autowired
|
|
|
83
|
+ private ColumnValueMapper columnValueMapper;
|
|
|
84
|
+ @Autowired
|
|
|
85
|
+ private ColumnValueLogMapper columnValueLogMapper;
|
|
|
86
|
+ @Autowired
|
|
|
87
|
+ private CaseAffiliateMapper caseAffiliateMapper;
|
|
|
88
|
+ // 申请人角色id
|
|
|
89
|
+ private long roleId;
|
|
|
90
|
+ private Integer maxCaseNum;
|
|
|
91
|
+ private Integer maxBatchNumber;
|
|
|
92
|
+
|
|
|
93
|
+ public AjaxResult zipImport(MultipartFile file, Long templateId) {
|
|
|
94
|
+ UUID uuid = UUID.randomUUID();
|
|
|
95
|
+ // todo
|
|
|
96
|
+ String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile/" + uuid + "/";
|
|
|
97
|
+// String targetPath = "D:/home/ruoyi/uploadPath/upload/unzipFile/"+uuid+ "/";
|
|
|
98
|
+ File zipFile = null;
|
|
|
99
|
+ InputStream ins = null;
|
|
|
100
|
+ try {
|
|
|
101
|
+ ins = file.getInputStream();
|
|
|
102
|
+ //上传的压缩包保存的路径
|
|
|
103
|
+ // todo
|
|
|
104
|
+ String savePath = "/home/ruoyi/uploadPath/upload/zipFile/";
|
|
|
105
|
+// String savePath = "D:/home/ruoyi/uploadPath/upload/zipFile/";
|
|
|
106
|
+ String saveName = uuid + "_" + file.getOriginalFilename();
|
|
|
107
|
+ zipFile = new File(savePath + saveName);
|
|
|
108
|
+ inputChangeToFile(ins, zipFile);
|
|
|
109
|
+ } catch (IOException e) {
|
|
|
110
|
+ e.printStackTrace();
|
|
|
111
|
+ }
|
|
|
112
|
+ //解压缩上传的压缩包
|
|
|
113
|
+ boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
|
|
|
114
|
+ if (!unzipSuccess) {
|
|
|
115
|
+ // 解压失败
|
|
|
116
|
+ return AjaxResult.error("解压失败");
|
|
|
117
|
+ }
|
|
|
118
|
+ // 查询抓取规则
|
|
|
119
|
+ // todo 批次需要再上传压缩包时用户填写
|
|
|
120
|
+ List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(templateId);
|
|
|
121
|
+ if (CollectionUtil.isEmpty(fatchRuleList)) {
|
|
|
122
|
+ return error("未设置抓取规则");
|
|
|
123
|
+ }
|
|
|
124
|
+ File directory = new File(targetPath);
|
|
|
125
|
+ // fileMap<caseId, List<File>>
|
|
|
126
|
+ Map<Long, List<File>> fileMap = findAndConvertPDF(directory);
|
|
|
127
|
+ if (fileMap == null || fileMap.size() <= 0) {
|
|
|
128
|
+ // 解压失败
|
|
|
129
|
+ return AjaxResult.error("未获取到文件");
|
|
|
130
|
+ }
|
|
|
131
|
+ Map<String, String> fatchMap = new HashMap<>();
|
|
|
132
|
+ if (CollectionUtil.isNotEmpty(fatchRuleList)) {
|
|
|
133
|
+
|
|
|
134
|
+ Map<String, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getFileName));
|
|
|
135
|
+ // 根据抓取规则循环抓取
|
|
|
136
|
+ fileMap.forEach((key, fileList) -> {
|
|
|
137
|
+ if (CollectionUtil.isNotEmpty(fileList)) {
|
|
|
138
|
+ for (File caseFile : fileList) {
|
|
|
139
|
+ if (fatchRuleMap.containsKey(caseFile.getName())) {
|
|
|
140
|
+ // 抓取内容
|
|
|
141
|
+ List<FatchRule> fatchRules = fatchRuleMap.get(caseFile.getName());
|
|
|
142
|
+ getFatchContentList(caseFile, fatchMap, fatchRules, key);
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
|
|
145
|
+ }
|
|
|
146
|
+ });
|
|
|
147
|
+
|
|
|
148
|
+ }
|
|
|
149
|
+ if (fatchMap.size() <= 0) {
|
|
|
150
|
+ return error("从压缩包中未抓取到内容,请检查抓取字段配置");
|
|
|
151
|
+ }
|
|
|
152
|
+ // 新增的案件
|
|
|
153
|
+ List<CaseApplication> caseApplications = new ArrayList<>();
|
|
|
154
|
+ // 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue
|
|
|
155
|
+ // 抓取规则,0-内置字段,1-自定义字段
|
|
|
156
|
+ Map<Integer, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getIsDefault));
|
|
|
157
|
+ // 在系统表中查询案件内置字段
|
|
|
158
|
+ SysDictData sysDictData = new SysDictData();
|
|
|
159
|
+ sysDictData.setDictType("case_built_type");
|
|
|
160
|
+ List<SysDictData> dictDataList = dictDataMapper.selectDictDataList(sysDictData);
|
|
|
161
|
+ // 查询所有的组织机构,组装成map
|
|
|
162
|
+ List<SysDept> deptList = sysDeptMapper.selectDeptList(new SysDept());
|
|
|
163
|
+ // 所有部门
|
|
|
164
|
+ Map<String, Long> deptMap = new HashMap<>();
|
|
|
165
|
+ if (CollectionUtil.isNotEmpty(deptList)) {
|
|
|
166
|
+ deptMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptName, SysDept::getDeptId, (oldV, newV) -> newV));
|
|
|
167
|
+
|
|
|
168
|
+ }
|
|
|
169
|
+ // 角色用户
|
|
|
170
|
+ List<SysUserRole> userRoleList = new ArrayList<>();
|
|
|
171
|
+ // 查询申请人角色id
|
|
|
172
|
+ roleId = roleMapper.selectRoleIdByName("申请人");
|
|
|
173
|
+
|
|
|
174
|
+ // 案件基本信息
|
|
|
175
|
+ caseApplications = new ArrayList<>();
|
|
|
176
|
+ // 自定义字段,组装columnValue表
|
|
|
177
|
+ List<ColumnValue> columnValueList = new ArrayList<>();
|
|
|
178
|
+ // 案件人员
|
|
|
179
|
+ List<CaseAffiliate> caseAffiliates = new ArrayList<>();
|
|
|
180
|
+ // 组装机构
|
|
|
181
|
+ List<SysDept> sysDepts = new ArrayList<>();
|
|
|
182
|
+ // 案件附件
|
|
|
183
|
+ List<CaseAttach> caseAttachs = new ArrayList<>();
|
|
|
184
|
+ /**
|
|
|
185
|
+ * 用户表已存在的用户
|
|
|
186
|
+ */
|
|
|
187
|
+ List<SysUser> existUsers = userMapper.selectUserList(new SysUser());
|
|
|
188
|
+ Map<String, SysUser> userMap = new HashMap<>();
|
|
|
189
|
+ if (CollectionUtil.isNotEmpty(existUsers)) {
|
|
|
190
|
+ userMap = existUsers.stream().collect(Collectors.toMap(SysUser::getPhonenumber, Function.identity(), (n1, n2) -> n2));
|
|
|
191
|
+ }
|
|
|
192
|
+ //查询出当天的案件编号的最大值
|
|
|
193
|
+ String currentDay = DateUtils.dateTime();
|
|
|
194
|
+ String caseNum = "zc" + currentDay;
|
|
|
195
|
+ maxCaseNum = caseApplicationMapper.selectCaseNumLike(caseNum, caseNum.length());
|
|
|
196
|
+ // 需要新增的用户
|
|
|
197
|
+ List<SysUser> addUsers = new ArrayList<>();
|
|
|
198
|
+ for (Long caseId : fileMap.keySet()) {
|
|
|
199
|
+ if (CollectionUtil.isEmpty(fileMap.get(caseId))) {
|
|
|
200
|
+ continue;
|
|
|
201
|
+ }
|
|
|
202
|
+ CaseApplication caseApplication = new CaseApplication();
|
|
|
203
|
+ caseApplications.add(caseApplication);
|
|
|
204
|
+ caseApplication.setId(caseId);
|
|
|
205
|
+ caseApplication.setTemplateId(templateId);
|
|
|
206
|
+
|
|
|
207
|
+ caseApplication.setCaseStatus(CaseApplicationConstants.CASE_APPLICATION);
|
|
|
208
|
+ caseApplication.setCaseLogId(IdWorkerUtil.getId());
|
|
|
209
|
+ caseApplication.setUpdateSubmitStatus(UpdateSubmitStatus.UNCOMMITTED.getCode());
|
|
|
210
|
+ caseApplication.setCaseAppliId(caseApplication.getId());
|
|
|
211
|
+ //默认案件标的 todo 案件标的是什么,默认写死
|
|
|
212
|
+ caseApplication.setCaseSubjectAmount(new BigDecimal(100000));
|
|
|
213
|
+ //todo 暂时设置计费比率为0.01
|
|
|
214
|
+ BigDecimal feeRate = new BigDecimal(0.01);
|
|
|
215
|
+ BigDecimal feePayable = caseApplication.getCaseSubjectAmount().multiply(feeRate).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
216
|
+ caseApplication.setFeePayable(feePayable);
|
|
|
217
|
+ // 设置批号
|
|
|
218
|
+ if (StrUtil.isEmpty(caseApplication.getBatchNumber())) {
|
|
|
219
|
+ maxBatchNumber = caseApplicationMapper.selectBatchNumberLike();
|
|
|
220
|
+ if (maxBatchNumber == null) {
|
|
|
221
|
+ maxBatchNumber=1;
|
|
|
222
|
+ caseApplication.setBatchNumber(maxBatchNumber.toString());
|
|
|
223
|
+ } else {
|
|
|
224
|
+ maxBatchNumber=maxBatchNumber+1;
|
|
|
225
|
+ caseApplication.setBatchNumber( maxBatchNumber.toString());
|
|
|
226
|
+ }
|
|
|
227
|
+ }
|
|
|
228
|
+ // 设置编号
|
|
|
229
|
+ String maxCaseNumStr=generateCaseNum();
|
|
|
230
|
+ caseApplication.setCaseNum(maxCaseNumStr);
|
|
|
231
|
+ caseApplication.setCreateBy(getUsername());
|
|
|
232
|
+ caseApplication.setVersion(1);
|
|
|
233
|
+ // 组装案件内置字段主表内容
|
|
|
234
|
+
|
|
|
235
|
+ if (fatchRuleMap.size() > 0 && fatchRuleMap.containsKey(1)) {
|
|
|
236
|
+ List<FatchRule> columnRules = fatchRuleMap.get(1);
|
|
|
237
|
+ columnRules.forEach(columnRule -> {
|
|
|
238
|
+ ColumnValue columnValue = new ColumnValue();
|
|
|
239
|
+ columnValue.setColumn(columnRule.getColumn());
|
|
|
240
|
+ columnValue.setName(columnRule.getColumnName());
|
|
|
241
|
+ columnValue.setName(columnRule.getColumnName());
|
|
|
242
|
+ columnValue.setValue(fatchMap.get(columnRule.getColumnName() + Constants.PDFSTR + caseId));
|
|
|
243
|
+ columnValue.setIsDefault(1);
|
|
|
244
|
+ columnValue.setCaseId(caseId);
|
|
|
245
|
+ columnValue.setCaseAppliLogId(caseApplication.getCaseLogId());
|
|
|
246
|
+ columnValueList.add(columnValue);
|
|
|
247
|
+ });
|
|
|
248
|
+ }
|
|
|
249
|
+ caseApplication.setColumnValues(columnValueList);
|
|
|
250
|
+ // 组装内置字段
|
|
|
251
|
+ buildDefaultColumn(caseApplication, dictDataList, fatchMap, caseAffiliates, deptMap, sysDepts, userMap, addUsers, userRoleList);
|
|
|
252
|
+ for (File caseFile : fileMap.get(caseId)) {
|
|
|
253
|
+ String fileUrl = caseFile.getAbsolutePath();
|
|
|
254
|
+ if (StrUtil.isEmpty(fileUrl)) {
|
|
|
255
|
+ continue;
|
|
|
256
|
+ }
|
|
|
257
|
+ // 上传
|
|
|
258
|
+ String filePath = RuoYiConfig.getUploadPath();
|
|
|
259
|
+
|
|
|
260
|
+ CaseAttach caseAttach = new CaseAttach();
|
|
|
261
|
+ caseAttach.setCaseAppliId(caseApplication.getId());
|
|
|
262
|
+ caseAttach.setCaseAppliLogId(caseApplication.getCaseLogId());
|
|
|
263
|
+ caseAttach.setAnnexPath(filePath);
|
|
|
264
|
+ if (StrUtil.isNotEmpty(fileUrl)) {
|
|
|
265
|
+ String fileName = fileUrl.replace(filePath, "/profile/upload");
|
|
|
266
|
+ caseAttach.setAnnexName(fileName);
|
|
|
267
|
+ }
|
|
|
268
|
+ // 申请人提供的证据材料
|
|
|
269
|
+ caseAttach.setAnnexType(2);
|
|
|
270
|
+ caseAttachs.add(caseAttach);
|
|
|
271
|
+ if (fileUrl.contains("仲裁申请书")) {
|
|
|
272
|
+ CaseAttach applyFile = new CaseAttach();
|
|
|
273
|
+ BeanUtil.copyProperties(caseAttach, applyFile);
|
|
|
274
|
+ applyFile.setAnnexType(1);
|
|
|
275
|
+ caseAttachs.add(applyFile);
|
|
|
276
|
+ }
|
|
|
277
|
+ }
|
|
|
278
|
+ // 案件压缩包导入
|
|
|
279
|
+ caseApplication.setImportFlag(2);
|
|
|
280
|
+
|
|
|
281
|
+ }
|
|
|
282
|
+ // 多线程执行
|
|
|
283
|
+ List<MultipleThreadListParam> execList=new ArrayList<>();
|
|
|
284
|
+ if (CollectionUtil.isNotEmpty(addUsers)) {
|
|
|
285
|
+ Function<List<SysUser>,Integer> function=userMapper::batchSave;
|
|
|
286
|
+ execList.add(new MultipleThreadListParam(function,addUsers));
|
|
|
287
|
+ }
|
|
|
288
|
+ if (CollectionUtil.isNotEmpty(userRoleList)) {
|
|
|
289
|
+ Function<List<SysUserRole>,Integer> function=userRoleMapper::batchUserRole;
|
|
|
290
|
+ execList.add(new MultipleThreadListParam(function,userRoleList));
|
|
|
291
|
+
|
|
|
292
|
+ }
|
|
|
293
|
+ if (CollectionUtil.isNotEmpty(sysDepts)) {
|
|
|
294
|
+ Function<List<SysDept>,Integer> function=sysDeptMapper::batchSave;
|
|
|
295
|
+ execList.add(new MultipleThreadListParam(function,sysDepts));
|
|
|
296
|
+
|
|
|
297
|
+ }
|
|
|
298
|
+ if (CollectionUtil.isNotEmpty(caseApplications)) {
|
|
|
299
|
+ Function<List<CaseApplication>,Integer> function=caseApplicationMapper::batchSave;
|
|
|
300
|
+ execList.add(new MultipleThreadListParam(function,caseApplications));
|
|
|
301
|
+ Function<List<CaseApplication>,Integer> functionLog=caseApplicationLogMapper::batchSave;
|
|
|
302
|
+ execList.add(new MultipleThreadListParam(functionLog,caseApplications));
|
|
|
303
|
+
|
|
|
304
|
+ }
|
|
|
305
|
+ if (CollectionUtil.isNotEmpty(caseAffiliates)) {
|
|
|
306
|
+ Function<List<CaseAffiliate>,Integer> function=caseAffiliateMapper::batchCaseAffiliate;
|
|
|
307
|
+ execList.add(new MultipleThreadListParam(function,caseAffiliates));
|
|
|
308
|
+ Function<List<CaseAffiliate>,Integer> functionLog=caseAffiliateLogMapper::batchCaseAffiliate;
|
|
|
309
|
+ execList.add(new MultipleThreadListParam(functionLog,caseAffiliates));
|
|
|
310
|
+ }
|
|
|
311
|
+ if (CollectionUtil.isNotEmpty(caseAttachs)) {
|
|
|
312
|
+ Function<List<CaseAttach>,Integer> function=caseAttachMapper::batchSave;
|
|
|
313
|
+ execList.add(new MultipleThreadListParam(function,caseAttachs));
|
|
|
314
|
+ Function<List<CaseAttach>,Integer> functionLog=caseAttachLogMapper::batchSave;
|
|
|
315
|
+ execList.add(new MultipleThreadListParam(functionLog,caseAttachs));
|
|
|
316
|
+ }
|
|
|
317
|
+ if (CollectionUtil.isNotEmpty(columnValueList)) {
|
|
|
318
|
+ Function<List<ColumnValue>,Integer> function=columnValueMapper::batchSave;
|
|
|
319
|
+ execList.add(new MultipleThreadListParam(function,columnValueList));
|
|
|
320
|
+ Function<List<ColumnValue>,Integer> functionLog=columnValueLogMapper::batchSave;
|
|
|
321
|
+ execList.add(new MultipleThreadListParam(functionLog,columnValueList));
|
|
|
322
|
+ }
|
|
|
323
|
+ if(CollectionUtil.isNotEmpty(execList)){
|
|
|
324
|
+ MultipleThreadWorkUtil.execListFun(execList.toArray(new MultipleThreadListParam[execList.size()]));
|
|
|
325
|
+ }
|
|
|
326
|
+ return success("导入成功");
|
|
|
327
|
+
|
|
|
328
|
+ }
|
|
|
329
|
+ /**
|
|
|
330
|
+ * 获取自动编码
|
|
|
331
|
+ *
|
|
|
332
|
+ * @return
|
|
|
333
|
+ */
|
|
|
334
|
+
|
|
|
335
|
+ public String generateCaseNum() {
|
|
|
336
|
+ // 自动编码格式 zc+yyyyMMdd+001
|
|
|
337
|
+ String currentDay = DateUtils.dateTime();
|
|
|
338
|
+ String caseNum = "zc" + currentDay;
|
|
|
339
|
+
|
|
|
340
|
+
|
|
|
341
|
+ if (null == maxCaseNum) {
|
|
|
342
|
+ maxCaseNum=1;
|
|
|
343
|
+ caseNum = caseNum + "001";
|
|
|
344
|
+ } else {
|
|
|
345
|
+ maxCaseNum=maxCaseNum+1;
|
|
|
346
|
+ caseNum = caseNum + String.format("%03d", maxCaseNum);
|
|
|
347
|
+ }
|
|
|
348
|
+ return caseNum;
|
|
|
349
|
+
|
|
|
350
|
+ }
|
|
|
351
|
+ public void inputChangeToFile(InputStream instream, File file) {
|
|
|
352
|
+ try {
|
|
|
353
|
+ OutputStream outStr = new FileOutputStream(file);
|
|
|
354
|
+ int bytesRead = 0;
|
|
|
355
|
+ byte[] buffer = new byte[8192];
|
|
|
356
|
+ while ((bytesRead = instream.read(buffer, 0, 1024)) != -1) {
|
|
|
357
|
+ outStr.write(buffer, 0, bytesRead);
|
|
|
358
|
+ }
|
|
|
359
|
+ outStr.flush();
|
|
|
360
|
+ outStr.close();
|
|
|
361
|
+ instream.close();
|
|
|
362
|
+ } catch (Exception e) {
|
|
|
363
|
+ e.printStackTrace();
|
|
|
364
|
+ }
|
|
|
365
|
+ }
|
|
|
366
|
+
|
|
|
367
|
+ /**
|
|
|
368
|
+ * 查找文件
|
|
|
369
|
+ *
|
|
|
370
|
+ * @param directory
|
|
|
371
|
+ * @param
|
|
|
372
|
+ * @return
|
|
|
373
|
+ */
|
|
|
374
|
+ public static Map<Long, List<File>> findAndConvertPDF(File directory) {
|
|
|
375
|
+ // caseMap<caseId,Map<fileName,filePath>>
|
|
|
376
|
+ Map<Long, List<File>> caseMap = new HashMap<>();
|
|
|
377
|
+ if (directory.isFile()) {
|
|
|
378
|
+ String path = "";
|
|
|
379
|
+ // 如果传入的参数是一个文件
|
|
|
380
|
+ path = directory.getAbsolutePath();
|
|
|
381
|
+ List<File> fileList = new ArrayList<>();
|
|
|
382
|
+ fileList.add(directory);
|
|
|
383
|
+ caseMap.put(IdWorkerUtil.getId(), fileList);
|
|
|
384
|
+
|
|
|
385
|
+ } else if (directory.isDirectory()) {
|
|
|
386
|
+ searchAndConvertPDF(directory, caseMap, 1, new HashMap<>());
|
|
|
387
|
+ } else {
|
|
|
388
|
+ return null;
|
|
|
389
|
+ }
|
|
|
390
|
+ return caseMap;
|
|
|
391
|
+ }
|
|
|
392
|
+
|
|
|
393
|
+ public static boolean isPDF(File file) {
|
|
|
394
|
+ String extension = FileUtils.getFileExtension(file);
|
|
|
395
|
+ return extension.equalsIgnoreCase("pdf");
|
|
|
396
|
+ }
|
|
|
397
|
+
|
|
|
398
|
+
|
|
|
399
|
+ /**
|
|
|
400
|
+ * 递归查找文件夹
|
|
|
401
|
+ *
|
|
|
402
|
+ * @param directory
|
|
|
403
|
+ * @param caseMap<caseId,List<file>>
|
|
|
404
|
+ * @param i 第几层文件夹
|
|
|
405
|
+ * @param fileMap<filePath,caseId>>
|
|
|
406
|
+ */
|
|
|
407
|
+ public static void searchAndConvertPDF(File directory, Map<Long, List<File>> caseMap, int i, Map<String, Long> fileMap) {
|
|
|
408
|
+ File[] files = directory.listFiles();
|
|
|
409
|
+ // 约定压缩包第二层一个文件夹为一个案件
|
|
|
410
|
+ if (files != null) {
|
|
|
411
|
+ if (i == 2) {
|
|
|
412
|
+ for (File file : files) {
|
|
|
413
|
+ fileMap.put(file.getAbsolutePath(), IdWorkerUtil.getId());
|
|
|
414
|
+ }
|
|
|
415
|
+ }
|
|
|
416
|
+ i++;
|
|
|
417
|
+ for (File file : files) {
|
|
|
418
|
+
|
|
|
419
|
+ if (file.getName().contains("zip") || file.getName().contains("rar")) {
|
|
|
420
|
+ continue;
|
|
|
421
|
+ }
|
|
|
422
|
+ if (file.isFile()) {
|
|
|
423
|
+ for (Map.Entry<String, Long> entry : fileMap.entrySet()) {
|
|
|
424
|
+ // 为同一个案件
|
|
|
425
|
+ if (!file.getAbsolutePath().contains(entry.getKey())) {
|
|
|
426
|
+ continue;
|
|
|
427
|
+ }
|
|
|
428
|
+ List<File> fileList;
|
|
|
429
|
+ if (caseMap.containsKey(entry.getValue())) {
|
|
|
430
|
+ fileList = caseMap.get(entry.getValue());
|
|
|
431
|
+ } else {
|
|
|
432
|
+ fileList = new ArrayList<>();
|
|
|
433
|
+ }
|
|
|
434
|
+ fileList.add(file);
|
|
|
435
|
+ caseMap.put(entry.getValue(), fileList);
|
|
|
436
|
+
|
|
|
437
|
+ }
|
|
|
438
|
+
|
|
|
439
|
+ } else if (file.isDirectory()) {
|
|
|
440
|
+ // 如果是目录,递归查找
|
|
|
441
|
+ searchAndConvertPDF(file, caseMap, i, fileMap);
|
|
|
442
|
+ }
|
|
|
443
|
+ }
|
|
|
444
|
+ }
|
|
|
445
|
+ }
|
|
|
446
|
+
|
|
|
447
|
+
|
|
|
448
|
+ private static int getFileNumPage(String pdfUrl) {
|
|
|
449
|
+ File pdfFile = new File(pdfUrl);
|
|
|
450
|
+ int pageCount = 0;
|
|
|
451
|
+ try (PDDocument document = PDDocument.load(pdfFile)) {
|
|
|
452
|
+ pageCount = document.getNumberOfPages();
|
|
|
453
|
+ } catch (IOException e) {
|
|
|
454
|
+ e.printStackTrace();
|
|
|
455
|
+ }
|
|
|
456
|
+ return pageCount;
|
|
|
457
|
+ }
|
|
|
458
|
+
|
|
|
459
|
+ /**
|
|
|
460
|
+ * 获取模板和正文中替换符的内容
|
|
|
461
|
+ *
|
|
|
462
|
+ * @param a
|
|
|
463
|
+ * @param b
|
|
|
464
|
+ * @return
|
|
|
465
|
+ */
|
|
|
466
|
+ public static List<String> getReplaceList(String a, String b) {
|
|
|
467
|
+ String aTmpe = filterString(a);
|
|
|
468
|
+ String bTmpe = filterString(b);
|
|
|
469
|
+ String regex = "(\\{[^}}]*})";
|
|
|
470
|
+ String[] ptTemplate = aTmpe.replaceAll(regex, "@=").split("@=");
|
|
|
471
|
+ String replace = "";
|
|
|
472
|
+ for (int i = 0; i < ptTemplate.length; i++) {
|
|
|
473
|
+ if (ptTemplate[i] == null || ptTemplate[i].equals(" ")) continue;
|
|
|
474
|
+ if (replace.equals("")) {
|
|
|
475
|
+ replace = bTmpe.replace(ptTemplate[i], "@=");
|
|
|
476
|
+ } else {
|
|
|
477
|
+ replace = replace.replace(ptTemplate[i], "@=");
|
|
|
478
|
+ }
|
|
|
479
|
+ }
|
|
|
480
|
+ List<String> aList = new ArrayList<>();
|
|
|
481
|
+ String[] split = replace.split("@=");
|
|
|
482
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
483
|
+ if (split[i] == "" || split[i].equals("")) continue;
|
|
|
484
|
+ aList.add(split[i]);
|
|
|
485
|
+ }
|
|
|
486
|
+ return aList;
|
|
|
487
|
+ }
|
|
|
488
|
+
|
|
|
489
|
+ // 去掉内容中的换行符
|
|
|
490
|
+ public static String filterString(String str) {
|
|
|
491
|
+ if (str == null || str.equals("")) {
|
|
|
492
|
+ return null;
|
|
|
493
|
+ }
|
|
|
494
|
+ String regEx = "[\\r\\n]";
|
|
|
495
|
+ Pattern p = Pattern.compile(regEx);
|
|
|
496
|
+ Matcher m = p.matcher(str);
|
|
|
497
|
+ return m.replaceAll(" ").trim();
|
|
|
498
|
+ }
|
|
|
499
|
+
|
|
|
500
|
+ // 检索时,转换特殊字符
|
|
|
501
|
+ public static String escapeQueryChars(String s) {
|
|
|
502
|
+ if (StringUtils.isBlank(s)) {
|
|
|
503
|
+ return s;
|
|
|
504
|
+ }
|
|
|
505
|
+ StringBuilder sb = new StringBuilder();
|
|
|
506
|
+ for (int i = 0; i < s.length(); i++) {
|
|
|
507
|
+ char c = s.charAt(i);
|
|
|
508
|
+ // These characters are part of the query syntax and must be escaped
|
|
|
509
|
+ if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')'
|
|
|
510
|
+ || c == ':' || c == '^' || c == '[' || c == ']' || c == '\"'
|
|
|
511
|
+ || c == '{' || c == '}' || c == '~' || c == '*' || c == '?'
|
|
|
512
|
+ || c == '|' || c == '&' || c == ';' || c == '/' || c == '.'
|
|
|
513
|
+ || c == '$' || Character.isWhitespace(c)) {
|
|
|
514
|
+ sb.append('\\');
|
|
|
515
|
+ }
|
|
|
516
|
+ sb.append(c);
|
|
|
517
|
+ }
|
|
|
518
|
+ return sb.toString();
|
|
|
519
|
+ }
|
|
|
520
|
+
|
|
|
521
|
+ /**
|
|
|
522
|
+ * 组装内置字段
|
|
|
523
|
+ *
|
|
|
524
|
+ * @param caseApplication 案件信息
|
|
|
525
|
+ * @param dictDataList 内置字段
|
|
|
526
|
+ * @param fatchMap 抓取字段内容
|
|
|
527
|
+ */
|
|
|
528
|
+ private void buildDefaultColumn(CaseApplication caseApplication, List<SysDictData> dictDataList, Map<String, String> fatchMap,
|
|
|
529
|
+ List<CaseAffiliate> caseAffiliates, Map<String, Long> deptMap, List<SysDept> sysDepts,
|
|
|
530
|
+ Map<String, SysUser> userMap, List<SysUser> addUsers, List<SysUserRole> userRoleList) {
|
|
|
531
|
+ // 组装内置字段
|
|
|
532
|
+ if (CollectionUtil.isEmpty(dictDataList)) {
|
|
|
533
|
+ return;
|
|
|
534
|
+ }
|
|
|
535
|
+ // 被申请人
|
|
|
536
|
+ CaseAffiliate debtorAffiliate = new CaseAffiliate();
|
|
|
537
|
+ debtorAffiliate.setCaseAppliId(caseApplication.getId());
|
|
|
538
|
+ debtorAffiliate.setCaseAppliLogId(caseApplication.getCaseLogId());
|
|
|
539
|
+ // 申请人
|
|
|
540
|
+ CaseAffiliate affiliate = new CaseAffiliate();
|
|
|
541
|
+ affiliate.setCaseAppliLogId(caseApplication.getCaseLogId());
|
|
|
542
|
+ affiliate.setCaseAppliId(caseApplication.getId());
|
|
|
543
|
+ for (SysDictData dictData : dictDataList) {
|
|
|
544
|
+ if (StrUtil.isNotEmpty(dictData.getDictLabel())) {
|
|
|
545
|
+ if (dictData.getDictLabel().contains("被申请人")) {
|
|
|
546
|
+ // 组装被申请人内置自段
|
|
|
547
|
+ buildDebtorColumn(dictData, fatchMap, debtorAffiliate,caseApplication.getId());
|
|
|
548
|
+ } else if (dictData.getDictLabel().contains("申请人") || dictData.getDictLabel().contains("统一社会信用代码")
|
|
|
549
|
+ || dictData.getDictLabel().contains("法定代表人") || dictData.getDictLabel().contains("委托代理人")) {
|
|
|
550
|
+ // 组装申请人内置自段
|
|
|
551
|
+ buildAffilcateColumn(dictData, fatchMap, affiliate, deptMap, sysDepts, userMap, addUsers, userRoleList,caseApplication.getId());
|
|
|
552
|
+ } else if (dictData.getDictLabel().contains("合同编号")) {
|
|
|
553
|
+ // 合同编号
|
|
|
554
|
+ String contractNumber = fatchMap.get("合同编号"+ Constants.PDFSTR + caseApplication.getId());
|
|
|
555
|
+ if (StrUtil.isNotEmpty(contractNumber)) {
|
|
|
556
|
+ // 提取字母和数字
|
|
|
557
|
+ String regx = "[^a-zA-Z0-9]";
|
|
|
558
|
+ String replaceAll = contractNumber.replaceAll(regx, "");
|
|
|
559
|
+ caseApplication.setContractNumber(replaceAll.toUpperCase());
|
|
|
560
|
+ }
|
|
|
561
|
+ } else {
|
|
|
562
|
+ ObjectFieldUtils.setValue(caseApplication, dictData.getDictValue(), fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseApplication.getId()));
|
|
|
563
|
+ }
|
|
|
564
|
+
|
|
|
565
|
+ } else {
|
|
|
566
|
+ ObjectFieldUtils.setValue(caseApplication, dictData.getDictValue(), fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseApplication.getId()));
|
|
|
567
|
+
|
|
|
568
|
+ }
|
|
|
569
|
+
|
|
|
570
|
+ }
|
|
|
571
|
+ if (ObjectUtil.isNotEmpty(affiliate)) {
|
|
|
572
|
+ caseAffiliates.add(affiliate);
|
|
|
573
|
+ }
|
|
|
574
|
+ if (ObjectUtil.isNotEmpty(debtorAffiliate)) {
|
|
|
575
|
+ caseAffiliates.add(debtorAffiliate);
|
|
|
576
|
+ }
|
|
|
577
|
+
|
|
|
578
|
+
|
|
|
579
|
+ }
|
|
|
580
|
+
|
|
|
581
|
+ /**
|
|
|
582
|
+ * 组装申请人内置字段
|
|
|
583
|
+ *
|
|
|
584
|
+ * @param dictData 内置字段
|
|
|
585
|
+ * @param fatchMap 抓取内容
|
|
|
586
|
+ * @param affiliate 案件人员
|
|
|
587
|
+ */
|
|
|
588
|
+ private void buildAffilcateColumn(SysDictData dictData, Map<String, String> fatchMap, CaseAffiliate affiliate,
|
|
|
589
|
+ Map<String, Long> deptMap, List<SysDept> sysDepts,
|
|
|
590
|
+ Map<String, SysUser> userMap, List<SysUser> addUsers, List<SysUserRole> userRoleList,Long caseId) {
|
|
|
591
|
+
|
|
|
592
|
+ affiliate.setIdentityType(1);
|
|
|
593
|
+
|
|
|
594
|
+ // 申请人
|
|
|
595
|
+ switch (dictData.getDictLabel()) {
|
|
|
596
|
+ case "申请人姓名":
|
|
|
597
|
+ affiliate.setName((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)));
|
|
|
598
|
+ if (StrUtil.isNotEmpty(affiliate.getName())) {
|
|
|
599
|
+ // 组装申请机构
|
|
|
600
|
+ // 将组织机构id设为申请人名称
|
|
|
601
|
+ if (deptMap.containsKey(affiliate.getName())) {
|
|
|
602
|
+ affiliate.setApplicationOrganId(String.valueOf(deptMap.get(affiliate.getName())));
|
|
|
603
|
+ affiliate.setApplicationOrganName(affiliate.getName());
|
|
|
604
|
+ } else {
|
|
|
605
|
+ // 如果不存在则新增
|
|
|
606
|
+ SysDept dept = new SysDept();
|
|
|
607
|
+ dept.setParentId(0L);
|
|
|
608
|
+ dept.setDeptName(affiliate.getName());
|
|
|
609
|
+ dept.setAncestors("0");
|
|
|
610
|
+ dept.setOrderNum(1);
|
|
|
611
|
+ dept.setStatus("0");
|
|
|
612
|
+ dept.setDelFlag("0");
|
|
|
613
|
+ dept.setCreateBy(getUsername());
|
|
|
614
|
+ dept.setUpdateBy(getUsername());
|
|
|
615
|
+ dept.setDeptId(Long.valueOf(IdWorkerUtil.getId()));
|
|
|
616
|
+ sysDepts.add(dept);
|
|
|
617
|
+ deptMap.put(dept.getDeptName(), dept.getDeptId());
|
|
|
618
|
+ affiliate.setApplicationOrganId(String.valueOf(dept.getDeptId()));
|
|
|
619
|
+ affiliate.setApplicationOrganName(affiliate.getName());
|
|
|
620
|
+
|
|
|
621
|
+ }
|
|
|
622
|
+ }
|
|
|
623
|
+ break;
|
|
|
624
|
+ case "统一社会信用代码":
|
|
|
625
|
+ affiliate.setIdentityNum((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)));
|
|
|
626
|
+ break;
|
|
|
627
|
+ case "法定代表人":
|
|
|
628
|
+ affiliate.setCompLegalPerson(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
629
|
+ break;
|
|
|
630
|
+ case "法定代表人职位":
|
|
|
631
|
+ affiliate.setCompLegalperPost((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)));
|
|
|
632
|
+ break;
|
|
|
633
|
+ case "申请人住所":
|
|
|
634
|
+ affiliate.setResidenAffili((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)));
|
|
|
635
|
+ break;
|
|
|
636
|
+ case "申请人联系地址":
|
|
|
637
|
+ affiliate.setContactAddress(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
638
|
+ break;
|
|
|
639
|
+ case "委托代理人姓名":
|
|
|
640
|
+ affiliate.setNameAgent(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
641
|
+ break;
|
|
|
642
|
+ case "委托代理人联系电话":
|
|
|
643
|
+ affiliate.setContactTelphoneAgent(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
644
|
+ if (StrUtil.isNotEmpty(affiliate.getContactTelphoneAgent())) {
|
|
|
645
|
+ // 用户已存在
|
|
|
646
|
+ if (userMap.containsKey(affiliate.getContactTelphoneAgent())) {
|
|
|
647
|
+ SysUser agentUser = userMap.get(affiliate.getContactTelphoneAgent());
|
|
|
648
|
+ if (null != agentUser.getDeptId() && String.valueOf(agentUser.getDeptId()).equals(affiliate.getApplicationOrganId())) {
|
|
|
649
|
+ // 同步用户表和案件关联人表的手机号和名称
|
|
|
650
|
+ affiliate.setContactTelphoneAgent(agentUser.getPhonenumber());
|
|
|
651
|
+ affiliate.setNameAgent(agentUser.getNickName());
|
|
|
652
|
+ affiliate.setApplicantAgentUserId(String.valueOf(agentUser.getUserId()));
|
|
|
653
|
+ if (StrUtil.isNotEmpty(agentUser.getIdCard())) {
|
|
|
654
|
+ affiliate.setIdentityNumAgent(agentUser.getIdCard());
|
|
|
655
|
+ } else {
|
|
|
656
|
+ affiliate.setIdentityNumAgent(affiliate.getIdentityNumAgent());
|
|
|
657
|
+ }
|
|
|
658
|
+ List<Long> longList = new ArrayList<>();
|
|
|
659
|
+ // 新增角色为申请人
|
|
|
660
|
+ if (CollectionUtil.isNotEmpty(agentUser.getRoles())) {
|
|
|
661
|
+ longList = agentUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
|
|
662
|
+ if (!longList.contains(roleId)) {
|
|
|
663
|
+ insertAgentUserRole(agentUser, roleId, userRoleList);
|
|
|
664
|
+ }
|
|
|
665
|
+ } else {
|
|
|
666
|
+
|
|
|
667
|
+ insertAgentUserRole(agentUser, roleId, userRoleList);
|
|
|
668
|
+ }
|
|
|
669
|
+
|
|
|
670
|
+ }
|
|
|
671
|
+ } else {
|
|
|
672
|
+ // 用户不存在,新增
|
|
|
673
|
+ SysUser agentUser = new SysUser();
|
|
|
674
|
+ agentUser.setUserId(Long.valueOf(IdWorkerUtil.getId()));
|
|
|
675
|
+ agentUser.setIdCard(affiliate.getIdentityNumAgent());
|
|
|
676
|
+ agentUser.setNickName(affiliate.getNameAgent());
|
|
|
677
|
+ agentUser.setUserName(affiliate.getContactTelphoneAgent());
|
|
|
678
|
+ agentUser.setPhonenumber(affiliate.getContactTelphoneAgent());
|
|
|
679
|
+ agentUser.setPassword(SecurityUtils.encryptPassword("abc123456"));
|
|
|
680
|
+ agentUser.setDeptId(Long.valueOf(affiliate.getApplicationOrganId()));
|
|
|
681
|
+ addUsers.add(agentUser);
|
|
|
682
|
+ userMap.put(agentUser.getPhonenumber(), agentUser);
|
|
|
683
|
+ insertAgentUserRole(agentUser, roleId, userRoleList);
|
|
|
684
|
+
|
|
|
685
|
+ }
|
|
|
686
|
+ }
|
|
|
687
|
+ break;
|
|
|
688
|
+ case "委托代理人电子邮件":
|
|
|
689
|
+ affiliate.setAgentEmail(StrUtil.isNotEmpty(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)) ? fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId).replace("\n", "").replaceAll("\\s", "") : null);
|
|
|
690
|
+
|
|
|
691
|
+ break;
|
|
|
692
|
+ default:
|
|
|
693
|
+ break;
|
|
|
694
|
+ }
|
|
|
695
|
+ }
|
|
|
696
|
+
|
|
|
697
|
+ /**
|
|
|
698
|
+ * 新增角色为申请人
|
|
|
699
|
+ *
|
|
|
700
|
+ * @param agentUser
|
|
|
701
|
+ * @param roleId
|
|
|
702
|
+ */
|
|
|
703
|
+ private void insertAgentUserRole(SysUser agentUser, Long roleId, List<SysUserRole> userRoleList) {
|
|
|
704
|
+
|
|
|
705
|
+ SysUserRole sysUserRole = new SysUserRole();
|
|
|
706
|
+ sysUserRole.setUserId(agentUser.getUserId());
|
|
|
707
|
+ sysUserRole.setRoleId(roleId);
|
|
|
708
|
+ userRoleList.add(sysUserRole);
|
|
|
709
|
+
|
|
|
710
|
+ }
|
|
|
711
|
+
|
|
|
712
|
+ /**
|
|
|
713
|
+ * 组装被申请人内置字段
|
|
|
714
|
+ *
|
|
|
715
|
+ * @param dictData 内置字段
|
|
|
716
|
+ * @param fatchMap 抓取内容
|
|
|
717
|
+ * @param debtorAffiliate 被申请人
|
|
|
718
|
+ */
|
|
|
719
|
+ private void buildDebtorColumn(SysDictData dictData, Map<String, String> fatchMap, CaseAffiliate debtorAffiliate,Long caseId) {
|
|
|
720
|
+
|
|
|
721
|
+ debtorAffiliate.setIdentityType(2);
|
|
|
722
|
+ // 被申请人
|
|
|
723
|
+ switch (dictData.getDictLabel()) {
|
|
|
724
|
+ case "被申请人姓名":
|
|
|
725
|
+ debtorAffiliate.setName(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
726
|
+ break;
|
|
|
727
|
+ case "被申请人身份证号":
|
|
|
728
|
+ String identityNum = fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId);
|
|
|
729
|
+ debtorAffiliate.setIdentityNum(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
730
|
+ // 出生年月日,从身份证抓取
|
|
|
731
|
+ if (StrUtil.isNotEmpty(identityNum)) {
|
|
|
732
|
+ identityNum = identityNum.replace("\n", "");
|
|
|
733
|
+ Map<String, String> identityNumMap = IdCardUtils.getBirAgeSex(identityNum);
|
|
|
734
|
+ String birthday = identityNumMap.get("birthday");
|
|
|
735
|
+ if (StrUtil.isNotEmpty(birthday)) {
|
|
|
736
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
737
|
+ Date birthdayDate = null;
|
|
|
738
|
+ try {
|
|
|
739
|
+ birthdayDate = simpleDateFormat.parse(birthday);
|
|
|
740
|
+ } catch (Exception e) {
|
|
|
741
|
+ e.printStackTrace();
|
|
|
742
|
+ }
|
|
|
743
|
+ debtorAffiliate.setResponBirth(birthdayDate);
|
|
|
744
|
+ }
|
|
|
745
|
+ //从身份证抓取性别
|
|
|
746
|
+ debtorAffiliate.setResponSex(identityNumMap.get("sexCode"));
|
|
|
747
|
+ }
|
|
|
748
|
+
|
|
|
749
|
+ break;
|
|
|
750
|
+ case "被申请人住所":
|
|
|
751
|
+ debtorAffiliate.setResidenAffili(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
752
|
+ break;
|
|
|
753
|
+ case "被申请人联系电话":
|
|
|
754
|
+ debtorAffiliate.setContactTelphone(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId));
|
|
|
755
|
+ break;
|
|
|
756
|
+ case "被申请人电子邮件":
|
|
|
757
|
+ debtorAffiliate.setEmail(StrUtil.isNotEmpty(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)) ? fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId).replace("\n", "").replaceAll("\\s", "") : null);
|
|
|
758
|
+
|
|
|
759
|
+ break;
|
|
|
760
|
+ default:
|
|
|
761
|
+ break;
|
|
|
762
|
+ }
|
|
|
763
|
+
|
|
|
764
|
+ }
|
|
|
765
|
+
|
|
|
766
|
+ /**
|
|
|
767
|
+ * 获取抓取内容
|
|
|
768
|
+ *
|
|
|
769
|
+ * @param fatchRules 抓取规则
|
|
|
770
|
+ */
|
|
|
771
|
+ private void getFatchContentList(File caseFile, Map<String, String> fatchMap, List<FatchRule> fatchRules, Long caseId) {
|
|
|
772
|
+ String fileURL = caseFile.getAbsolutePath();
|
|
|
773
|
+ if (fileURL.endsWith("txt")) {
|
|
|
774
|
+ String readerFile = ReadFileUtils.readerTxtFile(fileURL);
|
|
|
775
|
+ OCRUtils.fatchRuleGetContent(readerFile, fatchRules, fatchMap, caseId);
|
|
|
776
|
+ } else if (fileURL.endsWith("doc") || fileURL.endsWith("docx")) {
|
|
|
777
|
+ // doc,docx,text识别内容
|
|
|
778
|
+ String readerFile = null;
|
|
|
779
|
+ try {
|
|
|
780
|
+ readerFile = ReadFileUtils.readWord(fileURL);
|
|
|
781
|
+ } catch (Exception e) {
|
|
|
782
|
+ e.printStackTrace();
|
|
|
783
|
+ }
|
|
|
784
|
+ OCRUtils.fatchRuleGetContent(readerFile, fatchRules, fatchMap, caseId);
|
|
|
785
|
+
|
|
|
786
|
+ } else if (fileURL.endsWith("pdf")) {
|
|
|
787
|
+ //获取文件的页数
|
|
|
788
|
+ int fileNumPage = getFileNumPage(fileURL);
|
|
|
789
|
+ //文件转成base64
|
|
|
790
|
+ String base64 = OCRUtils.pdfConvertBase64(fileURL);
|
|
|
791
|
+ if (base64 == null) {
|
|
|
792
|
+ throw new ServiceException("pdf转base64失败");
|
|
|
793
|
+ // return false;
|
|
|
794
|
+ }
|
|
|
795
|
+ StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
|
|
|
796
|
+ for (int i = 1; i <= fileNumPage; i++) {
|
|
|
797
|
+ //对接腾讯云接口.识别里面的数据
|
|
|
798
|
+ String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules);
|
|
|
799
|
+ ocrText.append(text); // 拼接当前的字符串
|
|
|
800
|
+ // 根据抓取规则截取内容
|
|
|
801
|
+ OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules, fatchMap, caseId);
|
|
|
802
|
+
|
|
|
803
|
+ }
|
|
|
804
|
+ }
|
|
|
805
|
+
|
|
|
806
|
+
|
|
|
807
|
+ }
|
|
|
808
|
+
|
|
|
809
|
+
|
|
|
810
|
+
|
|
|
811
|
+}
|