zhuwei 1 рік тому
батько
коміт
e7def5147f

+ 2 - 2
blade-common/src/main/java/org/springblade/common/constant/LauncherConstant.java

@@ -32,11 +32,11 @@ public interface LauncherConstant {
 
     String APPLICATION_ARCHIVE_NAME = APPLICATION_NAME_PREFIX + "archive";
 
-    String APPLICATION_LAND_NAME = APPLICATION_NAME_PREFIX + "land";
-
 
     String APPLICATION_VISUAL_NAME = APPLICATION_NAME_PREFIX + "visual";
 
+    String APPLICATION_LAND_NAME = APPLICATION_NAME_PREFIX + "land";
+
     /**
      * xxljob
      */

+ 3 - 2
blade-service/blade-business/src/main/java/org/springblade/business/controller/TaskController.java

@@ -23,6 +23,7 @@ import org.springblade.business.vo.TaskQueryVO;
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.sms.model.SmsResponse;
@@ -411,8 +412,8 @@ public class TaskController extends BladeController {
     @GetMapping("/query-task-type-status")
     @ApiOperationSupport(order = 6)
     @ApiOperation(value = "获取任务类型或任务状态")
-    public R<List<DictBiz>> queryTaskTypeOrStatus(String typeOrStatus) {
-        return R.data(jdbcTemplate.query("select dict_key, dict_value from blade_dict_biz where code = '" + typeOrStatus + "' and parent_id > 0 and is_sealed = 0 and is_deleted = 0 order by sort", new BeanPropertyRowMapper<>(DictBiz.class)));
+    public R<List<DictBiz>> queryTaskTypeOrStatus(String typeOrStatus, BladeUser bladeUser) {
+        return R.data(jdbcTemplate.query("select dict_key, dict_value from blade_dict_biz where code = '" + typeOrStatus + "' and tenant_id="+bladeUser.getTenantId()+" and parent_id > 0 and is_sealed = 0 and is_deleted = 0 order by sort", new BeanPropertyRowMapper<>(DictBiz.class)));
     }
 
     /**

+ 13 - 0
blade-service/blade-e-visa/pom.xml

@@ -12,6 +12,14 @@
 
     <artifactId>blade-e-visa</artifactId>
 
+    <repositories>
+        <repository>
+            <id>com.e-iceblue</id>
+            <name>e-iceblue</name>
+            <url>https://repo.e-iceblue.cn/repository/maven-public/</url>
+        </repository>
+    </repositories>
+
     <dependencies>
         <dependency>
             <groupId>org.springblade</groupId>
@@ -195,6 +203,11 @@
             <version>2.0.20</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>e-iceblue</groupId>
+            <artifactId>spire.office.free</artifactId>
+            <version>5.3.1</version>
+        </dependency>
         <dependency>
             <groupId>org.springblade</groupId>
             <artifactId>blade-system-api</artifactId>

+ 115 - 38
blade-service/blade-e-visa/src/main/java/org/springblade/evisa/service/impl/EVisaServiceImpl.java

@@ -40,8 +40,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.tool.utils.FileUtil;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.evisa.redissionUtil.DistributedRedisLock;
 import org.springblade.evisa.service.EVisaService;
+import org.springblade.evisa.utils.PDFUtils;
 import org.springblade.evisa.vo.EVisaMakeSealVO;
 import org.springblade.evisa.vo.EVisaTaskApprovalVO;
 import org.springblade.evisa.vo.SealPdfVO;
@@ -57,6 +59,10 @@ 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.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.namedparam.SqlParameterSource;
 import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
@@ -70,10 +76,7 @@ import javax.imageio.stream.ImageOutputStream;
 import java.awt.image.BufferedImage;
 import java.io.*;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 @Service
 @AllArgsConstructor
@@ -106,6 +109,9 @@ public class EVisaServiceImpl implements EVisaService {
     @Autowired
     StringRedisTemplate RedisTemplate;
 
+    private final JdbcTemplate jdbcTemplate;
+
+
     @Override
     public String certification(String pdfUrl, String fileName, String contractId) {
         try {
@@ -213,6 +219,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);
+
+
+                //准备签章策略
+                List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
+                for (Map<String, Object> eVisaConfig : maps) {
+                    //设置签章策略
+                    SealStrategyVO vo = new SealStrategyVO();
+                    vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + eVisaConfig.get("id"));
+                    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) {
@@ -237,6 +320,8 @@ public class EVisaServiceImpl implements EVisaService {
         System.out.println(AuthUtil.getUserId().toString());
         if (DistributedRedisLock.acquire(AuthUtil.getUserId().toString(), batch)) {
             try {
+
+
                 //准备签章策略
                 List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
                 for (JSONObject eVisaConfig : eVisaConfigList) {
@@ -320,70 +405,62 @@ 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) {
-            //没有电签配置,默认当前任务为不签字审批,返回成功
-            RedisTemplate.delete("sign-" + task.getFormDataId());
-            return SUCCESS + "@@@@" + taskFile.getApprovalFileList().get(0).getFileUrl();
-        }
-
-        //获取当前用户的证书信息
-        List<SignPfxFile> userPfxList = this.signPfxClient.querySignPfxByUserIdOrContractId(task.getUserId().toString(), "");
-        if (userPfxList == null || userPfxList.size() <= 0) {
-            //没有签章,不执行电签
-            RedisTemplate.delete("sign-" + task.getFormDataId());
-            return NOT_PFX_OR_FILE;
-        }
-
         //上锁
-        //if (DistributedRedisLock.acquire(task.getUserId().toString(), batch)) {
+        //if (DistributedRedisLock.acquire(task.getUserId().toString(), batch)) {*/
         try {
             //获取需要签章的数据
             List<TaskApprovalVO.ApprovalFile> files = taskFile.getApprovalFileList();
             //这里的文件只会是一张拼接好的PDF
             for (TaskApprovalVO.ApprovalFile file : files) {
-
                 if (file.getFileName().contains("(关联试验文件)") || file.getFileName().contains("(关联试验工程部位信息文件)") || file.getFileName().contains("(原材料检测报告)")) {
                     //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.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 a.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 {

+ 65 - 0
blade-service/blade-e-visa/src/main/java/org/springblade/evisa/utils/PDFUtils.java

@@ -0,0 +1,65 @@
+package org.springblade.evisa.utils;
+
+import com.spire.pdf.PdfDocument;
+import com.spire.pdf.utilities.PdfTable;
+import com.spire.pdf.utilities.PdfTableExtractor;
+
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.core.tool.utils.Func;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class PDFUtils {
+    public static List<String> getPdfSignIds(String pdfUrl) {
+        PdfDocument pdf = new PdfDocument();
+        List<String> eVisaConfigList = new ArrayList<>();
+
+        try {
+            InputStream ossInputStream = CommonUtil.getOSSInputStream(pdfUrl);
+            //加载PDF文档
+            pdf.loadFromStream(ossInputStream);
+            //创建PdfTableExtractor类的对象
+            PdfTableExtractor extractor = new PdfTableExtractor(pdf);
+            for (int page = 0; page < pdf.getPages().getCount(); page++) {
+                //提取页面中的表格存入PdfTable[]数组
+                PdfTable[] tableLists = extractor.extractTable(page);
+                if (tableLists != null && tableLists.length > 0) {
+                    //遍历表格
+                    for (PdfTable table : tableLists) {
+                        int row = table.getRowCount();//获取表格行
+                        int column = table.getColumnCount();//获取表格列
+                        for (int i = 0; i < row; i++) {
+                            for (int j = 0; j < column; j++) {
+                                //获取表格中的文本内容
+                                String text = table.getText(i, j);
+                                String textVal[] = text.split(" ");
+                                for (String textStr : textVal) {
+                                    if (textStr.length() >= 15 && Func.isNumeric(textStr)) {
+                                        eVisaConfigList.add(textStr);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            ossInputStream.close();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return eVisaConfigList;
+    }
+
+    public static void main1231(String[] args) {
+        //getPdfSignIds("https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230911/c8cab7dd0eebf9b11579223e860d0320.pdf");
+        List<String> eVisaConfigList = new ArrayList<>();
+        eVisaConfigList.add("1235677");
+        eVisaConfigList.add("123567722");
+        System.out.println(eVisaConfigList.toArray());
+        System.out.println(Func.toStr(eVisaConfigList));
+        System.out.println(String.join(",", eVisaConfigList));
+    }
+}

+ 0 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/FormulaController.java

@@ -125,7 +125,6 @@ public class FormulaController {
                         WbsTree wbsTree = this.wbsTreeService.getById(f.getNodeId());
                         efm.setWbsId(Long.parseLong(wbsTree.getWbsId()));
                     }
-
                 }
                 this.elementFormulaMappingService.save(efm);
                 /*假如不存在projectId则认为是系统级模版公式,必须同步给所有项目TODO*/

+ 1 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -528,7 +528,7 @@ public class TextdictInfoController extends BladeController {
             throw new ServiceException("请勿重复提交,请3秒后再尝试");
         }
         JSONArray jsonArray = dataInfo.getJSONArray("dataInfo");
-        Long tableId = dataInfo.getLong("tabId");
+        Long tableId = dataInfo.getLong("tabId"); //节点pkid
 
         //当前清表信息
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(tableId);
@@ -547,7 +547,6 @@ public class TextdictInfoController extends BladeController {
         }
 
         // 读取html页面信息
-        // File file1 = ResourceUtil.getFile(wbsTreePrivate.getHtmlUrl());
 
         InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(wbsTreePrivate.getHtmlUrl());
         String htmlString = IoUtil.readToString(inputStreamByUrl);

+ 36 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -1611,7 +1611,41 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             }
 
             // 组装电签设置
-            QueryWrapper<TextdictInfo> queryWrapper = new QueryWrapper<>();
+
+            Elements dqids = table.getElementsByAttribute("dqid");
+
+            for (Element element : dqids){
+                String dqid = element.attr("dqid");
+               // if(element.hasAttr("x1") && element.hasAttr("y1")){
+                    Elements x11 = element.getElementsByAttribute("x1");
+                    if(x11!=null && x11.size()>=1){
+                        Element element1 = x11.get(x11.size()-1);
+                       int x1 = Func.toInt(element1.attr("x1"));
+                       int y1 = Func.toInt(element1.attr("y1"));
+
+                        Row row = sheet.getRow(y1 - 1);
+                        if (row != null) {
+                            Cell cell = row.getCell(x1 - 1);
+                            if (cell != null || ObjectUtils.isNotEmpty(cell)) {
+                                short fontIndex = cell.getCellStyle().getFontIndex();
+                                Font oldfontAt = workbook.getFontAt(fontIndex);
+                                Font redFont = workbook.createFont();
+                                redFont.setColor(IndexedColors.WHITE.getIndex()); //设置字体颜色
+                                redFont.setFontHeightInPoints(Short.valueOf("1"));//设置字体大小
+                                redFont.setFontName(oldfontAt.getFontName());//设置字体
+                                CellStyle newStyle = workbook.createCellStyle(); //创建单元格样式
+                                newStyle.cloneStyleFrom(cell.getCellStyle());
+                                newStyle.setFont(redFont);
+                                newStyle.setShrinkToFit(true);
+                                cell.setCellStyle(newStyle);
+                                cell.setCellValue(dqid);
+                            }
+                        }
+                    }
+               // }
+            }
+
+          /*  QueryWrapper<TextdictInfo> queryWrapper = new QueryWrapper<>();
             queryWrapper.in("type", 2, 6);
             queryWrapper.eq("tab_id", wbsTreeContract.getIsTypePrivatePid());
             List<TextdictInfo> textdictInfos = textdictInfoService.getBaseMapper().selectList(queryWrapper);
@@ -1664,7 +1698,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                         }
                     }
                 }
-            }
+            }*/
         }
 
         //输出流

+ 0 - 6
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/ExcelInfoUtils.java

@@ -15,7 +15,6 @@ import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
 
-import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.tool.utils.FileUtil;
 import org.springblade.core.tool.utils.Func;
@@ -81,23 +80,18 @@ public class ExcelInfoUtils {
             oldcell.getDataValidation().setErrorMessage("");
         }
 
-
         CellRange[] mergedCells1 = sheet.getMergedCells();
         for(int i=0;i<mergedCells1.length;i++) {
             CellRange oldcell = mergedCells1[i];
             oldcell.getDataValidation().setErrorMessage(i+"");
         }
 
-
-
         CellRange[] cells = sheet.getCells();
         for(int i=0;i< cells.length;i++){
             CellRange oldcell = cells[i];
             System.out.println(oldcell.getRow()+"---"+oldcell.getColumn()+"---="+oldcell.getText()+"---x="+oldcell.getDataValidation().getErrorMessage());
         }
 
-
-
         String new_html = "/Users/hongchuangyanfa/Desktop/pdf/new_html.html";
         String new_xlsx = "/Users/hongchuangyanfa/Desktop/pdf/new_html.xlsx";
        // excelInfo(old_xlsx,new_xlsx,new_html);

+ 271 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/ExcelInfoUtils2.java

@@ -0,0 +1,271 @@
+package org.springblade.manager.utils;
+
+import com.spire.pdf.PdfDocument;
+import com.spire.pdf.utilities.PdfTable;
+import com.spire.pdf.utilities.PdfTableExtractor;
+import com.spire.xls.CellRange;
+import com.spire.xls.FileFormat;
+import com.spire.xls.Workbook;
+import com.spire.xls.Worksheet;
+import com.spire.xls.core.spreadsheet.HTMLOptions;
+import org.apache.commons.lang.StringUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.tool.utils.FileUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.manager.vo.DateFormat;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ExcelInfoUtils2 {
+
+
+    public static void excelInfo(InputStream inputStream, String excelURL, String htmlUrl,String type) {
+        try {
+            String file_path = "/Users/hongchuangyanfa/Desktop//pdf/";
+            String filecode = SnowFlakeUtil.getId() + "";
+            String thmlUrl2 = file_path + filecode + "123.html";
+
+            // 解析原始excel
+            Workbook wb = new Workbook();
+            wb.loadFromMHtml(inputStream);
+            Worksheet sheet = wb.getWorksheets().get(0);
+
+            HTMLOptions options = new HTMLOptions();
+            options.setImageEmbedded(true);
+
+            //复制一份
+            wb.saveToFile(excelURL,FileFormat.Version2013);
+            // 操作
+            Workbook wb2 = new Workbook();
+            wb2.loadFromMHtml(excelURL);
+            Worksheet sheet2 = wb2.getWorksheets().get(0);
+
+            // 坐标map
+            Map<String, Map<String, Integer>> xyList = new HashMap<>();
+            int j = 0;
+            int maxVal = 0;
+            if(type.equals("2")){
+                CellRange[] sheet2Cells = sheet2.getCells();
+                for (int i = 0; i < sheet2Cells.length; i++) {
+                    CellRange oldcell = sheet2Cells[i];
+                    String data = oldcell.getDataValidation().getErrorMessage();
+                    int k = 0;
+                    if(Func.isNumeric(data)){
+                        k = Func.toInt(data);
+                    }
+                    if (maxVal < k) {
+                        maxVal = k;
+                    }
+                }
+            }else if(type.equals("1")){
+                CellRange[] sheet2Cells = sheet.getCells();
+                for (int i = 0; i < sheet2Cells.length; i++) {
+                    CellRange oldcell = sheet2Cells[i];
+                    oldcell.getDataValidation().setErrorMessage("");
+                    sheet.get(oldcell.getRow(),oldcell.getColumn()).getDataValidation().setErrorMessage("");
+                }
+            }
+
+            //合并单元格操作
+            CellRange[] mergedCells = sheet.getMergedCells();
+            for (int i = 0; i < mergedCells.length; i++) {
+                Map<String, Integer> dataMap = new HashMap<>();
+                CellRange oldcell = mergedCells[i];
+                CellRange mergedCell = sheet.getCellRange(oldcell.getRow(), oldcell.getColumn());
+                if(type.equals("2")){
+                    String data = mergedCell.getDataValidation().getErrorMessage();
+                    if (StringUtils.isEmpty(data)) {
+                        if(maxVal<=0){
+                            j = j + 1;
+                        }else{
+                            maxVal = maxVal+1;
+                            j=maxVal;
+                        }
+                    } else {
+                        j = Func.toInt(data);
+                    }
+                }else{
+                    j = j + 1;
+                }
+                // 目标表添加备注信息
+                mergedCell.getDataValidation().setErrorMessage(j+"");
+                oldcell.getDataValidation().setErrorMessage(j+"");
+                sheet2.getMergedCells()[i].setText(j+"");
+                dataMap.put("y1", oldcell.getRow());
+                dataMap.put("y2", oldcell.getLastRow());
+                dataMap.put("x1", oldcell.getColumn());
+                dataMap.put("x2", oldcell.getLastColumn());
+                xyList.put(j + "", dataMap);
+            }
+
+            //变更最大值
+            if(maxVal<=0){
+                maxVal = j;
+            }
+
+            // 单个
+            CellRange[] onCell = sheet.getCells();
+            // 单个cell
+            for (int i = 0; i < onCell.length; i++) {
+                CellRange oldcell = onCell[i];
+                String data = oldcell.getDataValidation().getErrorMessage();
+                System.out.println(oldcell.getRow()+"---"+oldcell.getColumn()+"---="+oldcell.getText()+"---x="+data);
+                if (StringUtils.isEmpty(data)) {
+                    if(maxVal<=0){
+                        j = j + 1;
+                    }else{
+                        maxVal = maxVal+1;
+                        j=maxVal;
+                    }
+                } else {
+                    j = Func.toInt(data);
+                }
+
+              /*  if(StringUtils.isEmpty(data)){
+                    oldcell.getDataValidation().setErrorMessage(j+"");
+                    sheet2.getCells()[i].setText(j+"");
+                }*/
+
+                if(!xyList.containsKey(j+"")){
+                    Map<String, Integer> dataMap = new HashMap<>();
+                    dataMap.put("y1", oldcell.getRow());
+                    dataMap.put("y2", oldcell.getLastRow());
+                    dataMap.put("x1", oldcell.getColumn());
+                    dataMap.put("x2", oldcell.getLastColumn());
+                    xyList.put(j + "", dataMap);
+                }
+            }
+
+            // 保存上传的excel
+            wb.saveToFile(excelURL,FileFormat.Version2013);
+           // sheet.saveToHtml(htmlUrl, options);
+            sheet2.saveToHtml(thmlUrl2);
+
+            // html 转换值
+
+            // 组装坐标
+            File html1 = new File(htmlUrl);  // 原始html
+            File html2 = new File(thmlUrl2); // 坐标html
+            InputStream inputStream1 = new FileInputStream(html1);
+            InputStream inputStream2 = new FileInputStream(html2);
+            String htmlString1 = IoUtil.readToString(inputStream1);
+            String htmlString2 = IoUtil.readToString(inputStream2);
+
+            Document doc1 = Jsoup.parse(htmlString1);
+            Element table1 = doc1.select("table").first();
+            Elements trs1 = table1.select("tr");
+            Document doc2 = Jsoup.parse(htmlString2);
+            Element table2 = doc2.select("table").first();
+            Elements trs2 = table2.select("tr");
+
+            for (int i = 0; i < trs1.size(); i++) {
+                Elements td1 = trs1.get(i).select("td");
+                Elements td2 = trs2.get(i).select("td");
+                for (int x = 0; x < td1.size(); x++) {
+                    Element cell1 = td1.get(x);
+                    Element cell2 = td2.get(x);
+                    String html = cell2.text();
+                    Map<String, Integer> xyMap = xyList.get(html);
+                    if (xyMap != null) {
+                        // td 添加坐标
+                        cell1.attr("x1", xyMap.get("x1") + "");
+                        cell1.attr("x2", xyMap.get("x2") + "");
+                        cell1.attr("y1", xyMap.get("y1") + "");
+                        cell1.attr("y2", xyMap.get("y2") + "");
+                        cell1.attr("exceVal",html);
+
+
+                        // 为下面对象添加坐标
+                        if(cell1.children().size()>=1){
+                            Element element = cell1.children().get(0);
+                            if(element.hasAttr("x1") && element.hasAttr("y1")){
+                                element.removeAttr("x1");
+                                element.removeAttr("x2");
+                                element.removeAttr("y1");
+                                element.removeAttr("y2");
+                                element.attr("x1", xyMap.get("x1") + "");
+                                element.attr("x2", xyMap.get("x2") + "");
+                                element.attr("y1", xyMap.get("y1") + "");
+                                element.attr("y2", xyMap.get("y2") + "");
+                            }else{
+                                if(element.children().size()>=1){
+                                    Element element2 = element.children().get(0);
+                                    if(element2.hasAttr("x1") && element2.hasAttr("y1")){
+                                        element2.removeAttr("x1");
+                                        element2.removeAttr("x2");
+                                        element2.removeAttr("y1");
+                                        element2.removeAttr("y2");
+                                        element2.attr("x1", xyMap.get("x1") + "");
+                                        element2.attr("x2", xyMap.get("x2") + "");
+                                        element2.attr("y1", xyMap.get("y1") + "");
+                                        element2.attr("y2", xyMap.get("y2") + "");
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            FileUtil.writeToFile(html1, doc1.html(), Boolean.parseBoolean("UTF-8"));
+
+            if (html2.exists()) {
+                html2.delete();
+            }
+            wb2.dispose();
+            wb.dispose();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    public static void main123(String[] args) throws Exception {
+
+       /* String html="/Users/hongchuangyanfa/Desktop/privateUrl/1701131518073634816.html";
+        File html1 = new File(html);  // 原始html
+        InputStream inputStream1 = new FileInputStream(html1);
+
+        String htmlString1 = IoUtil.readToString(inputStream1);
+        Document doc1 = Jsoup.parse(htmlString1);
+        Element table1 = doc1.select("table").first();
+        Elements dqids = table1.getElementsByAttribute("dqid");
+        int x1=0;
+        int y1=0;
+        for (Element element : dqids){
+            if(element.hasAttr("x1") && element.hasAttr("y1")){
+                Elements x11 = element.getElementsByAttribute("x1");
+                Element element1 = x11.get(x11.size()-1);
+                x1 = Func.toInt(element1.attr("x1"));
+                y1 = Func.toInt(element1.attr("y1"));
+            }
+        }*/
+        String excelPath="/Users/hongchuangyanfa/Desktop/pdf/1234567.xlsx";
+        String data="https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230911/b63658909c268efeb753dcf673ce34ab.xlsx";
+        InputStream exceInp = CommonUtil.getOSSInputStream(data);
+        org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(exceInp);
+
+        //获取工作表
+        Sheet sheet = workbook.getSheetAt(0);
+        Row row = sheet.getRow(7-1);
+        Cell cell = row.getCell(5-1);
+        cell.setCellValue("123444");
+
+        FileOutputStream outputStream = new FileOutputStream(excelPath);
+        workbook.write(outputStream);
+    }
+
+}