瀏覽代碼

2023 08 16 bug修改

zhuwei 2 年之前
父節點
當前提交
4ac28d9927

+ 79 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -287,15 +287,14 @@ public class ExcelTabController extends BladeController {
             @ApiImplicitParam(name = "nodeId", value = "节点id", required = true)
     })
     public R putFileAttach(@RequestParam("file") MultipartFile file, Long nodeId) {
-
         String file_path = FileUtils.getSysLocalFileUrl();
-
         ExcelTab detail = excelTabService.getById(nodeId);
         // 上传excel文件
         R<BladeFile> bladeFile = iossClient.addFileInfo(file);
         BladeFile bladeFile1 = bladeFile.getData();
         String filecode = SnowFlakeUtil.getId() + "";
         String thmlUrl = file_path + filecode + ".html";
+        String thmlUrl2 = file_path + filecode + "123.html";
         // 解析excel
         Workbook wb = new Workbook();
         wb.loadFromMHtml(file.getInputStream());
@@ -305,11 +304,88 @@ public class ExcelTabController extends BladeController {
         //获取工作表
         Worksheet sheet = wb.getWorksheets().get(0);
         sheet.saveToHtml(thmlUrl, options);
+
+        CellRange[] mergedCells = sheet.getMergedCells();
+        Map<String,Map<String,Integer>> xyList = new HashMap<>();
+        int j=0;
+        for (int i=0;i<mergedCells.length;i++){
+            Map<String,Integer> dataMap = new HashMap<>();
+            CellRange mergedCell = mergedCells[i];
+            j = j+1;
+            mergedCell.getComment().getRichText().setText(j+"");
+            mergedCell.setValue(j+"");
+            dataMap.put("x1",mergedCell.getRow());
+            dataMap.put("x2",mergedCell.getLastRow());
+            dataMap.put("y1",mergedCell.getColumn());
+            dataMap.put("y2",mergedCell.getLastColumn());
+            xyList.put(j+"",dataMap);
+        }
+
+        CellRange[] mergedCells2 = sheet.getCells();
+        for (int i=0;i<mergedCells2.length;i++){
+            CellRange mergedCell = mergedCells2[i];
+            String data = mergedCell.getComment().getRichText().getText();
+            if(StringUtils.isEmpty(data)){
+                j = j+1;
+                mergedCell.getComment().getRichText().setText(j+"");
+                mergedCell.setValue(j+"");
+                Map<String,Integer> dataMap = new HashMap<>();
+                dataMap.put("x1",mergedCell.getRow());
+                dataMap.put("x2",mergedCell.getLastRow());
+                dataMap.put("y1",mergedCell.getColumn());
+                dataMap.put("y2",mergedCell.getLastColumn());
+                xyList.put(j+"",dataMap);
+            }
+        }
+        sheet.saveToHtml(thmlUrl2, options);
+
+        // 组装坐标
+        File html1 = new File(thmlUrl);  // 原始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.html();
+                if(html.indexOf("div")>=0){
+                    html=cell2.children().get(0).html();
+                }
+                Map<String, Integer> xyMap = xyList.get(html);
+                if(xyMap!=null){
+                    cell1.attr("x1",xyMap.get("x1")+"");
+                    cell1.attr("x2",xyMap.get("x2")+"");
+                    cell1.attr("y1",xyMap.get("y1")+"");
+                    cell1.attr("y2",xyMap.get("y2")+"");
+                }
+            }
+        }
+
+        File writeFile = new File(thmlUrl);
+        FileUtil.writeToFile(writeFile, doc1.html(), Boolean.parseBoolean("UTF-8"));
+
         detail.setExtension(file.getOriginalFilename());
         detail.setFileUrl(bladeFile1.getLink());
         detail.setFileType(3); // 表示为清表信息  1 表示祖节点  2 表示为节点信息 3 表示清表
         detail.setHtmlUrl(thmlUrl);
         excelTabService.saveOrUpdate(detail);
+
+        if(html2.exists()){
+            html2.delete();
+        }
         // 解析html
         expailHtmlInfo(thmlUrl, detail.getId());
         return R.success("上传成功");
@@ -454,7 +530,7 @@ public class ExcelTabController extends BladeController {
             @ApiImplicitParam(name = "tabId", value = "表Id", required = true),
     })
     public R<List<ExceTabTreVO>> saveLinkeTab(Long exceTabId, Long tabId) throws IOException {
-        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        String file_path = FileUtils.getSysLocalFileUrl();
         // 关联 私有项目 wbs 数据信息
         WbsTreePrivate wbsTree = new WbsTreePrivate();
         wbsTree.setPKeyId(tabId);
@@ -599,7 +675,6 @@ public class ExcelTabController extends BladeController {
             //关联清表后 表单名和清表一样
             aPrivate.setNodeName(excelTab.getName());
             aPrivate.setFullName(excelTab.getName());
-
             wbsTreeContractService.updateAllNodeTabById(aPrivate);
         }
         return R.success("关联成功");

+ 16 - 5
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -1336,12 +1336,19 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         //标题添加
         ProjectInfo projectInfo = projectInfoService.getById(wbsTreeContract.getProjectId());
 
+        //判断是否是水利水电表,水利水电项目名14,表名12 。   其他表都是18
+        int isWater = 14;
+        ExcelTab tab = baseMapper.getWaterByTableId(wbsTreeContract.getExcelId());
+        if (tab != null){
+            isWater = 12;
+        }
+
         int all = sheet.getRow(0).getLastCellNum();
         int mergedCellCnt = sheet.getNumMergedRegions();
         for (int i = 0; i < mergedCellCnt - 1; i++) {
             CellRangeAddress mergedCell = sheet.getMergedRegion(i);
-            int xx = mergedCell.getNumberOfCells();
-            if (xx == all) {
+            int xx = mergedCell.getNumberOfCells()+2;
+            if (xx >= all) {
                 int fisRow = mergedCell.getFirstRow();
                 int firsrCol = mergedCell.getFirstColumn();
 
@@ -1357,9 +1364,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 CellStyle newStyle = workbook.createCellStyle(); //创建单元格样式
                 newStyle.cloneStyleFrom(cell.getCellStyle());
 
-
                 short fontHeightInPoints = redFont.getFontHeightInPoints();
-                if (fontHeightInPoints >= 14 && StringUtils.isEmpty(cell.getStringCellValue()) && fisRow <= 8) {
+                if (fontHeightInPoints >= isWater && StringUtils.isEmpty(cell.getStringCellValue()) && fisRow <= 8) {
 
                     String title = projectInfo.getProjectName();
                     if (title.length() >= 30) {
@@ -1501,12 +1507,17 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                     if (cell != null || ObjectUtils.isNotEmpty(cell)) {
                                         cell.setCellValue(myData);
                                     }
+                                   boolean wrap = cell.getCellStyle().getWrapText();
+                                    if(!wrap){
+                                        cell.getCellStyle().setShrinkToFit(true);
+                                    }
                                 }
                             }
                         }
                     }
                 }
             }
+
             // 组装电签设置
             QueryWrapper<TextdictInfo> queryWrapper = new QueryWrapper<>();
             queryWrapper.in("type", 2, 6);
@@ -1625,7 +1636,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
 
     @Override
     public void getBussPdfs(String nodeId, String classify, String contractId, String projectId) throws Exception {
-        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        String file_path = FileUtils.getSysLocalFileUrl();
         // 获取有权限的节点信息
         List<AppWbsTreeContractVO> wbsTreeContractList = wbsTreeContractService.searchNodeAllTable(nodeId, classify, contractId, projectId);
         List<String> data = new ArrayList<>();