案件功能优化

This commit is contained in:
18792927508
2023-12-11 09:23:47 +08:00
parent 397950e033
commit 27fa06ab04
6 changed files with 376 additions and 407 deletions
@@ -59,4 +59,11 @@ public interface IDeptIdentifyService {
List<FatchRule> selectColumnandComment();
FatchRule selectColumnbycomment(FatchRule fatchRule);
/**
* 根据模板id查询模板字段列表
* @param templateManage
* @return
*/
List<FatchRule> getTemplateInfoById(TemplateManage templateManage);
}
@@ -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";
@@ -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,11 +1017,21 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
List<CaseAttach> caseAttachList = caseApplication.getCaseAttachList();
if (caseAttachList != null && caseAttachList.size() > 0) {
for (CaseAttach caseAttach : caseAttachList) {
caseAttach.setCaseAppliId(caseApplication.getId());
// 修改案件附件
caseAttachMapper.updateCaseAttach(caseAttach);
// 是否是压缩包导入,压缩包导入则不更新附件
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);
}
}
// 新增日志
@@ -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,113 +3086,107 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
//解压缩上传的压缩包
boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
if (unzipSuccess) {
// 查询抓取规则
// todo 批次需要再上传压缩包时用户填写
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(templateId);
if (CollectionUtil.isEmpty(fatchRuleList)) {
return error("未设置抓取规则");
}
File directory = new File(targetPath);
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());
}
}
if (fatchMap.size() <= 0) {
return error("从压缩包中未抓取到内容,请检查抓取字段配置");
}
// 组装案件内置字段主表内容
CaseApplication caseApplication = new CaseApplication();
caseApplication.setTemplateId(templateId);
//默认案件标的 todo 案件标的是什么,默认写死
caseApplication.setCaseSubjectAmount(new BigDecimal(100000));
// todo 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue
// 抓取规则,0-内置字段,1-自定义字段
Map<Integer, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getIsDefault));
// 自定义字段,组装columnValue表
List<ColumnValue> columnValueList = new ArrayList<>();
if (fatchRuleMap.size() > 0 && fatchRuleMap.containsKey(1)) {
List<FatchRule> columnRules = fatchRuleMap.get(1);
columnRules.forEach(columnRule -> {
ColumnValue columnValue = new ColumnValue();
columnValue.setColumn(columnRule.getColumn());
columnValue.setName(columnRule.getColumnName());
columnValue.setValue(fatchMap.get(columnRule.getColumnName()));
columnValue.setIsDefault(1);
columnValueList.add(columnValue);
});
}
// 在系统表中查询案件内置字段
SysDictData sysDictData = new SysDictData();
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();
// }
// }
// 设置批号
if(StrUtil.isEmpty(caseApplication.getBatchNumber())){
Integer maxBatchNumber = caseApplicationMapper.selectBatchNumberLike();
if(maxBatchNumber==null){
caseApplication.setBatchNumber("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();
// 上传
String filePath = RuoYiConfig.getUploadPath();
CaseAttach caseAttach = new CaseAttach();
caseAttach.setCaseAppliId(caseApplication.getId());
caseAttach.setAnnexPath(filePath);
if(StrUtil.isNotEmpty(fileUrl)) {
String fileName = fileUrl.replace(filePath, "/profile/upload");
caseAttach.setAnnexName(fileName);
}
// 申请人提供的证据材料
caseAttach.setAnnexType(2);
caseAttachs.add(caseAttach);
}
if (CollectionUtil.isNotEmpty(caseAttachs)) {
// 新增申请人证据材料
caseAttachMapper.batchSave(caseAttachs);
}
return AjaxResult.success("导入成功");
}
} else {
// 没有找到符合条件的文件
return AjaxResult.error("未找到符合条件的文件");
}
} else {
if (!unzipSuccess) {
// 解压失败
return AjaxResult.error("解压失败");
}
return null;
// 查询抓取规则
// todo 批次需要再上传压缩包时用户填写
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(templateId);
if (CollectionUtil.isEmpty(fatchRuleList)) {
return error("未设置抓取规则");
}
File directory = new File(targetPath);
Map<String, String> andConvertPDF = findAndConvertPDF(directory, fatchRuleList);
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()) {
getFatchContent(andConvertPDF, entry.getKey(), fatchMap, entry.getValue());
}
}
if (fatchMap.size() <= 0) {
return error("从压缩包中未抓取到内容,请检查抓取字段配置");
}
// 组装案件内置字段主表内容
CaseApplication caseApplication = new CaseApplication();
caseApplication.setTemplateId(templateId);
//默认案件标的 todo 案件标的是什么,默认写死
caseApplication.setCaseSubjectAmount(new BigDecimal(100000));
// 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue
// 抓取规则,0-内置字段,1-自定义字段
Map<Integer, List<FatchRule>> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getIsDefault));
// 自定义字段,组装columnValue表
List<ColumnValue> columnValueList = new ArrayList<>();
if (fatchRuleMap.size() > 0 && fatchRuleMap.containsKey(1)) {
List<FatchRule> columnRules = fatchRuleMap.get(1);
columnRules.forEach(columnRule -> {
ColumnValue columnValue = new ColumnValue();
columnValue.setColumn(columnRule.getColumn());
columnValue.setName(columnRule.getColumnName());
columnValue.setValue(fatchMap.get(columnRule.getColumnName()));
columnValue.setIsDefault(1);
columnValueList.add(columnValue);
});
}
// 在系统表中查询案件内置字段
SysDictData sysDictData = new SysDictData();
sysDictData.setDictType("case_built_type");
List<SysDictData> dictDataList = dictDataMapper.selectDictDataList(sysDictData);
// 组装内置字段
buildDefaultColumn(caseApplication, dictDataList, fatchMap);
// 设置批号
if (StrUtil.isEmpty(caseApplication.getBatchNumber())) {
Integer maxBatchNumber = caseApplicationMapper.selectBatchNumberLike();
if (maxBatchNumber == null) {
caseApplication.setBatchNumber("1");
} else {
caseApplication.setBatchNumber(maxBatchNumber + 1 + "");
}
}
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)) {
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);
}
}
caseApplication.setCaseAttachList(caseAttachs);
// 案件压缩包导入
caseApplication.setImportFlag(2);
// 新增案件基本信息表
this.insertcaseApplication(caseApplication, columnValueList);
return AjaxResult.success("导入成功");
}
/**
* 组装内置字段
* @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,50 +3474,52 @@ 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);
}
}else if(pdfUrl.endsWith("doc")||pdfUrl.endsWith("docx")){
// doc,docx,text识别内容
String readerFile = null;
try {
readerFile = readWord(pdfUrl);
} catch (Exception e) {
e.printStackTrace();
}
if(StrUtil.isNotEmpty(readerFile)){
OCRUtils.fatchRuleGetContent(readerFile, fatchRules,map);
}
}else if(pdfUrl.endsWith("pdf")){
//获取文件的页数
int fileNumPage = getFileNumPage(pdfUrl);
//文件转成base64
String base64 = OCRUtils.pdfConvertBase64(pdfUrl);
if (base64 == null) {
throw new ServiceException("pdf转base64失败");
// return false;
}
StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
for (int i = 1; i <= fileNumPage; i++) {
//对接腾讯云接口.识别里面的数据
String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules);
ocrText.append(text); // 拼接当前的字符串
if(StrUtil.isNotEmpty(ocrText)){
OCRUtils.fatchRuleGetContent(ocrText.toString(), 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;
}
return true;
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(fileURL);
} catch (Exception e) {
e.printStackTrace();
}
OCRUtils.fatchRuleGetContent(readerFile, fatchRules, map);
} else if (fileURL.endsWith("pdf")) {
//获取文件的页数
int fileNumPage = getFileNumPage(fileURL);
//文件转成base64
String base64 = OCRUtils.pdfConvertBase64(fileURL);
if (base64 == null) {
throw new ServiceException("pdf转base64失败");
// return false;
}
StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
for (int i = 1; i <= fileNumPage; i++) {
//对接腾讯云接口.识别里面的数据
String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules);
ocrText.append(text); // 拼接当前的字符串
// 根据抓取规则截取内容
OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules, map);
}
}
}
/**
@@ -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) {