调解系统初始化版本
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.wisdomarbitrate.domain.CaseLogRecord;
|
||||
import com.ruoyi.wisdomarbitrate.mapper.CaseLogRecordMapper;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 案件记录日志文件
|
||||
*
|
||||
* @author wangqiong
|
||||
*/
|
||||
public class CaseLogUtils
|
||||
{
|
||||
private static CaseLogRecordMapper caseLogRecordMapper= SpringUtil.getBean(CaseLogRecordMapper.class);
|
||||
private static SysUserMapper userMapper= SpringUtil.getBean(SysUserMapper.class);
|
||||
|
||||
/**
|
||||
* 新增案件日志
|
||||
* @param caseAppliId 案件id,不能为空
|
||||
* @param caseNode 案件节点,不能为空
|
||||
* @param notes 备注
|
||||
*/
|
||||
public static void insertCaseLog(@NotNull Long caseAppliId, @NotEmpty Integer caseNode, String notes ){
|
||||
CaseLogRecord operLog = new CaseLogRecord();
|
||||
// 获取当前的用户
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if(loginUser!=null) {
|
||||
SysUser sysUser = userMapper.selectUserById(loginUser.getUserId());
|
||||
operLog.setCreateBy(sysUser.getUserName());
|
||||
operLog.setCreateNickName(sysUser.getNickName());
|
||||
operLog.setUpdateBy(sysUser.getUserName());
|
||||
}else {
|
||||
operLog.setCreateBy("admin");
|
||||
operLog.setCreateNickName("管理员");
|
||||
operLog.setUpdateBy("admin");
|
||||
}
|
||||
operLog.setCaseAppliId(caseAppliId);
|
||||
operLog.setCaseNode(caseNode);
|
||||
operLog.setNotes(notes);
|
||||
caseLogRecordMapper.insertCaseLogRecord(operLog);
|
||||
}
|
||||
/**
|
||||
* 新增案件日志
|
||||
* @param caseAppliId 案件id,不能为空
|
||||
* @param caseNode 案件节点,不能为空
|
||||
* @param notes 备注
|
||||
*/
|
||||
public static void insertCaseLog(@NotNull Long caseAppliId, @NotEmpty Integer caseNode, String notes ,LoginUser loginUser ){
|
||||
CaseLogRecord operLog = new CaseLogRecord();
|
||||
// 获取当前的用户
|
||||
if(loginUser!=null) {
|
||||
SysUser sysUser = userMapper.selectUserById(loginUser.getUserId());
|
||||
operLog.setCreateBy(sysUser.getUserName());
|
||||
operLog.setCreateNickName(sysUser.getNickName());
|
||||
operLog.setUpdateBy(sysUser.getUserName());
|
||||
}else {
|
||||
operLog.setCreateBy("admin");
|
||||
operLog.setCreateNickName("管理员");
|
||||
operLog.setUpdateBy("admin");
|
||||
}
|
||||
operLog.setCaseAppliId(caseAppliId);
|
||||
operLog.setCaseNode(caseNode);
|
||||
operLog.setNotes(notes);
|
||||
caseLogRecordMapper.insertCaseLogRecord(operLog);
|
||||
}
|
||||
/**
|
||||
* 批量新增案件日志
|
||||
* @param list
|
||||
*/
|
||||
public static void batchInsertCaseLog(List<CaseLogRecord> list ){
|
||||
|
||||
caseLogRecordMapper.batchInsertRecord(list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+362
@@ -0,0 +1,362 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ruoyi.common.constant.CaseApplicationConstants;
|
||||
import com.ruoyi.common.constant.FileTransformation;
|
||||
import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
|
||||
import com.ruoyi.common.exception.EsignDemoException;
|
||||
import com.ruoyi.common.utils.SealUtil;
|
||||
import com.ruoyi.common.utils.file.SaaSAPIFileUtils;
|
||||
import com.ruoyi.wisdomarbitrate.domain.*;
|
||||
import com.ruoyi.wisdomarbitrate.mapper.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class FixSelectFlowDetailUtils {
|
||||
|
||||
@Autowired
|
||||
private CaseApplicationMapper caseApplicationMapper;
|
||||
@Autowired
|
||||
private SealSignRecordMapper sealSignRecordMapper;
|
||||
@Autowired
|
||||
private CaseAttachMapper caseAttachMapper;
|
||||
@Autowired
|
||||
private DeptIdentifyMapper deptIdentifyMapper;
|
||||
@Autowired
|
||||
private SealManageMapper sealManageMapper;
|
||||
|
||||
/*
|
||||
定时查询签署流程详情
|
||||
*/
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
@Transactional
|
||||
public void fixExecuteSelectFlowDetailUtils() {
|
||||
Gson gson = new Gson();
|
||||
|
||||
SealSignRecord sealSignRecordselect = new SealSignRecord();
|
||||
// sealSignRecordselect.setSignFlowStatus(1);
|
||||
List<SealSignRecord> sealSignRecords = sealSignRecordMapper.selectSealSignRecordbyStat(sealSignRecordselect);
|
||||
|
||||
try {
|
||||
if (sealSignRecords != null && sealSignRecords.size() > 0) {
|
||||
for (int i = 0; i < sealSignRecords.size(); i++) {
|
||||
SealSignRecord sealSignRecord = sealSignRecords.get(i);
|
||||
EsignHttpResponse signFlowDetail = SignAward.signFlowDetail(sealSignRecord);
|
||||
JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(), JsonObject.class);
|
||||
JsonObject flowDetailData = signFlowDetailJsonObject.getAsJsonObject("data");
|
||||
JsonArray signersArray = flowDetailData.get("signers").getAsJsonArray();
|
||||
Integer psnsignStatus = null;
|
||||
Integer orgsignStatus = null;
|
||||
for (int j = 0; j < signersArray.size(); j++) {
|
||||
JsonObject signerObject = (JsonObject) signersArray.get(j);
|
||||
|
||||
if (!(signerObject.get("psnSigner").toString()).equals("null")) {
|
||||
JsonObject psnSignerData = signerObject.getAsJsonObject("psnSigner");
|
||||
if (psnSignerData != null) {
|
||||
psnsignStatus = signerObject.get("signStatus").getAsInt();
|
||||
}
|
||||
}
|
||||
if (!(signerObject.get("orgSigner").toString()).equals("null")) {
|
||||
JsonObject orgSignerData = signerObject.getAsJsonObject("orgSigner");
|
||||
if (orgSignerData != null) {
|
||||
orgsignStatus = signerObject.get("signStatus").getAsInt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ((psnsignStatus.intValue() == 2) && (orgsignStatus.intValue() == 1)) {
|
||||
//更新立案申请状态为待用印
|
||||
CaseApplication caseApplication = new CaseApplication();
|
||||
caseApplication.setId(sealSignRecord.getCaseAppliId());
|
||||
|
||||
CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication);
|
||||
if (caseApplicationselect != null) {
|
||||
if ((caseApplicationselect.getCaseStatus() != null) && (caseApplicationselect.getCaseStatus().intValue() == CaseApplicationConstants.SIGN_ARBITRATION)) {
|
||||
caseApplication.setCaseStatus(CaseApplicationConstants.ARBITRATED_SEAL);
|
||||
caseApplicationMapper.submitCaseApplication(caseApplication);
|
||||
|
||||
//修改"签署用印记录表"的状态为待用印
|
||||
sealSignRecord.setSignFlowStatus(2);
|
||||
sealSignRecordMapper.updataSealSignRecord(sealSignRecord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ((psnsignStatus.intValue() == 2) && (orgsignStatus.intValue() == 2)) {
|
||||
//更新立案申请状态为待送达
|
||||
CaseApplication caseApplication = new CaseApplication();
|
||||
caseApplication.setId(sealSignRecord.getCaseAppliId());
|
||||
|
||||
CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication);
|
||||
if (caseApplicationselect != null) {
|
||||
if ((caseApplicationselect.getCaseStatus() != null) && (caseApplicationselect.getCaseStatus().intValue() == CaseApplicationConstants.ARBITRATED_SEAL)) {
|
||||
caseApplication.setCaseStatus(CaseApplicationConstants.ARBITRATION_DELIVERY);
|
||||
//下载审核完成的裁决书,
|
||||
String signFlowId = sealSignRecord.getSignFlowid();
|
||||
EsignHttpResponse fileDownload = SaaSAPIFileUtils.fileDownloadUrl(signFlowId);
|
||||
JsonObject fileDownloadJsonObject = gson.fromJson(fileDownload.getBody(), JsonObject.class);
|
||||
JsonObject fileDownloadData = fileDownloadJsonObject.getAsJsonObject("data");
|
||||
JsonArray filesArray = fileDownloadData.get("files").getAsJsonArray();
|
||||
if (filesArray != null && filesArray.size() > 0) {
|
||||
JsonObject fileObject = (JsonObject) filesArray.get(0);
|
||||
String fileDownloadUrl = fileObject.get("downloadUrl").toString();
|
||||
//修改"签署用印记录表"的状态为签署完成
|
||||
sealSignRecord.setSignFlowStatus(3);
|
||||
sealSignRecord.setFileDownloadUrl(fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1));
|
||||
sealSignRecordMapper.updataSealSignRecord(sealSignRecord);
|
||||
|
||||
String filearbitraUrl = fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1);
|
||||
caseApplication.setFilearbitraUrl(filearbitraUrl);
|
||||
caseApplicationMapper.submitCaseApplication(caseApplication);
|
||||
|
||||
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("-", "") + ".pdf";
|
||||
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 = fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1);
|
||||
boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
|
||||
if (downLoadFile) {
|
||||
Long caseAppliId = sealSignRecord.getCaseAppliId();
|
||||
CaseAttach caseAttach = new CaseAttach();
|
||||
caseAttach.setCaseAppliId(caseAppliId);
|
||||
caseAttach.setAnnexType(3);
|
||||
caseAttach.setAnnexPath(savePath);
|
||||
caseAttach.setAnnexName(saveName);
|
||||
caseAttachMapper.updateCaseAttachBycaseid(caseAttach);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (EsignDemoException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时查询企业认证状态
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
@Transactional
|
||||
public void fixExecuteSelectDeptIndentifyUtils() throws Exception {
|
||||
Gson gson = new Gson();
|
||||
DeptIdentify deptIdentify = new DeptIdentify();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定时查询印章审核状态
|
||||
*/
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
@Transactional
|
||||
public void searchForInstitutionalSeal() {
|
||||
try {
|
||||
SealManage sealManage = new SealManage();
|
||||
sealManage.setSealStatus(0);
|
||||
List<SealManage> sealManageList = sealManageMapper.selectSealList(sealManage);
|
||||
if (sealManageList != null && sealManageList.size() > 0) {
|
||||
for (SealManage sealManage1 : sealManageList) {
|
||||
//查询企业内部印章
|
||||
Integer annexId = sealManage1.getAnnexId();
|
||||
String sealId = sealManage1.getSealId();
|
||||
DeptIdentify deptIdentify = new DeptIdentify();
|
||||
deptIdentify.setId(sealManage1.getIdentifyId());
|
||||
List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
|
||||
if (deptIdentifies != null && deptIdentifies.size() > 0) {
|
||||
DeptIdentify deptIdentify1 = deptIdentifies.get(0);
|
||||
String orgId = deptIdentify1.getOrgId();
|
||||
if (orgId == null) {
|
||||
continue;
|
||||
}
|
||||
if (annexId == null) {
|
||||
//说明之前没有下载过
|
||||
EsignHttpResponse response = SignAward.getOrgSeal(orgId, sealId);
|
||||
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
||||
int code = jsonObject.getIntValue("code");
|
||||
if (code == 0) {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
int sealStatus = data.getIntValue("sealStatus");
|
||||
if (sealStatus == 1) {//印章状态 1已启用,2待审核,3审核不通过,4 挂起
|
||||
//已启用证明审核通过,下载到数据库
|
||||
String sealImageDownloadUrl = data.getString("sealImageDownloadUrl");
|
||||
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();
|
||||
}
|
||||
boolean downLoadFile = FileTransformation.downLoadFileByUrl(sealImageDownloadUrl, 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) {
|
||||
//将附件id保存到公章管理表里
|
||||
Integer annexId1 = caseAttach.getAnnexId();
|
||||
sealManage1.setAnnexId(annexId1);
|
||||
sealManage1.setSealStatus(1);
|
||||
sealManage1.setIsUse(0);
|
||||
sealManageMapper.updateSealManage(sealManage1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (EsignDemoException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
|
||||
public class ImageToBase64Converter {
|
||||
public static String imageToBase64(String imagePath) throws Exception {
|
||||
Path path = Paths.get(imagePath);
|
||||
byte[] imageBytes = Files.readAllBytes(path);
|
||||
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
|
||||
return base64Image;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String imagePath = "D:\\develop\\2.jpg";
|
||||
try {
|
||||
String base64Image = imageToBase64(imagePath);
|
||||
System.out.println(base64Image);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.wisdomarbitrate.domain.FatchRule;
|
||||
import com.tencentcloudapi.bsca.v20210811.models.LicenseSummary;
|
||||
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.*;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OCRUtils {
|
||||
//API的SecretId
|
||||
private static final String SECRET_ID = "AKIDeEf2A8uX1HSainvvnXAc3X9ZlhtyvkMp";
|
||||
//API的SecretKey
|
||||
private static final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
|
||||
// 仲裁申请书识别字段
|
||||
private static final String[] applicantName = {"申请人", "统一社会信用代码", "负责人", "住所", "联系地址"
|
||||
, "委托代理人", "联系电话", "电子邮件", "被申请人", "居民身份证号码", "仲裁请求", "事实和理由"};
|
||||
// 贷款合同识别字段
|
||||
private static final String[] contractName = {
|
||||
"合同编号", "甲方(贷款人)", "或委托代理人签字:", "本合同的初始贷款年利率为", "乙方确认有效的电子信箱地址为"};
|
||||
// 调解协议识别字段
|
||||
private static final String[] accordName = {"金融消费纠纷基本情况", "经调解,双方自愿达成如下协议"};
|
||||
// 授权委托书识别字段
|
||||
private static final String[] powerAttorneyName = {"职务"};
|
||||
|
||||
/**
|
||||
* pdf识别成文字
|
||||
*
|
||||
* @param imageBase64
|
||||
* @param pageNumber
|
||||
* @param fatchRules 抓取规则
|
||||
* @return
|
||||
*/
|
||||
public static String pdfIdentifyText(String imageBase64, Integer pageNumber, List<FatchRule> fatchRules) {
|
||||
StringBuilder respStr = new StringBuilder();
|
||||
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.setImageBase64(imageBase64);
|
||||
req.setIsPdf(true);
|
||||
req.setPdfPageNumber(pageNumber.longValue());
|
||||
// 返回的resp是一个SmartStructuralOCRV2Response的实例,与请求对象对应
|
||||
GeneralAccurateOCRResponse resp = client.GeneralAccurateOCR(req);
|
||||
// 输出json格式的字符串回包
|
||||
System.out.println(GeneralAccurateOCRResponse.toJsonString(resp));
|
||||
// 获取响应内容
|
||||
TextDetection[] textDetections = resp.getTextDetections();
|
||||
if (textDetections == null || textDetections.length == 0) {
|
||||
return respStr.toString();
|
||||
}
|
||||
for (TextDetection textDetection : textDetections) {
|
||||
respStr.append(textDetection.getDetectedText());
|
||||
}
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new ServiceException("ocr识别失败");
|
||||
}
|
||||
if (respStr.toString().endsWith(String.valueOf(pageNumber))) {
|
||||
int lastIndexOf = respStr.toString().lastIndexOf(String.valueOf(pageNumber));
|
||||
return respStr.toString().substring(0, lastIndexOf);
|
||||
}
|
||||
return respStr.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String pdfConvertBase64(String pathUrl) {
|
||||
try {
|
||||
File file = new File(pathUrl);
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
byte[] fileBytes = new byte[(int) file.length()];
|
||||
fileInputStream.read(fileBytes);
|
||||
fileInputStream.close();
|
||||
// 将字节数组转换为Base64值
|
||||
return Base64.getEncoder().encodeToString(fileBytes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据抓取规则获取内容
|
||||
*
|
||||
* @param ocrText ocr识别的text
|
||||
* @param fatchRules 抓取规则
|
||||
* @return
|
||||
*/
|
||||
public static void fatchRuleGetContent(String ocrText, List<FatchRule> fatchRules, Map<String, String> fatchMap) {
|
||||
if (StrUtil.isEmpty(ocrText) || CollectionUtil.isEmpty(fatchRules)) {
|
||||
return;
|
||||
}
|
||||
for (FatchRule fatchRule : fatchRules) {
|
||||
// 从后往前抓取
|
||||
if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) {
|
||||
reverseSubstringText(ocrText, fatchRule, fatchMap,null);
|
||||
} else {
|
||||
// 从前往后抓取
|
||||
substringText(ocrText, fatchRule, fatchMap,null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据抓取规则获取内容
|
||||
*
|
||||
* @param ocrText ocr识别的text
|
||||
* @param fatchRules 抓取规则
|
||||
* @return
|
||||
*/
|
||||
public static void fatchRuleGetContent(String ocrText, List<FatchRule> fatchRules, Map<String, String> fatchMap, Long caseId) {
|
||||
if (StrUtil.isEmpty(ocrText) || CollectionUtil.isEmpty(fatchRules)) {
|
||||
return;
|
||||
}
|
||||
for (FatchRule fatchRule : fatchRules) {
|
||||
// 从后往前抓取
|
||||
if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) {
|
||||
reverseSubstringText(ocrText, fatchRule, fatchMap, caseId);
|
||||
} else {
|
||||
// 从前往后抓取
|
||||
substringText(ocrText, fatchRule, fatchMap, caseId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 正向截取字段
|
||||
*
|
||||
* @param text
|
||||
* @param fatchRule
|
||||
* @param fatchMap
|
||||
*/
|
||||
private static void substringText(String text, FatchRule fatchRule, Map<String, String> fatchMap, Long caseId) {
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从后往前截取字符串
|
||||
*
|
||||
* @param text
|
||||
* @param fatchRule
|
||||
* @param fatchMap
|
||||
*/
|
||||
public static void reverseSubstringText(String text, FatchRule fatchRule, Map<String, String> fatchMap, Long caseId) {
|
||||
|
||||
// 反正字符串
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除末尾空格
|
||||
*
|
||||
* @param substring
|
||||
* @return
|
||||
*/
|
||||
private static String trimStr(String substring) {
|
||||
if (StrUtil.isNotEmpty(substring)) {
|
||||
return StrUtil.trim(substring);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
|
||||
import com.ruoyi.common.enums.EsignRequestType;
|
||||
import com.ruoyi.common.exception.EsignDemoException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.EsignApplicaConfig;
|
||||
import com.ruoyi.common.utils.EsignHttpHelper;
|
||||
import com.ruoyi.common.utils.SealUtil;
|
||||
import com.ruoyi.wisdomarbitrate.StringIdsReq;
|
||||
import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
|
||||
import com.ruoyi.wisdomarbitrate.domain.SealSignRecord;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SignAward {
|
||||
|
||||
private static String eSignHost = EsignApplicaConfig.EsignHost;
|
||||
private static String eSignAppId = EsignApplicaConfig.EsignAppId;
|
||||
private static String eSignAppSecret = EsignApplicaConfig.EsignAppSecret;
|
||||
|
||||
|
||||
public static void main(String[] args) throws EsignDemoException {
|
||||
Gson gson = new Gson();
|
||||
|
||||
|
||||
|
||||
/* 发起签署*/
|
||||
// EsignHttpResponse createByFile = createByFile(sealSignRecord);
|
||||
// JsonObject createByFileJsonObject = gson.fromJson(createByFile.getBody(), JsonObject.class);
|
||||
// JsonObject createByFileData = createByFileJsonObject.getAsJsonObject("data");
|
||||
// String signFlowId = createByFileData.get("signFlowId").getAsString();
|
||||
// System.err.println("流程id:"+signFlowId);
|
||||
|
||||
/* 获取文件签名印章位置*/
|
||||
// EsignHttpResponse positions = getPositions(sealSignRecord);
|
||||
// JsonObject positionsJsonObject = gson.fromJson(positions.getBody(), JsonObject.class);
|
||||
// JsonObject positionsData = positionsJsonObject.getAsJsonObject("data");
|
||||
// JsonArray keywordPositions = positionsData.get("keywordPositions").getAsJsonArray();
|
||||
// System.out.println("获取文件签名印章位置:" +keywordPositions.toString());
|
||||
|
||||
// String signFlowId = "c9955453716344f9971d308abdc13464";
|
||||
//获取合同文件签名链接
|
||||
// EsignHttpResponse signUrl = signUrl(sealSignRecord);
|
||||
// JsonObject signUrlJsonObject = gson.fromJson(signUrl.getBody(), JsonObject.class);
|
||||
// JsonObject signUrlData = signUrlJsonObject.getAsJsonObject("data");
|
||||
// String shortUrl = signUrlData.get("shortUrl").getAsString();
|
||||
// String url = signUrlData.get("url").getAsString();
|
||||
// System.out.println("签署短链接:" +shortUrl);
|
||||
// System.out.println("签署长链接:"+url);
|
||||
|
||||
//获取合同文件用印链接
|
||||
// EsignHttpResponse usesealUrl = usesealUrl(sealSignRecord);
|
||||
// JsonObject usesealUrlJsonObject = gson.fromJson(usesealUrl.getBody(), JsonObject.class);
|
||||
// JsonObject usesealUrlData = usesealUrlJsonObject.getAsJsonObject("data");
|
||||
// String shortusesealUrl = usesealUrlData.get("shortUrl").getAsString();
|
||||
// String sealUrl = usesealUrlData.get("url").getAsString();
|
||||
// System.out.println("签署长链接:" +shortusesealUrl);
|
||||
// System.out.println("签署短链接:"+sealUrl);
|
||||
|
||||
//查询机构认证信息
|
||||
// DeptIdentify deptIdentify = new DeptIdentify();
|
||||
// deptIdentify.setDeptName("西安云美电子科技有限公司");
|
||||
// EsignHttpResponse identifyInfo = getDeptIdentifyInfo(deptIdentify);
|
||||
// JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
|
||||
// JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
|
||||
// int realnameStatus = identifyInfoData.get("realnameStatus").getAsInt();
|
||||
// String orgId = identifyInfoData.get("orgId").getAsString();
|
||||
// System.out.println("机构认证状态:" +realnameStatus);
|
||||
// System.out.println("机构id:" +orgId);
|
||||
|
||||
// EsignHttpResponse identifyInfo = deptIdentifySealList(orgId);
|
||||
// JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
|
||||
// JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
|
||||
// JsonArray sealArray = identifyInfoData.get("seals").getAsJsonArray();
|
||||
// String sealNames = "";
|
||||
// if(sealArray.size()>0){
|
||||
// for (int i = 0; i < sealArray.size(); i++) {
|
||||
// JsonObject sealObject = (JsonObject)sealArray.get(i);
|
||||
// String sealName = sealObject.get("sealName").toString();
|
||||
// String sealNamenew = sealName.substring(1,sealName.length()-1);
|
||||
// sealNames += sealNamenew +",";
|
||||
// }
|
||||
// }
|
||||
// System.out.println("机构印章名称:" +sealNames.substring(0,sealNames.length()-1));
|
||||
|
||||
|
||||
//查询签署流程详情
|
||||
// EsignHttpResponse signFlowDetail = signFlowDetail(sealSignRecord);
|
||||
// JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(),JsonObject.class);
|
||||
// JsonObject flowDetailData = signFlowDetailJsonObject.getAsJsonObject("data");
|
||||
// JsonArray signersArray = flowDetailData.get("signers").getAsJsonArray();
|
||||
// for (int i = 0; i < signersArray.size(); i++) {
|
||||
// JsonObject signerObject = (JsonObject)signersArray.get(i);
|
||||
// Integer psnsignStatus ;
|
||||
// Integer orgsignStatus ;
|
||||
// if(!(signerObject.get("psnSigner").toString()).equals("null")){
|
||||
// JsonObject psnSignerData = signerObject.getAsJsonObject("psnSigner");
|
||||
// if(psnSignerData!=null){
|
||||
// psnsignStatus = signerObject.get("signStatus").getAsInt();
|
||||
// sealSignRecord.setPsnsignStatus(psnsignStatus);
|
||||
// }
|
||||
// }
|
||||
// if(!(signerObject.get("orgSigner").toString()).equals("null")){
|
||||
// JsonObject orgSignerData = signerObject.getAsJsonObject("orgSigner");
|
||||
// if(orgSignerData!=null){
|
||||
// orgsignStatus = signerObject.get("signStatus").getAsInt();
|
||||
// sealSignRecord.setOrgsignStatus(orgsignStatus);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println(signFlowDetailJsonObject);
|
||||
DeptIdentify deptIdentify = new DeptIdentify();
|
||||
deptIdentify.setAuthFlowId("OF-2b5883bf4508000c");
|
||||
EsignHttpResponse deptIdentifyInfo = getDeptIdentifyInfo(deptIdentify);
|
||||
System.out.println(deptIdentifyInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询签署流程详情
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static EsignHttpResponse signFlowDetail(SealSignRecord sealSignRecord) throws EsignDemoException {
|
||||
String signFlowId = sealSignRecord.getSignFlowid();
|
||||
String apiaddr = "/v3/sign-flow/" + signFlowId + "/detail";
|
||||
String jsonParm = null;
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.GET;
|
||||
//生成签名鉴权方式的的header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起签署
|
||||
*
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static EsignHttpResponse createByFile(SealSignRecord sealSignRecord ,List<String> sealIdList) throws EsignDemoException {
|
||||
String apiaddr = "/v3/sign-flow/create-by-file";
|
||||
|
||||
String fileId = sealSignRecord.getFileid();
|
||||
String fileName = sealSignRecord.getFilename();
|
||||
|
||||
String psnAccount = sealSignRecord.getPensonAccount();
|
||||
String psnName = sealSignRecord.getPensonName();
|
||||
|
||||
String orgName = sealSignRecord.getOrgnizeName();
|
||||
String orgNamePsnAccount = sealSignRecord.getOrgnizeNamePsnAccount();
|
||||
String orgNamepsnName = sealSignRecord.getOrgnizeNamepsnName();
|
||||
|
||||
String positionPagepsn = sealSignRecord.getPositionPagepsn();
|
||||
double positionXpsn = sealSignRecord.getPositionXpsn();
|
||||
double positionYpsn = sealSignRecord.getPositionYpsn();
|
||||
|
||||
String positionPageorg = sealSignRecord.getPositionPageorg();
|
||||
double positionXorg = sealSignRecord.getPositionXorg();
|
||||
double positionYorg = sealSignRecord.getPositionYorg();
|
||||
String availableSealId = "209af82b-5f87-4e0a-b0d8-cc4923b6e652";
|
||||
|
||||
|
||||
String jsonParm = "{\n" +
|
||||
" \"docs\": [\n" +
|
||||
" {\n" +
|
||||
" \"fileId\": \"" + fileId + "\",\n" +
|
||||
" \"fileName\": \"" + fileName + "\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"signFlowConfig\": {\n" +
|
||||
" \"signFlowTitle\": \"测试合同\",\n" +
|
||||
" \"autoStart\": true,\n" +
|
||||
" \"authConfig\": {\n" +
|
||||
" \"willingnessAuthModes\": [\n" +
|
||||
" \"CODE_SMS\"\n" +
|
||||
" ],\n" +
|
||||
" \"psnAvailableAuthModes\": [\n" +
|
||||
" \"PSN_MOBILE3\"\n" +
|
||||
" ],\n" +
|
||||
" \"orgAvailableAuthModes\": [\n" +
|
||||
" \"ORG_LEGALREP\"\n" +
|
||||
" ]\n" +
|
||||
" },\n" +
|
||||
|
||||
" \"signConfig\": {\n" +
|
||||
" \"availableSignClientTypes\": \"1\"\n" +
|
||||
" },\n" +
|
||||
|
||||
" \"autoFinish\": true\n" +
|
||||
" },\n" +
|
||||
|
||||
" \"signers\": [\n" +
|
||||
" {\n" +
|
||||
" \"psnSignerInfo\": {\n" +
|
||||
" \"psnAccount\": \"" + psnAccount + "\",\n" +
|
||||
" \"psnInfo\": {\n" +
|
||||
" \"psnName\": \"" + psnName + "\"\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"signFields\": [\n" +
|
||||
" {\n" +
|
||||
" \"fileId\": \"" + fileId + "\",\n" +
|
||||
" \"normalSignFieldConfig\": {\n" +
|
||||
" \"autoSign\": false,\n" +
|
||||
" \"freeMode\": false,\n" +
|
||||
" \"movableSignField\": false,\n" +
|
||||
" \"signFieldPosition\": {\n" +
|
||||
" \"positionPage\": \"" + positionPagepsn + "\",\n" +
|
||||
" \"positionX\": " + positionXpsn + ",\n" +
|
||||
" \"positionY\": " + positionYpsn + "\n" +
|
||||
" },\n" +
|
||||
" \"signFieldStyle\": 1\n" +
|
||||
" },\n" +
|
||||
" \"signFieldType\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"signerType\": 0\n" +
|
||||
" },\n" +
|
||||
|
||||
" {\n" +
|
||||
" \"orgSignerInfo\": {\n" +
|
||||
" \"orgName\": \"" + orgName + "\",\n" +
|
||||
" \"transactorInfo\": {\n" +
|
||||
" \"psnAccount\": \"" + orgNamePsnAccount + "\",\n" +
|
||||
" \"psnInfo\": {\n" +
|
||||
" \"psnName\": \"" + orgNamepsnName + "\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
|
||||
" \"signFields\": [\n" +
|
||||
" {\n" +
|
||||
" \"fileId\": \"" + fileId + "\",\n" +
|
||||
" \"normalSignFieldConfig\": {\n" +
|
||||
" \"autoSign\": false,\n" +
|
||||
" \"freeMode\": false,\n" +
|
||||
|
||||
/* " \"availableSealIds\": [\n" +
|
||||
" \"" + availableSealId + "\"\n" +
|
||||
" ],\n" +*/
|
||||
// " \"availableSealIds\": " + new Gson().toJson(sealIdList) + ",\n" +
|
||||
|
||||
" \"signFieldPosition\": {\n" +
|
||||
" \"positionPage\": \"" + positionPageorg + "\",\n" +
|
||||
" \"positionX\": " + positionXorg + ",\n" +
|
||||
" \"positionY\": " + positionYorg + "\n" +
|
||||
" },\n" +
|
||||
" \"signFieldStyle\": 1\n" +
|
||||
" },\n" +
|
||||
" \"signFieldType\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"signerType\": 1\n" +
|
||||
" }\n" +
|
||||
|
||||
" ]\n" +
|
||||
"}";
|
||||
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取合同文件签名链接
|
||||
*
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static EsignHttpResponse signUrl(SealSignRecord sealSignRecord) throws EsignDemoException {
|
||||
|
||||
String signFlowId = sealSignRecord.getSignFlowid();
|
||||
String psnAccount = sealSignRecord.getPensonAccount();
|
||||
|
||||
String apiaddr = "/v3/sign-flow/" + signFlowId + "/sign-url";
|
||||
String jsonParm = "{\n" +
|
||||
|
||||
" \"clientType\": \"PC\",\n" +
|
||||
|
||||
" \"operator\": {\n" +
|
||||
" \"psnAccount\": \"" + psnAccount + "\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
/**
|
||||
* 获取批量签页面链接
|
||||
*
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static EsignHttpResponse batchSignUrl(StringIdsReq idsReq) throws EsignDemoException {
|
||||
|
||||
List<String> signFlowIds = idsReq.getIds();
|
||||
String psnAccount = idsReq.getPsnAccount();
|
||||
String apiaddr = "/v3/sign-flow/batch-sign-url";
|
||||
JSONObject paramObj = new JSONObject();
|
||||
paramObj.put("operatorId",idsReq.getPsnId());
|
||||
paramObj.put("signFlowIds",signFlowIds);
|
||||
paramObj.put("clientType","PC");
|
||||
String jsonParm = JSON.toJSONString(paramObj);
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
/**
|
||||
* 根据手机号获取账户id
|
||||
*
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static EsignHttpResponse identityInfo(StringIdsReq idsReq) throws EsignDemoException {
|
||||
|
||||
List<String> signFlowIds = idsReq.getIds();
|
||||
String psnAccount = idsReq.getPsnAccount();
|
||||
String apiaddr = "/v3/persons/identity-info?psnAccount=" +psnAccount;
|
||||
|
||||
String jsonParm = "{}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.GET;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取合同文件用印链接
|
||||
*
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static EsignHttpResponse usesealUrl(SealSignRecord sealSignRecord) throws EsignDemoException {
|
||||
String signFlowId = sealSignRecord.getSignFlowid();
|
||||
String apiaddr = "/v3/sign-flow/" + signFlowId + "/sign-url";
|
||||
|
||||
String psnAccount = sealSignRecord.getOrgnizeNamePsnAccount();
|
||||
String orgName = sealSignRecord.getOrgnizeName();
|
||||
|
||||
String jsonParm = "{\n" +
|
||||
" \"operator\": {\n" +
|
||||
|
||||
" \"psnAccount\": \"" + psnAccount + "\"\n" +
|
||||
" },\n" +
|
||||
" \"organization\": {\n" +
|
||||
" \"orgName\": \"" + orgName + "\"\n" +
|
||||
|
||||
" }\n" +
|
||||
"}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机构认证&授权页面链接
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static EsignHttpResponse deptIdentifyUrl(DeptIdentify deptIdentify) throws EsignDemoException {
|
||||
String apiaddr = "/v3/org-auth-url";
|
||||
String psnName = deptIdentify.getOperName();
|
||||
String phonenumber = deptIdentify.getOperPhone();
|
||||
String orgName = deptIdentify.getIdentifyName();
|
||||
String jsonParm = "{\n" +
|
||||
" \"orgAuthConfig\": {\n" +
|
||||
" \"orgName\": \"" + orgName + " \",\n" +
|
||||
" \"transactorInfo\": {\n" +
|
||||
" \"psnAccount\": \"" + phonenumber + "\",\n" +
|
||||
" \"psnInfo\": {\n" +
|
||||
" \"psnName\": \"" + psnName + "\",\n" +
|
||||
" \"psnMobile\": \"" + phonenumber + "\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"authorizeConfig\": {\n" +
|
||||
" \"authorizedScopes\": [\n" +
|
||||
" \"get_org_identity_info\",\n" +
|
||||
" \"get_psn_identity_info\",\n" +
|
||||
" \"org_initiate_sign\",\n" +
|
||||
" \"psn_initiate_sign\",\n" +
|
||||
" \"manage_org_resource\",\n" +
|
||||
" \"manage_psn_resource\",\n" +
|
||||
" \"use_org_order\"\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询企业认证状态
|
||||
*/
|
||||
public static EsignHttpResponse getDeptIdentifyInfo(DeptIdentify deptIdentify) throws EsignDemoException {
|
||||
String apiaddr = "/v3/organizations/identity-info?orgName=" + deptIdentify.getIdentifyName();
|
||||
|
||||
String jsonParm = "{}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.GET;
|
||||
//生成签名鉴权方式的的header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询企业内部印章
|
||||
*/
|
||||
public static EsignHttpResponse deptIdentifySealList(String orgId) throws EsignDemoException {
|
||||
int pageNum = 1;
|
||||
int pageSize = 10;
|
||||
String apiaddr = "/v3/seals/org-own-seal-list?orgId=" + orgId + "&pageNum=" + pageNum + "&pageSize=" + pageSize;
|
||||
String jsonParm = null;
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.GET;
|
||||
//生成签名鉴权方式的的header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件签名印章位置
|
||||
*
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static EsignHttpResponse getPositions(SealSignRecord sealSignRecord) throws EsignDemoException {
|
||||
String fileId = sealSignRecord.getFileid();
|
||||
String apiaddr = "/v3/files/" + fileId + "/keyword-positions";
|
||||
String jsonParm = "{\n" +
|
||||
" \"keywords\": [\n" +
|
||||
" \"仲裁员:\",\n" +
|
||||
" \"(仲裁委员会盖章)\"\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成请求签名鉴权方式的Header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建机构图片印章
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static EsignHttpResponse createOrgByImage(DeptIdentify deptIdentify,String sealName, String filePath) throws EsignDemoException {
|
||||
String apiaddr = "/v3/seals/org-seals/create-by-image";
|
||||
String orgId = deptIdentify.getOrgId();
|
||||
//上传印章图片
|
||||
//步骤一:获取印章图片上传地址fileUploadUrl
|
||||
EsignHttpResponse response1 = SealUtil.getFileUploadUrl(filePath);
|
||||
JSONObject jsonObject1 = JSONObject.parseObject(response1.getBody());
|
||||
String fileUploadUrl = jsonObject1.getJSONObject("data").getString("fileUploadUrl");
|
||||
//步骤二:将印章图片文件流上传到fileUploadUrl
|
||||
EsignHttpResponse response2 = SealUtil.fileStreamUpload(fileUploadUrl, filePath);
|
||||
JSONObject jsonObject2 = JSONObject.parseObject(response2.getBody());
|
||||
int errCode = jsonObject2.getIntValue("errCode");
|
||||
if (errCode == 0) { //业务码,0表示成功,非0表示异常。
|
||||
//获取步骤一里面的fileKey
|
||||
String sealImageFileKey = jsonObject1.getJSONObject("data").getString("fileKey");
|
||||
|
||||
//请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
|
||||
String jsonParm = "{\n" +
|
||||
" \"orgId\": \"" + orgId + "\",\n" +
|
||||
" \"sealImageFileKey\": \"" + sealImageFileKey + "\",\n" +
|
||||
" \"sealName\": \"" + sealName + "\",\n" +
|
||||
" \"sealWidth\": 50,\n" +
|
||||
" \"sealHeight\": 50,\n" +
|
||||
" \"sealBizType\": \"COMMON\"\n" +
|
||||
"}";
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.POST;
|
||||
//生成签名鉴权方式的的header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询指定印章详情(机构)
|
||||
*/
|
||||
|
||||
public static EsignHttpResponse getOrgSeal(String orgId, String sealId) throws EsignDemoException {
|
||||
String apiaddr = "/v3/seals/org-seal-info?orgId=" + orgId + "&sealId=" + sealId;
|
||||
|
||||
//请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
|
||||
String jsonParm = null;
|
||||
//请求方法
|
||||
EsignRequestType requestType = EsignRequestType.GET;
|
||||
//生成签名鉴权方式的的header
|
||||
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, false);
|
||||
//发起接口请求
|
||||
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
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 com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Request;
|
||||
import com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Response;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
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 = "http://121.40.189.20:9000/API/uploadPath/upload/ca2ca4697e5449ff9b9d23f95b221f58.pdf";
|
||||
// String pdfFilePath = "http://121.40.189.20:9000/API/uploadPath/upload/2023/11/14/ca2ca4697e5449ff9b9d23f95b221f58.pdf";
|
||||
String pdfFilePath ="D:/home/unzip/b92a7291-441e-4fad-95b4-7305f206eabd/仲裁材料/二、案件基本材料/2-1 仲裁申请书.pdf";
|
||||
try{
|
||||
// 读取文件内容到字节数组
|
||||
byte[] fileBytes = readFileToBytes(pdfFilePath);
|
||||
// 将字节数组转换为Base64值
|
||||
String base64String = encodeBytesToBase64(fileBytes);
|
||||
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户 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(base64String);
|
||||
req.setIsPdf(true);
|
||||
req.setPdfPageNumber(1L);
|
||||
String[] itemNames1 = {"申请人", "统一社会信用代码", "负责人", "住所", "联系地址"
|
||||
, "委托代理人", "联系电话", "电子邮件", "被申请人", "居民身份证号码", "仲裁请求", "事实和理由"};
|
||||
req.setItemNames(itemNames1);
|
||||
// 返回的resp是一个SmartStructuralOCRV2Response的实例,与请求对象对应
|
||||
SmartStructuralOCRV2Response resp = client.SmartStructuralOCRV2(req);
|
||||
|
||||
|
||||
//解析数据
|
||||
String s = SmartStructuralOCRV2Response.toJsonString(resp);
|
||||
// 解析JSON数据
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
JSONArray structuralList = jsonObject.getJSONArray("StructuralList");
|
||||
// 遍历StructuralList中的Groups,获取Key对应的AutoName和Value对应的AutoContent
|
||||
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 + ":" + autoContent;
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(","); // 在已有内容的情况下添加逗号分隔符
|
||||
}
|
||||
stringBuilder.append(text); // 拼接当前的字符串
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("stringBuilder======"+stringBuilder.toString());
|
||||
// 将字符串按逗号分隔符切割
|
||||
String[] fields = stringBuilder.toString().split(",");
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
for (String field : fields) {
|
||||
// 对于每个字段,再按冒号分隔符拆分出键和值
|
||||
String[] keyValue = field.split(":");
|
||||
if (keyValue.length == 2) { // 对于合法的键值对,将其添加到JSON对象中
|
||||
String key = keyValue[0];
|
||||
String value = keyValue[1];
|
||||
// 判断Map中是否已存在该键
|
||||
if (map.containsKey(key)) {
|
||||
// 如果已存在,获取该键对应的值,并将新的值添加到集合中
|
||||
List<String> values = map.get(key);
|
||||
values.add(value);
|
||||
} else {
|
||||
// 如果不存在,创建一个新的集合,并将值添加到集合中
|
||||
List<String> values = new ArrayList<>();
|
||||
values.add(value);
|
||||
map.put(key, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(map);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
private static byte[] readFileToBytes(String filePath) throws IOException {
|
||||
File file = new File(filePath);
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
byte[] fileBytes = new byte[(int) file.length()];
|
||||
fileInputStream.read(fileBytes);
|
||||
fileInputStream.close();
|
||||
return fileBytes;
|
||||
}
|
||||
|
||||
private static String encodeBytesToBase64(byte[] bytes) {
|
||||
return Base64.getEncoder().encodeToString(bytes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@Slf4j
|
||||
public class UnZipFileUtils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file = new File("D:\\home\\ruoyi\\仲裁委项目-测试单.zip");
|
||||
String targetPath = "D:\\home\\unzip\\";
|
||||
unZipFile(file,targetPath);
|
||||
}
|
||||
|
||||
public static boolean unZipFile(File aboriginalFile, String targetPath) {
|
||||
if (!aboriginalFile.exists()) {
|
||||
log.error("此文件不存在:", aboriginalFile.getPath());
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ZipFile srcZipFile = new ZipFile(aboriginalFile, Charset.forName("GBK"));
|
||||
for (Enumeration enumeration = srcZipFile.entries(); enumeration.hasMoreElements(); ) {
|
||||
ZipEntry entryZip = (ZipEntry) enumeration.nextElement();
|
||||
//若是文件夹,就创建文件夹
|
||||
if (entryZip.isDirectory()) {
|
||||
String directPath = targetPath + File.separator + entryZip.getName();
|
||||
File directFile = new File(directPath);
|
||||
boolean makeDirs = directFile.mkdirs();
|
||||
System.out.println("创建文件夹是否成功:" + makeDirs);
|
||||
} else {
|
||||
//若是文件,就创建文件
|
||||
File sourceFile = new File(targetPath + File.separator + entryZip.getName());
|
||||
if (!sourceFile.getParentFile().exists()) {
|
||||
boolean mDirect = sourceFile.getParentFile().mkdirs();
|
||||
System.out.println("创建压缩文件时,创建父文件夹是否成功:" + mDirect);
|
||||
}
|
||||
boolean newUnZipFile = sourceFile.createNewFile();
|
||||
if (newUnZipFile) {
|
||||
// 将压缩文件内容写入到这个文件中
|
||||
try {
|
||||
InputStream is = srcZipFile.getInputStream(entryZip);
|
||||
FileOutputStream fos = new FileOutputStream(sourceFile);
|
||||
int len;
|
||||
byte[] buf = new byte[2048];
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("解压失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("解压失败", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void getFiles(File fileSource, List<File> allFiles) {
|
||||
if (!fileSource.exists()) {
|
||||
System.out.println("目录不存在");
|
||||
return;
|
||||
}
|
||||
File[] fileArray = fileSource.listFiles();
|
||||
if (fileArray != null && fileArray.length > 0) {
|
||||
for (File fileIter : fileArray) {
|
||||
if (fileIter.isDirectory()) {
|
||||
getFiles(fileIter, allFiles);
|
||||
} else {
|
||||
allFiles.add(fileIter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class ZipFileUtils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String file1 = "F:\\testZip\\123.pdf";
|
||||
String file2 = "F:\\testZip\\456.png";
|
||||
String zipFileOutPath = "F:\\testZip\\outputfile123.zip";
|
||||
|
||||
try {
|
||||
FileOutputStream zfous = new FileOutputStream(zipFileOutPath);
|
||||
ZipOutputStream zipFileOutstream = new ZipOutputStream(zfous);
|
||||
FileInputStream fis1 = new FileInputStream(file1);
|
||||
FileInputStream fis2 = new FileInputStream(file2);
|
||||
zipFile(file1, fis1, zipFileOutstream);
|
||||
zipFile(file2, fis2, zipFileOutstream);
|
||||
|
||||
zipFileOutstream.close();
|
||||
zfous.close();
|
||||
System.out.println("文件成功打包成ZIP文件!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void zipFile(String zipfilePath, FileInputStream zipFileinsteam, ZipOutputStream zipfileOut)
|
||||
throws IOException {
|
||||
ZipEntry zipfileEntry = new ZipEntry(new File(zipfilePath).getName());
|
||||
zipfileOut.putNextEntry(zipfileEntry);
|
||||
|
||||
// 从输入流读取数据并写入ZIP文件
|
||||
byte[] bytes = new byte[1024];
|
||||
int length;
|
||||
while ((length = zipFileinsteam.read(bytes)) >= 0) {
|
||||
zipfileOut.write(bytes, 0, length);
|
||||
}
|
||||
zipfileOut.closeEntry();
|
||||
zipFileinsteam.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user