|
@@ -23,34 +23,29 @@ import cfca.paperless.dto.response.responsebody.tx40.VerifyPdfSealResponseBody;
|
|
|
import cfca.paperless.dto.response.tx20.MakeSealResponse;
|
|
|
import cfca.paperless.dto.response.tx40.CompoundSealPdfListDetachedResponse;
|
|
|
import cfca.paperless.dto.response.tx40.VerifyPdfSealResponse;
|
|
|
-import cfca.sadk.com.itextpdf.styledxmlparser.jsoup.helper.DataUtil;
|
|
|
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;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springblade.business.entity.ArchiveFile;
|
|
|
-import org.springblade.business.entity.Task;
|
|
|
import org.springblade.business.feign.TaskClient;
|
|
|
import org.springblade.business.vo.TaskApprovalVO;
|
|
|
import org.springblade.common.constant.CommonConstant;
|
|
|
import org.springblade.common.constant.EVisaConstant;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
-import org.springblade.common.utils.SystemUtils;
|
|
|
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.evisa.redissionUtil.DistributedRedisLock;
|
|
|
import org.springblade.evisa.service.EVisaService;
|
|
|
-import org.springblade.evisa.vo.*;
|
|
|
+import org.springblade.evisa.vo.EVisaMakeSealVO;
|
|
|
+import org.springblade.evisa.vo.EVisaTaskApprovalVO;
|
|
|
+import org.springblade.evisa.vo.SealPdfVO;
|
|
|
+import org.springblade.evisa.vo.SealStrategyVO;
|
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
|
import org.springblade.manager.entity.SignPfxFile;
|
|
|
import org.springblade.manager.feign.ContractClient;
|
|
@@ -62,8 +57,6 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
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.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
@@ -77,8 +70,10 @@ import javax.imageio.stream.ImageOutputStream;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
@@ -108,11 +103,12 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
|
|
|
private final ContractClient contractClient;
|
|
|
|
|
|
- private final JdbcTemplate jdbcTemplate;
|
|
|
-
|
|
|
@Autowired
|
|
|
StringRedisTemplate RedisTemplate;
|
|
|
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public String certification(String pdfUrl, String fileName, String contractId) {
|
|
|
try {
|
|
@@ -220,6 +216,83 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
*/
|
|
|
@Override
|
|
|
public String eVisaContractSeal(EVisaTaskApprovalVO task, String finalPdfUrl) {
|
|
|
+
|
|
|
+ //获取任务对应表格的电签配置(合同张)
|
|
|
+ String sysBatch = ParamCache.getValue(CommonConstant.SYS_USER_TASK_BATCH);
|
|
|
+ int batch = 2;
|
|
|
+ if (CommonUtil.checkIsBigDecimal(sysBatch)) {
|
|
|
+ batch = new Integer(sysBatch);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (DistributedRedisLock.acquire(AuthUtil.getUserId().toString(), batch)) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ List<String> eVisaConfigList = PDFUtils.getPdfSignIds(finalPdfUrl);
|
|
|
+ if (eVisaConfigList == null || eVisaConfigList.size() == 0) {
|
|
|
+ return finalPdfUrl;
|
|
|
+ }
|
|
|
+ String contractId = this.taskClient.queryTaskContractId(task.getParallelProcessInstanceId());
|
|
|
+
|
|
|
+ String ids = String.join(",", eVisaConfigList);
|
|
|
+ String sqlinfo = "SELECT a.id,a.pyzbx,a.pyzby,b.signature_file_url,b.id as sfId,b.certificate_password,b.certificate_user_name from m_textdict_info a ,m_sign_pfx_file b where a.sig_role_id = b.pfx_type and b.project_contract_role like '%" + contractId + "%' and a.is_deleted=0 and b.is_deleted=0 and a.type=6 and a.id in(" + ids + ")";
|
|
|
+ List<Map<String, Object>> maps = jdbcTemplate.queryForList(sqlinfo);
|
|
|
+ System.out.println("合同-"+contractId+"--"+sqlinfo);
|
|
|
+
|
|
|
+ //准备签章策略
|
|
|
+ List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
+ for (Map<String, Object> eVisaConfig : maps) {
|
|
|
+ //设置签章策略
|
|
|
+ SealStrategyVO vo = new SealStrategyVO();
|
|
|
+ vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + eVisaConfig.get("sfId"));
|
|
|
+ vo.setSealPassword(eVisaConfig.get("certificate_password")+"");
|
|
|
+ vo.setSealPerson(eVisaConfig.get("certificate_user_name")+"" + System.currentTimeMillis());
|
|
|
+ //设置签字文件
|
|
|
+ vo.setImageUrl(eVisaConfig.get("signature_file_url")+"");
|
|
|
+ vo.setSealType("3");
|
|
|
+ vo.setCompanySeal(true);
|
|
|
+ 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(finalPdfUrl));
|
|
|
+ //执行电签
|
|
|
+ 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) {
|
|
|
+ finalPdfUrl = bladeFile.getLink();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //释放锁
|
|
|
+ DistributedRedisLock.release(AuthUtil.getUserId().toString());
|
|
|
+
|
|
|
+ return finalPdfUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同章 签字
|
|
|
+ *
|
|
|
+ * @param task
|
|
|
+ * @param finalPdfUrl
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ public String eVisaContractSeal222(EVisaTaskApprovalVO task, String finalPdfUrl) {
|
|
|
//获取任务对应表格的电签配置(合同张)
|
|
|
List<JSONObject> eVisaConfigList = this.taskClient.queryBusinessTableEVisaConfig(task.getParallelProcessInstanceId(), task.getUserId(), "true");
|
|
|
if (eVisaConfigList == null || eVisaConfigList.size() == 0) {
|
|
@@ -327,7 +400,7 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
return NOT_PFX_OR_FILE;
|
|
|
}
|
|
|
|
|
|
- //获取任务对应表格的电签配置
|
|
|
+ /*//获取任务对应表格的电签配置
|
|
|
List<JSONObject> eVisaConfigList = this.taskClient.queryBusinessTableEVisaConfig(task.getParallelProcessInstanceId(), task.getUserId(), "false");
|
|
|
if (eVisaConfigList == null || eVisaConfigList.size() == 0) {
|
|
|
//没有电签配置,默认当前任务为不签字审批,返回成功
|
|
@@ -341,7 +414,7 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
//没有签章,不执行电签
|
|
|
RedisTemplate.delete("sign-" + task.getFormDataId());
|
|
|
return NOT_PFX_OR_FILE;
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
//上锁
|
|
|
//if (DistributedRedisLock.acquire(task.getUserId().toString(), batch)) {
|
|
@@ -355,42 +428,51 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
//TODO ============== 试验相关的关联文件不电签 liuYC 2023-03-17 ==============
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+ String pdfUrl = file.getFileUrl();
|
|
|
+ List<String> eVisaConfigList = PDFUtils.getPdfSignIds(pdfUrl);
|
|
|
+ if (eVisaConfigList == null || eVisaConfigList.size() == 0) {
|
|
|
+ //没有电签配置,默认当前任务为不签字审批,返回成功
|
|
|
+ RedisTemplate.delete("sign-" + task.getFormDataId());
|
|
|
+ return SUCCESS + "@@@@" + taskFile.getApprovalFileList().get(0).getFileUrl();
|
|
|
+ }
|
|
|
+ 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 (JSONObject eVisaConfig : eVisaConfigList) {
|
|
|
+ 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(userPfxList.get(0).getSignatureFileUrl());
|
|
|
+ vo.setImageUrl(eVisaConfig.get("signature_file_url") + "");
|
|
|
vo.setSealType("3");
|
|
|
-
|
|
|
- vo.setKeyword(eVisaConfig.getString("KEY"));
|
|
|
- vo.setOffSetX(eVisaConfig.getString("X"));
|
|
|
- vo.setOffSetY(eVisaConfig.getString("Y"));
|
|
|
+ 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(file.getFileUrl()));
|
|
|
+ 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])));
|
|
|
-
|
|
|
- byte[] byteArray = IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0]));
|
|
|
- String dataUrl = "/www/wwwroot/Users/hongchuangyanfa/Desktop/pdf/" + SnowFlakeUtil.getId() + ".pdf";
|
|
|
- File file1 = new File(dataUrl);
|
|
|
- FileUtil.copy(byteArray, file1);
|
|
|
+ MultipartFile newFiles = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", "text/plain", IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0])));
|
|
|
//重新上传
|
|
|
- BladeFile bladeFile = this.newIOSSClient.uploadFile(SnowFlakeUtil.getId() + ".pdf", dataUrl);
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(newFiles);
|
|
|
if (bladeFile != null) {
|
|
|
resultMessage = SUCCESS + "@@@@" + bladeFile.getLink();
|
|
|
} else {
|
|
@@ -762,15 +844,12 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
//对图片进行扣白底
|
|
|
imageData = ImageUtil.transferAlpha(imageData);
|
|
|
|
|
|
- //设置大小(首先排查档案水印章,因为水印章要保持原样)
|
|
|
- if (!vo.getImageUrl().equals("https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230911/5b42583d931664b785ebf481c37d17bc.png")) {
|
|
|
- if (vo.isCompanySeal()) {
|
|
|
- //合同章
|
|
|
- imageData = ImageUtil.resizeImage(imageData, 540, 540);
|
|
|
- } else {
|
|
|
- //非合同章
|
|
|
- imageData = ImageUtil.resizeImage(imageData, 480, 132);
|
|
|
- }
|
|
|
+ //设置大小
|
|
|
+ if (vo.isCompanySeal()) {
|
|
|
+ imageData = ImageUtil.resizeImage(imageData, 540, 540);
|
|
|
+ } else {
|
|
|
+ imageData = ImageUtil.resizeImage(imageData, 480, 132);
|
|
|
+// imageData = ImageUtil.resizeImage(imageData,540,540);
|
|
|
}
|
|
|
|
|
|
//图片dpi设置
|
|
@@ -795,7 +874,7 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
sealStrategy.setOffsetX(vo.getOffSetX());
|
|
|
sealStrategy.setOffsetY(vo.getOffSetY());
|
|
|
} else if (vo.getSealType().equals("2")) {
|
|
|
- //设置PDF坐标原点,签章图片定位点,默认为PDF左下角,签章图片定位为左下角
|
|
|
+ //设置PDF坐标原点,签章图片定位点 默认为PDF左下角,签章图片定位为左下角
|
|
|
if (StringUtils.isNotEmpty(vo.getIsCenterCoordinate())) {
|
|
|
sealStrategy.setIsCenterCoordinate(vo.getIsCenterCoordinate());
|
|
|
}
|