|
|
@@ -49,6 +49,13 @@ import com.tencentyun.TLSSigAPIv2;
|
|
49
|
49
|
|
|
50
|
50
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
51
|
51
|
|
|
|
52
|
+
|
|
|
53
|
+import org.apache.poi.hwpf.extractor.WordExtractor;
|
|
|
54
|
+import org.apache.poi.ooxml.POIXMLDocument;
|
|
|
55
|
+import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
|
|
|
56
|
+import org.apache.poi.openxml4j.opc.OPCPackage;
|
|
|
57
|
+import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
|
|
58
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
52
|
59
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
53
|
60
|
import org.springframework.beans.factory.annotation.Value;
|
|
54
|
61
|
import org.springframework.stereotype.Service;
|
|
|
@@ -1162,11 +1169,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
1162
|
1169
|
maxVersion = 1;
|
|
1163
|
1170
|
}
|
|
1164
|
1171
|
caseApplication.setVersion(maxVersion + 1);
|
|
1165
|
|
- // 将修改提交状态改为未提交
|
|
1166
|
|
- // caseApplication.setUpdateSubmitStatus(UpdateSubmitStatus.UNCOMMITTED.getCode());
|
|
1167
|
|
- // 修改案件表的版本号
|
|
1168
|
|
- // caseApplicationMapper.updateVersionById(caseApplication.getId(),caseApplication.getVersion());
|
|
1169
|
|
-
|
|
1170
|
1172
|
// 异步新增案件日志
|
|
1171
|
1173
|
ThreadPoolUtil.execute(() -> {
|
|
1172
|
1174
|
try {
|
|
|
@@ -2875,6 +2877,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
2875
|
2877
|
* @param userId
|
|
2876
|
2878
|
* @return
|
|
2877
|
2879
|
*/
|
|
|
2880
|
+ @Override
|
|
2878
|
2881
|
public String generateUserSign(String userId) {
|
|
2879
|
2882
|
TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, sdkSecretKey);
|
|
2880
|
2883
|
return tlsSigAPIv2.genUserSig(userId, 60 * 60 * 10);
|
|
|
@@ -3016,7 +3019,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3016
|
3019
|
if (unzipSuccess) {
|
|
3017
|
3020
|
// 查询抓取规则
|
|
3018
|
3021
|
// todo 批次需要再上传压缩包时用户填写
|
|
3019
|
|
- List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(18L);
|
|
|
3022
|
+ List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(templateId);
|
|
3020
|
3023
|
if (CollectionUtil.isEmpty(fatchRuleList)) {
|
|
3021
|
3024
|
return error("未设置抓取规则");
|
|
3022
|
3025
|
}
|
|
|
@@ -3034,14 +3037,13 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3034
|
3037
|
if (fatchMap.size() <= 0) {
|
|
3035
|
3038
|
return error("从压缩包中未抓取到内容,请检查抓取字段配置");
|
|
3036
|
3039
|
}
|
|
3037
|
|
- if (fatchMap.size() > 0) {
|
|
3038
|
3040
|
|
|
3039
|
3041
|
// todo 从压缩包中识别各字段填充到数据库
|
|
3040
|
3042
|
//调用新增案件的接口
|
|
3041
|
3043
|
CaseApplication caseApplication = new CaseApplication();
|
|
3042
|
3044
|
caseApplication.setTemplateId(templateId);
|
|
3043
|
|
- //默认案件标的 todo 案件标的是什么
|
|
3044
|
|
- caseApplication.setCaseSubjectAmount(new BigDecimal(1));
|
|
|
3045
|
+ //默认案件标的 todo 案件标的是什么,默认写死
|
|
|
3046
|
+ caseApplication.setCaseSubjectAmount(new BigDecimal(10000));
|
|
3045
|
3047
|
// todo 这些以后要去掉,不在案件基本信息表维护,现在往基本信息表设置字段是因为修改以及查询详情的时候页面中字段是固定的,以后也要动态维护字段
|
|
3046
|
3048
|
// 仲裁请求
|
|
3047
|
3049
|
caseApplication.setArbitratClaims(fatchMap.get("arbitrationClaims"));
|
|
|
@@ -3152,14 +3154,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3152
|
3154
|
caseAffiliate.setResidenAffili(fatchMap.get("applicantHome"));
|
|
3153
|
3155
|
// 申请人联系地址
|
|
3154
|
3156
|
caseAffiliate.setContactAddress(fatchMap.get("applicantAddress"));
|
|
3155
|
|
-// if(map.get("职务").size()>0) {
|
|
3156
|
3157
|
// // 法定代表人职务
|
|
3157
|
|
-// caseAffiliate.setCompLegalperPost(map.get("职务").get(0));
|
|
3158
|
|
-// if(map.get("职务").size()>1) {
|
|
3159
|
|
-// // 代理人职务
|
|
3160
|
|
-// caseAffiliate.setAppliAgentTitle(map.get("职务").get(1));
|
|
3161
|
|
-// }
|
|
3162
|
|
-// }
|
|
|
3158
|
+ caseAffiliate.setCompLegalperPost(fatchMap.get("compLegalperPost"));
|
|
3163
|
3159
|
// 委托代理人
|
|
3164
|
3160
|
caseAffiliate.setNameAgent(fatchMap.get("agentName"));
|
|
3165
|
3161
|
// 委托代理人联系电话
|
|
|
@@ -3221,7 +3217,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3221
|
3217
|
if (null != caseApplication.getId()) {
|
|
3222
|
3218
|
List<CaseAttach> caseAttachs = new ArrayList<>();
|
|
3223
|
3219
|
for (Map.Entry<String, String> entry : andConvertPDF.entrySet()) {
|
|
3224
|
|
- if (entry.getValue().contains("证据材料") || entry.getValue().contains("申请书") || entry.getValue().contains("调解协议") || entry.getValue().contains("情况说明")) {
|
|
3225
|
3220
|
String pdfUrl = entry.getValue();
|
|
3226
|
3221
|
File file1 = new File(pdfUrl);
|
|
3227
|
3222
|
CaseAttach caseAttach = new CaseAttach();
|
|
|
@@ -3231,7 +3226,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3231
|
3226
|
// 申请人提供的证据材料
|
|
3232
|
3227
|
caseAttach.setAnnexType(2);
|
|
3233
|
3228
|
caseAttachs.add(caseAttach);
|
|
3234
|
|
- }
|
|
|
3229
|
+
|
|
3235
|
3230
|
}
|
|
3236
|
3231
|
if (CollectionUtil.isNotEmpty(caseAttachs)) {
|
|
3237
|
3232
|
// 新增申请人证据材料
|
|
|
@@ -3239,9 +3234,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3239
|
3234
|
}
|
|
3240
|
3235
|
return AjaxResult.success("导入成功");
|
|
3241
|
3236
|
}
|
|
3242
|
|
- } else {
|
|
3243
|
|
- return AjaxResult.error("文件识别内容失败,请检查");
|
|
3244
|
|
- }
|
|
|
3237
|
+
|
|
3245
|
3238
|
|
|
3246
|
3239
|
} else {
|
|
3247
|
3240
|
// 没有找到符合条件的文件
|
|
|
@@ -3282,27 +3275,117 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3282
|
3275
|
}
|
|
3283
|
3276
|
}
|
|
3284
|
3277
|
|
|
|
3278
|
+ public static String readerTxtFile(String filePath){
|
|
|
3279
|
+ BufferedReader br=null;
|
|
|
3280
|
+ StringBuilder result=new StringBuilder();
|
|
|
3281
|
+ try {
|
|
|
3282
|
+ br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)),"GBK"));
|
|
|
3283
|
+ String line=null;
|
|
|
3284
|
+ while ((line=br.readLine())!=null) {
|
|
|
3285
|
+ result.append(line).append("\n");
|
|
|
3286
|
+ }
|
|
|
3287
|
+ } catch (IOException e) {
|
|
|
3288
|
+ e.printStackTrace();
|
|
|
3289
|
+ } finally {
|
|
|
3290
|
+ if (null!=br){
|
|
|
3291
|
+ try {
|
|
|
3292
|
+ br.close();
|
|
|
3293
|
+ } catch (IOException e) {
|
|
|
3294
|
+ e.printStackTrace();
|
|
|
3295
|
+ }
|
|
|
3296
|
+ }
|
|
|
3297
|
+ }
|
|
|
3298
|
+ return result.toString();
|
|
|
3299
|
+ }
|
|
|
3300
|
+ public static String readWord(String filePath) throws Exception{
|
|
|
3301
|
+
|
|
|
3302
|
+ File file = new File(filePath);
|
|
|
3303
|
+ if(file.length()==0) return ""; // 需要操作原因是可能会空文件问题,如果不做处理,在下面读取中会报错
|
|
|
3304
|
+ StringBuffer sb = new StringBuffer();
|
|
|
3305
|
+ String buffer = "";
|
|
|
3306
|
+ try {
|
|
|
3307
|
+ if (filePath.endsWith(".doc")) {
|
|
|
3308
|
+ InputStream is = new FileInputStream(file);
|
|
|
3309
|
+ WordExtractor ex = new WordExtractor(is);
|
|
|
3310
|
+ buffer = ex.getText();
|
|
|
3311
|
+ if(buffer.length() > 0){
|
|
|
3312
|
+ //使用回车换行符分割字符串
|
|
|
3313
|
+ String [] arry = buffer.split("r\\n");
|
|
|
3314
|
+ for (String string : arry) {
|
|
|
3315
|
+ sb.append(string.trim());
|
|
|
3316
|
+ }
|
|
|
3317
|
+ }
|
|
|
3318
|
+ } else if (filePath.endsWith(".docx")) {
|
|
|
3319
|
+ FileInputStream fis = new FileInputStream(file);
|
|
|
3320
|
+ XWPFDocument xdoc = new XWPFDocument(fis);
|
|
|
3321
|
+ XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
|
|
|
3322
|
+ buffer = extractor.getText();
|
|
|
3323
|
+
|
|
|
3324
|
+
|
|
|
3325
|
+
|
|
|
3326
|
+// OPCPackage opcPackage = POIXMLDocument.openPackage(filePath);
|
|
|
3327
|
+// XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
|
|
|
3328
|
+// buffer = extractor.getText();
|
|
|
3329
|
+ if(buffer.length() > 0){
|
|
|
3330
|
+ //使用换行符分割字符串
|
|
|
3331
|
+ String [] arry = buffer.split("\r\n");
|
|
|
3332
|
+ for (String string : arry) {
|
|
|
3333
|
+ sb.append(string.trim());
|
|
|
3334
|
+ }
|
|
|
3335
|
+ }
|
|
|
3336
|
+ } else {
|
|
|
3337
|
+ return null;
|
|
|
3338
|
+ }
|
|
|
3339
|
+ return sb.toString();
|
|
|
3340
|
+ } catch (Exception e) {
|
|
|
3341
|
+ System.out.print("error---->"+filePath);
|
|
|
3342
|
+ e.printStackTrace();
|
|
|
3343
|
+ return null;
|
|
|
3344
|
+ }
|
|
|
3345
|
+ }
|
|
|
3346
|
+
|
|
3285
|
3347
|
private boolean OCRAndBuildInfo( Map<String, String> andConvertPDF,String mapKey, Map<String, String> map, List<FatchRule> fatchRules) {
|
|
3286
|
3348
|
String pdfUrl = andConvertPDF.get(mapKey);
|
|
3287
|
3349
|
|
|
3288
|
3350
|
if(StrUtil.isNotEmpty(pdfUrl)) {
|
|
3289
|
|
- //获取文件的页数
|
|
3290
|
|
- int fileNumPage = getFileNumPage(pdfUrl);
|
|
3291
|
|
- //文件转成base64
|
|
3292
|
|
- String base64 = OCRUtils.pdfConvertBase64(pdfUrl);
|
|
3293
|
|
- if (base64 == null) {
|
|
3294
|
|
- throw new ServiceException("文件转成base64,转码失败pdfUrl:"+pdfUrl);
|
|
3295
|
|
- // return false;
|
|
3296
|
|
- }
|
|
3297
|
|
- StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
|
|
3298
|
|
- for (int i = 1; i <= fileNumPage; i++) {
|
|
3299
|
|
- //对接腾讯云接口.识别里面的数据
|
|
3300
|
|
- String text = OCRUtils.pdfIdentifyText(base64, i , fatchRules);
|
|
3301
|
|
- ocrText.append(text); // 拼接当前的字符串
|
|
3302
|
|
- }
|
|
3303
|
|
- if(StrUtil.isNotEmpty(ocrText)){
|
|
3304
|
|
- OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules,map);
|
|
|
3351
|
+ if(pdfUrl.endsWith("txt")){
|
|
|
3352
|
+ String readerFile = readerTxtFile(pdfUrl);
|
|
|
3353
|
+ if(StrUtil.isNotEmpty(readerFile)){
|
|
|
3354
|
+ OCRUtils.fatchRuleGetContent(readerFile, fatchRules,map);
|
|
|
3355
|
+ }
|
|
|
3356
|
+
|
|
|
3357
|
+ }else if(pdfUrl.endsWith("doc")||pdfUrl.endsWith("docx")){
|
|
|
3358
|
+ // doc,docx,text识别内容
|
|
|
3359
|
+ String readerFile = null;
|
|
|
3360
|
+ try {
|
|
|
3361
|
+ readerFile = readWord(pdfUrl);
|
|
|
3362
|
+ } catch (Exception e) {
|
|
|
3363
|
+ e.printStackTrace();
|
|
|
3364
|
+ }
|
|
|
3365
|
+ if(StrUtil.isNotEmpty(readerFile)){
|
|
|
3366
|
+ OCRUtils.fatchRuleGetContent(readerFile, fatchRules,map);
|
|
|
3367
|
+ }
|
|
|
3368
|
+
|
|
|
3369
|
+ }else if(pdfUrl.endsWith("pdf")){
|
|
|
3370
|
+ //获取文件的页数
|
|
|
3371
|
+ int fileNumPage = getFileNumPage(pdfUrl);
|
|
|
3372
|
+ //文件转成base64
|
|
|
3373
|
+ String base64 = OCRUtils.pdfConvertBase64(pdfUrl);
|
|
|
3374
|
+ if (base64 == null) {
|
|
|
3375
|
+ throw new ServiceException("文件转成base64,转码失败");
|
|
|
3376
|
+ // return false;
|
|
|
3377
|
+ }
|
|
|
3378
|
+ StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
|
|
|
3379
|
+ for (int i = 1; i <= fileNumPage; i++) {
|
|
|
3380
|
+ //对接腾讯云接口.识别里面的数据
|
|
|
3381
|
+ String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules);
|
|
|
3382
|
+ ocrText.append(text); // 拼接当前的字符串
|
|
|
3383
|
+ if(StrUtil.isNotEmpty(ocrText)){
|
|
|
3384
|
+ OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules,map);
|
|
|
3385
|
+ }
|
|
|
3386
|
+ }
|
|
3305
|
3387
|
}
|
|
|
3388
|
+
|
|
3306
|
3389
|
}
|
|
3307
|
3390
|
return true;
|
|
3308
|
3391
|
}
|
|
|
@@ -3367,33 +3450,10 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3367
|
3450
|
Map<String,String> pdfPathMap= new HashMap<>();
|
|
3368
|
3451
|
if (directory.isFile()) {
|
|
3369
|
3452
|
String path = "";
|
|
3370
|
|
- String fileName = "";
|
|
3371
|
3453
|
// 如果传入的参数是一个文件
|
|
3372
|
|
- // if (directory.getName().contains("仲裁申请书")) {
|
|
3373
|
|
- if (isPDF(directory)) {
|
|
3374
|
|
- // 如果文件名包含"仲裁申请书"且是PDF格式,直接返回路径
|
|
3375
|
3454
|
path = directory.getAbsolutePath();
|
|
3376
|
|
- } else {
|
|
3377
|
|
- String extension = getFileExtension(directory);
|
|
3378
|
|
- if( extension.contains("doc")|| extension.contains("docx")) {
|
|
3379
|
|
- // 如果不是PDF格式,进行转换成PDF并返回路径
|
|
3380
|
|
- String pdfPath = convertToPDF(directory);
|
|
3381
|
|
- if (pdfPath != null) {
|
|
3382
|
|
- path = pdfPath;
|
|
3383
|
|
- }
|
|
3384
|
|
- }
|
|
3385
|
|
- }
|
|
3386
|
|
- // 如果文件名包含"仲裁申请书"且是PDF格式,直接返回路径
|
|
3387
|
|
- // 如果是PDF格式,直接添加到列表中
|
|
3388
|
|
-// if(CollectionUtil.isNotEmpty(fatchRuleList)) {
|
|
3389
|
|
-// for (FatchRule fatchRule : fatchRuleList) {
|
|
3390
|
|
-// if(fatchRule.getFileName().contains(directory.getName())){
|
|
3391
|
|
- pdfPathMap.put(directory.getName(), path);
|
|
3392
|
|
-// }
|
|
3393
|
|
-// }
|
|
3394
|
|
-//
|
|
3395
|
|
-// }
|
|
3396
|
|
- // }
|
|
|
3455
|
+ pdfPathMap.put(directory.getName(), path);
|
|
|
3456
|
+
|
|
3397
|
3457
|
} else if (directory.isDirectory()) {
|
|
3398
|
3458
|
searchAndConvertPDF(directory, pdfPathMap);
|
|
3399
|
3459
|
} else {
|
|
|
@@ -3425,21 +3485,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3425
|
3485
|
}
|
|
3426
|
3486
|
if (file.isFile()) {
|
|
3427
|
3487
|
|
|
3428
|
|
- // 如果是文件且文件名包含"仲裁申请书"
|
|
3429
|
|
- // if (file.getName().contains("仲裁申请书")) {
|
|
3430
|
|
- if (isPDF(file)) {
|
|
3431
|
|
- // 如果是PDF格式,直接添加到列表中
|
|
3432
|
|
- pdfPathMap.put(file.getName(),file.getAbsolutePath());
|
|
3433
|
|
- } else {
|
|
3434
|
|
- // 如果不是PDF格式,进行转换成PDF并添加转换后的路径到列表中
|
|
3435
|
|
- String pdfPath = convertToPDF(file);
|
|
3436
|
|
- if (pdfPath != null) {
|
|
3437
|
|
- // 如果是PDF格式,直接添加到列表中
|
|
3438
|
|
- pdfPathMap.put(file.getName(),pdfPath);
|
|
3439
|
|
- }
|
|
3440
|
|
- }
|
|
3441
|
|
-
|
|
3442
|
|
- // }
|
|
|
3488
|
+ pdfPathMap.put(file.getName(),file.getAbsolutePath());
|
|
3443
|
3489
|
} else if (file.isDirectory()) {
|
|
3444
|
3490
|
// 如果是目录,递归查找
|
|
3445
|
3491
|
searchAndConvertPDF(file, pdfPathMap);
|
|
|
@@ -3448,43 +3494,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
3448
|
3494
|
}
|
|
3449
|
3495
|
}
|
|
3450
|
3496
|
|
|
3451
|
|
- private static String convertToPDF(File file) {
|
|
3452
|
|
- String wordFilePath = file.getAbsolutePath();
|
|
3453
|
|
- // todo
|
|
3454
|
|
- String pdfSaveDirectory = "/home/ruoyi/uploadPath/upload/wordToPDF/";
|
|
3455
|
|
-// String pdfSaveDirectory = "D:/home/ruoyi/uploadPath/upload/wordToPDF/";
|
|
3456
|
|
- File directory = new File(pdfSaveDirectory);
|
|
3457
|
|
- if (!directory.exists()) {
|
|
3458
|
|
- directory.mkdirs();
|
|
3459
|
|
- }
|
|
3460
|
|
- String name = file.getName();
|
|
3461
|
|
- String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
|
|
3462
|
|
-
|
|
3463
|
|
- String pdfFilePath = pdfSaveDirectory + nameWithoutExtension + ".pdf";
|
|
3464
|
|
- File inputWord = new File(wordFilePath);
|
|
3465
|
|
- if(!inputWord.exists()){
|
|
3466
|
|
- throw new ServiceException("文件不存在wordFilePath:"+wordFilePath);
|
|
3467
|
|
- }
|
|
3468
|
|
- File outputFile = new File(pdfFilePath);
|
|
3469
|
|
-
|
|
3470
|
|
- try {
|
|
3471
|
|
- LibreOfficeUtil.doc2pdf2(inputWord,outputFile);
|
|
3472
|
|
-
|
|
3473
|
|
-
|
|
3474
|
|
-//
|
|
3475
|
|
-// InputStream docxInputStream = new FileInputStream(inputWord);
|
|
3476
|
|
-// OutputStream outputStream = new FileOutputStream(outputFile);
|
|
3477
|
|
-// IConverter converter = LocalConverter.builder().build();
|
|
3478
|
|
-// converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
|
|
3479
|
|
-// docxInputStream.close();
|
|
3480
|
|
-// outputStream.close();
|
|
3481
|
|
-
|
|
3482
|
|
- } catch (Exception e) {
|
|
3483
|
|
- throw new ServiceException(e.getMessage()+"wordFilePath:"+wordFilePath+"pdfFilePath:"+pdfFilePath);
|
|
3484
|
|
- // e.printStackTrace();
|
|
3485
|
|
- }
|
|
3486
|
|
- return pdfFilePath;
|
|
3487
|
|
- }
|
|
3488
|
3497
|
|
|
3489
|
3498
|
private static int getFileNumPage(String pdfUrl) {
|
|
3490
|
3499
|
File pdfFile = new File(pdfUrl);
|