Merge branch 'hjb' of SH-Arbitrate/Arbitrate-Backend into dev

This commit was merged in pull request #241.
This commit is contained in:
2023-11-25 18:08:23 +08:00
committed by Gitea
9 changed files with 352 additions and 255 deletions
@@ -429,4 +429,17 @@ public class CaseApplicationController extends BaseController {
return success(caseApplicationService.reserveConferenceList(caseId));
}
/**
* 案件压缩包导入
* @param file
* @return
* @throws IOException
*/
@PostMapping("/uploadCaseZipFile")
public AjaxResult uploadCaseZipFile(@RequestParam("file") MultipartFile file) throws IOException {
return caseApplicationService.uploadCaseZipFile(file);
}
}
+14
View File
@@ -164,6 +164,20 @@
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.0.3</version>
</dependency>
<!-- 发送邮件-->
<dependency>
<groupId>org.springframework.boot</groupId>
+2
View File
@@ -22,6 +22,7 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>pay</artifactId>
@@ -32,6 +33,7 @@
<artifactId>tls-sig-api-v2</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
@@ -112,4 +112,6 @@ public interface ICaseApplicationService {
AjaxResult deleteRoom( String roomId);
AjaxResult uploadCaseZipFile(MultipartFile file);
}
@@ -4,13 +4,18 @@ package com.ruoyi.wisdomarbitrate.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
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;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.*;
@@ -19,6 +24,7 @@ import com.ruoyi.common.enums.UpdateSubmitStatus;
import com.ruoyi.common.exception.EsignDemoException;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.SaaSAPIFileUtils;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.thread.ThreadPoolUtil;
@@ -44,11 +50,14 @@ 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.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;
@@ -61,6 +70,8 @@ import java.time.ZoneId;
import java.util.*;
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.success;
import static com.ruoyi.common.utils.PageUtils.startPage;
@@ -362,7 +373,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
return AjaxResult.error("请选择要上传的文件");
}
String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
// String targetPath = "F:\\testZip\\uploadPath\\upload\\upload1\\unzipFile";
// String targetPath = "D:\\home\\unzip\\";
File zipFile = null;
InputStream ins = null;
try {
@@ -542,7 +553,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
}
}
}
return success();
}
@@ -880,6 +890,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
/**
* 新增案件
*
* @param caseApplication
* @return
*/
@@ -2836,6 +2847,141 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
return success(reservedConferenceMapper.deleteByRoomId(roomId));
}
@Override
public AjaxResult uploadCaseZipFile(MultipartFile file) {
if (file.isEmpty()) {
return AjaxResult.error("请选择要上传的文件");
}
//String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
UUID uuid = UUID.randomUUID();
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);
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("."));
File directory = new File(targetPath);
List<String> andConvertPDF = findAndConvertPDF(directory);
if (andConvertPDF != null && andConvertPDF.size() > 0){
// 返回找到的PDF文件路径
return AjaxResult.success(andConvertPDF);
}else {
// 没有找到符合条件的文件
return AjaxResult.error("未找到符合条件的文件");
}
}else {
// 解压失败
return AjaxResult.error("解压失败");
}
}
public static List<String> findAndConvertPDF(File directory) {
List<String> pdfPaths = new ArrayList<>();
if (directory.isFile()) {
String path = "";
// 如果传入的参数是一个文件
if (directory.getName().contains("仲裁申请书")) {
if (isPDF(directory)) {
// 如果文件名包含"仲裁申请书"且是PDF格式,直接返回路径
path = directory.getAbsolutePath();
} else {
// 如果不是PDF格式,进行转换成PDF并返回路径
String pdfPath = convertToPDF(directory);
if (pdfPath != null) {
path = pdfPath;
}
}
if (path!= null) {
pdfPaths.add(path);
}
}
} else if (directory.isDirectory()) {
searchAndConvertPDF(directory, pdfPaths);
}else {
return null;
}
return pdfPaths;
}
public static boolean isPDF(File file) {
String extension = getFileExtension(file);
return extension.equalsIgnoreCase("pdf");
}
public static String getFileExtension(File file) {
String name = file.getName();
int lastIndexOfDot = name.lastIndexOf(".");
if (lastIndexOfDot != -1 && lastIndexOfDot < name.length() - 1) {
return name.substring(lastIndexOfDot + 1);
} else {
return "";
}
}
public static void searchAndConvertPDF(File directory, List<String> pdfPaths) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
// 如果是文件且文件名包含"仲裁申请书"
if (file.getName().contains("仲裁申请书")) {
if (isPDF(file)) {
// 如果是PDF格式,直接添加到列表中
pdfPaths.add(file.getAbsolutePath());
} else {
// 如果不是PDF格式,进行转换成PDF并添加转换后的路径到列表中
String pdfPath = convertToPDF(file);
if (pdfPath != null) {
pdfPaths.add(pdfPath);
}
}
}
} else if (file.isDirectory()) {
// 如果是目录,递归查找
searchAndConvertPDF(file, pdfPaths);
}
}
}
}
private static String convertToPDF(File file) {
String wordFilePath = file.getAbsolutePath();
String pdfSaveDirectory ="D:\\home\\unzip\\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);
File outputFile = new File(pdfFilePath);
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;
}
}
@@ -223,7 +223,6 @@ public class CasePaymentServiceImpl implements ICasePaymentService {
casePaymentRecordMapper.saveRecord(paymentRecord);
// 新增日志
CaseLogUtils.insertCaseLog(caseApplication.getId(), CaseApplicationConstants.PENDING_PAYMENT_CONFIRM, "");
}
}
@@ -182,11 +182,12 @@ public class FixSelectFlowDetailUtils {
public void fixExecuteSelectDeptIndentifyUtils() throws Exception {
Gson gson = new Gson();
DeptIdentify deptIdentify = new DeptIdentify();
deptIdentify.setIdentifyStatus(0);
List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
if (deptIdentifysnew != null && deptIdentifysnew.size() > 0) {
for (int i = 0; i < deptIdentifysnew.size(); i++) {
DeptIdentify deptIdentify1 = deptIdentifysnew.get(i);
Integer identifyStatus = deptIdentify1.getIdentifyStatus();
if (identifyStatus!=1){
String authFlowId = deptIdentify1.getAuthFlowId();
if (authFlowId != null) {
EsignHttpResponse identifyInfo = SignAward.getDeptIdentifyInfo(deptIdentify1);
@@ -267,109 +268,9 @@ public class FixSelectFlowDetailUtils {
deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
}
}
}
}
}
/**
* 定时查询企业认证状态
*
* @throws Exception
*/
@Scheduled(cron = "*/30 * * * * *")
@Transactional
public void fixExecuteSelectDeptIndentify() throws Exception {
Gson gson = new Gson();
DeptIdentify deptIdentify = new DeptIdentify();
deptIdentify.setIdentifyStatus(2);
List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
if (deptIdentifysnew != null && deptIdentifysnew.size() > 0) {
for (int i = 0; i < deptIdentifysnew.size(); i++) {
DeptIdentify deptIdentify1 = deptIdentifysnew.get(i);
String authFlowId = deptIdentify1.getAuthFlowId();
if (authFlowId != null) {
EsignHttpResponse identifyInfo = SignAward.getDeptIdentifyInfo(deptIdentify1);
JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
int code = identifyInfoJsonObject.get("code").getAsInt();
if (code == 0) {
JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
int realnameStatus = identifyInfoData.get("realnameStatus").getAsInt();
if (realnameStatus == 1) {
String orgId = identifyInfoData.get("orgId").getAsString();
//查询企业内部印章
EsignHttpResponse response = SignAward.deptIdentifySealList(orgId);
JsonObject jsonObject = gson.fromJson(response.getBody(), JsonObject.class);
int code1 = jsonObject.get("code").getAsInt();
if (code1 == 0) {
JsonObject data = jsonObject.getAsJsonObject("data");
JsonArray seals = data.get("seals").getAsJsonArray();
if (seals.size() > 0) {
for (int j = 0; j < seals.size(); j++) {
//保存印章信息到数据库
JsonObject asJsonObject = seals.get(j).getAsJsonObject();
SealManage sealManage = new SealManage();
String sealName = asJsonObject.get("sealName").toString();
String sealId = asJsonObject.get("sealId").toString();
String url = asJsonObject.get("sealImageDownloadUrl").toString();
LocalDate now = LocalDate.now();
String year = Integer.toString(now.getYear());
String month = String.format("%02d", now.getMonthValue());
String day = String.format("%02d", now.getDayOfMonth());
String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
String fileName = UUID.randomUUID().toString().replace("-", "") + ".jpg";
String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
String savePath = "/home/ruoyi/uploadPath/upload/";
// 创建日期目录
File saveFolder = new File(saveFolderPath);
if (!saveFolder.exists()) {
saveFolder.mkdirs();
}
String resultFilePath = saveFolderPath + "/" + fileName;
File resultFilePathFile = new File(resultFilePath);
if (!resultFilePathFile.exists()) {
resultFilePathFile.createNewFile();
}
String fileDownloadUrlnew = url.substring(1, url.length() - 1);
boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
if (downLoadFile) {
CaseAttach caseAttach = new CaseAttach();
caseAttach.setAnnexType(10); //10代表印章图片
caseAttach.setAnnexPath(savePath);
caseAttach.setAnnexName(saveName);
int i1 = caseAttachMapper.save(caseAttach);
if (i1 > 0) {
//将印章信息保存到公章管理表里
String sealName1 = sealName.substring(1, sealName.length() - 1);
String sealId1 = sealId.substring(1, sealId.length() - 1);
Integer annexId1 = caseAttach.getAnnexId();
sealManage.setAnnexId(annexId1);
sealManage.setSealId(sealId1);
sealManage.setSealName(sealName1);
sealManage.setIdentifyId(deptIdentify1.getId());
sealManage.setSealStatus(1);
sealManage.setIsUse(1);
sealManageMapper.insertSealManage(sealManage);
}
}
}
}
}
//将orgId保存到数据库里
deptIdentify1.setOrgId(orgId);
deptIdentify1.setIdentifyStatus(1);
deptIdentify1.setIsUse(0); //默认机构为未启用
int row = deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
}
}else {
deptIdentify1.setIdentifyStatus(2);
deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
}
}
}
}
}
@@ -0,0 +1,52 @@
package com.ruoyi.wisdomarbitrate.utils;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRResponse;
import java.io.*;
public class Tset {
public static void main(String[] args) {
//API的SecretId
final String SECRET_ID = "AKIDeEf2A8uX1HSainvvnXAc3X9ZlhtyvkMp";
//API的SecretKey
final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
String pdfFilePath = "D:\\data\\1. 仲裁申请书-陈博.pdf";
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对象
GeneralAccurateOCRRequest req = new GeneralAccurateOCRRequest();
req.setImageUrl(pdfFilePath);
req.setIsPdf(true);
req.setPdfPageNumber(1L);
// 返回的resp是一个GeneralAccurateOCRResponse的实例,与请求对象对应
GeneralAccurateOCRResponse resp = client.GeneralAccurateOCR(req);
// 输出json格式的字符串回包
System.out.println(GeneralAccurateOCRResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}
@@ -17,38 +17,9 @@ import java.util.zip.ZipFile;
public class UnZipFileUtils {
public static void main(String[] args) {
// 压缩包路径
// String zipPath = "F:\\testZip\\zipFile\\上传申请书证据材料.zip";
// 解压后存放路径
// String targetPath = "F:\\testZip\\unzipFile";
// unZipFile(new File(zipPath),targetPath);
// String zipPath = "F:\\testZip\\unzipFile\\上传申请书证据材料";
// File dirUnzipPath = new File(zipPath);
// List<File> allFiles = new ArrayList<>();
// getFiles(dirUnzipPath,allFiles);
// if(allFiles!=null&&allFiles.size()>0){
// for (File fileIter : allFiles) {
// System.out.println(fileIter.getName());
// System.out.println(fileIter.getAbsolutePath());
// }
// }
String key = "\\";
String str = "F:\\testZip\\上传申请书证据材料\\证据材料\\仲裁裁决书模板.docx";
List<Integer> allindex = new ArrayList<>();
int a = str.indexOf(key);//*第一个出现的索引位置
allindex.add(a);
while (a != -1) {
System.out.print(a + "\t");
a = str.indexOf(key, a + 1);//*从这个索引往后开始第一个出现的位置
allindex.add(a);
}
String substr = str.substring(allindex.get(1)+1,allindex.get(2));
System.out.println("substr---"+substr);
File file = new File("D:\\home\\ruoyi\\仲裁委项目-测试单.zip");
String targetPath = "D:\\home\\unzip\\";
unZipFile(file,targetPath);
}
public static boolean unZipFile(File aboriginalFile, String targetPath) {
@@ -120,7 +91,4 @@ public class UnZipFileUtils {
}
}