This commit is contained in:
hejinbo
2023-11-27 17:28:37 +08:00
parent 1a1f87c998
commit 6a0009a3ad
4 changed files with 272 additions and 58 deletions
@@ -40,6 +40,7 @@ import com.ruoyi.wisdomarbitrate.domain.*;
import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO;
import com.ruoyi.wisdomarbitrate.mapper.*;
import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
import com.ruoyi.wisdomarbitrate.utils.OCRUtils;
import com.ruoyi.wisdomarbitrate.utils.SignAward;
import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
import com.tencentyun.TLSSigAPIv2;
@@ -50,6 +51,7 @@ 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;
@@ -980,10 +982,10 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
if (insertRow != 0 && CollectionUtil.isNotEmpty(caseAffiliates)) {
caseAffiliates.forEach(caseAffiliate -> caseAffiliate.setCaseAppliLogId(caseApplication.getId()));
// 插入案件日志人员相关表
if(CollectionUtil.isNotEmpty(caseAttachList)) {
if (CollectionUtil.isNotEmpty(caseAttachList)) {
List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
// 插入日志附件表
if(CollectionUtil.isNotEmpty(filterList)) {
if (CollectionUtil.isNotEmpty(filterList)) {
for (CaseAttach caseAttach : filterList) {
// 查询附件表
CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
@@ -992,7 +994,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
}
} caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
}
caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
}
});
@@ -1098,21 +1101,21 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
List<CaseAttach> caseAttachList = caseApplication.getCaseAttachList();
// 立案申请状态直接修改主表信息
if (caseAttachList != null && caseAttachList.size() > 0
&& caseApplication.getCaseStatus()!=null && caseApplication.getCaseStatus().equals(CaseApplicationConstants.CASE_APPLICATION)) {
List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(filterList)){
// 先删除2的附件在新增
if (caseAttachList != null && caseAttachList.size() > 0
&& caseApplication.getCaseStatus() != null && caseApplication.getCaseStatus().equals(CaseApplicationConstants.CASE_APPLICATION)) {
List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(filterList)) {
// 先删除2的附件在新增
// caseAttachMapper.deleteByCasedIdAndType(caseApplication.getId(),2,0);
// for (CaseAttach caseAttach : filterList) {
// caseAttach.setCaseAppliId(caseApplication.getId());
// caseAttachMapper.save(caseAttach);
// }
for (CaseAttach caseAttach : caseAttachList) {
caseAttach.setCaseAppliId(caseApplication.getId());
caseAttachMapper.updateCaseAttach(caseAttach);
}
for (CaseAttach caseAttach : caseAttachList) {
caseAttach.setCaseAppliId(caseApplication.getId());
caseAttachMapper.updateCaseAttach(caseAttach);
}
}
@@ -1133,23 +1136,23 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
try {
caseApplication.setCaseAppliId(caseApplication.getId());
int insertRow = caseApplicationLogMapper.insert(caseApplication);
if (insertRow != 0 ) {
if( CollectionUtil.isNotEmpty(caseAffiliates)) {
if (insertRow != 0) {
if (CollectionUtil.isNotEmpty(caseAffiliates)) {
caseAffiliates.forEach(caseAffiliate -> caseAffiliate.setCaseAppliLogId(caseApplication.getId()));
// 插入案件日志人员相关表
caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
}
if(CollectionUtil.isNotEmpty(caseAttachList)) {
if (CollectionUtil.isNotEmpty(caseAttachList)) {
List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
// 插入日志附件表
if(CollectionUtil.isNotEmpty(filterList)) {
for (CaseAttach caseAttach : filterList) {
// 查询附件表
CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
attach.setCaseAppliLogId(caseApplication.getId());
caseAttachLogMapper.save(attach);
}
}
if (CollectionUtil.isNotEmpty(filterList)) {
for (CaseAttach caseAttach : filterList) {
// 查询附件表
CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
attach.setCaseAppliLogId(caseApplication.getId());
caseAttachLogMapper.save(attach);
}
}
}
}
@@ -2806,17 +2809,17 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
if (CollectionUtil.isEmpty(reservedConferences)) {
return reservedConferences;
}
Map<Long,String> userIdMap = null;
Map<Long, String> userIdMap = null;
List<Long> userIds = reservedConferences.stream().map(ReservedConference::getUserId).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(userIds)){
if (CollectionUtil.isNotEmpty(userIds)) {
// 根据userids查询用户名
List<SysUser> userList = sysUserMapper.selectUserListByIds(userIds);
if(CollectionUtil.isNotEmpty(userList)){
userIdMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId,SysUser::getUserName));
if (CollectionUtil.isNotEmpty(userList)) {
userIdMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getUserName));
}
}
for (ReservedConference reservedConference : reservedConferences) {
if(null!=reservedConference.getUserId() && null!=userIdMap){
if (null != reservedConference.getUserId() && null != userIdMap) {
reservedConference.setUserName(userIdMap.get(reservedConference.getUserId()));
}
Date startTime = reservedConference.getScheduleStartTime();
@@ -2852,41 +2855,106 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
if (file.isEmpty()) {
return AjaxResult.error("请选择要上传的文件");
}
//String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
UUID uuid = UUID.randomUUID();
String targetPath = "D:\\home\\unzip\\"+uuid+"\\";
String targetPath = "\\home\\ruoyi\\uploadPath\\upload\\unzipFile\\";
//String targetPath = "D:\\home\\unzip\\" + uuid + "\\";
File zipFile = null;
InputStream ins = null;
try {
ins = file.getInputStream();
String savePath = "D:\\develop\\java\\";
String saveName = uuid+file.getOriginalFilename();
zipFile = new File(savePath+saveName);
//上传的压缩包保存的路径
//String savePath = "D:\\develop\\java\\";
String savePath = "\\home\\ruoyi\\uploadPath\\upload\\zipFile\\";
String saveName = uuid + file.getOriginalFilename();
zipFile = new File(savePath + saveName);
inputChangeToFile(ins, zipFile);
} catch (IOException e) {
e.printStackTrace();
}
//解压缩上传的压缩包
boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
if (unzipSuccess ) {
//去掉后缀名,拿到解压后的文件夹路径
String fileName = file.getOriginalFilename();
String nameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."));
boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
if (unzipSuccess) {
File directory = new File(targetPath);
List<String> andConvertPDF = findAndConvertPDF(directory);
if (andConvertPDF != null && andConvertPDF.size() > 0){
// 返回找到的PDF文件路径
return AjaxResult.success(andConvertPDF);
}else {
if (andConvertPDF != null && andConvertPDF.size() > 0) {
//遍历路径
for (String pdfUrl : andConvertPDF) {
//获取文件的页数
int fileNumPage = getFileNumPage(pdfUrl);
StringBuilder stringBuilder = new StringBuilder(); // 创建一个StringBuilder对象
for (int i = 0; i < fileNumPage; i++) {
//对接腾讯云接口.识别里面的数据
//暂时写死
String pdfFilePath = "http://121.40.189.20:9000/API/uploadPath/upload/2023/11/14/ca2ca4697e5449ff9b9d23f95b221f58.pdf";
String text = OCRUtils.pdfIdentifyText(pdfUrl, i + 1);
if (stringBuilder.length() > 0) {
stringBuilder.append(","); // 在已有内容的情况下添加逗号分隔符
}
stringBuilder.append(text); // 拼接当前的字符串
}
// 将字符串按逗号分隔符切割
String[] fields = stringBuilder.toString().split(",");
JSONObject jsonObject = new JSONObject(); // 创建一个空的JSON对象
for (String field : fields) {
// 对于每个字段,再按冒号分隔符拆分出键和值
String[] keyValue = field.split(":");
if (keyValue.length == 2) { // 对于合法的键值对,将其添加到JSON对象中
jsonObject.put(keyValue[0], keyValue[1]);
}
}
//调用新增案件的接口
CaseApplication caseApplication = new CaseApplication();
caseApplication.setApplicationOrganId(jsonObject.getString("统一社会信用代码"));
caseApplication.setCompLegalPerson(jsonObject.getString("法定代表人"));
caseApplication.setResidenAffiliAppli(jsonObject.getString("住所"));
caseApplication.setContactAddressAgent(jsonObject.getString("联系地址"));
caseApplication.setNameAgent(jsonObject.getString("委托代理人"));
caseApplication.setContactTelphoneAgent(jsonObject.getString("联系电话"));
caseApplication.setDebtorName(jsonObject.getString("被申请人"));
caseApplication.setDebtorIdentityNum(jsonObject.getString("居民身份证号码"));
caseApplication.setArbitratClaims(jsonObject.getString("仲裁请求"));
caseApplication.setCaseSubjectAmount(new BigDecimal(1));
List<CaseAffiliate> caseAffiliates = new ArrayList<>();
CaseAffiliate caseAffiliate = new CaseAffiliate();
caseAffiliate.setIdentityType(1);
caseAffiliate.setName(jsonObject.getString("申请人"));
caseAffiliate.setIdentityNum("");
caseAffiliate.setContactTelphone(jsonObject.getString("申请人联系电话"));
caseAffiliates.add(caseAffiliate);
CaseAffiliate caseAffiliate1 = new CaseAffiliate();
caseAffiliate1.setIdentityType(2);
caseAffiliate1.setName(jsonObject.getString("被申请人"));
caseAffiliate1.setIdentityNum("");
caseAffiliate1.setContactTelphone(jsonObject.getString("被申请人联系电话"));
caseAffiliates.add(caseAffiliate1);
caseApplication.setCaseAffiliates(caseAffiliates);
this.insertcaseApplication(caseApplication);
if (null != caseApplication.getId()) {
// 绑定案件与申请书
File file1 = new File(pdfUrl);
CaseAttach caseAttach = new CaseAttach();
caseAttach.setCaseAppliId(caseApplication.getId());
String saveName = "/profile/upload/" + file1.getName();
String savePath = "/home/ruoyi/uploadPath/upload";
caseAttach.setAnnexPath(savePath);
caseAttach.setAnnexName(saveName);
caseAttach.setAnnexType(1);
caseAttachMapper.save(caseAttach);
}
}
return AjaxResult.success("导入成功");
} else {
// 没有找到符合条件的文件
return AjaxResult.error("未找到符合条件的文件");
}
}else {
} else {
// 解压失败
return AjaxResult.error("解压失败");
}
}
public static List<String> findAndConvertPDF(File directory) {
List<String> pdfPaths = new ArrayList<>();
if (directory.isFile()) {
@@ -2903,16 +2971,16 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
path = pdfPath;
}
}
if (path!= null) {
if (path != null) {
pdfPaths.add(path);
}
}
} else if (directory.isDirectory()) {
searchAndConvertPDF(directory, pdfPaths);
}else {
} else {
return null;
}
return pdfPaths;
return pdfPaths;
}
public static boolean isPDF(File file) {
@@ -2929,6 +2997,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
return "";
}
}
public static void searchAndConvertPDF(File directory, List<String> pdfPaths) {
File[] files = directory.listFiles();
if (files != null) {
@@ -2954,34 +3023,44 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
}
}
private static String convertToPDF(File file) {
String wordFilePath = file.getAbsolutePath();
String pdfSaveDirectory ="D:\\home\\unzip\\wordToPDF\\";
// String pdfSaveDirectory = "D:\\home\\unzip\\wordToPDF\\";
String pdfSaveDirectory = "\\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";
String pdfFilePath = pdfSaveDirectory + nameWithoutExtension + ".pdf";
File inputWord = new File(wordFilePath);
File outputFile = new File(pdfFilePath);
try {
try {
InputStream docxInputStream = new FileInputStream(inputWord);
OutputStream outputStream = new FileOutputStream(outputFile);
IConverter converter = LocalConverter.builder().build();
converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
docxInputStream.close();
outputStream.close();
System.out.println("success");
File file1= new File(pdfFilePath);
System.out.println("这是转化后的PDF文件路径"+file1);
} catch (Exception e) {
e.printStackTrace();
}
return pdfFilePath;
}
private static int getFileNumPage(String pdfUrl) {
File pdfFile = new File(pdfUrl);
int pageCount = 0;
try (PDDocument document = PDDocument.load(pdfFile)) {
pageCount = document.getNumberOfPages();
} catch (IOException e) {
e.printStackTrace();
}
return pageCount;
}
}