案件压缩包导入

This commit is contained in:
18792927508
2023-12-07 15:07:51 +08:00
parent 6d720c5757
commit a525fd6a16
5 changed files with 145 additions and 132 deletions
@@ -15,7 +15,7 @@ public interface FatchRuleMapper {
/**
* 根据批次查询
*/
List<FatchRule> listByTemplateId(@Param("templateId")String templateId);
List<FatchRule> listByTemplateId(@Param("templateId")Long templateId);
List<FatchRule> selectFatchRuleList(FatchRule fatchRule);
@@ -14,6 +14,7 @@ import com.documents4j.job.LocalConverter;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.CaseApplicationConstants;
@@ -37,7 +38,6 @@ import com.ruoyi.system.mapper.SysUserRoleMapper;
import com.ruoyi.wisdomarbitrate.domain.vo.ColumnValue;
import com.ruoyi.wisdomarbitrate.domain.vo.ReservedConferenceVO;
import com.ruoyi.wisdomarbitrate.domain.vo.ToDoCount;
import com.ruoyi.wisdomarbitrate.utils.CaseLogUtils;
import com.ruoyi.wisdomarbitrate.domain.*;
import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO;
import com.ruoyi.wisdomarbitrate.mapper.*;
@@ -46,41 +46,33 @@ import com.ruoyi.wisdomarbitrate.utils.OCRUtils;
import com.ruoyi.wisdomarbitrate.utils.SignAward;
import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
import com.tencentyun.TLSSigAPIv2;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.poi.xwpf.usermodel.Document;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;
import static com.ruoyi.common.utils.PageUtils.startPage;
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
@@ -253,6 +245,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
@Override
public ToDoCount selectToDoCount() {
@@ -398,9 +391,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
if (file.isEmpty()) {
return AjaxResult.error("请选择要上传的文件");
}
// todo 服务器路径需要改
String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
// String targetPath = "D:/";
String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
File zipFile = null;
InputStream ins = null;
try {
@@ -416,10 +408,9 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
//得到解压缩的所有文件
String zipName = file.getOriginalFilename();
String subzipName = zipName.substring(0, zipName.indexOf(".zip"));
// String zipPath = "F:\\testZip\\uploadPath\\upload\\upload1\\unzipFile\\"+subzipName;
// todo 服务器路径需要改
// todo
String zipPath = "/home/ruoyi/uploadPath/upload/unzipFile/" + subzipName;
// String zipPath = "D:/" + subzipName;
// String zipPath = "D:/home/ruoyi/uploadPath/upload/unzipFile/" + subzipName;
File dirUnzipPath = new File(zipPath);
List<File> allFiles = new ArrayList<>();
@@ -511,9 +502,9 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
String year = Integer.toString(now.getYear());
String month = String.format("%02d", now.getMonthValue());
String day = String.format("%02d", now.getDayOfMonth());
// // todo 服务器路径需要改
// todo
String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
// String saveFolderPath = "D:/" + year + "/" + month + "/" + day;
// String saveFolderPath = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
String fileName = UUID.randomUUID().toString().replace("-", "") + "_" + substrfile;
String resultFilePath = saveFolderPath + "/" + fileName;
try {
@@ -3003,17 +2994,17 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
return AjaxResult.error("请选择要上传的文件");
}
UUID uuid = UUID.randomUUID();
// todo 服务器路径需要改
String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile/"+uuid+ "/";
// String targetPath = "D:/zip";
// todo
String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile/" + uuid + "/";
// String targetPath = "D:/home/ruoyi/uploadPath/upload/unzipFile/"+uuid+ "/";
File zipFile = null;
InputStream ins = null;
try {
ins = file.getInputStream();
//上传的压缩包保存的路径
// todo 服务器路径需要改
// todo
String savePath = "/home/ruoyi/uploadPath/upload/zipFile/";
// String savePath = "D:/zip/";
// String savePath = "D:/home/ruoyi/uploadPath/upload/zipFile/";
String saveName = uuid + "_" + file.getOriginalFilename();
zipFile = new File(savePath + saveName);
inputChangeToFile(ins, zipFile);
@@ -3025,34 +3016,39 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
if (unzipSuccess) {
// 查询抓取规则
// todo 批次需要再上传压缩包时用户填写
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId("9");
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(17L);
if (CollectionUtil.isEmpty(fatchRuleList)) {
return error("未设置抓取规则");
}
File directory = new File(targetPath);
Map<String,String> andConvertPDF = findAndConvertPDF(directory,fatchRuleList);
Map<String, String> andConvertPDF = findAndConvertPDF(directory, fatchRuleList);
if (andConvertPDF != null && andConvertPDF.size() > 0) {
Map<String,String> fatchMap = new HashMap<>();
if(CollectionUtil.isNotEmpty(fatchRuleList)){
Map<String, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getFileName));
// 根据抓取规则循环抓取
for (Map.Entry<String, List<FatchRule>> entry : fatchRuleMap.entrySet()) {
OCRAndBuildInfo(andConvertPDF,entry.getKey(),fatchMap,entry.getValue());
}
Map<String, String> fatchMap = new HashMap<>();
if (CollectionUtil.isNotEmpty(fatchRuleList)) {
Map<String, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getFileName));
// 根据抓取规则循环抓取
for (Map.Entry<String, List<FatchRule>> entry : fatchRuleMap.entrySet()) {
OCRAndBuildInfo(andConvertPDF, entry.getKey(), fatchMap, entry.getValue());
}
if (fatchMap.size()>0){
}
if (fatchMap.size() <= 0) {
return error("从压缩包中未抓取到内容,请检查抓取字段配置");
}
if (fatchMap.size() > 0) {
// todo 从压缩包中识别各字段填充到数据库
//调用新增案件的接口
CaseApplication caseApplication = new CaseApplication();
//默认案件标的 todo 案件标的是什么
caseApplication.setCaseSubjectAmount(new BigDecimal(1));
// todo 这些以后要去掉,不在案件基本信息表维护,现在往基本信息表设置字段是因为修改以及查询详情的时候页面中字段是固定的,以后也要动态维护字段
//调用新增案件的接口
CaseApplication caseApplication = new CaseApplication();
//默认案件标的 todo 案件标的是什么
caseApplication.setCaseSubjectAmount(new BigDecimal(1));
// todo 这些以后要去掉,不在案件基本信息表维护,现在往基本信息表设置字段是因为修改以及查询详情的时候页面中字段是固定的,以后也要动态维护字段
// 仲裁请求
caseApplication.setArbitratClaims(fatchMap.get("arbitrationClaims"));
// 事实和理由
caseApplication.setFacts(fatchMap.get("factsAndReason"));
// 合同编号
String contractNumber = fatchMap.get("contractNumber");
if(StrUtil.isNotEmpty(contractNumber)) {
if (StrUtil.isNotEmpty(contractNumber)) {
// 提取字母和数字
String regx = "[^a-zA-Z0-9]";
String replaceAll = contractNumber.replaceAll(regx, "");
@@ -3063,7 +3059,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
String lonStartDate = fatchMap.get("lonStartDate:");
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy年MM月dd日");
if(StrUtil.isNotEmpty(lonStartDate)) {
if (StrUtil.isNotEmpty(lonStartDate)) {
try {
caseApplication.setLoanStartDate(sdf.parse(lonStartDate));
} catch (ParseException e) {
@@ -3138,19 +3134,19 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
// caseApplication.setOutstandingMoney(mediationAgreementList.get(2));
// }
// }
// 合同甲方(贷款人)
caseApplication.setPartyA(fatchMap.get("partyA"));
List<CaseAffiliate> caseAffiliates = new ArrayList<>();
CaseAffiliate caseAffiliate = new CaseAffiliate();
caseAffiliate.setIdentityType(1);
// 申请人
caseAffiliate.setName(fatchMap.get("applicantName"));
// 统一社会信用代码
caseAffiliate.setIdentityNum(fatchMap.get("creditCode"));
// 法定代表人
caseAffiliate.setCompLegalPerson(fatchMap.get("legalRepresentative"));
// 申请人联系电话
caseAffiliate.setContactTelphone(fatchMap.get("applicantPhone"));
// 合同甲方(贷款人)
caseApplication.setPartyA(fatchMap.get("partyA"));
List<CaseAffiliate> caseAffiliates = new ArrayList<>();
CaseAffiliate caseAffiliate = new CaseAffiliate();
caseAffiliate.setIdentityType(1);
// 申请人
caseAffiliate.setName(fatchMap.get("applicantName"));
// 统一社会信用代码
caseAffiliate.setIdentityNum(fatchMap.get("creditCode"));
// 法定代表人
caseAffiliate.setCompLegalPerson(fatchMap.get("legalRepresentative"));
// 申请人联系电话
caseAffiliate.setContactTelphone(fatchMap.get("applicantPhone"));
// 申请人住所
caseAffiliate.setResidenAffili(fatchMap.get("applicantHome"));
// 申请人联系地址
@@ -3163,30 +3159,30 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
// caseAffiliate.setAppliAgentTitle(map.get("职务").get(1));
// }
// }
// 委托代理人
caseAffiliate.setNameAgent(fatchMap.get("agentName"));
// 委托代理人联系电话
caseAffiliate.setContactTelphoneAgent(fatchMap.get("agentPhone"));
// 委托代理人
caseAffiliate.setNameAgent(fatchMap.get("agentName"));
// 委托代理人联系电话
caseAffiliate.setContactTelphoneAgent(fatchMap.get("agentPhone"));
// 代理人电子邮件
caseAffiliate.setAgentEmail(fatchMap.get("agentEmail").replaceAll("\\s", ""));
// 代理人电子邮件
caseAffiliate.setAgentEmail(StrUtil.isNotEmpty(fatchMap.get("agentEmail")) ? fatchMap.get("agentEmail").replaceAll("\\s", "") : null);
//设置默认代理人的身份证号码,暂时写死 要不然新增方法报错
// caseAffiliate.setIdentityNumAgent("610423199603171716");
caseAffiliates.add(caseAffiliate);
// 被申请人信息
CaseAffiliate respondentAffiliate = new CaseAffiliate();
//设置默认代理人的身份证号码,暂时写死 要不然新增方法报错
// caseAffiliate.setIdentityNumAgent("610423199603171716");
caseAffiliates.add(caseAffiliate);
// 被申请人信息
CaseAffiliate respondentAffiliate = new CaseAffiliate();
respondentAffiliate.setIdentityType(2);
// 被申请人名称
respondentAffiliate.setName(fatchMap.get("respondentName"));
// 被申请人身份证
String identityNum = fatchMap.get("respondentCard");
// 被申请人身份证
String identityNum = fatchMap.get("respondentCard");
// 出生年月日,从身份证抓取
if(StrUtil.isNotEmpty(identityNum)) {
if (StrUtil.isNotEmpty(identityNum)) {
Map<String, String> identityNumMap = getBirAgeSex(identityNum);
String birthday = identityNumMap.get("birthday");
if(StrUtil.isNotEmpty(birthday)) {
if (StrUtil.isNotEmpty(birthday)) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date birthdayDate = null;
try {
@@ -3198,11 +3194,11 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
respondentAffiliate.setResponBirth(birthdayDate);
}
//从身份证抓取性别
fatchMap.put("resSex",identityNumMap.get("sexCode"));
fatchMap.put("resSex", identityNumMap.get("sexCode"));
respondentAffiliate.setResponSex(identityNumMap.get("sexCode"));
}
respondentAffiliate.setIdentityNum(identityNum);
// 被申请人电子邮件
// 被申请人电子邮件
// if(map.get("乙方确认有效的电子信箱地址为").size()>1) {
// if(map.get("乙方确认有效的电子信箱地址为").get(0).contains("/")) {
// respondentAffiliate.setEmail(map.get("乙方确认有效的电子信箱地址为").get(1).replaceAll("\\s", ""));
@@ -3211,40 +3207,40 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
// }
// }
// 被申请人电子邮件
respondentAffiliate.setEmail(fatchMap.get("respondentEmail").replaceAll("\\s", ""));
respondentAffiliate.setEmail(StrUtil.isNotEmpty(fatchMap.get("respondentEmail")) ? fatchMap.get("respondentEmail").replaceAll("\\s", "") : null);
// 被申请人联系电话
respondentAffiliate.setContactTelphone(fatchMap.get("respondentPhone"));
// 被申请人住所
respondentAffiliate.setResidenAffili(fatchMap.get("respondentHome"));
caseAffiliates.add(respondentAffiliate);
caseApplication.setCaseAffiliates(caseAffiliates);
// 新增案件基本信息表
this.insertcaseApplication(caseApplication,fatchMap);
if (null != caseApplication.getId()) {
List<CaseAttach> caseAttachs=new ArrayList<>();
for (Map.Entry<String, String> entry : andConvertPDF.entrySet()) {
if(entry.getValue().contains("证据材料")||entry.getValue().contains("申请书")||entry.getValue().contains("调解协议")||entry.getValue().contains("情况说明")){
String pdfUrl = entry.getValue();
File file1 = new File(pdfUrl);
CaseAttach caseAttach = new CaseAttach();
caseAttach.setCaseAppliId(caseApplication.getId());
caseAttach.setAnnexPath(file1.getPath());
caseAttach.setAnnexName(file1.getName());
// 申请人提供的证据材料
caseAttach.setAnnexType(2);
caseAttachs.add(caseAttach);
}
caseAffiliates.add(respondentAffiliate);
caseApplication.setCaseAffiliates(caseAffiliates);
// 新增案件基本信息表
this.insertcaseApplication(caseApplication, fatchMap);
if (null != caseApplication.getId()) {
List<CaseAttach> caseAttachs = new ArrayList<>();
for (Map.Entry<String, String> entry : andConvertPDF.entrySet()) {
if (entry.getValue().contains("证据材料") || entry.getValue().contains("申请书") || entry.getValue().contains("调解协议") || entry.getValue().contains("情况说明")) {
String pdfUrl = entry.getValue();
File file1 = new File(pdfUrl);
CaseAttach caseAttach = new CaseAttach();
caseAttach.setCaseAppliId(caseApplication.getId());
caseAttach.setAnnexPath(file1.getPath());
caseAttach.setAnnexName(file1.getName());
// 申请人提供的证据材料
caseAttach.setAnnexType(2);
caseAttachs.add(caseAttach);
}
if(CollectionUtil.isNotEmpty(caseAttachs)) {
// 新增申请人证据材料
caseAttachMapper.batchSave(caseAttachs);
}
return AjaxResult.success("导入成功");
}
}else{
return AjaxResult.error("文件识别内容失败,请检查");
if (CollectionUtil.isNotEmpty(caseAttachs)) {
// 新增申请人证据材料
caseAttachMapper.batchSave(caseAttachs);
}
return AjaxResult.success("导入成功");
}
} else {
return AjaxResult.error("文件识别内容失败,请检查");
}
} else {
// 没有找到符合条件的文件
@@ -3298,9 +3294,9 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
// return false;
}
StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
for (int i = 0; i < fileNumPage; i++) {
for (int i = 1; i <= fileNumPage; i++) {
//对接腾讯云接口.识别里面的数据
String text = OCRUtils.pdfIdentifyText(base64, i + 1, fatchRules);
String text = OCRUtils.pdfIdentifyText(base64, i , fatchRules);
ocrText.append(text); // 拼接当前的字符串
}
if(StrUtil.isNotEmpty(ocrText)){
@@ -3377,10 +3373,13 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
// 如果文件名包含"仲裁申请书"且是PDF格式,直接返回路径
path = directory.getAbsolutePath();
} else {
// 如果不是PDF格式,进行转换成PDF并返回路径
String pdfPath = convertToPDF(directory);
if (pdfPath != null) {
path = pdfPath;
String extension = getFileExtension(directory);
if( extension.contains("doc")|| extension.contains("docx")) {
// 如果不是PDF格式,进行转换成PDF并返回路径
String pdfPath = convertToPDF(directory);
if (pdfPath != null) {
path = pdfPath;
}
}
}
// 如果文件名包含"仲裁申请书"且是PDF格式,直接返回路径
@@ -3432,7 +3431,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
pdfPathMap.put(file.getName(),file.getAbsolutePath());
} else {
// 如果不是PDF格式,进行转换成PDF并添加转换后的路径到列表中
String pdfPath = convertToPDF(file);
String pdfPath = convertToPDF(file);
if (pdfPath != null) {
// 如果是PDF格式,直接添加到列表中
pdfPathMap.put(file.getName(),pdfPath);
@@ -3450,19 +3449,23 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
private static String convertToPDF(File file) {
String wordFilePath = file.getAbsolutePath();
//String pdfSaveDirectory = "D:\\home\\unzip\\wordToPDF\\";
// todo 服务器路径需要改
// todo
String pdfSaveDirectory = "/home/ruoyi/uploadPath/upload/wordToPDF/";
// String pdfSaveDirectory = "D:/";
// String pdfSaveDirectory = "D:/home/ruoyi/uploadPath/upload/wordToPDF/";
File directory = new File(pdfSaveDirectory);
if (!directory.exists()) {
directory.mkdirs();
}
String name = file.getName();
String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
String pdfFilePath = pdfSaveDirectory + nameWithoutExtension + ".pdf";
File inputWord = new File(wordFilePath);
if(!inputWord.exists()){
throw new ServiceException("文件不存在wordFilePath:"+wordFilePath);
}
File outputFile = new File(pdfFilePath);
try {
InputStream docxInputStream = new FileInputStream(inputWord);
OutputStream outputStream = new FileOutputStream(outputFile);
@@ -3472,7 +3475,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage()+"wordFilePath:"+wordFilePath+"pdfFilePath:"+pdfFilePath);
// e.printStackTrace();
}
return pdfFilePath;
}
@@ -555,12 +555,8 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
public AjaxResult saveFatchRules(TemplateManage templateManage) {
TemplateFatchRule templateFatchRule = new TemplateFatchRule();
templateFatchRule.setTemplateId(templateManage.getId());
List<TemplateFatchRule> templateFatchRulelist = templateFatchRuleMapper.selectTemplateFatchRuleList(templateFatchRule);
if(templateFatchRulelist!=null&&templateFatchRulelist.size()>0){
List<Long> fatchRuleIds = templateFatchRulelist.stream().map(TemplateFatchRule::getFatchRuleId).collect(Collectors.toList());
fatchRuleMapper.deletebatchFatchRule(fatchRuleIds);
templateFatchRuleMapper.deleteTemplateFatchRule(templateManage.getId());
}
templateFatchRuleMapper.deleteTemplateFatchRule(templateManage.getId());
List<FatchRule> fatchRules = templateManage.getFatchRules();
if(fatchRules!=null&&fatchRules.size()>0){
for (FatchRule fatchRule : fatchRules) {
@@ -221,15 +221,20 @@ public class OCRUtils {
// 开始截取字符串 申请人:赵会
// String[] startContentSplit = ocrText.split(fatchRule.getStartContent());
int startFirstIndex = ocrText.indexOf(fatchRule.getStartContent()) + fatchRule.getStartContent().length();
if(startFirstIndex<0){
continue;
}
if (ocrText.length() >= startFirstIndex) {
ocrText = ocrText.substring(startFirstIndex);
}
if (StrUtil.isNotEmpty(fatchRule.getEndContent())) {
int endFirstIndex = ocrText.indexOf(fatchRule.getEndContent()) + fatchRule.getEndContent().length();
if (ocrText.length() >= (endFirstIndex-fatchRule.getEndContent().length())) {
fatchMap.put(fatchRule.getColumn(), ocrText.substring(0, endFirstIndex-fatchRule.getEndContent().length()));
ocrText = ocrText.substring(endFirstIndex-fatchRule.getEndContent().length());
if(ocrText.indexOf(fatchRule.getEndContent())>=0) {
int endFirstIndex = ocrText.indexOf(fatchRule.getEndContent()) + fatchRule.getEndContent().length();
if (ocrText.length() >= (endFirstIndex - fatchRule.getEndContent().length())) {
fatchMap.put(fatchRule.getColumn(), ocrText.substring(0, endFirstIndex - fatchRule.getEndContent().length()));
ocrText = ocrText.substring(endFirstIndex - fatchRule.getEndContent().length());
}
}
}
}