案件功能优化
This commit is contained in:
+14
-1
@@ -1,4 +1,5 @@
|
||||
package com.ruoyi.web.controller.wisdomarbitrate;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
@@ -219,7 +220,19 @@ public class DeptIdentifyController extends BaseController {
|
||||
return AjaxResult.success(fatchRulesel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据模板id查询模板字段列表
|
||||
* @param templateManage
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getTemplateInfoById")
|
||||
public AjaxResult getTemplateInfoById(@RequestBody TemplateManage templateManage){
|
||||
if(templateManage.getId()==null){
|
||||
return error("参数校验错误");
|
||||
}
|
||||
List<FatchRule> fatchRuleList = deptIdentifyService.getTemplateInfoById(templateManage);
|
||||
return AjaxResult.success(fatchRuleList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -59,4 +59,11 @@ public interface IDeptIdentifyService {
|
||||
List<FatchRule> selectColumnandComment();
|
||||
|
||||
FatchRule selectColumnbycomment(FatchRule fatchRule);
|
||||
|
||||
/**
|
||||
* 根据模板id查询模板字段列表
|
||||
* @param templateManage
|
||||
* @return
|
||||
*/
|
||||
List<FatchRule> getTemplateInfoById(TemplateManage templateManage);
|
||||
}
|
||||
|
||||
+10
-5
@@ -158,10 +158,19 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
||||
return AjaxResult.error("请先指定裁决书模板");
|
||||
}
|
||||
templatePath = templateManages.get(0).getTemOrigPath();
|
||||
if(StrUtil.isEmpty(templatePath)){
|
||||
return AjaxResult.error("未找到该模板");
|
||||
}
|
||||
|
||||
// todo 部署放开
|
||||
if(templatePath!=null){
|
||||
templatePath="/home/ruoyi/" +templatePath;
|
||||
}
|
||||
try {
|
||||
File file = new File(templatePath);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("未找到该模板");
|
||||
}
|
||||
templateName = templateManages.get(0).getFileName();
|
||||
// 查询案件相关表信息
|
||||
CaseAffiliate caseAffiliate = new CaseAffiliate();
|
||||
@@ -199,9 +208,7 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
||||
// 获取模板中的占位符key
|
||||
List<String> bookmarkList = getBookmarkByDocx(templatePath);
|
||||
if (CollectionUtil.isEmpty(bookmarkList)) {
|
||||
// 直接保存模板为裁决书
|
||||
saveArbitorFile(id, templateName, templatePath, caseApplicationById, arbitrateRecordSelect);
|
||||
return AjaxResult.success("生成裁决书成功");
|
||||
return AjaxResult.success("请检查模板是否配置正确,未获取到占位符");
|
||||
}
|
||||
// 遍历书签,给书签赋值
|
||||
replaceBookmark(bookmarkList,datas,valueMap);
|
||||
@@ -231,8 +238,6 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
||||
String month = String.format("%02d", now.getMonthValue());
|
||||
String day = String.format("%02d", now.getDayOfMonth());
|
||||
// todo
|
||||
// String modalFilePath = "/data/arbitrate-document/template/新裁决书模板.docx";
|
||||
// todo
|
||||
String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
|
||||
// String saveFolderPath = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
|
||||
String fileName = UUID.randomUUID().toString().replace("-", "") + ".docx";
|
||||
|
||||
+75
-67
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.wisdomarbitrate.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdcardUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -1016,12 +1017,22 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
}
|
||||
|
||||
List<CaseAttach> caseAttachList = caseApplication.getCaseAttachList();
|
||||
if (caseAttachList != null && caseAttachList.size() > 0) {
|
||||
// 是否是压缩包导入,压缩包导入则不更新附件
|
||||
boolean isZipImport = caseApplication.getImportFlag() == null || caseApplication.getImportFlag() != 2;
|
||||
if (caseAttachList != null && caseAttachList.size() > 0 ) {
|
||||
if(isZipImport) {
|
||||
for (CaseAttach caseAttach : caseAttachList) {
|
||||
caseAttach.setCaseAppliId(caseApplication.getId());
|
||||
// 修改案件附件
|
||||
caseAttachMapper.updateCaseAttach(caseAttach);
|
||||
}
|
||||
}else {
|
||||
// 压缩包导入
|
||||
for (CaseAttach caseAttach : caseAttachList) {
|
||||
caseAttach.setCaseAppliId(caseApplication.getId());
|
||||
}
|
||||
caseAttachMapper.batchSave(caseAttachList);
|
||||
}
|
||||
}
|
||||
// 新增日志
|
||||
insertCaseLog(caseApplication.getId(), CaseApplicationConstants.CASE_APPLICATION, "");
|
||||
@@ -1254,7 +1265,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
agentUser.setNickName(caseAffiliate.getNameAgent());
|
||||
agentUser.setUserName(caseAffiliate.getContactTelphoneAgent());
|
||||
agentUser.setPhonenumber(caseAffiliate.getContactTelphoneAgent());
|
||||
// agentUser.setPassword(SecurityUtils.encryptPassword(Constants.DEFAULT_PASSWORD));
|
||||
agentUser.setPassword(SecurityUtils.encryptPassword("abc123456"));
|
||||
agentUser.setDeptId(Long.valueOf(caseAffiliate.getApplicationOrganId()));
|
||||
int insertUserRow = sysUserMapper.insertUser(agentUser);
|
||||
// 新增角色为申请人
|
||||
@@ -3049,9 +3060,9 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
|
||||
return success(reservedConferenceMapper.deleteByRoomId(roomId));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public AjaxResult uploadCaseZipFile(MultipartFile file,Long templateId) {
|
||||
public AjaxResult uploadCaseZipFile(MultipartFile file, Long templateId) {
|
||||
if (file.isEmpty()) {
|
||||
return AjaxResult.error("请选择要上传的文件");
|
||||
}
|
||||
@@ -3075,7 +3086,10 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
}
|
||||
//解压缩上传的压缩包
|
||||
boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
|
||||
if (unzipSuccess) {
|
||||
if (!unzipSuccess) {
|
||||
// 解压失败
|
||||
return AjaxResult.error("解压失败");
|
||||
}
|
||||
// 查询抓取规则
|
||||
// todo 批次需要再上传压缩包时用户填写
|
||||
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(templateId);
|
||||
@@ -3084,13 +3098,16 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
}
|
||||
File directory = new File(targetPath);
|
||||
Map<String, String> andConvertPDF = findAndConvertPDF(directory, fatchRuleList);
|
||||
if (andConvertPDF != null && andConvertPDF.size() > 0) {
|
||||
if (andConvertPDF == null || andConvertPDF.size() <= 0) {
|
||||
// 解压失败
|
||||
return AjaxResult.error("未获取到文件");
|
||||
}
|
||||
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());
|
||||
getFatchContent(andConvertPDF, entry.getKey(), fatchMap, entry.getValue());
|
||||
}
|
||||
}
|
||||
if (fatchMap.size() <= 0) {
|
||||
@@ -3101,7 +3118,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
caseApplication.setTemplateId(templateId);
|
||||
//默认案件标的 todo 案件标的是什么,默认写死
|
||||
caseApplication.setCaseSubjectAmount(new BigDecimal(100000));
|
||||
// todo 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue
|
||||
// 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue
|
||||
// 抓取规则,0-内置字段,1-自定义字段
|
||||
Map<Integer, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getIsDefault));
|
||||
// 自定义字段,组装columnValue表
|
||||
@@ -3122,66 +3139,54 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
sysDictData.setDictType("case_built_type");
|
||||
List<SysDictData> dictDataList = dictDataMapper.selectDictDataList(sysDictData);
|
||||
// 组装内置字段
|
||||
buildDefaultColumn(caseApplication,dictDataList,fatchMap);
|
||||
// 借款开始日期
|
||||
// String lonStartDate = fatchMap.get("借款开始日期:");
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
// if (StrUtil.isNotEmpty(lonStartDate)) {
|
||||
// try {
|
||||
// caseApplication.setLoanStartDate(sdf.parse(lonStartDate));
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
buildDefaultColumn(caseApplication, dictDataList, fatchMap);
|
||||
// 设置批号
|
||||
if(StrUtil.isEmpty(caseApplication.getBatchNumber())){
|
||||
if (StrUtil.isEmpty(caseApplication.getBatchNumber())) {
|
||||
Integer maxBatchNumber = caseApplicationMapper.selectBatchNumberLike();
|
||||
if(maxBatchNumber==null){
|
||||
if (maxBatchNumber == null) {
|
||||
caseApplication.setBatchNumber("1");
|
||||
}else {
|
||||
caseApplication.setBatchNumber(maxBatchNumber+1+"");
|
||||
} else {
|
||||
caseApplication.setBatchNumber(maxBatchNumber + 1 + "");
|
||||
}
|
||||
}
|
||||
// 新增案件基本信息表
|
||||
this.insertcaseApplication(caseApplication, columnValueList);
|
||||
if (null != caseApplication.getId()) {
|
||||
List<CaseAttach> caseAttachs = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : andConvertPDF.entrySet()) {
|
||||
String fileUrl = entry.getValue();
|
||||
if(StrUtil.isEmpty(fileUrl)){
|
||||
continue;
|
||||
}
|
||||
// 上传
|
||||
String filePath = RuoYiConfig.getUploadPath();
|
||||
|
||||
CaseAttach caseAttach = new CaseAttach();
|
||||
caseAttach.setCaseAppliId(caseApplication.getId());
|
||||
caseAttach.setAnnexPath(filePath);
|
||||
if(StrUtil.isNotEmpty(fileUrl)) {
|
||||
if (StrUtil.isNotEmpty(fileUrl)) {
|
||||
String fileName = fileUrl.replace(filePath, "/profile/upload");
|
||||
caseAttach.setAnnexName(fileName);
|
||||
}
|
||||
// 申请人提供的证据材料
|
||||
caseAttach.setAnnexType(2);
|
||||
caseAttachs.add(caseAttach);
|
||||
if(fileUrl.contains("仲裁申请书")){
|
||||
CaseAttach applyFile = new CaseAttach();
|
||||
BeanUtil.copyProperties(caseAttach,applyFile);
|
||||
applyFile.setAnnexType(1);
|
||||
caseAttachs.add(applyFile);
|
||||
}
|
||||
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(caseAttachs)) {
|
||||
// 新增申请人证据材料
|
||||
caseAttachMapper.batchSave(caseAttachs);
|
||||
}
|
||||
caseApplication.setCaseAttachList(caseAttachs);
|
||||
// 案件压缩包导入
|
||||
caseApplication.setImportFlag(2);
|
||||
// 新增案件基本信息表
|
||||
this.insertcaseApplication(caseApplication, columnValueList);
|
||||
|
||||
return AjaxResult.success("导入成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// 没有找到符合条件的文件
|
||||
return AjaxResult.error("未找到符合条件的文件");
|
||||
}
|
||||
} else {
|
||||
// 解压失败
|
||||
return AjaxResult.error("解压失败");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装内置字段
|
||||
* @param caseApplication 案件信息
|
||||
@@ -3224,12 +3229,13 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
}
|
||||
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(debtorAffiliate)){
|
||||
caseAffiliates.add(debtorAffiliate);
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(affiliate)){
|
||||
caseAffiliates.add(affiliate);
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(debtorAffiliate)){
|
||||
caseAffiliates.add(debtorAffiliate);
|
||||
}
|
||||
|
||||
caseApplication.setCaseAffiliates(caseAffiliates);
|
||||
|
||||
}
|
||||
@@ -3468,33 +3474,36 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean OCRAndBuildInfo( Map<String, String> andConvertPDF,String mapKey, Map<String, String> map, List<FatchRule> fatchRules) {
|
||||
String pdfUrl = andConvertPDF.get(mapKey);
|
||||
|
||||
if(StrUtil.isNotEmpty(pdfUrl)) {
|
||||
if(pdfUrl.endsWith("txt")){
|
||||
String readerFile = readerTxtFile(pdfUrl);
|
||||
if(StrUtil.isNotEmpty(readerFile)){
|
||||
OCRUtils.fatchRuleGetContent(readerFile, fatchRules,map);
|
||||
/**
|
||||
* 获取抓取内容
|
||||
* @param andConvertPDF 文件路径map
|
||||
* @param mapKey 文件名
|
||||
* @param map 抓取内容map
|
||||
* @param fatchRules 抓取规则
|
||||
*/
|
||||
private void getFatchContent(Map<String, String> andConvertPDF, String mapKey, Map<String, String> map, List<FatchRule> fatchRules) {
|
||||
String fileURL = andConvertPDF.get(mapKey);
|
||||
if (StrUtil.isEmpty(fileURL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
}else if(pdfUrl.endsWith("doc")||pdfUrl.endsWith("docx")){
|
||||
if (fileURL.endsWith("txt")) {
|
||||
String readerFile = readerTxtFile(fileURL);
|
||||
OCRUtils.fatchRuleGetContent(readerFile, fatchRules, map);
|
||||
} else if (fileURL.endsWith("doc") || fileURL.endsWith("docx")) {
|
||||
// doc,docx,text识别内容
|
||||
String readerFile = null;
|
||||
try {
|
||||
readerFile = readWord(pdfUrl);
|
||||
readerFile = readWord(fileURL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(StrUtil.isNotEmpty(readerFile)){
|
||||
OCRUtils.fatchRuleGetContent(readerFile, fatchRules,map);
|
||||
}
|
||||
OCRUtils.fatchRuleGetContent(readerFile, fatchRules, map);
|
||||
|
||||
}else if(pdfUrl.endsWith("pdf")){
|
||||
} else if (fileURL.endsWith("pdf")) {
|
||||
//获取文件的页数
|
||||
int fileNumPage = getFileNumPage(pdfUrl);
|
||||
int fileNumPage = getFileNumPage(fileURL);
|
||||
//文件转成base64
|
||||
String base64 = OCRUtils.pdfConvertBase64(pdfUrl);
|
||||
String base64 = OCRUtils.pdfConvertBase64(fileURL);
|
||||
if (base64 == null) {
|
||||
throw new ServiceException("pdf转base64失败");
|
||||
// return false;
|
||||
@@ -3504,14 +3513,13 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
||||
//对接腾讯云接口.识别里面的数据
|
||||
String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules);
|
||||
ocrText.append(text); // 拼接当前的字符串
|
||||
if(StrUtil.isNotEmpty(ocrText)){
|
||||
OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules,map);
|
||||
}
|
||||
// 根据抓取规则截取内容
|
||||
OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules, map);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+39
@@ -1,5 +1,7 @@
|
||||
package com.ruoyi.wisdomarbitrate.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@@ -10,6 +12,7 @@ import com.ruoyi.common.constant.FileTransformation;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.EsignDemoException;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
@@ -17,6 +20,7 @@ import com.ruoyi.common.utils.SealUtil;
|
||||
import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysDictDataMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserPostMapper;
|
||||
import com.ruoyi.wisdomarbitrate.domain.*;
|
||||
@@ -63,6 +67,8 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
|
||||
private TemplateFatchRuleMapper templateFatchRuleMapper;
|
||||
@Autowired
|
||||
private FatchRuleMapper fatchRuleMapper;
|
||||
@Autowired
|
||||
private SysDictDataMapper dictDataMapper;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -603,6 +609,39 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
|
||||
return fatchRulesel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板id查询模板字段列表
|
||||
* @param templateManage
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FatchRule> getTemplateInfoById(TemplateManage templateManage) {
|
||||
FatchRule fatchRule = new FatchRule();
|
||||
fatchRule.setTemplateId(templateManage.getId());
|
||||
List<FatchRule> fatchRuleList = fatchRuleMapper.selectFatchRuleList(fatchRule);
|
||||
if(CollectionUtil.isEmpty(fatchRuleList)){
|
||||
fatchRuleList=new ArrayList<>();
|
||||
}
|
||||
List<String> columnNameList = fatchRuleList.stream().map(FatchRule::getColumnName).collect(Collectors.toList());
|
||||
// 在系统表中查询案件内置字段
|
||||
SysDictData sysDictData = new SysDictData();
|
||||
sysDictData.setDictType("case_built_type");
|
||||
List<SysDictData> dictDataList = dictDataMapper.selectDictDataList(sysDictData);
|
||||
if(CollectionUtil.isNotEmpty(dictDataList)){
|
||||
for (SysDictData dictData : dictDataList) {
|
||||
if(StrUtil.isEmpty(dictData.getDictLabel())||columnNameList.contains(dictData.getDictLabel())){
|
||||
continue;
|
||||
}
|
||||
FatchRule rule=new FatchRule();
|
||||
rule.setColumn(dictData.getDictValue());
|
||||
rule.setColumnName(dictData.getDictLabel());
|
||||
fatchRuleList.add(rule);
|
||||
}
|
||||
}
|
||||
|
||||
return fatchRuleList;
|
||||
}
|
||||
|
||||
private String getFileExtension(String fileName) {
|
||||
int lastDotIndex = fileName.lastIndexOf(".");
|
||||
if (lastDotIndex > 0 && lastDotIndex < fileName.length() - 1) {
|
||||
|
||||
@@ -86,112 +86,8 @@ public class OCRUtils {
|
||||
return respStr.toString().substring(0, lastIndexOf);
|
||||
}
|
||||
return respStr.toString();
|
||||
|
||||
|
||||
//
|
||||
// //解析数据
|
||||
// String s = GeneralAccurateOCRResponse.toJsonString(resp);
|
||||
// // 解析JSON数据
|
||||
// JSONObject jsonObject = new JSONObject(s);
|
||||
// JSONArray structuralList = jsonObject.getJSONArray("TextDetections");
|
||||
// // 遍历StructuralList中的Groups,获取Key对应的AutoName和Value对应的AutoConten
|
||||
// StringBuilder stringBuilder = new StringBuilder(); // 创建一个StringBuilder对象
|
||||
// for (int i = 0; i < structuralList.length(); i++) {
|
||||
// JSONArray groups = structuralList.getJSONObject(i).getJSONArray("Groups");
|
||||
// for (int j = 0; j < groups.length(); j++) {
|
||||
// JSONArray lines = groups.getJSONObject(j).getJSONArray("Lines");
|
||||
// for (int k = 0; k < lines.length(); k++) {
|
||||
// JSONObject line = lines.getJSONObject(k);
|
||||
// JSONObject key = line.getJSONObject("Key");
|
||||
// JSONObject value = line.getJSONObject("Value");
|
||||
// String autoName = key.getString("AutoName");
|
||||
// String autoContent = value.getString("AutoContent");
|
||||
// String text = autoName + Constants.PDFSTR + autoContent;
|
||||
// if (stringBuilder.length() > 0) {
|
||||
// stringBuilder.append(Constants.BR); // 在已有内容的情况下添加逗号分隔符
|
||||
// }
|
||||
// stringBuilder.append(text); // 拼接当前的字符串
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return stringBuilder.toString(); // 获取最终的拼接结果
|
||||
// } catch (TencentCloudSDKException e) {
|
||||
// System.out.println(e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* pdf识别成文字
|
||||
*
|
||||
* @param imageBase64
|
||||
* @param pageNumber
|
||||
* @param type pdf类型
|
||||
* @return
|
||||
*/
|
||||
public static String pdfIdentifyText1(String imageBase64, Integer pageNumber, String type) {
|
||||
try {
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
|
||||
// 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
|
||||
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
|
||||
Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("ocr.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
SmartStructuralOCRV2Request req = new SmartStructuralOCRV2Request();
|
||||
req.setImageBase64(imageBase64);
|
||||
req.setIsPdf(true);
|
||||
req.setPdfPageNumber(pageNumber.longValue());
|
||||
if (type.contains("申请书")) {
|
||||
req.setItemNames(applicantName);
|
||||
} else if (type.contains("调解协议")) {
|
||||
req.setItemNames(accordName);
|
||||
} else if (type.contains("合同")) {
|
||||
req.setItemNames(contractName);
|
||||
} else if (type.contains("授权委托书")) {
|
||||
req.setItemNames(powerAttorneyName);
|
||||
}
|
||||
|
||||
// 返回的resp是一个SmartStructuralOCRV2Response的实例,与请求对象对应
|
||||
SmartStructuralOCRV2Response resp = client.SmartStructuralOCRV2(req);
|
||||
// 输出json格式的字符串回包
|
||||
System.out.println(SmartStructuralOCRV2Response.toJsonString(resp));
|
||||
//解析数据
|
||||
String s = SmartStructuralOCRV2Response.toJsonString(resp);
|
||||
// 解析JSON数据
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
JSONArray structuralList = jsonObject.getJSONArray("StructuralList");
|
||||
// 遍历StructuralList中的Groups,获取Key对应的AutoName和Value对应的AutoConten
|
||||
StringBuilder stringBuilder = new StringBuilder(); // 创建一个StringBuilder对象
|
||||
for (int i = 0; i < structuralList.length(); i++) {
|
||||
JSONArray groups = structuralList.getJSONObject(i).getJSONArray("Groups");
|
||||
for (int j = 0; j < groups.length(); j++) {
|
||||
JSONArray lines = groups.getJSONObject(j).getJSONArray("Lines");
|
||||
for (int k = 0; k < lines.length(); k++) {
|
||||
JSONObject line = lines.getJSONObject(k);
|
||||
JSONObject key = line.getJSONObject("Key");
|
||||
JSONObject value = line.getJSONObject("Value");
|
||||
String autoName = key.getString("AutoName");
|
||||
String autoContent = value.getString("AutoContent");
|
||||
String text = autoName + Constants.PDFSTR + autoContent;
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(Constants.BR); // 在已有内容的情况下添加逗号分隔符
|
||||
}
|
||||
stringBuilder.append(text); // 拼接当前的字符串
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString(); // 获取最终的拼接结果
|
||||
} catch (TencentCloudSDKException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String pdfConvertBase64(String pathUrl) {
|
||||
try {
|
||||
@@ -216,52 +112,24 @@ public class OCRUtils {
|
||||
* @return
|
||||
*/
|
||||
public static void fatchRuleGetContent(String ocrText, List<FatchRule> fatchRules, Map<String, String> fatchMap) {
|
||||
String text = ocrText;
|
||||
if (CollectionUtil.isNotEmpty(fatchRules)) {
|
||||
|
||||
if (StrUtil.isEmpty(ocrText) || CollectionUtil.isEmpty(fatchRules)) {
|
||||
return;
|
||||
}
|
||||
for (FatchRule fatchRule : fatchRules) {
|
||||
// 从后往前抓取
|
||||
if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) {
|
||||
String reverseText = StrUtil.reverse(ocrText);
|
||||
if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
|
||||
} else if(StrUtil.isEmpty(fatchRule.getStartContent())&&StrUtil.isNotEmpty(fatchRule.getEndContent())) {
|
||||
// 开始字段为空,结束字段不为空
|
||||
String endReverseText = StrUtil.reverse(fatchRule.getEndContent());
|
||||
int endContIndex = StrUtil.ordinalIndexOf(reverseText, endReverseText, fatchRule.getEndContentRepeatOrder());
|
||||
if (endContIndex != -1) {
|
||||
String substring = text.substring(0, endContIndex);
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
// }else if(StrUtil.isNotEmpty(fatchRule.getStartContent())&&StrUtil.isEmpty(fatchRule.getEndContent())){
|
||||
// // 开始字段不为空,结束字段为空
|
||||
// // 开始字段为空,结束字段不为空
|
||||
// String startReverseText = StrUtil.reverse(fatchRule.getStartContent());
|
||||
// int startContIndex = StrUtil.ordinalIndexOf(reverseText, startReverseText, fatchRule.getStartContentRepeatOrder());
|
||||
// if (startContIndex != -1) {
|
||||
// String substring = text.substring(0, startContIndex);
|
||||
// fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
|
||||
// }
|
||||
//
|
||||
// }else if(StrUtil.isNotEmpty(fatchRule.getStartContent())&&StrUtil.isNotEmpty(fatchRule.getEndContent())){
|
||||
// String startReverseText = StrUtil.reverse(fatchRule.getStartContent());
|
||||
// String endReverseText = StrUtil.reverse(fatchRule.getEndContent());
|
||||
// int startContIndex = StrUtil.ordinalIndexOf(reverseText, startReverseText, fatchRule.getStartContentRepeatOrder());
|
||||
// if (startContIndex != -1) {
|
||||
// // 结束字段不为空
|
||||
// int endContIndex = StrUtil.ordinalIndexOf(reverseText, endReverseText, fatchRule.getEndContentRepeatOrder());
|
||||
// if (endContIndex != -1 && (startContIndex + fatchRule.getStartContent().length()) <= text.length()) {
|
||||
// String substring = text.substring(startContIndex + fatchRule.getStartContent().length(), endContIndex);
|
||||
// // 去除\n
|
||||
// fatchMap.put(fatchRule.getColumnName(),trimStr(StrUtil.reverse(substring)));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
reverseSubstringText(ocrText, fatchRule, fatchMap);
|
||||
} else {
|
||||
// 开始为空结束为空
|
||||
// 从前往后抓取
|
||||
substringText(ocrText, fatchRule, fatchMap);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void sub1(String text, FatchRule fatchRule, Map<String, String> fatchMap) {
|
||||
if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
|
||||
} else if (StrUtil.isNotEmpty(fatchRule.getStartContent())) {
|
||||
@@ -278,7 +146,7 @@ public class OCRUtils {
|
||||
} else {
|
||||
// 开始不为空结束不为空
|
||||
int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder());
|
||||
if (endContIndex != -1 && (startContIndex + fatchRule.getStartContent().length()) <= text.length()&&(startContIndex + fatchRule.getStartContent().length())<=endContIndex ) {
|
||||
if (endContIndex != -1 && endContIndex <= text.length() && (startContIndex + fatchRule.getStartContent().length()) <= endContIndex) {
|
||||
String substring = text.substring(startContIndex + fatchRule.getStartContent().length(), endContIndex);
|
||||
// 去除\n
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
|
||||
@@ -297,10 +165,47 @@ public class OCRUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正向截取字段
|
||||
*
|
||||
* @param text
|
||||
* @param fatchRule
|
||||
* @param fatchMap
|
||||
*/
|
||||
private static void substringText(String text, FatchRule fatchRule, Map<String, String> fatchMap) {
|
||||
String startContent = fatchRule.getStartContent();
|
||||
String endContent = fatchRule.getEndContent();
|
||||
// 开始为空结束为空
|
||||
if (StrUtil.isEmpty(startContent) && StrUtil.isEmpty(endContent)) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
|
||||
} else if (StrUtil.isNotEmpty(startContent) && StrUtil.isEmpty(endContent)) {
|
||||
// 开始不为空结束为空
|
||||
int startContIndex = StrUtil.ordinalIndexOf(text, startContent, fatchRule.getStartContentRepeatOrder());
|
||||
if (startContIndex != -1 && text.length() >= (startContIndex + startContent.length())) {
|
||||
String substring = text.substring(startContIndex + startContent.length());
|
||||
// 去除\n
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
|
||||
}
|
||||
|
||||
} else if (StrUtil.isEmpty(startContent) && StrUtil.isNotEmpty(endContent)) {
|
||||
// 开始为空结束不为空
|
||||
int endContIndex = StrUtil.ordinalIndexOf(text, endContent, fatchRule.getEndContentRepeatOrder());
|
||||
if (endContIndex != -1) {
|
||||
String substring = text.substring(0, endContIndex);
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
|
||||
}
|
||||
} else if (StrUtil.isNotEmpty(startContent) && StrUtil.isNotEmpty(endContent)) {
|
||||
// 开始结束不为空
|
||||
int startIndexOf = StrUtil.ordinalIndexOf(text, startContent, fatchRule.getStartContentRepeatOrder());
|
||||
int endIndexOf = StrUtil.ordinalIndexOf(text, endContent, fatchRule.getEndContentRepeatOrder());
|
||||
if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + startContent.length()) && text.length() >= endIndexOf) {
|
||||
String substring = text.substring(startIndexOf + startContent.length(), endIndexOf);
|
||||
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,71 +223,63 @@ public class OCRUtils {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String text="和 解 协 议\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"甲方:上海维信荟智金融科技有限公司\n" +
|
||||
"地址:上海市虹口区乍浦路89号办公楼1幢2801室\n" +
|
||||
"电子邮箱【shaoyijie01@vcredit.com】\n" +
|
||||
"\n" +
|
||||
"乙方:【马旭】\n" +
|
||||
"地址:【重庆市城口县蓼子乡长元路109号】\n" +
|
||||
"手机号:【13585580076】\n" +
|
||||
"身份证号:【500229198908244338】\n" +
|
||||
"电子邮箱:【feiwen@vcredit.com】\n" +
|
||||
"\n" +
|
||||
"鉴于:\n" +
|
||||
"乙方于【2023】年【3】月【1】日至【2023】年【4】月【26】日通过甲方旗下平台申请总计【2】笔贷款,本金合计【18000】元。乙方已于2023年4月31日结清上述2笔贷款。2023年10月6日,乙方称其对上述2笔贷款的担保合同、担保咨询服务合同(个人贷款委托担保合同:DD181b16j22010315099-1、担保服务合同:DD18qe30023020066644-1、担保咨询服务合同:DD18qe30023020066644-7)中约定的担保费、担保服务费不知情,向甲方要求退还上述担保费、担保服务费。甲方认为甲乙双方之间的上述合同真实有效,其中明确约定了上述担保费、担保服务费。双方因此产生纠纷。现甲方出于业务考虑,同意乙方履行保密义务的前提下,甲方给予特殊和解方案;乙方确认其充分知晓并理解本《和解协议》(下称“本协议”)中全部条款的实质含义及其相应的法律后果,并基于此种理解,履行相应义务,签署本协议。本协议于签署当日生效,对甲、乙双方具有同等法律拘束力。\n" +
|
||||
"\n" +
|
||||
"一、仲裁条款\n" +
|
||||
"1、为了确保本协议的充分履行,甲乙双方达成一致:将本协议共同提交上海仲裁委员会予以立案确认其效力并作出裁决。由甲方作为仲裁案件申请人,乙方作为仲裁案件的被申请人。双方同意由甲方承担全部仲裁费。仲裁费以上海仲裁委员会实际出具的缴费通知书为准。双方均同意,上海仲裁委员会受理案件后,可通过电话或邮件的方式告知双方案件已受理的情况,无需再发送其他纸质书面的材料。(包括但不限于仲裁通知书、规则、名册、其他程序性文件以及本案仲裁申请书、证据材料等)。本案仲裁申请书、证据材料双方已经于提起仲裁前确认收到。\n" +
|
||||
"\n" +
|
||||
"双方同意本案适用快速程序,确认委托上海仲裁委员会主任指定一名仲裁员成立仲裁庭进行书面审理,并依法根据本协议作出裁决书,事实与理由从简。双方均同意放弃相应的答辩、举证等期限权利。双方同意由仲裁庭决定以其认为合适的方式,从简、从速处理本案。\n" +
|
||||
"\n" +
|
||||
"双方同意上海仲裁委员会通过电子送达方式向双方送达包括裁决书在内的各类仲裁法律文书,裁决书及各类仲裁法律文书发送至双方当事人所确认之电子邮箱的日期即为送达日期。双方确认本协议首部所载电子邮箱、联系地址和联系电话均为有效的送达信息。\n" +
|
||||
"\n" +
|
||||
"二、甲方郑重承诺\n" +
|
||||
"1、甲方是独立线上消费金融服务提供商,合作方均为持牌金融机构。旗下各平台所经营的所有产品均合法合规,不存在任何违法、违规经营情形。\n" +
|
||||
"2、甲方出于业务考虑,在乙方履行保密义务的前提下,给予乙方以下方案:【甲方于签署本协议之日起5日内给予乙方1000元补偿金】。\n" +
|
||||
"\n" +
|
||||
"三、乙方郑重承诺\n" +
|
||||
"1、乙方接受甲方在本协议第二条项下所给予的和解方案,并在【3】个工作日内撤销对甲方及在甲方平台办理贷款涉及的所有资金方、担保方和其他相关方(上述公司的关联公司)的一切投诉,再无其他任何异议或主张,包括但不限于诉讼、信访、投诉、媒体平台举报等任何不利于甲方、资金方、担保方和其他相关方的言行或举动等。\n" +
|
||||
"2、乙方承诺对本协议承担无限期保密义务,任何情况下不得将本协议内容泄露给任意第三方。\n" +
|
||||
"3、若乙方违反上述任一承诺,则构成根本违约,应当退还甲方给予的全部补偿金,并承担违约责任。\n" +
|
||||
"\n" +
|
||||
"四、违约责任\n" +
|
||||
"如果乙方违反本协议第三条项下任一承诺内容,则应当退还甲方给予的全部补偿金【1000】元,并向甲方一次性支付违约金【1000】元,上述金额共计【2000】元。同时,乙方应立即纠正违约行为并采取一切必要手段消除/挽回/弥补甲方因此遭受的损失或影响。\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"甲方(盖章): 乙方(签字):\n" +
|
||||
"\n" +
|
||||
"日期:2023年11月3日 日期:\n" +
|
||||
"\n";
|
||||
String[] split = text.split("日期:");
|
||||
int order=1;
|
||||
String s1 = spiltRtoL(text);
|
||||
String substring = s1.substring(0, StrUtil.ordinalIndexOf(s1, StrUtil.reverse("日期:"), 2) + "日期:".length());
|
||||
/**
|
||||
* 从后往前截取字符串
|
||||
*
|
||||
* @param text
|
||||
* @param fatchRule
|
||||
* @param fatchMap
|
||||
*/
|
||||
public static void reverseSubstringText(String text, FatchRule fatchRule, Map<String, String> fatchMap) {
|
||||
|
||||
if(split.length>0){
|
||||
String s = split[split.length - order];
|
||||
// 反正字符串
|
||||
String reverseText = StrUtil.reverse(text);
|
||||
// 结束截取字段
|
||||
String reverseEndContent = "";
|
||||
// 开始截取字段
|
||||
String reverseStartContent = "";
|
||||
if (StrUtil.isNotEmpty(fatchRule.getEndContent())) {
|
||||
reverseEndContent = StrUtil.reverse(fatchRule.getEndContent());
|
||||
}
|
||||
if (StrUtil.isNotEmpty(fatchRule.getStartContent())) {
|
||||
reverseStartContent = StrUtil.reverse(fatchRule.getStartContent());
|
||||
}
|
||||
// 开始和结束截取都为空
|
||||
if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
|
||||
} else if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) {
|
||||
// 开始为空,结束不为空
|
||||
// 根据截取的序号查找出位置
|
||||
int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder());
|
||||
if (indexOf != -1) {
|
||||
String substring = reverseText.substring(0, indexOf);
|
||||
if (StrUtil.isNotEmpty(substring)) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
|
||||
}
|
||||
}
|
||||
} else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) {
|
||||
// 开始不为空,结束为空
|
||||
int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder());
|
||||
if (indexOf != -1 && (indexOf + reverseStartContent.length() <= text.length())) {
|
||||
String substring = reverseText.substring(indexOf + reverseStartContent.length());
|
||||
if (StrUtil.isNotEmpty(substring)) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
|
||||
}
|
||||
}
|
||||
|
||||
} else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) {
|
||||
// 开始结束都不为空
|
||||
int endIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder());
|
||||
int startIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder());
|
||||
if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + reverseStartContent.length()) && text.length() >= endIndexOf) {
|
||||
String substring = reverseText.substring(startIndexOf + reverseStartContent.length(), endIndexOf);
|
||||
if (StrUtil.isNotEmpty(substring)) {
|
||||
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
|
||||
}
|
||||
public static String spiltRtoL(String s) {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int length = s.length();
|
||||
char[] c = new char[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
c[i] = s.charAt(i);
|
||||
}
|
||||
for (int i = length - 1; i >= 0; i--) {
|
||||
sb.append(c[i]);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user