|
@@ -59,10 +59,12 @@ import org.springblade.evisa.utils.PDFUtils;
|
|
|
import org.springblade.evisa.vo.*;
|
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
|
import org.springblade.manager.entity.SignPfxFile;
|
|
|
+import org.springblade.manager.entity.TextdictInfo;
|
|
|
import org.springblade.manager.feign.ContractClient;
|
|
|
import org.springblade.manager.feign.SignPfxClient;
|
|
|
import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springblade.system.cache.ParamCache;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
@@ -71,6 +73,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.mock.web.MockMultipartFile;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -82,6 +85,7 @@ import javax.imageio.metadata.IIOMetadataNode;
|
|
|
import javax.imageio.stream.ImageOutputStream;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
+import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
@@ -1445,168 +1449,217 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // @Scheduled(cron = "0/40 * * * * ?")
|
|
|
+ public void SignInfo() throws IOException {
|
|
|
+ //获取字节
|
|
|
+ String pdfUrl="/Users/hongchuangyanfa/Desktop/excel/TJ06标咨询意见单.pdf";
|
|
|
+ byte[] fileByte = IOUtils.toByteArray(new FileInputStream(new File(pdfUrl)));
|
|
|
+
|
|
|
+ SealPdfVO pdfVO = new SealPdfVO();
|
|
|
+ List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ String userId ="1794916072011603970";
|
|
|
+ SealStrategyVO vo = new SealStrategyVO();
|
|
|
+ vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId);
|
|
|
+
|
|
|
+ if(userId.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo.setSealPassword(userId);
|
|
|
+ }else{
|
|
|
+ vo.setSealPassword(userId.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo.setSealPerson("谭立剑");
|
|
|
+ //设置签字文件
|
|
|
+ vo.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240530/d935381e0ba7e9a7d97cbcebd2b25702.png");
|
|
|
+ vo.setSealType("3");
|
|
|
+ vo.setKeyword("1808342935356309504");
|
|
|
+
|
|
|
+ String userId2 ="1794914652935954434";
|
|
|
+ SealStrategyVO vo2 = new SealStrategyVO();
|
|
|
+ vo2.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId2);
|
|
|
+ if(userId2.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo2.setSealPassword(userId2);
|
|
|
+ }else{
|
|
|
+ vo2.setSealPassword(userId2.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo2.setSealPerson("黎军丰");
|
|
|
+ //设置签字文件
|
|
|
+ vo2.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240530/e7f435510f9b4dc7080d05d8d6061de6.png");
|
|
|
+ vo2.setSealType("3");
|
|
|
+ vo2.setKeyword("1808342935364698112");
|
|
|
+
|
|
|
+ String userId3 ="1794914652935954434";
|
|
|
+ SealStrategyVO vo3 = new SealStrategyVO();
|
|
|
+ vo3.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId3);
|
|
|
+ if(userId3.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo3.setSealPassword(userId3);
|
|
|
+ }else{
|
|
|
+ vo3.setSealPassword(userId3.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo3.setSealPerson("李梦君");
|
|
|
+ //设置签字文件
|
|
|
+ vo3.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240419/2a56ec080c61c812875f797658414de1.png");
|
|
|
+ vo3.setSealType("3");
|
|
|
+ vo3.setKeyword("1810847886083096576");
|
|
|
+
|
|
|
+ String userId4 ="104326754034";
|
|
|
+ SealStrategyVO vo4 = new SealStrategyVO();
|
|
|
+ vo3.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId4);
|
|
|
+ if(userId4.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo4.setSealPassword(userId4);
|
|
|
+ }else{
|
|
|
+ vo4.setSealPassword(userId4.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo4.setSealPerson("王涛");
|
|
|
+ //设置签字文件
|
|
|
+ vo4.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240419/0f6f989997036b9f4d3a3a288da96dcc.png");
|
|
|
+ vo4.setSealType("3");
|
|
|
+ vo4.setKeyword("1810847886083096576");
|
|
|
+
|
|
|
+ //设置签章策略
|
|
|
+ SealStrategyVO vo5 = new SealStrategyVO();
|
|
|
+ vo5.setSealCode(EVisaConstant.SIGN_SEAL_CODE + "1808350880450215936");
|
|
|
+ vo5.setSealPassword("123456");
|
|
|
+ vo5.setSealPerson("万邦工程管理咨询有限公司");
|
|
|
+ //设置签字文件
|
|
|
+ vo5.setImageUrl("http://183.247.216.148:9000//minio-oss-chongqing/upload/20240826/0726789415206b444d0bbe88840cf459.png");
|
|
|
+ vo5.setSealType("3");
|
|
|
+ vo5.setCompanySeal(true);
|
|
|
+ vo5.setKeyword("1808342935356309504");
|
|
|
+
|
|
|
+
|
|
|
+ // 6期
|
|
|
+
|
|
|
+ String userId6 ="1796388593051426817";
|
|
|
+ SealStrategyVO vo6 = new SealStrategyVO();
|
|
|
+ vo6.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId6);
|
|
|
+ if(userId6.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo6.setSealPassword(userId6);
|
|
|
+ }else{
|
|
|
+ vo6.setSealPassword(userId6.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo6.setSealPerson("刘宝平");
|
|
|
+ //设置签字文件
|
|
|
+ vo6.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240605/e234e767e38d3e0c84c81dffab7f3c19.png");
|
|
|
+ vo6.setSealType("3");
|
|
|
+ vo6.setKeyword("1808342935356309504");
|
|
|
+
|
|
|
+
|
|
|
+ String userId7 ="1796388092851314689";
|
|
|
+ SealStrategyVO vo7 = new SealStrategyVO();
|
|
|
+ vo7.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId7);
|
|
|
+ if(userId7.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo7.setSealPassword(userId7);
|
|
|
+ }else{
|
|
|
+ vo7.setSealPassword(userId7.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo7.setSealPerson("李富生");
|
|
|
+ //设置签字文件
|
|
|
+ vo7.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240531/d76792ab80aae67d5640d88813bd4175.png");
|
|
|
+ vo7.setSealType("3");
|
|
|
+ vo7.setKeyword("1808342935364698112");
|
|
|
+
|
|
|
+
|
|
|
+ String userId8 ="104326754036";
|
|
|
+ SealStrategyVO vo8 = new SealStrategyVO();
|
|
|
+ vo8.setSealCode(EVisaConstant.SIGN_SEAL_CODE + userId8);
|
|
|
+ if(userId8.length()<=EVisaConstant.USER_ID_SUB){
|
|
|
+ vo8.setSealPassword(userId8);
|
|
|
+ }else{
|
|
|
+ vo8.setSealPassword(userId8.substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ }
|
|
|
+ vo8.setSealPerson("许利利");
|
|
|
+ //设置签字文件
|
|
|
+ vo8.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240419/0ca5682ba89915e48b03676de4c1bc12.png");
|
|
|
+ vo8.setSealType("3");
|
|
|
+ vo8.setKeyword("1810847886083096576");
|
|
|
+
|
|
|
+ //设置签章策略
|
|
|
+ SealStrategyVO vo9 = new SealStrategyVO();
|
|
|
+ vo9.setSealCode(EVisaConstant.SIGN_SEAL_CODE + "1808351286031024128");
|
|
|
+ vo9.setSealPassword("123456");
|
|
|
+ vo9.setSealPerson("浙江同欣工程管理有限公司");
|
|
|
+ //设置签字文件
|
|
|
+ vo9.setImageUrl("https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240703/b40c2907e1cc4549a0f18df1504382ef.png");
|
|
|
+ vo9.setSealType("3");
|
|
|
+ vo9.setCompanySeal(true);
|
|
|
+ vo9.setKeyword("1808342935377281024");
|
|
|
+ //sealStrategyVOS.add(vo);
|
|
|
+ // sealStrategyVOS.add(vo2);
|
|
|
+ //sealStrategyVOS.add(vo3);
|
|
|
+ // 3期
|
|
|
+ // sealStrategyVOS.add(vo4);
|
|
|
+ // 6期
|
|
|
+ sealStrategyVOS.add(vo6);
|
|
|
+ sealStrategyVOS.add(vo7);
|
|
|
+ sealStrategyVOS.add(vo8);
|
|
|
+ sealStrategyVOS.add(vo9);
|
|
|
+
|
|
|
+ pdfVO.setStrategyVoList(sealStrategyVOS);
|
|
|
+ Object[] result = this.signPdfByAXQZ(pdfVO, fileByte);
|
|
|
+ if (result != null) {
|
|
|
+ if (result[0] != null) {
|
|
|
+ MultipartFile newFiles = null;
|
|
|
+ try {
|
|
|
+ newFiles = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", ContentType.APPLICATION_OCTET_STREAM.toString(), IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0])));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //重新上传
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(newFiles);
|
|
|
+
|
|
|
+ System.out.println(bladeFile.getLink());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* 单张PDF批量电签,返回电签后的PDF
|
|
|
- * @param vo
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public R<String> batchEVisa(SigInfoVO vo) {
|
|
|
+ public R<String> batchEVisa(SealPdfVO pdfVO) {
|
|
|
+ //获取字节
|
|
|
+ URL url = null;
|
|
|
try {
|
|
|
- List<SigInfoVO.SigInfo> list = vo.getList();
|
|
|
- String pdfUrl = vo.getPdfUrl();
|
|
|
-
|
|
|
- for (SigInfoVO.SigInfo sigInfo : list) {
|
|
|
- pdfUrl = myDoWork(sigInfo, pdfUrl);
|
|
|
- }
|
|
|
- return R.data(pdfUrl);
|
|
|
- }catch (Exception e){
|
|
|
- return R.fail(e.getMessage());
|
|
|
+ String fileUrl = CommonUtil.replaceOssUrl(pdfVO.getPdfFileUrl());
|
|
|
+ url = new URL(fileUrl);
|
|
|
+ } catch (MalformedURLException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- }
|
|
|
- public String myDoWork(SigInfoVO.SigInfo sig,String pdfUrl) throws Exception {
|
|
|
-
|
|
|
- PaperlessClient paperlessClient = new PaperlessClient(SIGN_HOST, SIGN_PORT, 300000, 1800000);
|
|
|
-
|
|
|
- paperlessClient.setSSL(false);
|
|
|
- /*******************************************************************************/
|
|
|
- SealPdfRequest sealPdfRequest = new SealPdfRequest();
|
|
|
- RequestHead requestHead = new RequestHead();
|
|
|
- String transactionNo = GUIDUtil.generateId();
|
|
|
- //机构编码非空
|
|
|
- String organizationCode = EVisaConstant.organizationCode;
|
|
|
- //操作员编码 可为空
|
|
|
- String operatorCode = "";
|
|
|
- //渠道编码 可为空
|
|
|
- String channelCode = "";
|
|
|
- //设置属性
|
|
|
- requestHead.setBasicInfo(transactionNo, organizationCode,operatorCode,channelCode);
|
|
|
-
|
|
|
- sealPdfRequest.setHead(requestHead);
|
|
|
- /*******************************************************************************/
|
|
|
- SealPdfRequestBody requestBody = new SealPdfRequestBody();
|
|
|
- //待签章文件
|
|
|
- byte[] pdfData = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(pdfUrl));
|
|
|
- // 数据源类型 1 pdf文件路径 2 pdf文件字节流
|
|
|
- String inputType = BaseConstants.INPUT_TYPE_FILEDATA;
|
|
|
- //设置数据源,数据源类型为2时,为空,数据源类型为1时,上送数据源路径(服务器可以访问到的文件路径)
|
|
|
- requestBody.setInputSource("");
|
|
|
- //数据源类型
|
|
|
- requestBody.setInputType(inputType);
|
|
|
- //数据源为2时,需上送 pdf文件数据
|
|
|
- requestBody.setPdfData(pdfData);
|
|
|
- //签章后文件保存地址,不为空时,直接将签章文件保存在此地址,不再返回签章后文档数据
|
|
|
- requestBody.setOutputFilepath("");
|
|
|
- //时间戳方式,默认为0;0:实时访问CFCA 时间戳服务;1:使用从CFCA购置并在本地部署的时间戳服务器产品;
|
|
|
- requestBody.setTimestampChannel(BaseConstants.TIME_STAMP_CHANNEL_CFCA);
|
|
|
-
|
|
|
- /************************ ②-2.构造机构章策略 *********************************************/
|
|
|
- SealStrategy sealStrategy = myGenerateSealStrategy(sig);
|
|
|
-
|
|
|
- requestBody.setSealStrategy(sealStrategy);
|
|
|
-
|
|
|
- sealPdfRequest.setBody(requestBody);
|
|
|
-
|
|
|
- /************************请求签章 ********************************************/
|
|
|
- ResponseDto responseDto = paperlessClient.execute(sealPdfRequest);
|
|
|
-
|
|
|
- /************************解析响应结果 *********************************************/
|
|
|
-
|
|
|
- SealPdfResponse sealPdfResponse = (SealPdfResponse)responseDto;
|
|
|
-
|
|
|
- ResponseHead responseHead = sealPdfResponse.getHead();
|
|
|
- SealPdfResponseBody responseBody = sealPdfResponse.getBody();
|
|
|
- String resultOutputFilepath = "";
|
|
|
- if(ClientConstants.CODE_SUCCESS.equals(responseHead.getCode())){
|
|
|
-
|
|
|
- resultOutputFilepath = responseBody.getOutputFilepath();
|
|
|
-
|
|
|
- byte[] pdf = responseBody.getPdf();
|
|
|
- System.out.println(pdf == null ? 0 : pdf.length);
|
|
|
-
|
|
|
- String resultPdfFileDataHash = responseBody.getPdfFileDataHash();
|
|
|
- System.out.println("resultPdfFileDataHash=" + resultPdfFileDataHash);
|
|
|
-
|
|
|
- if(cfca.paperless.base.util.StringUtil.isNotEmpty(resultOutputFilepath)) {
|
|
|
- System.out.println("文件已输出到:"+ resultOutputFilepath);
|
|
|
- } else {
|
|
|
- Random random = new Random();
|
|
|
- int i = random.nextInt(100000);
|
|
|
- String pdfFile = FileUtils.getSysLocalFileUrl() + "/archiveCheck/" + i +".pdf";
|
|
|
- resultOutputFilepath = pdfFile;
|
|
|
- IoUtil.write(resultOutputFilepath, pdf);
|
|
|
- System.out.println("文件已输出到:"+ resultOutputFilepath );
|
|
|
- BladeFile bladeFile = newIOSSClient.uploadFile("aa.pdf",pdfFile);
|
|
|
- if (bladeFile == null || StringUtils.isBlank(bladeFile.getLink())){
|
|
|
- throw new ServiceException("上传阿里云失败");
|
|
|
+ byte[] fileByte;
|
|
|
+ try {
|
|
|
+ fileByte = IOUtils.toByteArray(url);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //执行电签
|
|
|
+ Object[] result = this.signPdfByAXQZ(pdfVO, fileByte);
|
|
|
+ if (result != null) {
|
|
|
+ if (result[0] != null) {
|
|
|
+ MultipartFile newFiles = null;
|
|
|
+ try {
|
|
|
+ newFiles = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", ContentType.APPLICATION_OCTET_STREAM.toString(), IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0])));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- resultOutputFilepath = bladeFile.getLink();
|
|
|
- }
|
|
|
+ //重新上传
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(newFiles);
|
|
|
|
|
|
+ if (bladeFile != null) {
|
|
|
+ return R.data(bladeFile.getLink());
|
|
|
+ } else {
|
|
|
+ return R.data(bladeFile.getLink());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.fail("无法获取pdf路径");
|
|
|
+ }
|
|
|
} else {
|
|
|
- throw new ServiceException(" NG,Code:"+responseHead.getCode()+",Message:"+responseHead.getMessage());
|
|
|
+ return R.fail("电签解析失败");
|
|
|
}
|
|
|
-
|
|
|
- return resultOutputFilepath;
|
|
|
- }
|
|
|
- public SealStrategy myGenerateSealStrategy(SigInfoVO.SigInfo sig) throws Exception{
|
|
|
-
|
|
|
- String type = BaseConstants.SEAL_TYPE_IMAGE;
|
|
|
- String sealCode = sig.getSealCode();
|
|
|
- String sealPassword = PwdEncryptUtil.encrypto(sig.getSealPassword());
|
|
|
- SealStrategy sealStrategy = new SealStrategy();
|
|
|
- sealStrategy.setSealInfo(type, sealCode, sealPassword);
|
|
|
-
|
|
|
- String pngFilePath = sig.getSigPic();
|
|
|
- //外传图片
|
|
|
- byte[] imageData = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(pngFilePath));
|
|
|
- //图片进行Base64编码/
|
|
|
- String imageDataString = new String(Base64.encode(imageData), StandardCharsets.UTF_8);
|
|
|
- sealStrategy.setSealImage(imageDataString);
|
|
|
- //算法,非空
|
|
|
- String hashAlg = BaseConstants.HASHALG_SM3;
|
|
|
- sealStrategy.setHashAlg(hashAlg);
|
|
|
- //透明度,0-1.0f,默认1.0f,不透明
|
|
|
- String fillOpacity = "1";
|
|
|
- sealStrategy.setFillOpacity(fillOpacity);
|
|
|
- //是否显示,默认1 显示
|
|
|
- String visible = "1";
|
|
|
- sealStrategy.setVisible(visible);
|
|
|
- //签章图片显示尺寸 单位毫米 默认为图片本身尺寸
|
|
|
- //签章图片显示尺寸,单位毫米;如果是圆形,则为半径实际尺寸;如果是矩形,则为较长的一边的实际尺寸;如果是不规则图形,则为较长的一边的实际尺寸
|
|
|
- String displaySize = "50";
|
|
|
- sealStrategy.setDisplaySize(displaySize);
|
|
|
- // 业务码 businessCode ,businessCode为空,则不添加业务码,业务码相关属性都不需要设置
|
|
|
- //业务码内容
|
|
|
- String businessCode = "";
|
|
|
- // 业务码字体大小,默认12,可以为空
|
|
|
- String businessFontSize = "20";
|
|
|
- //以图片底部为起点,向上占图片百分之多少的位置开始显示业务码,默认0.5
|
|
|
- String textRectHeightPercent = "0.5";
|
|
|
- //颜色值,默认黑色 000000
|
|
|
- String businessColor = "FF0000";
|
|
|
- //字体,默认宋体,可以为空
|
|
|
- String bussinessFamily = "";
|
|
|
- // 业务码 end
|
|
|
- sealStrategy.setBusinessInfo(businessCode, businessFontSize, textRectHeightPercent, businessColor, bussinessFamily);
|
|
|
- // 签章杂项信息
|
|
|
- //签章人姓名,必填
|
|
|
- String sealPerson = sig.getUserName();
|
|
|
- //签章地点,可以为空
|
|
|
- String sealLocation = "";
|
|
|
- //签章原因,可以为空
|
|
|
- String sealReason = "";
|
|
|
- sealStrategy.setSealMiscInfo(sealPerson, sealLocation, sealReason);
|
|
|
- /************************关键字签章****************************************************/
|
|
|
- //关键字
|
|
|
- String keyword =sig.getUserSig();
|
|
|
- //x轴偏移,默认0
|
|
|
- String offSetX = "0";
|
|
|
- //y轴偏移,默认0
|
|
|
- String offSetY = "0";
|
|
|
- sealStrategy.setSignWithKeywordInfo(keyword, offSetX, offSetY);
|
|
|
- return sealStrategy;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|