|
@@ -29,7 +29,6 @@ import cfca.paperless.dto.response.tx40.VerifyPdfSealResponse;
|
|
|
import cn.hutool.core.io.file.FileReader;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
@@ -46,11 +45,10 @@ import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
-import org.springblade.core.tool.utils.DateUtil;
|
|
|
-import org.springblade.core.tool.utils.FileUtil;
|
|
|
-import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
import org.springblade.evisa.redissionUtil.DistributedRedisLock;
|
|
|
import org.springblade.evisa.service.EVisaService;
|
|
|
+import org.springblade.evisa.utils.FileUtils;
|
|
|
import org.springblade.evisa.utils.PDFUtils;
|
|
|
import org.springblade.evisa.vo.*;
|
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
@@ -411,6 +409,7 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
try {
|
|
|
//获取需要签章的数据
|
|
|
List<TaskApprovalVO.ApprovalFile> files = taskFile.getApprovalFileList();
|
|
|
+
|
|
|
//这里的文件只会是一张拼接好的PDF
|
|
|
for (TaskApprovalVO.ApprovalFile file : files) {
|
|
|
|
|
@@ -427,52 +426,100 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
}
|
|
|
String contractId = this.taskClient.queryTaskContractId(task.getParallelProcessInstanceId());
|
|
|
String ids = String.join(",", eVisaConfigList);
|
|
|
- String sqlinfo = " SELECT a.id,a.pyzbx ,a.pyzby,(SELECT signature_file_url from m_sign_pfx_file where is_register=1 and certificate_user_id='" + task.getUserId() + "' and is_deleted=0 ) as signature_file_url from m_textdict_info a where a.type =2 and a.id in (" + ids + ") and sig_role_id in (SELECT DISTINCT c.role_id from m_project_assignment_user c where c.contract_id=" + contractId + " and user_id=" + task.getUserId() + " and c.is_deleted=0 )";
|
|
|
- List<Map<String, Object>> maps = jdbcTemplate.queryForList(sqlinfo);
|
|
|
- System.out.println("个人-user-id" + task.getUserId() + "--SQL=" + sqlinfo);
|
|
|
- if (maps == null || maps.size() <= 0) {
|
|
|
- //没有签章,不执行电签
|
|
|
- RedisTemplate.delete("sign-" + task.getFormDataId());
|
|
|
- return NOT_PFX_OR_FILE;
|
|
|
- }
|
|
|
- //准备签章策略
|
|
|
- List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
- for (Map<String, Object> eVisaConfig : maps) {
|
|
|
- //设置签章策略
|
|
|
- SealStrategyVO vo = new SealStrategyVO();
|
|
|
- vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + task.getUserId());
|
|
|
- vo.setSealPassword(task.getUserId().toString().substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
- vo.setSealPerson(task.getNickName());
|
|
|
- //设置签字文件
|
|
|
- vo.setImageUrl(eVisaConfig.get("signature_file_url") + "");
|
|
|
- vo.setSealType("3");
|
|
|
- vo.setKeyword(eVisaConfig.get("id") + "");
|
|
|
- vo.setOffSetX(eVisaConfig.get("pyzbx") + "");
|
|
|
- vo.setOffSetY(eVisaConfig.get("pyzby") + "");
|
|
|
- sealStrategyVOS.add(vo);
|
|
|
- }
|
|
|
- SealPdfVO pdfVO = new SealPdfVO();
|
|
|
- pdfVO.setStrategyVoList(sealStrategyVOS);
|
|
|
|
|
|
- //获取字节
|
|
|
- byte[] fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(pdfUrl));
|
|
|
- //执行电签
|
|
|
- Object[] result = this.signPdfByAXQZ(pdfVO, fileByte);
|
|
|
- if (result != null) {
|
|
|
- if (result[0] != null) {
|
|
|
- MultipartFile newFiles = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", "text/plain", IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0])));
|
|
|
- //重新上传
|
|
|
- BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(newFiles);
|
|
|
- if (bladeFile != null) {
|
|
|
- resultMessage = SUCCESS + "@@@@" + bladeFile.getLink();
|
|
|
+ //判断电签类型
|
|
|
+
|
|
|
+ if (taskFile.getRemarkType().equals("2")) {//东方 中讯 daMap.put("keyWord","1673632651551965184");
|
|
|
+
|
|
|
+ String sqlinfo = " SELECT a.id as keyWord,(SELECT acc_code from blade_user where id='" + task.getUserId() + "' and is_deleted=0 ) as sealId from m_textdict_info a where a.type =2 and a.id in (" + ids + ") and sig_role_id in (SELECT DISTINCT c.role_id from m_project_assignment_user c where c.contract_id=" + contractId + " and user_id=" + task.getUserId() + " and c.is_deleted=0 )";
|
|
|
+ System.out.println("东方中讯-个人-user-id" + task.getUserId() + "--SQL=" + sqlinfo);
|
|
|
+ List<Map<String, Object>> maps = jdbcTemplate.queryForList(sqlinfo);
|
|
|
+ if(maps != null && !maps.isEmpty()){
|
|
|
+ String fileUrl = pdfUrl;
|
|
|
+ for(Map<String, Object> dataMap : maps){
|
|
|
+ HashMap<String,Object> daMa = new HashMap<>();
|
|
|
+ daMa.put("keyWord",dataMap.get("keyWord"));
|
|
|
+ daMa.put("sealId",dataMap.get("sealId"));
|
|
|
+
|
|
|
+ byte[] fileByte;
|
|
|
+ if(fileUrl.indexOf("aliyuncs.com")>=0){
|
|
|
+ fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(fileUrl));
|
|
|
+ }else {
|
|
|
+ FileReader fileReader = new FileReader(fileUrl);
|
|
|
+ fileByte = fileReader.readBytes();
|
|
|
+ }
|
|
|
+
|
|
|
+ String originalFileB64 = Base64.toBase64String(fileByte);
|
|
|
+ daMa.put("fileB64", originalFileB64);
|
|
|
+ daMa.put("lastSignFlag", false);
|
|
|
+ String reData = signPdfByDFZX(daMa);
|
|
|
+ if(reData.indexOf("success@")>=0){
|
|
|
+ fileUrl = reData.split("@@@@")[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(fileUrl.indexOf("aliyuncs.com")>=0){
|
|
|
+ return E_VISA_ERROR;
|
|
|
+ }else{
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFile(fileUrl.substring(fileUrl.lastIndexOf("/")+1,fileUrl.length()),fileUrl);
|
|
|
+ if (bladeFile != null) {
|
|
|
+ System.out.println("pdf上传="+bladeFile.getLink());
|
|
|
+ return SUCCESS + "@@@@" + bladeFile.getLink();
|
|
|
+ } else {
|
|
|
+ return E_VISA_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ RedisTemplate.delete("sign-" + task.getFormDataId());
|
|
|
+ return SUCCESS + "@@@@" + taskFile.getApprovalFileList().get(0).getFileUrl();
|
|
|
+ }
|
|
|
+ } else { //安心签证
|
|
|
+ String sqlinfo = " SELECT a.id,a.pyzbx ,a.pyzby,(SELECT signature_file_url from m_sign_pfx_file where is_register=1 and certificate_user_id='" + task.getUserId() + "' and is_deleted=0 ) as signature_file_url from m_textdict_info a where a.type =2 and a.id in (" + ids + ") and sig_role_id in (SELECT DISTINCT c.role_id from m_project_assignment_user c where c.contract_id=" + contractId + " and user_id=" + task.getUserId() + " and c.is_deleted=0 )";
|
|
|
+ List<Map<String, Object>> maps = jdbcTemplate.queryForList(sqlinfo);
|
|
|
+ System.out.println("安心签-个人-user-id" + task.getUserId() + "--SQL=" + sqlinfo);
|
|
|
+ if (maps == null || maps.size() <= 0) {
|
|
|
+ //没有签章,不执行电签
|
|
|
+ RedisTemplate.delete("sign-" + task.getFormDataId());
|
|
|
+ return NOT_PFX_OR_FILE;
|
|
|
+ }
|
|
|
+ //准备签章策略
|
|
|
+ List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
+ for (Map<String, Object> eVisaConfig : maps) {
|
|
|
+ //设置签章策略
|
|
|
+ SealStrategyVO vo = new SealStrategyVO();
|
|
|
+ vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + task.getUserId());
|
|
|
+ vo.setSealPassword(task.getUserId().toString().substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ vo.setSealPerson(task.getNickName());
|
|
|
+ //设置签字文件
|
|
|
+ vo.setImageUrl(eVisaConfig.get("signature_file_url") + "");
|
|
|
+ vo.setSealType("3");
|
|
|
+ vo.setKeyword(eVisaConfig.get("id") + "");
|
|
|
+ vo.setOffSetX(eVisaConfig.get("pyzbx") + "");
|
|
|
+ vo.setOffSetY(eVisaConfig.get("pyzby") + "");
|
|
|
+ sealStrategyVOS.add(vo);
|
|
|
+ }
|
|
|
+ SealPdfVO pdfVO = new SealPdfVO();
|
|
|
+ pdfVO.setStrategyVoList(sealStrategyVOS);
|
|
|
+
|
|
|
+ //获取字节
|
|
|
+ byte[] fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(pdfUrl));
|
|
|
+ //执行电签
|
|
|
+ Object[] result = this.signPdfByAXQZ(pdfVO, fileByte);
|
|
|
+ if (result != null) {
|
|
|
+ if (result[0] != null) {
|
|
|
+ MultipartFile newFiles = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", "text/plain", IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0])));
|
|
|
+ //重新上传
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(newFiles);
|
|
|
+ if (bladeFile != null) {
|
|
|
+ resultMessage = SUCCESS + "@@@@" + bladeFile.getLink();
|
|
|
+ } else {
|
|
|
+ resultMessage = E_VISA_ERROR;
|
|
|
+ }
|
|
|
} else {
|
|
|
- resultMessage = E_VISA_ERROR;
|
|
|
+ resultMessage = E_VISA_ERROR + "####" + result[2];
|
|
|
}
|
|
|
} else {
|
|
|
- resultMessage = E_VISA_ERROR + "####" + result[2];
|
|
|
+ resultMessage = E_VISA_ERROR;
|
|
|
}
|
|
|
- } else {
|
|
|
- resultMessage = E_VISA_ERROR;
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -543,11 +590,6 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
//返回结果集
|
|
|
if (result != null) {
|
|
|
if (result[0] != null) {
|
|
|
- /*byte[] byteArray = IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0]));
|
|
|
- String dataUrl = "C:\\pdfFiles\\" + SnowFlakeUtil.getId() + ".pdf";
|
|
|
- File file1 = new File(dataUrl);
|
|
|
- FileUtils.writeByteArrayToFile(file1, byteArray);*/
|
|
|
-
|
|
|
MultipartFile newFiles = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", "text/plain", IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0])));
|
|
|
BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(newFiles);
|
|
|
if (bladeFile != null) {
|
|
@@ -596,10 +638,6 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
signVO.setImageUrl(index.getUrl()); //固定签章
|
|
|
signVO.setSealType("2");//坐标签章
|
|
|
|
|
|
- /*xy坐标后面构造签章策略时再计算
|
|
|
- signVO.setLx(index.getLx()); //x轴
|
|
|
- signVO.setLy(index.getLy()); //y轴*/
|
|
|
-
|
|
|
signVO.setPage(index.getPage()); //page页码
|
|
|
sealStrategyVOS.add(signVO);
|
|
|
}
|
|
@@ -638,67 +676,91 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /* public static void main(String[] args) throws Exception {
|
|
|
+ String pdfPath ="/Users/hongchuangyanfa/Downloads/d2cf9f4ee9bef0cad6c1105e86b3ab09.pdf";
|
|
|
+ String sealId ="0ff724e095fc4a16b9c9c25ebe44e68f";
|
|
|
+ String formDataId ="vv";
|
|
|
+ List<Map<String,Object>> maps = new ArrayList<>();
|
|
|
+ Map<String,Object> daMap = new HashMap<>();
|
|
|
+ daMap.put("keyWord","1715216098053324800");
|
|
|
+ daMap.put("sealId",sealId);
|
|
|
+ maps.add(daMap);
|
|
|
+
|
|
|
+ Map<String,Object> daMap2 = new HashMap<>();
|
|
|
+ daMap2.put("keyWord","1673632651463884");
|
|
|
+ daMap2.put("sealId",sealId);
|
|
|
+ maps.add(daMap2);
|
|
|
+
|
|
|
+ String fileUrl =pdfPath;
|
|
|
+ for(int i=0;i<maps.size();i++){
|
|
|
+ HashMap daMa = (HashMap) maps.get(i);
|
|
|
+ FileReader fileReader = new FileReader(fileUrl);
|
|
|
+ String originalFileB64 = Base64.toBase64String(fileReader.readBytes());
|
|
|
+ daMa.put("fileB64", originalFileB64);
|
|
|
+
|
|
|
+ daMa.put("lastSignFlag", false);
|
|
|
+
|
|
|
+ if(maps.size()==1){
|
|
|
+ signPdfByDFZX(daMa);
|
|
|
+ }else{
|
|
|
+ String reData = signPdfByDFZX(daMa);
|
|
|
+ if(reData.indexOf("success@")>=0){
|
|
|
+ fileUrl = reData.split("@@@@")[1];
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ System.out.println(fileUrl);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
/**
|
|
|
* 东方 中讯
|
|
|
*
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public static void signPdfByDFZX(SealPdfVO pdfVO, byte[] fileByte) throws Exception {
|
|
|
- String url = "http://192.168.0.120:9125/FrontSys/SealServicezx/FileSignByPoint";
|
|
|
- HashMap<String, Object> request = new HashMap<>();
|
|
|
- String picFilePath = "/Users/hongchuangyanfa/Desktop/pdf/1606191494346047488.pdf".toLowerCase();//测试文件的绝对路径
|
|
|
-
|
|
|
- FileReader fileReader = new FileReader(picFilePath);
|
|
|
- String originalFileB64 = Base64.toBase64String(fileReader.readBytes());
|
|
|
- request.put("sealId", "abb54d49555b479b8216b0f3b03bf41f");
|
|
|
- request.put("fileB64", originalFileB64);
|
|
|
- request.put("pointX", 100);
|
|
|
- request.put("pointY", 100);
|
|
|
- request.put("showHeight", 1000);
|
|
|
- request.put("showWidth", 600);
|
|
|
- request.put("lastSignFlag", false);
|
|
|
-
|
|
|
- HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
|
|
- httpRequestFactory.setConnectionRequestTimeout(30000);
|
|
|
- httpRequestFactory.setConnectTimeout(30000);
|
|
|
- httpRequestFactory.setReadTimeout(30000);
|
|
|
- RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
|
|
|
- // 设置编码格式为UTF-8
|
|
|
- List<HttpMessageConverter<?>> converterList = restTemplate.getMessageConverters();
|
|
|
- HttpMessageConverter<?> converterTarget = null;
|
|
|
- for (HttpMessageConverter<?> item : converterList) {
|
|
|
- if (item.getClass() == StringHttpMessageConverter.class) {
|
|
|
- converterTarget = item;
|
|
|
- break;
|
|
|
+ public static String signPdfByDFZX(HashMap<String, Object> request) {
|
|
|
+ String url = "http://47.110.251.215:9125/FrontSysGs/SealServicezx/FileSignByKeyWord";
|
|
|
+ String sysLocalFileUrl = FileUtils.getSysLocalFileUrl();
|
|
|
+ String filecode = SnowFlakeUtil.getId() + "";
|
|
|
+ String dataFileUrl = sysLocalFileUrl+"/pdf/"+filecode+".pdf";
|
|
|
+ try {
|
|
|
+ HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
|
|
+ httpRequestFactory.setConnectionRequestTimeout(30000);
|
|
|
+ httpRequestFactory.setConnectTimeout(30000);
|
|
|
+ httpRequestFactory.setReadTimeout(30000);
|
|
|
+ RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
|
|
|
+ // 设置编码格式为UTF-8
|
|
|
+ List<HttpMessageConverter<?>> converterList = restTemplate.getMessageConverters();
|
|
|
+ HttpMessageConverter<?> converterTarget = null;
|
|
|
+ for (HttpMessageConverter<?> item : converterList) {
|
|
|
+ if (item.getClass() == StringHttpMessageConverter.class) {
|
|
|
+ converterTarget = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (converterTarget != null) {
|
|
|
- converterList.remove(converterTarget);
|
|
|
- }
|
|
|
- HttpMessageConverter<?> converter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
|
|
|
- converterList.add(1, converter);
|
|
|
+ if (converterTarget != null) {
|
|
|
+ converterList.remove(converterTarget);
|
|
|
+ }
|
|
|
+ HttpMessageConverter<?> converter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
|
|
|
+ converterList.add(1, converter);
|
|
|
|
|
|
- HashMap<String, Object> retData = restTemplate.postForObject(url, request, HashMap.class);
|
|
|
+ HashMap<String, Object> retData = restTemplate.postForObject(url, request, HashMap.class);
|
|
|
|
|
|
- String code = retData.get("code").toString();
|
|
|
- String msg = retData.get("msg").toString();
|
|
|
+ String code = retData.get("code").toString();
|
|
|
+ String msg = retData.get("msg").toString();
|
|
|
|
|
|
- if (!"0".equals(code)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!"0".equals(code)) {
|
|
|
+ return ERROR + "@@@@" + msg;
|
|
|
+ }
|
|
|
|
|
|
- String fileB64 = retData.get("fileB64").toString();
|
|
|
+ String fileB642 = retData.get("fileB64").toString();
|
|
|
|
|
|
- try {
|
|
|
- FileOutputStream fout = new FileOutputStream(picFilePath.replace(".pdf", "-签名后.pdf"));
|
|
|
- fout.write(Base64.decode(fileB64));//生成base64字符串格式文件
|
|
|
+ FileOutputStream fout = new FileOutputStream(dataFileUrl);
|
|
|
+ fout.write(Base64.decode(fileB642));//生成base64字符串格式文件
|
|
|
fout.close();
|
|
|
- System.out.println("文件保存成功");
|
|
|
+ return SUCCESS + "@@@@" + dataFileUrl;
|
|
|
} catch (Exception e) {
|
|
|
- System.out.println("文件保存失败");
|
|
|
- e.printStackTrace();
|
|
|
+ return ERROR + "@@@@异常出错";
|
|
|
}
|
|
|
}
|
|
|
|