Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

liuyc 2 жил өмнө
parent
commit
00ef53cad8
14 өөрчлөгдсөн 982 нэмэгдсэн , 7 устгасан
  1. 4 6
      blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/LargeFileEndpoint.java
  2. 34 0
      blade-service-api/blade-archive-api/src/main/java/org/springblade/archive/entity/ArchiveFormulaConfig.java
  3. 2 1
      blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/ArchiveFile.java
  4. 28 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchivesAutoController.java
  5. 13 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/mapper/ArchiveFormulaConfigMapper.java
  6. 5 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/mapper/ArchiveFormulaConfigMapper.xml
  7. 12 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/IArchiveAutoPdfService.java
  8. 16 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/IArchiveFormulaConfigService.java
  9. 513 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveAutoPdfServiceImpl.java
  10. 20 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveFormulaConfigServiceImpl.java
  11. 2 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java
  12. 175 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/utils/FileUtils.java
  13. 157 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/utils/FormulaUtil.java
  14. 1 0
      blade-service/blade-business/src/main/java/org/springblade/business/mapper/ArchiveFileMapper.xml

+ 4 - 6
blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/LargeFileEndpoint.java

@@ -276,23 +276,21 @@ public class LargeFileEndpoint {
 				System.out.println("jieshu===================================="+(l1-l));
 
 				File file1 = new File(filePath + param.getFilename());
-
+				MultipartFile multipartFile = getMultipartFile(file1);
 				NewBladeFile newBladeFile = new NewBladeFile();
 				if(param.getFilename().contains("pdf")){
-					FileInputStream inputStream1 = new FileInputStream(filePath + param.getFilename());
-					PDDocument document = PDDocument.load(inputStream1);
+//					FileInputStream inputStream1 = new FileInputStream(filePath + param.getFilename());
+					PDDocument document = PDDocument.load(multipartFile.getInputStream());
 					//获取文件页数
 					newBladeFile.setPage(document.getPages().getCount());
 					//pdf的路径就是文件上传的路径
 					newBladeFile.setPdfUrl(bladeFile.getLink());
 				}else if(param.getFilename().contains("xlsx") || param.getFilename().contains("xls")){
-					MultipartFile multipartFile = getMultipartFile(file1);
 					newBladeFile = this.commonFileClient.excelToPdf(multipartFile);
 				}else if(param.getFilename().contains("docx")){
-					MultipartFile multipartFile = getMultipartFile(file1);
 					newBladeFile = this.commonFileClient.wordToPdf(multipartFile);
 				}else if(param.getFilename().contains("png") || param.getFilename().contains("jpg")){
-					MultipartFile multipartFile = getMultipartFile(file1);
+
 					newBladeFile = this.commonFileClient.pngOrJpgToPdf(multipartFile);
 				}
 				BeanUtils.copyProperties(bladeFile, newBladeFile);

+ 34 - 0
blade-service-api/blade-archive-api/src/main/java/org/springblade/archive/entity/ArchiveFormulaConfig.java

@@ -0,0 +1,34 @@
+package org.springblade.archive.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import org.springblade.core.mp.base.BaseEntity;
+
+@Data
+@TableName("m_archive_formula_config")
+public class ArchiveFormulaConfig extends BaseEntity {
+
+    /**
+     * 名称,例如:“封面”
+     */
+    private String name;
+
+    /**
+     * r_Archives_back
+     */
+    private String number;
+
+    /**
+     * 公式
+     */
+    private String formula;
+    /**
+     * 公式名
+     */
+    private String formulaName;
+
+    /**
+     * 单元格
+     */
+    private String coords;
+}

+ 2 - 1
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/ArchiveFile.java

@@ -251,6 +251,7 @@ public class ArchiveFile extends BaseEntity {
 	@ApiModelProperty("是否组卷")
 	private Integer isArchive;
 
-
+	@ApiModelProperty("页号")
+	private String pageNum;
 
 }

+ 28 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchivesAutoController.java

@@ -21,6 +21,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
 import javax.validation.Valid;
 
+import org.springblade.archive.service.IArchiveAutoPdfService;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
@@ -48,6 +49,8 @@ public class ArchivesAutoController extends BladeController {
 
 	private final IArchivesAutoService archivesAutoService;
 
+	private final IArchiveAutoPdfService archiveAutoPdfService;
+
 	/**
 	 * 详情
 	 */
@@ -144,5 +147,30 @@ public class ArchivesAutoController extends BladeController {
 		return R.status(archivesAutoService.deleteLogic(Func.toLongList(ids)));
 	}
 
+
+	/**
+	 * 获取归档树同级节点
+	 */
+	@GetMapping("/test")
+	@ApiOperationSupport(order = 12)
+	@ApiOperation(value = "获取归档树同级节点", notes = "传入节点id")
+	public R test() {
+
+		archiveAutoPdfService.test();
+		return R.data("");
+	}
+
+	/**
+	 * 获取归档树同级节点
+	 */
+	@GetMapping("/test1")
+	@ApiOperationSupport(order = 12)
+	@ApiOperation(value = "获取归档树同级节点", notes = "传入节点id")
+	public R test1() {
+
+		archiveAutoPdfService.test1();
+		return R.data("");
+	}
+
 	
 }

+ 13 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/mapper/ArchiveFormulaConfigMapper.java

@@ -0,0 +1,13 @@
+package org.springblade.archive.mapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springblade.archive.entity.ArchiveFormulaConfig;
+
+/**
+ * <p>
+ * 档案号码公式配置 Mapper 接口
+ * </p>
+ *
+ * @since 2023-04-13
+ */
+public interface ArchiveFormulaConfigMapper extends BaseMapper<ArchiveFormulaConfig> {
+}

+ 5 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/mapper/ArchiveFormulaConfigMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.archive.mapper.ArchiveFormulaConfigMapper">
+
+</mapper>

+ 12 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/IArchiveAutoPdfService.java

@@ -0,0 +1,12 @@
+package org.springblade.archive.service;
+
+import java.util.Map;
+
+public interface IArchiveAutoPdfService {
+    public void test();
+
+    public void test1();
+
+    // 单个pdf 生成
+    String getBussPdfInfo(Long pkeyId, Map<String, Object> DataInfo, String excelUrl, String filePath )throws Exception;
+}

+ 16 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/IArchiveFormulaConfigService.java

@@ -0,0 +1,16 @@
+package org.springblade.archive.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springblade.archive.entity.ArchiveFormulaConfig;
+
+import java.util.List;
+
+public interface IArchiveFormulaConfigService extends IService<ArchiveFormulaConfig> {
+    /**
+     * 根据档案号码字符串获取对应的档案号码公式配置列表
+     *
+     * @param number 档案号码字符串,
+     * @return List<ArchiveFormulaConfig> 返回对应的档案号码公式配置列表
+     */
+    List<ArchiveFormulaConfig> getByNumber(String number);
+}

+ 513 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveAutoPdfServiceImpl.java

@@ -0,0 +1,513 @@
+package org.springblade.archive.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.AllArgsConstructor;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.util.IOUtils;
+import org.springblade.archive.entity.ArchiveFormulaConfig;
+import org.springblade.archive.entity.ArchiveProjectConfig;
+import org.springblade.archive.entity.ArchivesAuto;
+import org.springblade.archive.service.IArchiveAutoPdfService;
+import org.springblade.archive.service.IArchiveFormulaConfigService;
+import org.springblade.archive.service.IArchiveProjectConfigService;
+import org.springblade.archive.utils.FileUtils;
+import org.springblade.archive.utils.FormulaUtil;
+import org.springblade.business.entity.ArchiveFile;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.common.vo.DataVO;
+import org.springblade.core.oss.model.BladeFile;
+import org.springblade.core.tool.utils.ObjectUtil;
+import org.springblade.core.tool.utils.ResourceUtil;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.resource.feign.NewIOSSClient;
+import org.springframework.stereotype.Service;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@AllArgsConstructor
+public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
+
+    private final NewIOSSClient newIOSSClient;
+
+    private final IArchiveProjectConfigService archiveProjectConfigService;
+
+    private final IArchiveFormulaConfigService archiveFormulaConfigService;
+
+    public static final  String[] ARCHIVE_NUMBER = new String[]{"r_Archives_front","r_Archives_catalog","r_Archives_spare","r_Archives_back"};
+
+    public static final Map<String, String> URL_MAP = new HashMap<>();
+
+    static {
+        URL_MAP.put("r_Archives_front", "https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230413/306c87ffc640699aa92d53a5f4e6d632.xlsx");
+        URL_MAP.put("r_Archives_catalog", "https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230413/f2a083fca685c646e4a47daaaa46f04b.xlsx");
+        URL_MAP.put("r_Archives_spare", "https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230414/3798f8c3db6f94c8fce63eec8c716d6c.xlsx");
+        URL_MAP.put("r_Archives_back", "https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230413/31081917b41e12b9b0359f6a9c1755bd.xlsx");
+    }
+
+
+
+
+    public static final  String LocalPath = "/www/wwwroot/Users/hongchuangyanfa/Desktop/";
+
+
+
+    public void test1() {
+
+        Long pkeyId = SnowFlakeUtil.getId();
+
+        String file_path = "D:\\tmp";
+        String excelUrl = file_path +  "\\备考表.xlsx";
+
+        Map<String, Object> DataInfo = new HashMap<>();
+
+        DataVO dataVO = FormulaUtil.convertCellToIndex("C2");
+        String key =  "1__"+ dataVO.getY() + "_" + dataVO.getX();
+        DataInfo.put(key,"档号123456");
+
+        DataVO dataVO1 = FormulaUtil.convertCellToIndex("A9");
+        String key1 =  "2__"+ dataVO1.getY() + "_" + dataVO1.getX();
+        DataInfo.put(key1,"hahahahaa");
+        try {
+            String url = getBussPdfInfo(pkeyId,DataInfo,excelUrl,file_path);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        System.out.println();
+
+
+    }
+
+    public void test() {
+
+        Long projectId = 1578599210897772545L;
+
+        ArchivesAuto archivesAuto = new ArchivesAuto();
+        archivesAuto.setProjectId(projectId);
+        archivesAuto.setName("案卷提名");
+        archivesAuto.setFileNumber("档号");
+        archivesAuto.setMicron("缩微号");
+        archivesAuto.setUnit("单位");
+        archivesAuto.setQuantity("数量/单位");
+        archivesAuto.setSpecification("规格");
+        archivesAuto.setStorageTime("1");
+        archivesAuto.setSecretLevel("1");
+        archivesAuto.setCarrierType("载体类型");
+        archivesAuto.setKeywords("主题词");
+        archivesAuto.setReviewer("审核人");
+        archivesAuto.setReviewDate(LocalDateTime.now());
+        archivesAuto.setStartDate(LocalDateTime.now());
+        archivesAuto.setEndDate(LocalDateTime.now());
+        archivesAuto.setStorageLocation("存放位置");
+        archivesAuto.setIsArchive(0);
+        archivesAuto.setRemark("备注");
+        archivesAuto.setRollDate(LocalDateTime.now().minusDays(1));
+        archivesAuto.setRollor("立卷人");
+        archivesAuto.setNodeId(123L);
+        archivesAuto.setOutUrl("http://example.com");
+        archivesAuto.setCdId(456L);
+        archivesAuto.setFileN(2);
+        archivesAuto.setPageN(100);
+        archivesAuto.setMileage("统一里程信息");
+        archivesAuto.setFileType(1);
+        archivesAuto.setSize(1024);
+        archivesAuto.setTreeSort("ABC");
+        archivesAuto.setIsOpen(1);
+        archivesAuto.setIscheck(1);
+        archivesAuto.setIsAutoFile(0);
+        archivesAuto.setAutoFileSort(1);
+        archivesAuto.setFilingUnit("立卷单位");
+        archivesAuto.setIsLock(0);
+
+        ArchiveFile archiveFile = new ArchiveFile();
+        archiveFile.setProjectId(projectId.toString());
+        archiveFile.setContractId("合同段ID");
+        archiveFile.setNodeId("文件绑定的节点ID");
+        archiveFile.setFileNumber("");
+        archiveFile.setFileName("文件名称");
+        archiveFile.setFileTime("20230413");
+        archiveFile.setFileUrl("http://example.com/file");
+        archiveFile.setPdfFileUrl("http://example.com/pdf");
+        archiveFile.setFilePage(10);
+        archiveFile.setIsApproval(1);
+        archiveFile.setIsNeedCertification(1);
+        archiveFile.setIsCertification(1);
+        archiveFile.setCertificationTime("2023-04-13 14:30:00");
+        archiveFile.setDutyUser("责任者");
+        archiveFile.setSheetType("图幅");
+        archiveFile.setSheetSource("图表来源");
+        archiveFile.setDrawingNo("图号");
+        archiveFile.setCiteChangeNumber("引用变更令编号");
+        archiveFile.setEVisaFile("http://example.com/evisa");
+        archiveFile.setNodeExtId(123L);
+        archiveFile.setFileType(1L);
+        archiveFile.setArchiveId(456L);
+        archiveFile.setOriginId(789L);
+        archiveFile.setFilmingTime(LocalDateTime.now().minusDays(2));
+        archiveFile.setFilmingorTime(LocalDateTime.now().minusDays(1));
+        archiveFile.setTagId("标签ID");
+        archiveFile.setPicCode("相片号");
+        archiveFile.setReferCode("参见号");
+        archiveFile.setFilmCode("底片号");
+        archiveFile.setWidth(800);
+        archiveFile.setHeight(600);
+
+        List<ArchiveFile> archiveFiles = new ArrayList<>();
+
+        for (int i = 0; i < 20;i++) {
+            archiveFiles.add(archiveFile);
+        }
+
+
+
+        buildArchiveFrontPdfs(projectId,archivesAuto,archiveFiles);
+    }
+
+
+    /**
+     *
+     * @param projectId
+     * @param archivesAuto
+     * @param archiveFileList
+     */
+    public void buildArchiveFrontPdfs(Long projectId, ArchivesAuto archivesAuto,List<ArchiveFile> archiveFileList) {
+        // 调用 getByProjectIdOrNew 方法获取 ArchiveProjectConfig 对象,并从中取得 factorType 的值
+        ArchiveProjectConfig config = archiveProjectConfigService.getByProjectIdOrNew(projectId);
+
+        // 根据 factorType 字符串生成档案号码字符串链表
+        List<String> numberFronts = new ArrayList<>();
+        List<String> numberBacks = new ArrayList<>();
+        if (config.getFactorType().contains("1")) {
+            numberFronts.add(ARCHIVE_NUMBER[0]);
+        }
+        if (config.getFactorType().contains("2")) {
+            numberFronts.add(ARCHIVE_NUMBER[1]);
+        }
+        if (config.getFactorType().contains("3")) {
+            numberBacks.add(ARCHIVE_NUMBER[2]);
+        }
+        if (config.getFactorType().contains("4")) {
+            numberBacks.add(ARCHIVE_NUMBER[3]);
+        }
+
+        Map<String,Object> variables = dataSourceBuilder(archivesAuto,archiveFileList);
+
+        // 使用生成的档案号码字符串链表生成档案 PDF 文件
+        List<String> frontUrls = new ArrayList<>();
+        List<String> backUrls = new ArrayList<>();
+        for (String number : numberFronts) {
+            // 具体实现省略
+            buildFrontPdf(number, variables,frontUrls);
+        }
+
+        for (String number : numberBacks) {
+            // 具体实现省略
+            buildFrontPdf(number, variables,backUrls);
+        }
+    }
+
+    public void buildFrontPdf(String number, Map<String,Object> variables,List<String> urls) {
+        // Step 1: Get the list of formulas using archiveFormulaConfigService
+        List<ArchiveFormulaConfig> formulaConfigs = archiveFormulaConfigService.getByNumber(number);
+
+        String file_path = LocalPath;
+        String excelUrl = getUrlByNumber(number);
+        Map<String, Object> dataInfo = new HashMap<>();
+
+        ArchiveFormulaConfig multiLineconfig = null;
+
+
+        for (ArchiveFormulaConfig config : formulaConfigs) {
+            String coords = config.getCoords();
+            String formula = config.getFormula();
+
+            if(variables.containsKey("ArchiveFile") && variables.get("ArchiveFile") instanceof List
+                    && formula.indexOf("ArchiveFile") >= 0){
+
+                multiLineconfig = config;
+                //handleArchiveFile(coords, formula, variables, file_path, excelUrl, dataInfo,urls);
+                continue;
+            }
+            else{
+                handleNonArchiveFile(config, coords, formula, variables, file_path, excelUrl, dataInfo);
+            }
+        }
+        //一起处理
+        if (multiLineconfig != null) {
+            String coords = multiLineconfig.getCoords();
+            String formula = multiLineconfig.getFormula();
+            handleArchiveFile(coords, formula, variables, file_path, excelUrl, dataInfo,urls);
+
+        }else {
+            try {
+                String url = getBussPdfInfo(null, dataInfo, excelUrl, file_path);
+                urls.add(url);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+    private void handleArchiveFile(String coords, String formula,
+                                   Map<String,Object> variables,String file_path,
+                                   String excelUrl, Map<String, Object> dataInfo,List<String> urls){
+        String[] coordArr = coords.split("~");
+        if (coordArr.length == 2) {
+            DataVO dataVO1 = FormulaUtil.convertCellToIndex(coordArr[0]);
+            DataVO dataVO2 = FormulaUtil.convertCellToIndex(coordArr[1]);
+            Integer pageSize = dataVO2.getY() - dataVO1.getY() + 1;
+
+            List<Map<String,Object>> archiveFiles = (List<Map<String,Object>>)variables.get("ArchiveFile");
+
+            Map<String, Object> pageMap = new HashMap<>();
+            if(archiveFiles != null && archiveFiles.size() > 0){
+                int pageIndex = 0; // 当前页数
+                while (true) {
+                    List<Map<String,Object>> subList = archiveFiles.subList(pageIndex * pageSize,
+                            Math.min((pageIndex + 1) * pageSize, archiveFiles.size()));
+
+                    pageMap.clear();
+                    pageMap.putAll(dataInfo);
+
+                    int subIndex = 0;
+                    for (Map<String,Object> archiveMap : subList) {
+                        // 处理archiveFile逻辑
+                        int y = dataVO1.getY() + subIndex;
+                        List<Object> objects = FormulaUtil.expressionParseList(formula, archiveMap);
+                        int xIndex = 0;
+                        for (Object o: objects) {
+                            if (o == null) {
+                                xIndex++;
+                                continue;
+                            }
+                            int x = dataVO1.getX() + xIndex;
+                            String key = subIndex + "__" + y + "_" + x;
+                            pageMap.put(key, o);
+                            xIndex++;
+                        }
+
+                        subIndex++;
+                    }
+                    try {
+                        String url = getBussPdfInfo(null, pageMap, excelUrl, file_path);
+                        urls.add(url);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+
+                    if (subList.size() < pageSize) {
+                        break;
+                    }
+
+                    pageIndex++;
+                }
+            }
+        }
+    }
+
+    private void handleNonArchiveFile(ArchiveFormulaConfig config, String coords, String formula,
+                                      Map<String,Object> variables,String file_path,
+                                      String excelUrl, Map<String, Object> dataInfo) {
+        DataVO dataVO = FormulaUtil.convertCellToIndex(coords);
+        Object object = null;
+        if (formula.indexOf("~") > 0) {
+            String[] formulaArr = formula.split("~");
+            if (formulaArr.length == 2) {
+                Object object1 = FormulaUtil.expressionParse(formulaArr[0],variables);
+                Object object2 = FormulaUtil.expressionParse(formulaArr[1],variables);
+                object = object1 + "~" + object2;
+            }
+        }else {
+            object = FormulaUtil.expressionParse(formula,variables);
+        }
+
+
+        String key = config.getId() + "__" + dataVO.getY() + "_" + dataVO.getX();
+        dataInfo.put(key, object);
+    }
+
+
+    private static boolean isOssFilePath(String filePath) {
+        return filePath.contains("https") || filePath.contains("aliyun");
+    }
+
+    public String getBussPdfInfo(Long pkeyId,Map<String, Object> DataInfo,String excelUrl,String filePath) throws Exception{
+
+        if (pkeyId == null) {
+            pkeyId = SnowFlakeUtil.getId();
+        }
+
+        String pdfPath = filePath + "/pdf//" + pkeyId + ".pdf";
+        String excelPath = filePath + "/pdf//" + pkeyId + ".xlsx";
+        File tabPdf = ResourceUtil.getFile(pdfPath);
+        if (tabPdf.exists()) {
+            tabPdf.delete();
+        }
+
+        // 获取excel流 和 html流
+        InputStream exceInp = null;
+        if ( isOssFilePath(excelUrl)){
+            exceInp = CommonUtil.getOSSInputStream(excelUrl);
+        }else {
+            exceInp = new FileInputStream(new File(excelUrl));
+        }
+
+        org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(exceInp);
+
+        //获取工作表
+        Sheet sheet = workbook.getSheetAt(0);
+        sheet.setHorizontallyCenter(true);
+        sheet.setVerticallyCenter(true);
+        sheet.setForceFormulaRecalculation(true);
+
+        if (ObjectUtil.isNotEmpty(DataInfo)) {
+            for (String val : DataInfo.keySet()) {
+                if (val.indexOf("__") >= 0) {
+                    String[] DataVal = val.split("__");
+                    String[] xy = DataVal[1].split("_");
+
+                    int x1 = 0;
+                    int y1 = 0;
+                    int x2 = 0;
+                    int y2 = 0;
+
+                    if (xy.length == 2 ) {
+                        x1 = Integer.parseInt(xy[1]);
+                        y1 = Integer.parseInt(xy[0]);
+                    }
+
+                    if (xy.length == 4 ) {
+                        x2 = Integer.parseInt(xy[3]);
+                        y2 = Integer.parseInt(xy[2]);
+                    }
+
+                    String myData = DataInfo.get(val) + "";
+
+                    //https:bladex-test-info.oss-cn-chengdu.aliyuncs.com//upload/20220819/b53cb6700db369381e3b03d7737bcdec.jpg__16_1
+                    if (myData.indexOf("https") >= 0 && myData.indexOf("aliyuncs") >= 0) {
+
+                        InputStream imageIn = CommonUtil.getOSSInputStream(myData);
+                        byte[] bytes = IOUtils.toByteArray(imageIn);
+                        // 这里根据实际需求选择图片类型
+                        int pictureIdx = workbook.addPicture(bytes, 6);
+
+                        CreationHelper helper = workbook.getCreationHelper();
+                        ClientAnchor anchor = helper.createClientAnchor();
+                        anchor.setCol1(x1); // param1是列号
+                        anchor.setCol2(x2);
+                        anchor.setRow1(y1); // param2是行号
+                        anchor.setRow2(y2); // param2是行号
+                        //
+                        Drawing drawing = sheet.createDrawingPatriarch();
+                        anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
+                        // 插入图片
+                        Picture pict = drawing.createPicture(anchor, pictureIdx); // 调整图片占单元格百分比的大小,1.0就是100%
+                        pict.resize(1, 1);
+                        FileUtils.imageOrientation(sheet, anchor, new DataVO(x1 - 1, y1 - 1));
+
+                    }
+                    else {
+                        Row row = sheet.getRow(y1 );
+                        if (row != null) {
+                            Cell cell = row.getCell(x1 );
+                            if (cell != null || ObjectUtils.isNotEmpty(cell)) {
+                                cell.setCellValue(myData);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        FileOutputStream outputStream = new FileOutputStream(excelPath);
+        workbook.write(outputStream);
+        FileUtils.setExcelScaleToPdf(excelPath, pdfPath);
+        BladeFile bladeFile = newIOSSClient.uploadFile(pkeyId + ".pdf", pdfPath);
+
+        String pdfLink = "";
+        if (bladeFile!= null ){
+            pdfLink = bladeFile.getLink();
+        }
+        return pdfLink;
+    }
+
+    public static  Map<String,Object> dataSourceBuilder(ArchivesAuto archive, List<ArchiveFile> datas){
+
+        //预处理
+        archive.setSecretLevel(FormulaUtil.securityLevelMap.get(archive.getSecretLevel()));
+        archive.setStorageTime(FormulaUtil.storageTimeMap.get(archive.getStorageTime()));
+        archive.setFileN(datas.size());
+
+        Integer idx = 0;
+        Integer iStartPage = 1;
+        List<Map<String, Object>> fileMapList = new ArrayList<>();
+        for (ArchiveFile file:  datas) {
+            idx++;
+            file.setId(idx.longValue());
+            if (StringUtil.isEmpty(file.getFileNumber())) {
+                file.setFileNumber("\\");
+            }
+            file.setPageNum(iStartPage.toString());
+
+            iStartPage +=   file.getFilePage();
+            if (idx >= datas.size() ) {
+                String lastPageNum = file.getPageNum() + "~" + iStartPage;
+                file.setPageNum(lastPageNum);
+            }
+
+            Map<String, Object> fileMap = new ObjectMapper().convertValue(file, Map.class);
+            fileMapList.add(fileMap);
+        }
+        archive.setPageN(iStartPage - 1);
+
+
+        Map<String, Object> archivesAutoMap = new ObjectMapper().convertValue(archive, Map.class);
+        if (archive.getRollDate()!= null) {
+            archivesAutoMap.put("rollDate",FormulaUtil.formatLocalDateTime(archive.getRollDate(),"yyyy年MM月dd日"));
+        }
+
+        if (archive.getReviewDate()!= null) {
+            archivesAutoMap.put("reviewDate",FormulaUtil.formatLocalDateTime(archive.getReviewDate(),"yyyy年MM月dd日"));
+        }
+
+        if (archive.getStartDate()!= null) {
+            archivesAutoMap.put("startDate",FormulaUtil.formatLocalDateTime(archive.getStartDate(),"yyyyMMdd"));
+        }
+
+        if (archive.getEndDate()!= null) {
+            archivesAutoMap.put("endDate",FormulaUtil.formatLocalDateTime(archive.getEndDate(),"yyyyMMdd"));
+        }
+
+
+
+
+        Map<String,Object> variables = new HashMap<>();
+        variables.put("Archive",archivesAutoMap);
+
+
+
+        variables.put("ArchiveFile",fileMapList);
+        return  variables;
+    }
+
+
+    public String getUrlByNumber(String number) {
+        // Get the URL from the static map using the number as key
+        String url = URL_MAP.get(number);
+        return url;
+    }
+
+}

+ 20 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveFormulaConfigServiceImpl.java

@@ -0,0 +1,20 @@
+package org.springblade.archive.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.springblade.archive.entity.ArchiveFormulaConfig;
+import org.springblade.archive.mapper.ArchiveFormulaConfigMapper;
+import org.springblade.archive.service.IArchiveFormulaConfigService;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ArchiveFormulaConfigServiceImpl extends BaseServiceImpl<ArchiveFormulaConfigMapper, ArchiveFormulaConfig> implements IArchiveFormulaConfigService {
+    @Override
+    public List<ArchiveFormulaConfig> getByNumber(String number) {
+        QueryWrapper<ArchiveFormulaConfig> wrapper = new QueryWrapper<>();
+        wrapper.lambda().eq(ArchiveFormulaConfig::getNumber, number);
+        return this.list(wrapper);
+    }
+}

+ 2 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -60,6 +60,8 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 
 	private Map<String,Integer> indexMap; //按立卷位区分和生成流水号
 
+
+
 	@Override
 	public IPage<ArchivesAutoVO> selectArchivesAutoPage(IPage<ArchivesAutoVO> page, ArchivesAutoVO archivesAuto) {
 		return page.setRecords(baseMapper.selectArchivesAutoPage(page, archivesAuto));

+ 175 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/utils/FileUtils.java

@@ -1,16 +1,27 @@
 package org.springblade.archive.utils;
 
+import com.aspose.cells.SaveFormat;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.itextpdf.text.Document;
 import com.itextpdf.text.pdf.PdfCopy;
 import com.itextpdf.text.pdf.PdfReader;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
 import org.apache.commons.lang.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
 import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Units;
+import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.vo.DataVO;
 import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.core.tool.utils.ResourceUtil;
 
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
@@ -19,11 +30,15 @@ import java.awt.image.BufferedImage;
 import java.io.*;
 import java.net.URLEncoder;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
+
+
 public class FileUtils {
 
     public static void batchDownloadFileToZip(List<String> urls, HttpServletResponse response){
@@ -229,4 +244,164 @@ public class FileUtils {
         }
     }
 
+    /**
+     * excel 转pdf
+     * @param exUrl
+     * @param pdfUrl
+     */
+    public static void excelToPdf(String exUrl,String pdfUrl){
+
+        org.apache.poi.ss.usermodel.Workbook ss = null;
+        ByteArrayInputStream byteArrayInputStream = null;
+        InputStream pdfInput = null;
+        ByteArrayOutputStream outReport = null, bos = null;
+        try{
+            File file1 = ResourceUtil.getFile(exUrl);
+            InputStream inputStream = new FileInputStream(file1);
+            ss = WorkbookFactory.create(inputStream);
+            for(int i = 0, l = ss.getNumberOfSheets(); i < l; i ++){
+                Sheet sheet = ss.getSheetAt(i);
+                //去掉表格虚线
+                sheet.setPrintGridlines(false);
+                //设置 整个工作表为一页
+                sheet.setFitToPage(true);
+
+            }
+            outReport = new ByteArrayOutputStream();
+            ss.write(outReport);
+            byteArrayInputStream = new ByteArrayInputStream(outReport.toByteArray());
+            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(byteArrayInputStream);
+            File pdfFile = new File(pdfUrl);
+            if(!pdfFile.exists()){
+                pdfFile.mkdir();
+            }
+            wb.save(pdfUrl, SaveFormat.PDF);
+        }catch (Exception e){
+            e.printStackTrace();
+        } finally {
+            if(bos != null){
+                IoUtil.closeQuietly(bos);
+            }
+            if(outReport != null){
+                IoUtil.closeQuietly(outReport);
+            }
+            if(pdfInput != null){
+                IoUtil.closeQuietly(pdfInput);
+            }
+            if(byteArrayInputStream != null){
+                IoUtil.closeQuietly(byteArrayInputStream);
+            }
+            if(ss != null){
+                IoUtil.closeQuietly(ss);
+            }
+        }
+    }
+
+    /**
+     * 图片压缩
+     * @param imgUrl
+     */
+    public static void CompressImage(String imgUrl,InputStream img){
+        try {
+            //图片所在路径
+            BufferedImage templateImage = ImageIO.read(img);
+            //原始图片的长度和宽度
+            int height = templateImage.getHeight();
+            int width = templateImage.getWidth();
+
+            //通过比例压缩
+            float scale = 0.5f;
+
+            //通过固定长度压缩
+            /*int doWithHeight = 100;
+            int dowithWidth = 300;*/
+
+            //压缩之后的长度和宽度
+            int doWithHeight = (int) (scale * height);
+            int dowithWidth = (int) (scale * width);
+
+            BufferedImage finalImage = new BufferedImage(dowithWidth, doWithHeight, BufferedImage.TYPE_INT_RGB);
+
+            finalImage.getGraphics().drawImage(templateImage.getScaledInstance(dowithWidth, doWithHeight, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
+
+
+            //图片输出路径,以及图片名
+            FileOutputStream  fileOutputStream = new FileOutputStream(imgUrl);
+            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fileOutputStream);
+            encoder.encode(finalImage);
+            fileOutputStream.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+
+
+    /**
+     * excel设置 打印缩放比例
+     *
+     * @param inputPath
+     * @param outPath
+     */
+    public static void setExcelScaleToPdf(String inputPath, String outPath) {
+        //读取excel文件
+        XSSFWorkbook workbook = null;
+        ByteArrayOutputStream outReport = null, bos = null;
+        ByteArrayInputStream byteArrayInputStream = null;
+        try {
+            workbook = new XSSFWorkbook(new FileInputStream(inputPath));
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        OutputStream fos = null;
+        try {
+            for (int i = 0; i < workbook.getNumberOfSheets(); i++) {//获取每个Sheet表
+                XSSFSheet sheet = workbook.getSheetAt(i);
+                //打印设置
+                XSSFPrintSetup print = sheet.getPrintSetup();
+                // print.setLandscape(true); // 打印方向,true:横向,false:纵向(默认)
+                //   print.setFitHeight((short)0);//设置高度为自动分页
+                print.setFitWidth((short)1);//设置宽度为一页
+                print.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); //纸张类型
+//                print.setScale((short)55);//自定义缩放①,此处100为无缩放
+                //启用“适合页面”打印选项的标志
+                sheet.setFitToPage(true);
+            }
+            // Excel文件生成后存储的位置。
+            outReport = new ByteArrayOutputStream();
+            workbook.write(outReport);
+            byteArrayInputStream = new ByteArrayInputStream(outReport.toByteArray());
+            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(byteArrayInputStream);
+            File pdfFile = new File(outPath);
+            if(!pdfFile.exists()){
+                pdfFile.mkdir();
+            }
+            wb.save(outPath, SaveFormat.PDF);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (workbook != null) {
+                try {
+                    workbook.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+
+
+
+
+
 }

+ 157 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/utils/FormulaUtil.java

@@ -0,0 +1,157 @@
+package org.springblade.archive.utils;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springblade.common.vo.DataVO;
+import org.springblade.manager.entity.ArchiveTree;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class FormulaUtil {
+
+    public static Map<String, String> securityLevelMap = new HashMap<>();
+    static {
+        securityLevelMap.put("1", "机密");
+        securityLevelMap.put("2", "绝密");
+        securityLevelMap.put("3", "秘密");
+        securityLevelMap.put("4", "公开");
+    }
+
+    public static Map<String, String> storageTimeMap = new HashMap<>();
+    static {
+        storageTimeMap.put("1", "10年");
+        storageTimeMap.put("2", "30年");
+        storageTimeMap.put("3", "永久");
+    }
+
+    /**
+     * 时间格式转化,传入"yyyy.MM.dd" 或者 "yyyyMMdd"
+     * @param dateTime
+     * @param pattern
+     * @return
+     */
+    public static String formatLocalDateTime(LocalDateTime dateTime, String pattern) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
+        return dateTime.format(formatter);
+    }
+
+
+
+    public static DataVO convertCellToIndex(String cellRef) {
+        DataVO dataVO = new DataVO();
+        int idx = 0;
+        for (int i = 0; i < cellRef.length(); i++) {
+            char ch = Character.toUpperCase(cellRef.charAt(i));
+            if (Character.isLetter(ch)) {
+                // 计算字母对应的数字
+                idx = idx * 26 + (ch - 'A');
+                dataVO.setX(idx);
+
+            } else {
+                // 计算数字对应的行数
+                idx = Integer.parseInt(cellRef.substring(i)) - 1;
+                dataVO.setY(idx);
+                break;
+            }
+        }
+        return dataVO;
+    }
+
+
+    //
+    public static Object expressionParse(String formula, Map<String,Object> variables){
+
+        //后期转成Expression库,Object data = Expression.parse(formula).calculate(variables);
+        //需要将需要将Expression, 库放到公共位置
+
+
+        // 去除字符串中的引号
+        String key = formula.replaceAll("'", "");
+        // 以左中括号和右中括号进行字符串分割
+        String[] splittedKey = key.split("\\[|\\]");
+        // 确保分割后的数组长度为2
+        if (splittedKey.length < 2) {
+            return null;
+        }
+        // 获取对象名称和属性名称
+        String objectName = splittedKey[0];
+        String propertyName = splittedKey[1];
+        // 从map中获取名为objectName的Object
+        Object object = variables.get(objectName);
+        // 如果Object为null或不是Map类型,则返回null
+        if (object == null || !(object instanceof Map<?, ?>)) {
+            return null;
+        }
+        // 将Object转换为Map类型
+        Map<String, Object> objectMap = (Map<String, Object>) object;
+        // 使用propertyName作为key获取对应的属性值
+        Object propertyValue = objectMap.get(propertyName);
+        // 返回属性值
+        return propertyValue;
+
+    }
+
+    public static List<Object> expressionParseList(String formula, Map<String, Object> variables) {
+        List<Object> result = new ArrayList<>();
+
+        Pattern pattern = Pattern.compile("([^\\[\\],']+)|'([^']*)'"); // 创建正则表达式模式
+        Matcher matcher = pattern.matcher(formula); // 匹配字符串
+
+        List<String> props = new ArrayList<>();
+        while (matcher.find()) { // 查找匹配的子串
+            for (int i = 1; i <= matcher.groupCount(); ++i) {
+                if (matcher.group(i) != null) {
+                    props.add(matcher.group(i));
+                }
+            }
+        }
+
+        int i = 0;
+        for (String prop1:props) {
+            if (i == 0) {
+                i++;
+                continue;
+            }
+            String prop = prop1.trim();
+            Object value = variables.get(prop);
+            if (value == null) { // handle null values
+                result.add("");
+            } else {
+                result.add(value);
+            }
+            if (prop.equals(" ")) { // handle empty string values
+                result.add("");
+            }
+        }
+
+        return result;
+    }
+
+    public static void main(String[] args) {
+
+
+
+        String formula = "ArchiveFile['id','fileNumber','fileName','dutyUser','fileTime','pageNum',' ']";
+        Pattern pattern = Pattern.compile("([^\\[\\],']+)|'([^']*)'"); // 创建正则表达式模式
+        Matcher matcher = pattern.matcher(formula); // 匹配字符串
+
+        List<String> props = new ArrayList<>();
+        while (matcher.find()) { // 查找匹配的子串
+            for (int i = 1; i <= matcher.groupCount(); ++i) {
+                if (matcher.group(i) != null) {
+                    props.add(matcher.group(i));
+                }
+            }
+        }
+
+        System.out.println();
+    }
+
+
+}

+ 1 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ArchiveFileMapper.xml

@@ -51,6 +51,7 @@
         <result column="box_number" property="boxNumber"/>
         <result column="is_auto_file" property="isAutoFile"/>
         <result column="is_archive" property="isArchive"/>
+        <result column="page_num" property="pageNum"/>
     </resultMap>
     <update id="recoveryByIds">
         update u_archive_file set is_deleted = 0 where