|
@@ -0,0 +1,171 @@
|
|
|
+package org.springblade.evisa.service.impl;
|
|
|
+
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.pdmodel.PDPage;
|
|
|
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
|
|
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
|
|
|
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
|
|
|
+import org.springblade.business.vo.ScrSignInfoVO;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.evisa.service.ScrDataService;
|
|
|
+import org.springblade.evisa.utils.PdfAddimgUtil;
|
|
|
+import org.springblade.manager.vo.PDFIndexInfo;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import java.io.*;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class ScrDataServiceImpl implements ScrDataService {
|
|
|
+
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ // 主流程
|
|
|
+ @Override
|
|
|
+ public void sctTaskBatch(ScrSignInfoVO taskApp) throws Exception {
|
|
|
+ // 电签检查
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电签检查
|
|
|
+ */
|
|
|
+ public void sctTaskBatch2(ScrSignInfoVO taskApp) throws Exception {
|
|
|
+ int threshold = 5;
|
|
|
+
|
|
|
+ String fileUrl = CommonUtil.replaceOssUrl(taskApp.getEVisaPdfUrl());
|
|
|
+ String pdfUrl = taskApp.getEVisaPdfUrl();
|
|
|
+ InputStream inputStream = CommonUtil.getOSSInputStream(fileUrl);
|
|
|
+ InputStream inputStream2 = CommonUtil.getOSSInputStream(fileUrl);
|
|
|
+ //转换
|
|
|
+ byte[] pdfData = CommonUtil.InputStreamToBytes(inputStream);
|
|
|
+
|
|
|
+ PDDocument document = PDDocument.load(inputStream2);
|
|
|
+ List<String> positions = PdfAddimgUtil.getPdfSignIds(pdfUrl);
|
|
|
+
|
|
|
+ List<String> sucess = new ArrayList<>();
|
|
|
+ String ids = String.join(",", positions);
|
|
|
+ List<Map<String, Object>> strategyListByDFZX = getStrategyListByDFZX(taskApp,ids);
|
|
|
+
|
|
|
+ positions = strategyListByDFZX.stream().map(map -> map.get("keyWord").toString()).collect(Collectors.toList());
|
|
|
+ String keyWord = String.join(",", positions);
|
|
|
+ List<PDFIndexInfo> pdfIndexInfo = PdfAddimgUtil.findKeywordPostions(pdfData, keyWord);
|
|
|
+
|
|
|
+ //根据id分组
|
|
|
+ List<Map<String, Object>> list2 = strategyListByDFZX.stream().collect(
|
|
|
+ Collectors.collectingAndThen(
|
|
|
+ Collectors.toCollection(
|
|
|
+ () ->new TreeSet<>(Comparator.comparing(m->m.get("keyWord").toString()))
|
|
|
+ ),ArrayList::new
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<String, List<Map<String, Object>>> newMap = list2.stream().collect(Collectors.groupingBy(b -> Func.toStr(b.get("keyWord"))));
|
|
|
+
|
|
|
+ Map<String, List<PDFIndexInfo>> groupBy = pdfIndexInfo.stream().collect(Collectors.groupingBy(da -> Func.toStr(da.getDataInfo()[0])));
|
|
|
+
|
|
|
+ for (int i = 0; i < document.getPages().getCount(); i++) {
|
|
|
+ PDPage page = document.getPage(i);
|
|
|
+ List<PDAnnotation> annotations = page.getAnnotations();
|
|
|
+ for (PDAnnotation annotation : annotations) {
|
|
|
+ if (annotation instanceof PDAnnotationWidget) {
|
|
|
+ PDRectangle rect = annotation.getRectangle();
|
|
|
+
|
|
|
+ float imgW = rect.getWidth();
|
|
|
+ float imgH = rect.getHeight();
|
|
|
+ float imgX = rect.getLowerLeftX() + imgW / 2;
|
|
|
+ float imgY = rect.getLowerLeftY() + imgH / 2;
|
|
|
+ List<PDFIndexInfo> pdfIndexInfos = groupBy.get((i + 1) + ".0");
|
|
|
+
|
|
|
+ for (PDFIndexInfo pdfInfo : pdfIndexInfos) {
|
|
|
+ String pkeyid = pdfInfo.getPkeyid();
|
|
|
+
|
|
|
+ float[] dataInfo = pdfInfo.getDataInfo();
|
|
|
+
|
|
|
+ float keyX = dataInfo[1];
|
|
|
+ float keyY = dataInfo[2];
|
|
|
+
|
|
|
+ float pageHeight = page.getMediaBox().getHeight();
|
|
|
+ float pageWidth = page.getMediaBox().getWidth();
|
|
|
+
|
|
|
+ float keyw = keyX * pageWidth;
|
|
|
+ float keyh = pageHeight - keyY * pageHeight;
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = newMap.get(pkeyid);
|
|
|
+ if(mapList!=null && mapList.size()>=0){
|
|
|
+ Map<String, Object> map = mapList.get(0);
|
|
|
+ Float pyzbx = Func.toFloat(map.get("pyzbx"));
|
|
|
+ Float pyzby = Func.toFloat(map.get("pyzby"));
|
|
|
+ keyw = keyw + pyzbx;
|
|
|
+ keyh = keyh + pyzby;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Math.abs(imgX - keyw) <= threshold && Math.abs(imgY - keyh) <= threshold) {
|
|
|
+ sucess.add(pkeyid);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> differentElements = new HashSet<>(positions);
|
|
|
+ // 使用retainAll方法来移除两个集合中相同的元素,留下不同的元素
|
|
|
+ differentElements.removeAll(sucess);
|
|
|
+
|
|
|
+ System.out.println("总共:"+positions.size()+"-剩下-"+differentElements.size());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 添加电签策略 -- 东方中讯
|
|
|
+ public List<Map<String, Object>> getStrategyListByDFZX(ScrSignInfoVO taskApp,String ids) {
|
|
|
+ List<Map<String, Object>> maps = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> maps2 = new ArrayList<>();
|
|
|
+ String sql = "select * from u_task_parallel where process_instance_id = '" + taskApp.getProcessInstanceId() + "' and initiative=2 and status=2";
|
|
|
+ List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
+ if(mapList!=null && mapList.size()>0){
|
|
|
+ for(Map<String, Object> task : mapList){
|
|
|
+ String taskUserId = Func.toStr(task.get("task_user"));
|
|
|
+ String sqlinfo = " SELECT * from ( SELECT a.id as keyWord,a.project_id,a.pyzbx ,a.pyzby,(SELECT acc_code from blade_user where id='" + taskUserId + "' 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=" + taskApp.getContractId() + " and user_id=" + taskUserId + " and c.is_deleted=0 ) ) x where x.sealId is not null ";
|
|
|
+ List<Map<String, Object>> maps3 = jdbcTemplate.queryForList(sqlinfo);
|
|
|
+ maps2.addAll(maps3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加章
|
|
|
+ String sqlinfo = "SELECT a.id as keyWord,a.pyzbx,a.pyzby,b.certificate_number as sealId from m_textdict_info a ,m_sign_pfx_file b where a.sig_role_id = b.pfx_type and b.project_contract_role like '%" + taskApp.getContractId() + "%' and a.is_deleted=0 and b.is_deleted=0 and a.type=6 and a.id in(" + ids + ")";
|
|
|
+ List<Map<String, Object>> maps3 = jdbcTemplate.queryForList(sqlinfo);
|
|
|
+ if(mapList!=null && mapList.size()>0){
|
|
|
+ maps2.addAll(maps3);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<Map<String, Object>>> peopleByAge = maps2.stream()
|
|
|
+ .collect(Collectors.groupingBy(hada -> (Func.toStr(hada.get("keyWord")))));
|
|
|
+ for (String keyId : peopleByAge.keySet()) {
|
|
|
+ int exId = 0;
|
|
|
+ List<Map<String, Object>> keyList = peopleByAge.get(keyId);
|
|
|
+ if (keyList != null && keyList.size() == 1) {
|
|
|
+ maps.addAll(keyList);
|
|
|
+ exId = 1;
|
|
|
+ } else if (keyList != null && keyList.size() >= 2) {
|
|
|
+ for (Map<String, Object> datax : keyList) {
|
|
|
+ if ((datax.get("project_id") + "").equals(taskApp.getProjectId())) {
|
|
|
+ maps.add(datax);
|
|
|
+ exId = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (exId == 0) {
|
|
|
+ maps.add(keyList.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return maps;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|