Przeglądaj źródła

图片偏移量

xzc 1 tydzień temu
rodzic
commit
54c70054df

+ 3 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/dynamictb/vo/DynamicTbRespVO.java

@@ -82,4 +82,7 @@ public class DynamicTbRespVO {
 
     @Schema(description = "跳过页码数:生成报告时跳过前N页不添加页码,默认0")
     private Integer skipPageCount;
+
+    @Schema(description = "图片偏移量,格式:sheet,x,y,多个sheet用、隔开", example = "记录,10,20、报告,20,30")
+    private String imageOffset;
 }

+ 3 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/dynamictb/vo/DynamicTbSaveReqVO.java

@@ -57,4 +57,7 @@ public class DynamicTbSaveReqVO {
 
     @Schema(description = "跳过页码数:生成报告时跳过前N页不添加页码,默认0")
     private Integer skipPageCount;
+
+    @Schema(description = "图片偏移量,格式:sheet,x,y,多个sheet用、隔开", example = "记录,10,20、报告,20,30")
+    private String imageOffset;
 }

+ 5 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/dal/dataobject/dynamictb/DynamicTbDO.java

@@ -98,4 +98,9 @@ public class DynamicTbDO extends BaseDO {
      * 跳过页码数:生成报告时跳过前N页不添加页码,默认0
      */
     private Integer skipPageCount;
+
+    /**
+     * 图片偏移量,格式:sheet,x,y,多个sheet用、隔开
+     */
+    private String imageOffset;
 }

+ 42 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/service/dynamicOFData/util/GenerateReportJsonService.java

@@ -1,8 +1,10 @@
 package cn.start.tz.module.pressure2.service.dynamicOFData.util;
 
+import cn.start.tz.module.pressure2.dal.dataobject.dynamictb.DynamicTbDO;
 import cn.start.tz.module.pressure2.dal.dataobject.dynamictbcol.DynamicTbColDO;
 import cn.start.tz.module.pressure2.dal.dataobject.dynamictbins.DynamicTbInsDO;
 import cn.start.tz.module.pressure2.dal.dataobject.dynamictbval.DynamicTbValDO;
+import cn.start.tz.module.pressure2.service.dynamictb.DynamicTbService;
 import cn.start.tz.module.pressure2.service.dynamictbcol.DynamicTbColService;
 import cn.start.tz.module.pressure2.service.dynamictbins.DynamicTbInsService;
 import cn.start.tz.module.pressure2.service.dynamictbval.DynamicTbValService;
@@ -27,6 +29,9 @@ public class GenerateReportJsonService {
     @Resource
     private DynamicTbColService dynamicTbColService;
 
+    @Resource
+    private DynamicTbService dynamicTbService;
+
     @Resource
     private DynamicTbValService dynamicTbValService;
 
@@ -60,6 +65,43 @@ public class GenerateReportJsonService {
                 });
             });
         }
+        // 特殊处理图片偏移量
+        // imageOffset 格式: 记录,10,20、报告,20,30
+        // Illustration 格式: [{"url":"xxx.png","path":"记录","x":173,"y":168,"width":366,"height":305},...]
+        DynamicTbDO tbTbDO = dynamicTbService.getById(templateId);
+        if (tbTbDO != null && tbTbDO.getImageOffset() != null && !tbTbDO.getImageOffset().isEmpty()){
+            String illustration = result.getString("Illustration");
+            if (illustration != null && !illustration.isEmpty()){
+                // 解析偏移量配置: sheet,x,y 多个用、隔开
+                java.util.Map<String, int[]> offsetMap = new java.util.HashMap<>();
+                String[] groups = tbTbDO.getImageOffset().split("、");
+                for (String group : groups) {
+                    String[] parts = group.split(",");
+                    if (parts.length == 3) {
+                        String sheetName = parts[0].trim();
+                        int xOffset = Integer.parseInt(parts[1].trim());
+                        int yOffset = Integer.parseInt(parts[2].trim());
+                        offsetMap.put(sheetName, new int[]{xOffset, yOffset});
+                    }
+                }
+                // 解析 Illustration JSON 并应用偏移量
+                com.alibaba.fastjson2.JSONArray imgArray = com.alibaba.fastjson2.JSON.parseArray(illustration);
+                if (imgArray != null && !imgArray.isEmpty()) {
+                    for (int i = 0; i < imgArray.size(); i++) {
+                        com.alibaba.fastjson2.JSONObject imgObj = imgArray.getJSONObject(i);
+                        String path = imgObj.getString("path");
+                        if (path != null && offsetMap.containsKey(path)) {
+                            int[] offset = offsetMap.get(path);
+                            int originalX = imgObj.getIntValue("x");
+                            int originalY = imgObj.getIntValue("y");
+                            imgObj.put("x", originalX + offset[0]);
+                            imgObj.put("y", originalY + offset[1]);
+                        }
+                    }
+                    result.put("Illustration", imgArray.toJSONString());
+                }
+            }
+        }
 
         return result;