浏览代码

Merge branch 'dev' of http://219.151.181.73:3000/zhuwei/bladex into cr

chenr 2 月之前
父节点
当前提交
53c3956d0a

+ 6 - 416
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeContractController.java

@@ -66,6 +66,7 @@ import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import org.springframework.http.ContentDisposition;
 
 @RestController
 @AllArgsConstructor
@@ -366,8 +367,12 @@ public class WbsTreeContractController extends BladeController {
             //返回响应
             try (ServletOutputStream outputStream = response.getOutputStream();
                  ByteArrayOutputStream byteArrayOutputStreamResult = new ByteArrayOutputStream()) {
+                //文件编码处理
+                String encode = URLEncoder.encode(fileName, "UTF-8");
+                encode = encode.replaceAll( "\\+", " ");
+                encode = encode.replaceAll( "%2B", "+");
                 //设置响应头
-                response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
+                response.setHeader("Content-Disposition", "attachment; filename=" + encode + ".xlsx");
                 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                 workbook1.write(byteArrayOutputStreamResult);
                 byte[] excelBytesResult = byteArrayOutputStreamResult.toByteArray();
@@ -376,200 +381,6 @@ public class WbsTreeContractController extends BladeController {
                 logger.error("下载excel时出现异常:" + e.getMessage(), e);
                 e.printStackTrace();
             }
-
-//            htmlUrl = CommonUtil.replaceOssUrl(htmlUrl);
-//            InputStream htmlInputStream = FileUtils.getInputStreamByUrl(htmlUrl);
-//            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-//            LoadOptions lo = new LoadOptions(LoadFormat.HTML);
-//            workbook = new Workbook(htmlInputStream,lo);
-//
-//            workbook.save(byteArrayOutputStream, SaveFormat.XLSX);
-//
-//            //将转换的spireExcel存储到流中
-//            byte[] excelBytes = byteArrayOutputStream.toByteArray();
-
-
-
-
-
-
-
-            //把spireExcel转为poiExcel
-//            try (InputStream inputStream = new ByteArrayInputStream(excelBytes)) {
-//                org.apache.poi.ss.usermodel.Workbook poiWorkbook = new XSSFWorkbook(inputStream);
-//                Sheet poiSheet = poiWorkbook.getSheetAt(0); //获取第一个工作表
-//                //存储需要修改的单元格和相关信息的列表
-//                List<CellModificationInfo> cellsToModify = new ArrayList<>();
-//                //解析html 获取合并单元格
-//                InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(htmlUrl);
-//                String htmlString = IoUtil.readToString(inputStreamByUrl);
-//                Document doc = Jsoup.parse(htmlString);
-//                Element table = doc.select("table").first();
-//                Elements rows = table.select("tr");
-//                //最大列数
-//                int maxColumns = calculateMaxColumns(rows);
-//                List<CellRangeAddress> mergedRegions = new ArrayList<>();
-//                // 保存需要保留的单元格内容和样式
-//                Map<CellRangeAddress, String> data = new HashMap<>();
-//                Map<Integer,Integer> rowHeight = new HashMap<>();
-//
-//
-//
-//                // 记录每个单元格的位置和合并信息
-//                for (int i=0;i<rows.size();i++) {
-//                    Element row1 = rows.get(i);
-//                    Elements cells = row1.select("td, th");
-//                    int colVal = 0;
-//                    int index = 0;
-//                    for (int j=0;j<cells.size();j++) {
-//                        Element cell = cells.get(j);
-//                        // 获取html每行的高度
-//                        String style = cell.attr("style");
-//                        Pattern pattern = Pattern.compile("height:\\s*(\\d+)px");
-//                        Matcher matcher = pattern.matcher(style);
-//                        if (matcher.find()) {
-//                            int height = Integer.parseInt(matcher.group(1));
-//                            if(height>0){
-//                                rowHeight.put(i, height);  // 记录行高
-//                            }
-//                        }
-//
-//                        int rowspan = cell.hasAttr("rowspan") ? Integer.parseInt(cell.attr("rowspan")) : 1; //
-//                        int colspan = cell.hasAttr("colspan") ? Integer.parseInt(cell.attr("colspan")) : 1;
-//                        int x1 =-1;
-//                        int x2 =-1;
-//                        int y1 =-1;
-//                        int y2 =-1;
-//
-//                        if(cell.hasAttr("x1") && cell.hasAttr("y1")){ //直接获取
-//                            x1 = Integer.parseInt(cell.attr("x1")) - 1; //: -1;//起始列
-//                            x2 = Integer.parseInt(cell.attr("x2")) - 1; //: -1;//结束列
-//                            y1 = Integer.parseInt(cell.attr("y1")) - 1; //: -1;//起始行
-//                            y2 = Integer.parseInt(cell.attr("y2")) - 1; //: -1;//结束行
-//                            colVal=x2+1;
-//                        }else{
-//                            Elements ids = cell.getElementsByAttribute("id");
-//                            if(ids.size()==1){
-//                                Element cell2 = ids.get(0);
-//                                x1 = Integer.parseInt(cell2.attr("x1")) - 1; //: -1;//起始列
-//                                x2 = Integer.parseInt(cell2.attr("x2")) - 1; //: -1;//结束列
-//                                y1 = Integer.parseInt(cell2.attr("y1")) - 1; //: -1;//起始行
-//                                y2 = Integer.parseInt(cell2.attr("y2")) - 1; //: -1;//结束行
-//                                colVal=x2+1;
-//                            }else{
-//                                System.out.println(cell.text());
-//
-//                                if(i <=80) {
-//                                    if (j == 0) {
-//                                        x1 = 0;
-//                                        x2 = colspan - 1;
-//                                        y1 = i;
-//                                        y2 = i + rowspan - 1;
-//                                        colVal = x2 + 1;
-//                                    } else {
-//                                        if(colspan>=2){
-//                                            x1 = colVal;
-//                                            x2 = colVal + colspan - 1;
-//                                        }else{
-//                                            x1 = colVal;
-//                                            x2 = colVal ;
-//                                        }
-//
-//                                        y1 = i;
-//                                        y2 = i + rowspan - 1;
-//                                        colVal = x2 + 1;
-//                                    }
-//                                }
-//                            }
-//                        }
-//
-//                        // 记录合并区域
-//                        if (x1 != -1 && x2 != -1 && y1 != -1 && y2 != -1) {
-//                            if(rowspan >=2 || colspan >=2){
-//                                CellRangeAddress region = new CellRangeAddress(y1, y2, x1, x2);
-//                                mergedRegions.add(region);
-//                                data.put(region, cell.text());
-//                            }
-//                        }
-//                        index ++;
-//                    }
-//                }
-//                // 按顺序合并单元格(从上到下、从左到右)
-//                for (int i = poiSheet.getNumMergedRegions() - 1; i >= 0; i--) {
-//                    poiSheet.removeMergedRegion(i);
-//                }
-//                for (CellRangeAddress region : mergedRegions) {
-//                    poiSheet.addMergedRegion(region);
-//                }
-//
-//                for (Row row : poiSheet) {
-//                    //判断当前行是否是最大列 如果不是 就补充到最大列
-//                    short lastCellNum = row.getLastCellNum();
-//
-//                    int rowIndex = row.getRowNum();
-//                    if (rowHeight.containsKey(rowIndex)) {
-//                        // 将像素转换为POI的行高单位(1px ≈ 0.75 points)
-//                        row.setHeightInPoints(rowHeight.get(rowIndex) * 0.75f);
-//                    }
-//
-//                    if(maxColumns > lastCellNum){
-//                        for (int i = maxColumns - 1; i > lastCellNum; i--) {
-//                            row.createCell(i);
-//                            Cell cell = row.getCell(i);
-//                            //设置新单元格的样式为第一个单元格的样式
-//                            cell.setCellStyle(row.getCell(0).getCellStyle());
-//                        }
-//                    }
-//                    for (Cell cell : row) {
-//                        int cellType = cell.getCellType();
-//                        if (cellType == CellType.STRING.getCode() && ObjectUtil.isNotEmpty(cell.getStringCellValue())) {
-//                            //存储需要修改的单元格信息
-//                            cellsToModify.add(new CellModificationInfo(cell, cell.getStringCellValue().trim()));
-//                        }
-//                        //获取单元格所属的合并单元格区域
-//                        CellRangeAddress mergedRegion = findMergedRegion(poiSheet, cell.getRowIndex(), cell.getColumnIndex());
-//                        if (mergedRegion != null) {
-//                            //合并单元格的数据 为之前记录的数据
-//                            cell.setCellValue(data.get(mergedRegion));
-//
-//                            //存储需要修改的合并单元格信息
-//                            cellsToModify.add(new CellModificationInfo(cell, mergedRegion));
-//                        }
-//                    }
-//                }
-//
-//                //遍历结束后,实际修改单元格样式和内容
-//                for (CellModificationInfo info : cellsToModify) {
-//                    Cell cell = info.getCell();
-//                    //只更新非合并单元格的数据
-//                    if (info.getMergedRegion() == null && info.hasStringContent()) {
-//                        cell.setCellValue(info.getStringContent());
-//                    }
-//                    //复制单元格样式
-//                    CellStyle cellStyle = poiWorkbook.createCellStyle();
-//                    CellStyle sourceCellStyle = cell.getCellStyle(); //获取原单元格的样式
-//                    cellStyle.cloneStyleFrom(sourceCellStyle); //复制样式
-//                    setBlackBorder(cellStyle); //设置边框
-//                    cell.setCellStyle(cellStyle);
-//
-////                    if (info.hasMergedRegion()) { //修改合并单元格边框线
-////                        CellRangeAddress mergedRegion = info.getMergedRegion();
-////                        RegionUtil.setBorderTop(BorderStyle.THIN, mergedRegion, poiSheet);
-////                        RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, poiSheet);
-////                        RegionUtil.setBorderBottom(BorderStyle.THIN, mergedRegion, poiSheet);
-////                        RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, poiSheet);
-////                        RegionUtil.setBorderLeft(BorderStyle.THIN, mergedRegion, poiSheet);
-////                        RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, poiSheet);
-////                        RegionUtil.setBorderRight(BorderStyle.THIN, mergedRegion, poiSheet);
-////                        RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, poiSheet);
-////                    }
-//                }
-//
-//
-//            } catch (IOException e) {
-//                logger.error("下载excel时出现异常:" + e.getMessage(), e);
-//                e.printStackTrace();
-//            }
         } catch (Exception e) {
             logger.error("下载excel时出现异常:" + e.getMessage(), e);
             e.printStackTrace();
@@ -581,227 +392,6 @@ public class WbsTreeContractController extends BladeController {
     }
 
 
-    public static void maiqqn(String[] args) throws Exception {
-        String htmlUrl = "/Users/hongchuangyanfa/fsdownload/1892816666778140672.html";
-
-        InputStream htmlInputStream = new FileInputStream(new File(htmlUrl));
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        LoadOptions lo = new LoadOptions(LoadFormat.HTML);
-        Workbook workbook = new Workbook(htmlInputStream,lo);
-
-        workbook.save(byteArrayOutputStream, SaveFormat.XLSX);
-
-        //将转换的spireExcel存储到流中
-        byte[] excelBytes = byteArrayOutputStream.toByteArray();
-
-        //把spireExcel转为poiExcel
-        try (InputStream inputStream = new ByteArrayInputStream(excelBytes)) {
-            org.apache.poi.ss.usermodel.Workbook poiWorkbook = new XSSFWorkbook(inputStream);
-            Sheet poiSheet = poiWorkbook.getSheetAt(0); //获取第一个工作表
-            //存储需要修改的单元格和相关信息的列表
-            List<CellModificationInfo> cellsToModify = new ArrayList<>();
-            //解析html 获取合并单元格
-            InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(htmlUrl);
-            String htmlString = IoUtil.readToString(inputStreamByUrl);
-            Document doc = Jsoup.parse(htmlString);
-            Element table = doc.select("table").first();
-            Elements rows = table.select("tr");
-            //最大列数
-            int maxColumns = calculateMaxColumns(rows);
-            List<CellRangeAddress> mergedRegions = new ArrayList<>();
-            // 保存需要保留的单元格内容和样式
-            Map<CellRangeAddress, String> data = new HashMap<>();
-            Map<Integer,Integer> rowHeight = new HashMap<>();
-            // 记录每个单元格的位置和合并信息
-
-            for (int i=0;i<rows.size();i++) {
-                Element row1 = rows.get(i);
-                Elements cells = row1.select("td, th");
-                for (int j=0;j<cells.size();j++) {
-                    Element cell = cells.get(j);
-                    int rowspan = cell.hasAttr("rowspan") ? Integer.parseInt(cell.attr("rowspan")) : 1;
-                    int colspan = cell.hasAttr("colspan") ? Integer.parseInt(cell.attr("colspan")) : 1;
-                    int x1 =-1;
-                    int x2 =-1;
-                    int y1 =-1;
-                    int y2 =-1;
-                    if(cell.hasAttr("x1") && cell.hasAttr("y1")){ //直接获取
-                        x1 = Integer.parseInt(cell.attr("x1")) - 1; //: -1;//起始列
-                        x2 = Integer.parseInt(cell.attr("x2")) - 1; //: -1;//结束列
-                        y1 = Integer.parseInt(cell.attr("y1")) - 1; //: -1;//起始行
-                        y2 = Integer.parseInt(cell.attr("y2")) - 1; //: -1;//结束行
-                    }else{
-                        Elements ids = cell.getElementsByAttribute("id");
-                        if(ids.size()==1){
-                            Element cell2 = ids.get(0);
-                            x1 = Integer.parseInt(cell2.attr("x1")) - 1; //: -1;//起始列
-                            x2 = Integer.parseInt(cell2.attr("x2")) - 1; //: -1;//结束列
-                            y1 = Integer.parseInt(cell2.attr("y1")) - 1; //: -1;//起始行
-                            y2 = Integer.parseInt(cell2.attr("y2")) - 1; //: -1;//结束行
-                        }
-                    }
-                }
-            }
-
-
-
-
-            /*
-            for (int i=0;i<rows.size();i++) {
-                Element row1 = rows.get(i);
-                Elements cells = row1.select("td, th");
-                int rowVal = 0;
-                int colVal = 0;
-                int index = 0;
-                for (int j=0;j<cells.size();j++) {
-                    Element cell = cells.get(j);
-                    // 获取html每行的高度
-                    String style = cell.attr("style");
-                    Pattern pattern = Pattern.compile("height:\\s*(\\d+)px");
-                    Matcher matcher = pattern.matcher(style);
-                    if (matcher.find()) {
-                        int height = Integer.parseInt(matcher.group(1));
-                        if(height>0){
-                            rowHeight.put(i, height);  // 记录行高
-                        }
-                    }
-
-                    int rowspan = cell.hasAttr("rowspan") ? Integer.parseInt(cell.attr("rowspan")) : 1;
-                    int colspan = cell.hasAttr("colspan") ? Integer.parseInt(cell.attr("colspan")) : 1;
-                    int x1 =-1;
-                    int x2 =-1;
-                    int y1 =-1;
-                    int y2 =-1;
-
-                    if(cell.hasAttr("x1") && cell.hasAttr("y1")){ //直接获取
-                        x1 = Integer.parseInt(cell.attr("x1")) - 1; //: -1;//起始列
-                        x2 = Integer.parseInt(cell.attr("x2")) - 1; //: -1;//结束列
-                        y1 = Integer.parseInt(cell.attr("y1")) - 1; //: -1;//起始行
-                        y2 = Integer.parseInt(cell.attr("y2")) - 1; //: -1;//结束行
-                        colVal=x2+1;
-                    }else{
-                        Elements ids = cell.getElementsByAttribute("id");
-                        if(ids.size()==1){
-                            Element cell2 = ids.get(0);
-                            x1 = Integer.parseInt(cell2.attr("x1")) - 1; //: -1;//起始列
-                            x2 = Integer.parseInt(cell2.attr("x2")) - 1; //: -1;//结束列
-                            y1 = Integer.parseInt(cell2.attr("y1")) - 1; //: -1;//起始行
-                            y2 = Integer.parseInt(cell2.attr("y2")) - 1; //: -1;//结束行
-                            colVal=x2+1;
-                        }else{
-                            System.out.println(cell.text());
-
-                            if(i ==9 ) {
-                                if (j == 0) {
-                                    x1 = 0;
-                                    x2 = colspan - 1;
-                                    y1 = i;
-                                    y2 = i + rowspan - 1;
-                                    colVal = x2 + 1;
-                                } else {
-                                    if(colspan>=2){
-                                       x1 = colVal;
-                                       x2 = colVal + colspan - 1;
-                                    }else{
-                                        x1 = colVal;
-                                        x2 = colVal ;
-                                    }
-
-                                    if(rowspan>=2){
-                                        y1 = i;
-                                        y2 = i + rowspan - 1;
-                                    }else{
-                                        y1 = i;
-                                        y2 = i ;
-                                    }
-                                    colVal = x2 + 1;
-                                }
-                            }
-                        }
-                    }
-
-                    // 记录合并区域
-                    if (x1 != -1 && x2 != -1 && y1 != -1 && y2 != -1) {
-                        if(rowspan >=2 || colspan >=2){
-                            CellRangeAddress region = new CellRangeAddress(y1, y2, x1, x2);
-                            mergedRegions.add(region);
-                            data.put(region, cell.text());
-                        }
-                    }
-                    index ++;
-                }
-            }*/
-            // 按顺序合并单元格(从上到下、从左到右)
-            for (int i = poiSheet.getNumMergedRegions() - 1; i >= 0; i--) {
-                poiSheet.removeMergedRegion(i);
-            }
-            for (CellRangeAddress region : mergedRegions) {
-                poiSheet.addMergedRegion(region);
-            }
-
-            for (Row row : poiSheet) {
-                //判断当前行是否是最大列 如果不是 就补充到最大列
-                short lastCellNum = row.getLastCellNum();
-
-                int rowIndex = row.getRowNum();
-                if (rowHeight.containsKey(rowIndex)) {
-                    // 将像素转换为POI的行高单位(1px ≈ 0.75 points)
-                    row.setHeightInPoints(rowHeight.get(rowIndex) * 0.75f);
-                }
-
-                if(maxColumns > lastCellNum){
-                    for (int i = maxColumns - 1; i > lastCellNum; i--) {
-                        row.createCell(i);
-                        Cell cell = row.getCell(i);
-                        //设置新单元格的样式为第一个单元格的样式
-                        cell.setCellStyle(row.getCell(0).getCellStyle());
-                    }
-                }
-                for (Cell cell : row) {
-                    int cellType = cell.getCellType();
-                    if (cellType == CellType.STRING.getCode() && ObjectUtil.isNotEmpty(cell.getStringCellValue())) {
-                        //存储需要修改的单元格信息
-                        cellsToModify.add(new CellModificationInfo(cell, cell.getStringCellValue().trim()));
-                    }
-                    //获取单元格所属的合并单元格区域
-                    CellRangeAddress mergedRegion = findMergedRegion(poiSheet, cell.getRowIndex(), cell.getColumnIndex());
-                    if (mergedRegion != null) {
-                        //合并单元格的数据 为之前记录的数据
-                        cell.setCellValue(data.get(mergedRegion));
-
-                        //存储需要修改的合并单元格信息
-                        cellsToModify.add(new CellModificationInfo(cell, mergedRegion));
-                    }
-                }
-            }
-
-            //遍历结束后,实际修改单元格样式和内容
-            for (CellModificationInfo info : cellsToModify) {
-                Cell cell = info.getCell();
-                //只更新非合并单元格的数据
-                if (info.getMergedRegion() == null && info.hasStringContent()) {
-                    cell.setCellValue(info.getStringContent());
-                }
-                //复制单元格样式
-                CellStyle cellStyle = poiWorkbook.createCellStyle();
-
-                CellStyle sourceCellStyle = cell.getCellStyle(); //获取原单元格的样式
-                cellStyle.cloneStyleFrom(sourceCellStyle); //复制样式
-                setBlackBorder(cellStyle); //设置边框
-                cell.setCellStyle(cellStyle);
-            }
-
-            //返回响应
-            FileOutputStream outputStream = new FileOutputStream("/Users/hongchuangyanfa/Desktop/22222/123.xlsx");
-            poiWorkbook.write(outputStream);
-
-        } catch (IOException e) {
-            logger.error("下载excel时出现异常:" + e.getMessage(), e);
-            e.printStackTrace();
-        }
-
-    }
-
 
 
     // 计算最大列数以对齐所有行

+ 24 - 11
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreePrivateController.java

@@ -860,22 +860,35 @@ public class WbsTreePrivateController extends BladeController {
     @GetMapping("/getTitleRange")
     @ApiOperationSupport(order = 33)
     @ApiOperation(value = "获取题名范围",notes = "获取题名范围")
-    public R<List<TitleRangeVo>> getTitleRange(@RequestParam String projectId,@RequestParam Long nameId){
+    public R<List<TitleRangeVo>> getTitleRange(@RequestParam String projectId,@RequestParam(required = false) Long nameId){
         List<WbsTreePrivate>list=wbsTreeService.getTitleRange(projectId);
         List<WbsParam> list1 = iWbsParamService.getBaseMapper().selectList(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getK, "FILE_TITLE").eq(WbsParam::getProjectId, projectId));
         if(list1.size()>0){
-            Map<Long, Long> map = list1.stream()
-                .filter(o -> o.getNameType() != null && o.getNameType() == 2)
-                .collect(Collectors.toMap(
-                    WbsParam::getNodeId,   // key:nodeId
-                    WbsParam::getNameId    // value:nameId
-                ));
-            //判断是否已经被选中
-            for (WbsTreePrivate wbsTreePrivate : list) {
-                if(map.containsKey(wbsTreePrivate.getId())&& !Objects.equals(map.get(wbsTreePrivate.getId()), nameId)){
-                    wbsTreePrivate.setStatus(11);
+                //修改
+            if(nameId!=null){
+                Map<Long, Long> map = list1.stream()
+                    .filter(o -> o.getNameType() != null && o.getNameType() == 2)
+                    .collect(Collectors.toMap(
+                        WbsParam::getNodeId,   // key:nodeId
+                        WbsParam::getNameId    // value:nameId
+                    ));
+                //判断是否已经被选中
+                for (WbsTreePrivate wbsTreePrivate : list) {
+                    if(map.containsKey(wbsTreePrivate.getId())&& !Objects.equals(map.get(wbsTreePrivate.getId()), nameId)){
+                        wbsTreePrivate.setStatus(11);
+                    }
+                }
+            }else {
+                //新增
+                List<Long> longs = list1.stream().filter(o->o.getNameType()!=null&&o.getNameType()==2).map(l -> l.getNodeId()).collect(Collectors.toList());
+                //判断是否已经被选中
+                for (WbsTreePrivate wbsTreePrivate : list) {
+                    if(longs.contains(wbsTreePrivate.getId())){
+                        wbsTreePrivate.setStatus(11);
+                    }
                 }
             }
+
         }
         return R.data(list.stream()
             .map(wbsTreePrivate -> {

+ 16 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsFormElementMapper.java

@@ -12,6 +12,7 @@ import org.springblade.manager.entity.WbsTree;
 import org.springblade.manager.vo.WbsFormElementVO;
 
 import java.util.List;
+import java.util.Map;
 
 public interface WbsFormElementMapper extends BaseMapper<WbsFormElement> {
 
@@ -61,4 +62,19 @@ public interface WbsFormElementMapper extends BaseMapper<WbsFormElement> {
 
     //查询 元素与实体表字段不匹配的字段
     List<WbsFormElementDTO2> selColumnsByTabName(String parentId);
+
+    /**
+     * 查询表字段长度
+     * @param initTableName
+     * @return
+     */
+    List<Map<String, Object>> selectFiledLength(@Param("initTableName") String initTableName);
+
+    /**
+     * 查询指定字段最长数据的长度
+     * @param initTableName
+     * @param eKey
+     * @return
+     */
+    Integer selectFiledDataMaxLength(@Param("tableName") String initTableName,@Param("key") String eKey);
 }

+ 6 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsFormElementMapper.xml

@@ -166,5 +166,11 @@
     <select id="selColumnsByTabName" resultType="java.lang.String">
         SELECT data_type FROM information_schema.columns WHERE table_name=#{initTableName} AND column_name = #{eKey}
     </select>
+    <select id="selectFiledLength" resultType="java.util.Map">
+        select column_name `key`,character_octet_length length from INFORMATION_SCHEMA.COLUMNS  where table_name = #{initTableName}
+    </select>
+    <select id="selectFiledDataMaxLength" resultType="java.lang.Integer">
+        select MAX(LENGTH(${key})) from ${tableName}
+    </select>
 
 </mapper>

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeContractMapper.xml

@@ -444,7 +444,7 @@
             html_url = #{aPrivate.htmlUrl}
         where type = 2
           and project_id = #{aPrivate.projectId}
-          and id = #{aPrivate.id};
+          and is_type_private_pid = #{aPrivate.pKeyId};
     </select>
 
     <select id="selectWbsTableOwnerRoleList" resultType="org.springblade.manager.entity.WbsTableOwnerRole">

+ 11 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -2264,7 +2264,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                             } else {
                                 Row row = sheet.getRow(y1 - 1);
                                 if (row != null) {
-                                    Cell cell = row.getCell(x1 - 1);
+                                    Cell cell = row.getCell(x1 - 1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                                     if (cell != null || ObjectUtils.isNotEmpty(cell)) {
                                         short fontIndex = cell.getCellStyle().getFontIndex();
                                         Font fontAt = workbook.getFontAt(fontIndex);
@@ -2294,14 +2294,21 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
 
                     Row row = sheet.getRow(y1 - 1);
                     if (row != null) {
-                        Cell cell = row.getCell(x1 - 1);
+                        Cell cell = row.getCell(x1 - 1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                         if (cell != null || ObjectUtils.isNotEmpty(cell)) {
                              // 获取单元格的现有值
                             String existingValue = cell.getStringCellValue();
                             // 获取单元格的现有富文本字符串
                             RichTextString existingRichTextString = cell.getRichStringCellValue();
+                            String s = null;
+                            if(StringUtils.isEmpty(existingValue)){
+                                s = dqid;
+                            }else{
+                                s = existingValue + "*" + dqid;
+                            }
+
                              // 创建一个新的副文本字符串,原有值+电签ID
-                            RichTextString richTextString = workbook.getCreationHelper().createRichTextString(existingValue + dqid);
+                            RichTextString richTextString = workbook.getCreationHelper().createRichTextString(s);
                             // 复制原有部分的字体格式
                             if (existingRichTextString instanceof XSSFRichTextString) {
                                 XSSFRichTextString xssfRichTextString = (XSSFRichTextString) existingRichTextString;
@@ -2332,7 +2339,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                             newFont.setColor(IndexedColors.WHITE.getIndex());
                             newFont.setFontHeightInPoints(Short.valueOf("1")); // 可根据需要调整字体大小
                             //从原有值之后,电签ID开始设置成新的格式。
-                            richTextString.applyFont(existingValue.length(), existingValue.length() + dqid.length(), newFont);
+                            richTextString.applyFont(existingValue.length(), s.length(), newFont);
                              // 将副文本字符串设置到单元格
                             cell.setCellValue(richTextString);
                         }

+ 71 - 20
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsFormElementServiceImpl.java

@@ -36,6 +36,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
+import java.math.BigInteger;
 import java.text.ParseException;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -282,6 +283,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName) {
         if (StringUtils.isEmpty(initTableName)) {
             return R.fail("未获取到initTableName对应实体表名称,操作失败");
@@ -303,6 +305,19 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         wbsFormElementList.forEach(obj -> obj.setStatus(1));
         boolean b = this.updateBatchById(wbsFormElementList);
 
+        //字段级字段长度缓存
+        Map<String, Integer> lengthMap = new HashMap<>();
+
+        //查询当前表的所有字段级字段长度
+        List<Map<String, Object>> filedLengths = baseMapper.selectFiledLength(initTableName);
+        for (Map<String, Object> filedLength : filedLengths) {
+            BigInteger length = (BigInteger) filedLength.get("length");
+            if (length == null) {
+                continue;
+            }
+            lengthMap.put(filedLength.get("key").toString(), length.intValue());
+        }
+
         //修改实体表信息
         if (b) {
             String fId = "";
@@ -321,16 +336,16 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
 
                 if (eType.equals("bigint") && (eLength > 255 || eLength < 10)) {
                     this.updateBatchById(beforeUpdateWbsFormElements);
-                    return R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为10-255之间");
+                    return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为10-255之间");
                 } else if (eType.equals("varchar") && (eLength > 3000 || eLength < 10)) {
                     this.updateBatchById(beforeUpdateWbsFormElements);
-                    return  R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为10-3000之间");
+                    return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为10-3000之间");
                 } else if (eType.equals("decimal") && (eLength > 65 || eLength < 10)) {
                     this.updateBatchById(beforeUpdateWbsFormElements);
-                    return  R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为10-65之间");
+                    return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为10-65之间");
                 } else if (eType.equals("datetime") && (eLength > 400 || eLength < 0)) {
                     this.updateBatchById(beforeUpdateWbsFormElements);
-                    return  R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为0-400之间");
+                    return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为0-400之间");
                 }
 
                 //设置默认长度
@@ -346,7 +361,39 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                 int row1 = wbsTreeMapper.isThereAField(initTableName, eKey);
                 if (row1 > 0) {
                     try {
-                        baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength);
+                        //1、查询当前表当前字段
+
+                        //字段配置的长度
+                        Integer filedLength = lengthMap.get(eKey);
+                        if(filedLength == null){
+                            throw new RuntimeException("字段不存在");
+                        }
+                        //获取当前字段数据的最长数据长度
+                        Integer maxLength = baseMapper.selectFiledDataMaxLength(initTableName, eKey);
+                        //初始长度
+                        int initLength = 250;
+                        //当前字段数据长度为null
+                        if (maxLength == null) {
+                            //设置初始长度
+                            baseMapper.updateFiledType(initTableName, eKey, "varchar", initLength);
+                            wbsFormElement.setELength(initLength);
+                            baseMapper.updateById(wbsFormElement);
+                        } else {
+                            //动态扩容 每次根据最大数据长度扩容100
+                            int newLength = maxLength + 100;
+                            //如果字段的长度与扩容后的值一致则不去修改字段
+                            if (filedLength == newLength) {
+                                continue;
+                            }
+                            //如果数据的最大长度 +100 都大于字段配置的长度  则重新设置字段的长度
+                            if (filedLength >= newLength) {
+                                baseMapper.updateFiledType(initTableName, eKey, "varchar", newLength);
+                                wbsFormElement.setELength(newLength);
+                                baseMapper.updateById(wbsFormElement);
+                                continue;
+                            }
+                            baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength);
+                        }
                     } catch (Exception e) {
                         this.updateBatchById(beforeUpdateWbsFormElements);
                         throw new RuntimeException("字段长度范围超出总最大限制,请尝试缩小当前字段长度或其他字段长度");
@@ -868,23 +915,27 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
     }
 
     public boolean syncDataFiled(String initTableName, List<WbsFormElement> listData) {
-        for (WbsFormElement listDatum : listData) {
-            // String initTableFiledType = getInitTableFiledType(listDatum.getEType());
-            // int elementLength = getElementLength(initTableFiledType);
-            //同步
-            //判断是否存在该Key字段
-            int row1 = wbsTreeMapper.isThereAField(initTableName, listDatum.getEKey());
-            if (row1 == 0) {
-                //追加字段到实体表中
-                wbsTreeMapper.alterTableFiled(initTableName, listDatum.getEKey(), "varchar", DEFAULT_ELEMENT_LENGTH_VARCHAR);
-                //判断是否追加成功
-                int row2 = wbsTreeMapper.isThereAField(initTableName, listDatum.getEKey());
-                if (row2 != 1) {
-                    //追加失败,删除元素,跳过
-                    baseMapper.deleteElementByfId2(listDatum.getId());
+        try {
+            for (WbsFormElement listDatum : listData) {
+                // String initTableFiledType = getInitTableFiledType(listDatum.getEType());
+                // int elementLength = getElementLength(initTableFiledType);
+                //同步
+                //判断是否存在该Key字段
+                int row1 = wbsTreeMapper.isThereAField(initTableName, listDatum.getEKey());
+                if (row1 == 0) {
+                    //追加字段到实体表中
+                    wbsTreeMapper.alterTableFiled(initTableName, listDatum.getEKey(), "varchar", DEFAULT_ELEMENT_LENGTH_VARCHAR);
+                    //判断是否追加成功
+                    int row2 = wbsTreeMapper.isThereAField(initTableName, listDatum.getEKey());
+                    if (row2 != 1) {
+                        //追加失败,删除元素,跳过
+                        baseMapper.deleteElementByfId2(listDatum.getId());
+                    }
                 }
+                //baseMapper.addTableFiled(initTableName, listDatum.getEKey(), "varchar", DEFAULT_ELEMENT_LENGTH_VARCHAR);
             }
-            //baseMapper.addTableFiled(initTableName, listDatum.getEKey(), "varchar", DEFAULT_ELEMENT_LENGTH_VARCHAR);
+        } catch (Exception e) {
+            throw new RuntimeException("字段长度范围超出总最大限制,请尝试缩小当前字段长度或其他字段长度");
         }
         return true;
     }