Răsfoiți Sursa

批量上传清表

liuyc 2 ani în urmă
părinte
comite
6b0005ae7d

+ 167 - 406
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -16,11 +16,10 @@ import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.SneakyThrows;
 import org.apache.commons.codec.Charsets;
-import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang3.ObjectUtils;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Table;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -39,10 +38,13 @@ import org.springblade.core.mp.support.Query;
 import org.springblade.core.oss.model.BladeFile;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.utils.*;
 import org.springblade.manager.bean.TableInfo;
+import org.springblade.manager.dto.ExcelTabBatchUploadDTO;
+import org.springblade.manager.dto.ExcelTabFileDTO;
 import org.springblade.manager.entity.*;
 import org.springblade.manager.enums.ExecuteType;
 import org.springblade.manager.mapper.ExcelTabMapper;
@@ -307,35 +309,35 @@ public class ExcelTabController extends BladeController {
         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<>();
+        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.getColumn());
-            dataMap.put("x2",mergedCell.getLastColumn());
-            dataMap.put("y1",mergedCell.getRow());
-            dataMap.put("y2",mergedCell.getLastRow());
-            xyList.put(j+"",dataMap);
+            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++){
+        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.getColumn());
-                dataMap.put("x2",mergedCell.getLastColumn());
-                dataMap.put("y1",mergedCell.getRow());
-                dataMap.put("y2",mergedCell.getLastRow());
-                xyList.put(j+"",dataMap);
+            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);
@@ -355,20 +357,22 @@ public class ExcelTabController extends BladeController {
         Element table2 = doc2.select("table").first();
         Elements trs2 = table2.select("tr");
 
-        for(int i=0;i<trs1.size();i++){
+        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++){
+            for (int x = 0; x < td1.size(); x++) {
                 Element cell1 = td1.get(x);
                 Element cell2 = td2.get(x);
-                String html = cell2.text();
+                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")+"");
-                    cell1.attr("exc_xy",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") + "");
                 }
             }
         }
@@ -381,10 +385,10 @@ public class ExcelTabController extends BladeController {
         detail.setFileType(3); // 表示为清表信息  1 表示祖节点  2 表示为节点信息 3 表示清表
         detail.setHtmlUrl(thmlUrl);
         excelTabService.saveOrUpdate(detail);
-        if(html2.exists()){
+
+        if (html2.exists()) {
             html2.delete();
         }
-
         // 解析html
         expailHtmlInfo(thmlUrl, detail.getId());
         return R.success("上传成功");
@@ -534,10 +538,12 @@ public class ExcelTabController extends BladeController {
         WbsTreePrivate wbsTree = new WbsTreePrivate();
         wbsTree.setPKeyId(tabId);
         WbsTreePrivate aPrivate = wbsTreePrivateService.getOne(Condition.getQueryWrapper(wbsTree));
+
         aPrivate.setExcelId(exceTabId);
 
         // 获取excel 基本信息
         ExcelTab excelTab = excelTabService.getById(exceTabId);
+
         UpdateWrapper<WbsTreePrivate> updateWrapper = new UpdateWrapper<>();
         updateWrapper.in("p_key_id", tabId);
         updateWrapper.set("is_link_table", 2);
@@ -545,7 +551,9 @@ public class ExcelTabController extends BladeController {
         updateWrapper.set("excel_id", exceTabId);
 
         // 复制模版htmlURL
+
         File file_in = ResourceUtil.getFile(excelTab.getHtmlUrl());
+
         String filecode = SnowFlakeUtil.getId() + "";
         String thmlUrl = file_path + "/privateUrl/" + filecode + ".html";
         File file_out = ResourceUtil.getFile(thmlUrl);
@@ -561,12 +569,11 @@ public class ExcelTabController extends BladeController {
         //解析
         Element table = doc.select("table").first();
         Elements trs = table.select("tr");
-        if(StringUtils.isNotEmpty(excelTab.getTabId())){
+        if (StringUtils.isNotEmpty(excelTab.getTabId())) {
             updateWrapper.set("init_table_id", excelTab.getTabId());
             org.springblade.manager.entity.TableInfo tableInfo = tableInfoService.getById(excelTab.getTabId());
             updateWrapper.set("init_table_name", tableInfo.getTabEnName());
-            aPrivate.setInitTableName(tableInfo.getTabEnName());
-        }else {
+        } else {
             if (aPrivate.getInitTableId() == null) {
                 org.springblade.manager.entity.TableInfo tableInfo = tableInfoService.getOne(new LambdaQueryWrapper<org.springblade.manager.entity.TableInfo>()
                         .eq(org.springblade.manager.entity.TableInfo::getTabEnName, aPrivate.getInitTableName()));
@@ -575,9 +582,8 @@ public class ExcelTabController extends BladeController {
             }
         }
 
-
-
         List<WbsFormElement> elementList = wbsFormElementService.selectElementListByFid(aPrivate.getInitTableId() + "");
+
         for (int i = 0; i < trs.size(); i++) {
             Element tr = trs.get(i);
             Elements tds = tr.select("td");
@@ -624,6 +630,7 @@ public class ExcelTabController extends BladeController {
 
                     //字段正则表达式校验
                     String regularExpression = "$event" + "," + "'" + RegularExpressionUtil.getRegularExpression(filedType) + "','" + (StringUtils.isNotEmpty(filedType) ? WbsElementUtil.getTypeTips(filedType) : null) + "'," + i + "," + j;
+
                     if (is_true) {
                         element.children().get(0).attr("placeholder", lastName)
                                 .attr("weighing", maxScore + "").attr("id", attrInfo).attr("keyName", attrInfo)
@@ -661,15 +668,17 @@ public class ExcelTabController extends BladeController {
             pupdate.set("excel_id", aPrivate.getPKeyId());
             wbsTreePrivateService.update(pupdate);
         }
+
         wbsTreePrivateService.update(updateWrapper);
 
         //关联项目下所有的合同段
 //        if (aPrivate.getType() != 10) {
-            aPrivate.setHtmlUrl(thmlUrl);
-            //关联清表后 表单名和清表一样
-            aPrivate.setNodeName(excelTab.getName());
-            aPrivate.setFullName(excelTab.getName());
-            wbsTreeContractService.updateAllNodeTabById(aPrivate);
+        aPrivate.setHtmlUrl(thmlUrl);
+
+        //关联清表后 表单名和清表一样
+        aPrivate.setNodeName(excelTab.getName());
+        aPrivate.setFullName(excelTab.getName());
+        wbsTreeContractService.updateAllNodeTabById(aPrivate);
 //        }
         return R.success("关联成功");
     }
@@ -721,7 +730,7 @@ public class ExcelTabController extends BladeController {
         //判断是否是水利水电表,水利水电项目名14,表名12 。   其他表都是18
         Boolean isWater = false;
         ExcelTab tab = excelTabMapper.getWaterByTableId(wbsTreeContract.getExcelId());
-        if (tab != null){
+        if (tab != null) {
             isWater = true;
         }
 
@@ -736,11 +745,11 @@ public class ExcelTabController extends BladeController {
                 String style = data.attr("style");
                 if (style.indexOf("font-size") >= 0) {
                     int fontsize = Integer.parseInt(style.substring(style.indexOf("font-size:") + 10, style.indexOf(".0pt")));
-                    if (isWater){
+                    if (isWater) {
                         if (StringUtils.isNotEmpty(data.text()) && fontsize >= 12) {
                             trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
                         }
-                    }else {
+                    } else {
                         if (StringUtils.isNotEmpty(data.text()) && fontsize >= 14) {
                             trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
                         }
@@ -795,7 +804,8 @@ public class ExcelTabController extends BladeController {
             @ApiImplicitParam(name = "pkeyId", value = "pkeyId", required = true)
     })
     public R getExcelHtml(Long pkeyId) throws Exception {
-
+        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
         Thread.sleep(200);
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(pkeyId);
         if (wbsTreePrivate == null) {
@@ -806,27 +816,26 @@ public class ExcelTabController extends BladeController {
         }
 
         String fileUrl = wbsTreePrivate.getHtmlUrl();
+        File file1 = ResourceUtil.getFile(fileUrl);
+        InputStream fileInputStream;
+        if (file1.exists()) {
+            fileInputStream = new FileInputStream(file1);
+        } else {
+            String path = sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path, "");
+            fileInputStream = CommonUtil.getOSSInputStream(path);
+        }
 
-        InputStream  fileInputStream = FileUtils.getInputStreamByUrl(fileUrl);
         String htmlString = IoUtil.readToString(fileInputStream);
+
         // 远程搜索配置
         Document doc = Jsoup.parse(htmlString);
         Element table = doc.select("table").first();
         Elements col = doc.select("Col");
         doc.select("Col").remove();
         ProjectInfo projectInfo = projectInfoService.getById(wbsTreePrivate.getProjectId());
-        // 添加标题显示
-
-        //判断是否是水利水电表,水利水电项目名14,表名12 。   其他表都是18
-        Boolean isWater = false;
-        ExcelTab tab = excelTabMapper.getWaterByTableId(wbsTreePrivate.getExcelId());
-        if (tab != null){
-            isWater = true;
-        }
-
         // 添加标题显示
         Elements trs = table.select("tr");
-        for (int i = 1; i < 6; i++) {
+        for (int i = 0; i < 6; i++) {
             Element tr = trs.get(i);
             Elements tds = tr.select("td");
             for (int j = 0; j < tds.size(); j++) {
@@ -835,14 +844,9 @@ public class ExcelTabController extends BladeController {
                 String style = data.attr("style");
                 if (style.indexOf("font-size") >= 0) {
                     int fontsize = Integer.parseInt(style.substring(style.indexOf("font-size:") + 10, style.indexOf(".0pt")));
-                    if (isWater){
-                        if (StringUtils.isNotEmpty(data.text()) && fontsize >= 12) {
-                            trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
-                        }
-                    }else {
-                        if (StringUtils.isNotEmpty(data.text()) && fontsize >= 14) {
-                            trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
-                        }
+                    if (StringUtils.isNotEmpty(data.text()) && fontsize >= 12) {
+                        trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
+                        break;
                     }
                 }
             }
@@ -915,329 +919,6 @@ public class ExcelTabController extends BladeController {
         File file1 = ResourceUtil.getFile(thmlUrl);
         String htmlString = IoUtil.readToString(new FileInputStream(file1));
 
-        /*
-           解析
-           1 解析样式
-           2 计算坐标
-           3 计算区域位置
-         */
-        // 样式集合
-        Document doc = Jsoup.parse(htmlString);
-        // 解析 style
-        Map<String, String> styleMap = getHtmlStyle(doc);
-        //解析
-        Element table = doc.select("table").first();
-        Elements trs = table.select("tr");
-
-        // 获取图片信息
-        Elements imgs = doc.select("img");
-
-        // 获取总行列数
-        int maxCol = doc.select("Col").size();
-        String[] rowData = new String[trs.size() + 5]; //本来加一的 害怕出现特殊情况 故意 加 5
-
-        // 行的状态
-        boolean index_state = false;
-        // 区域划分表示
-        int xy_type = 1;
-
-        // 解析 excel元素集合
-        List<ExctabCell> colTitle = new ArrayList<>();
-
-//      标题集合信息
-        List<Map<String, String>> zikey = new ArrayList<>();
-        for (int i = 0; i <= trs.size() - 1; i++) {
-            Element tr = trs.get(i);
-            Elements tds = tr.select("td");
-            String xyInof = getTrInfo(tds, styleMap, index_state, xy_type, maxCol, i, zikey);
-            xy_type = Integer.parseInt(xyInof.split(",")[0]);
-            tr.attr("xy_type", xyInof);
-            index_state = Boolean.parseBoolean(xyInof.split(",")[1]);
-
-            boolean istrue = Boolean.parseBoolean(xyInof.split(",")[3]);
-
-            // 计算单元格坐标
-            for (int j = 0; j < tds.size(); j++) {
-                {
-                    Element data = tds.get(j);
-                    int colspan = data.attr("COLSPAN").equals("") ? 0 : Integer.parseInt(data.attr("COLSPAN"));
-                    int rowspan = data.attr("ROWSPAN").equals("") ? 0 : Integer.parseInt(data.attr("ROWSPAN"));
-                    String keyId = data.attr("class");
-                    if (StringUtils.isNotEmpty(keyId)) {
-                        data.removeAttr("class");
-                    }
-
-                    // 计算
-                    int x1 = Integer.parseInt(data.attr("x1"));
-                    int x2 = Integer.parseInt(data.attr("x2"));;
-                    int y1 = Integer.parseInt(data.attr("y1"));;
-                    int y2 = Integer.parseInt(data.attr("y2"));;
-
-                    String textInfo = data.text().trim().replaceAll(" ", "");
-                    System.out.println("-------=="+textInfo);
-
-                    data.text(textInfo.replaceAll(" ", ""));
-                    if (textInfo.indexOf("□") < 0 && !textInfo.isEmpty() && !(textInfo.equals("/") && textInfo.length() < 2) && !(textInfo.indexOf("年") >= 0 && textInfo.indexOf("月") >= 0 && textInfo.indexOf("日") >= 0) && !textInfo.equals("—") && !textInfo.equals("-")) {  // 标题区域
-                        Map<String, String> dataInfo = new HashMap<String, String>();
-                        dataInfo.put("name", textInfo);
-                        dataInfo.put("x1", x1 + "");
-                        dataInfo.put("x2", x2 + "");
-                        dataInfo.put("y1", y1 + "");
-                        dataInfo.put("y2", y2 + "");
-                        dataInfo.put("xytype", xy_type + "");
-                        if (textInfo.indexOf("/") < 0 || (textInfo.indexOf("/") >= 0 && textInfo.length() > 1)) { // 带/为分割数据
-                            zikey.add(dataInfo);
-                        }
-                    } else { //空行
-
-                        List<Map<String, String>> left = new ArrayList<>();
-                        List<Map<String, String>> top = new ArrayList<>();
-                        for (int k = 0; k < zikey.size(); k++) {
-                            String name = zikey.get(k).get("name");
-                            int xx1 = Integer.parseInt(zikey.get(k).get("x1"));
-                            int xx2 = Integer.parseInt(zikey.get(k).get("x2"));
-                            int yy1 = Integer.parseInt(zikey.get(k).get("y1"));
-                            int yy2 = Integer.parseInt(zikey.get(k).get("y2"));
-                            int xytype2 = Integer.parseInt(zikey.get(k).get("xytype"));
-
-                            // 左匹配
-                            if (yy1 <= y1 && yy2 >= y2 && xx2 < x1 && xytype2 == xy_type) {
-                                left.add(zikey.get(k));
-                            }
-
-                            //向 上 匹配
-                            if (index_state) {
-                                if (xx1 <= x1 && xx2 >= x2 && yy2 < y1 && xytype2 == xy_type) {
-                                    top.add(zikey.get(k));
-                                }
-                            }
-                        }
-
-                        String inputText = "";
-                        // 特征值赛选 规则
-                        for (int k = 0; k < left.size(); k++) { // 左计算
-                            String name = left.get(k).get("name");
-                            int xx2 = Integer.parseInt(left.get(k).get("x2"));
-                            int yy2 = Integer.parseInt(left.get(k).get("y2"));
-
-                            if (!StringUtil.isNumeric(name) && name.length() <= 20) { // 数字不匹配
-                                if (index_state) { // 正向规则匹配
-                                    if (istrue) { // 是否空格等于值
-                                        if (x1 - xx2 <= 1 && y1 == yy2) {
-                                            inputText = name;
-                                        } else {
-                                            inputText += name + "_";
-                                        }
-                                    } else {
-                                        inputText += name + "_";
-                                    }
-                                } else {
-                                    if (x1 - xx2 <= 1 && y1 == yy2) {
-                                        inputText = name;
-                                    }
-                                }
-                            }
-                        }
-
-                        // 特征值赛选 规则
-                        if (top != null && top.size() >= 1) {
-                            for (int k = 0; k < top.size(); k++) { // 向上计算
-                                String name = top.get(k).get("name");
-                                if (!StringUtil.isNumeric(name) && name.length() <= 20) {
-                                    inputText += name + "_";
-                                }
-                            }
-                        }
-
-                        if (inputText != null && inputText != "" && inputText.indexOf("_") >= 0) {
-                            inputText = inputText.substring(0, inputText.lastIndexOf("_"));
-                        }
-
-                        // 质检表特殊处理匹配
-
-                        String parm = i + "," + j + "," + x1 + "," + x2 + "," + y1 + "," + y2 + ",$event";
-                        // 设置文本信息
-                        ExctabCell exctabCell = new ExctabCell();
-                        if ((textInfo.indexOf("年") >= 0 && textInfo.indexOf("月") >= 0 && textInfo.indexOf("日") >= 0) || inputText.indexOf("日期") >= 0) {
-                            if (inputText.indexOf("日期") >= 0) {
-                                data.empty().append("<el-date-picker type='date' @keyDowns='dateKeydown()' format='YYYY年MM月DD日' value-format='YYYY年MM月DD日' @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;' placeholder='" + inputText + "'> </el-date-picker>");
-                            } else if (textInfo.indexOf("年") >= 0 && textInfo.indexOf("月") >= 0 && textInfo.indexOf("日") >= 0) {
-                                if (inputText.indexOf("专业监理工程师") >= 0) {
-                                    inputText = "专业监理工程师_年月日";
-                                } else if (inputText.indexOf("质检工程师") >= 0) {
-                                    inputText = "质检工程师_年月日";
-                                } else {
-                                    inputText = "年月日";
-                                }
-                            }
-                            data.empty().append("<el-date-picker @keyDowns='dateKeydown()'  type='date' format='YYYY年MM月DD日' value-format='YYYY年MM月DD日' @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;' placeholder='年月日'> </el-date-picker>");
-                            exctabCell.setTextInfo(inputText);
-                            exctabCell.setExctabId(excelId);
-                            exctabCell.setIsDeleted(0);
-                            exctabCell.setXys(i + "_" + j);
-                            colTitle.add(exctabCell);
-                            data.attr("title", inputText);
-
-                        } else if (textInfo.indexOf("□") >= 0) { //多选框
-                            exctabCell.setTextInfo(inputText);
-                            exctabCell.setExctabId(excelId);
-                            exctabCell.setIsDeleted(0);
-                            exctabCell.setXys(i + "_" + j);
-                            colTitle.add(exctabCell);
-                            data.attr("title", inputText);
-                            // 添加多选框
-
-                            String[] cheText = textInfo.split("□");
-                            JSONArray objs = new JSONArray();
-                            if (cheText != null && cheText.length >= 1) {
-                                int key = 1;
-                                for (String keyval : cheText) {
-                                    JSONObject jsonObject = new JSONObject();
-                                    if (StringUtils.isNotEmpty(keyval)) {
-                                        jsonObject.put("key", key);
-                                        jsonObject.put("name", keyval);
-                                        objs.add(jsonObject);
-                                        keyId += 1;
-                                    }
-                                }
-                            } else {
-                                JSONObject jsonObject = new JSONObject();
-                                jsonObject.put("key", "1");
-                                jsonObject.put("name", "");
-                                objs.add(jsonObject);
-                            }
-
-                            String checkbox = "<hc-form-checkbox-group @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft' @keydown.shift.right='keyupShiftRight' :objs='" + objs + "'  @change='checkboxGroupChange' @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " placeholder=''> </hc-form-checkbox-group>";
-                            data.empty().append(checkbox);
-
-                        } else {
-                            if (index_state) { // 区域内
-                                if (rowspan >= 1) {
-                                    data.empty().append("<el-input type='textarea' @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft'  @keydown.shift.right='keyupShiftRight'  @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;'   :rows=" + rowspan * 2 + " placeholder=''> </el-input>");
-                                } else {
-                                    data.empty().append("<el-input type='text' @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft'  @keydown.shift.right='keyupShiftRight'  @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;' placeholder=''> </el-input>");
-                                }
-                            } else { // 区域外
-                                if (j == 0) {
-                                    if (colspan == maxCol && i >= 1) {
-                                        if (rowspan >= 1) {
-                                            data.empty().append("<el-input @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft' @keydown.shift.right='keyupShiftRight' type='textarea'  @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;'   :rows=" + rowspan * 2 + " placeholder=''> </el-input>");
-                                        } else {
-                                            data.empty().append("<el-input @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft' @keydown.shift.right='keyupShiftRight' type='text' @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;' placeholder=''> </el-input>");
-                                        }
-                                    }
-                                } else {
-                                    Element bforData = tds.get(j - 1);
-                                    if (!bforData.text().isEmpty() || bforData.html().indexOf("hc-form-checkbox-group") >= 0) {
-                                        if (rowspan >= 1) {
-                                            data.empty().append("<el-input @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft' @keydown.shift.right='keyupShiftRight' type='textarea' @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;'   :rows=" + rowspan * 2 + " placeholder=''> </el-input>");
-                                        } else {
-                                            data.empty().append("<el-input @keydown.shift.up='keyupShiftUp' @keydown.shift.down='keyupShiftDown' @keydown.shift.left='keyupShiftLeft'  @keydown.shift.right='keyupShiftRight' type='text' @contextmenu.prevent.native='contextmenuClick(" + parm + ")'  @mouseup.right='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;' placeholder=''> </el-input>");
-                                        }
-                                    }
-                                }
-                            }
-
-                            if (!inputText.equals("")) {
-                                exctabCell.setExctabId(excelId);
-
-
-                                exctabCell.setTextInfo(inputText);
-                                if (inputText.contains("日期") || inputText.contains("年") || inputText.contains("月") || inputText.contains("日")) {
-                                    //日期
-                                    exctabCell.setTextElementType(4);
-                                } else if (inputText.indexOf("签字") >= 0) {
-                                    exctabCell.setTextElementType(6);
-                                } else {
-                                    //字符串
-                                    exctabCell.setTextElementType(1);
-                                }
-
-                                exctabCell.setIsDeleted(0);
-                                exctabCell.setXys(i + "_" + j);
-                                colTitle.add(exctabCell);
-                            }
-                            data.attr("title", inputText);
-                        }
-                    }
-                }
-            }
-        }
-
-        // 去掉重复的数
-        Map<String, String> groupMap2 = colTitle.stream()
-                .collect(Collectors.groupingBy(ExctabCell::getTextInfo, Collectors.mapping(ExctabCell::getXys, Collectors.joining(","))));
-
-        exctabCellService.DeletExcelByTableId(excelId + "");
-
-        List<ExctabCell> colTitle2 = new ArrayList<>();
-        for (String title : groupMap2.keySet()) {
-            ExctabCell exctabCell = new ExctabCell();
-            exctabCell.setExctabId(excelId);
-            exctabCell.setIsDeleted(0);
-            exctabCell.setTextInfo(title);
-            exctabCell.setCreateTime(new Date());
-
-            if (title.contains("日期") || title.contains("年") || title.contains("月") || title.contains("日")) {
-                //日期
-                exctabCell.setTextElementType(4);
-            } else {
-                //字符串
-                exctabCell.setTextElementType(1);
-            }
-
-            exctabCell.setXys(groupMap2.get(title));
-            colTitle2.add(exctabCell);
-        }
-        exctabCellService.saveBatch(colTitle2);
-
-
-        //对excel 的图片进行操作
-        ExcelTab exceltab = excelTabService.getById(excelId);
-        if(exceltab!=null){
-            // 获取excle 的数据
-            String fileUrl = exceltab.getFileUrl();
-            InputStream ossInputStream = CommonUtil.getOSSInputStream(fileUrl);
-            Workbook wb = new Workbook();
-            wb.loadFromMHtml(ossInputStream);
-            Worksheet sheet = wb.getWorksheets().get(0);
-            PicturesCollection pictures = sheet.getPictures();
-            if(pictures!=null && pictures.size()>=1){
-                for (int i=0 ; i<pictures.size() ; i++){
-                    ExcelPicture pic = pictures.get(i);
-                    int x = pic.getLeftColumn();
-                    int y = pic.getBottomRow();
-                    Elements select = doc.select("el-input[x1=" + x + "][y1=" + y + "]");
-                    System.out.println("xx=--"+x);
-                    System.out.println("yy=--"+y);
-                    if(select!=null && select.size()>=1){
-                        Element element = select.get(0);
-                        Element elementP = element.parent();
-                        element.remove();
-                        Element imgele = imgs.get(i);
-                        imgele.removeAttr("class");
-                        elementP.append(imgele.toString());
-                    }
-                }
-            }
-
-            ossInputStream.close();
-        }
-        // 移除图片
-        imgs.remove();
-        // 保存
-        File writefile = new File(thmlUrl);
-        FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
-
-    }
-
-    // 上传解析 html
-    public void expailHtmlInfo11111111111111(String thmlUrl, Long excelId) throws Exception {
-
-        // 读取
-        File file1 = ResourceUtil.getFile(thmlUrl);
-        String htmlString = IoUtil.readToString(new FileInputStream(file1));
-
         /*
            解析
            1 解析样式
@@ -1314,6 +995,9 @@ public class ExcelTabController extends BladeController {
                     //x 移位 算法
                     String getRowInfo = rowData[y1];
 
+                    if (y1 == 17) {
+                        System.out.println("1");
+                    }
                     if (getRowInfo != null) {
                         String[] dataInfo2 = getRowInfo.split(",");
 
@@ -1666,7 +1350,7 @@ public class ExcelTabController extends BladeController {
 
         //对excel 的图片进行操作
         ExcelTab exceltab = excelTabService.getById(excelId);
-        if(exceltab!=null){
+        if (exceltab != null) {
             // 获取excle 的数据
             String fileUrl = exceltab.getFileUrl();
             InputStream ossInputStream = CommonUtil.getOSSInputStream(fileUrl);
@@ -1674,15 +1358,15 @@ public class ExcelTabController extends BladeController {
             wb.loadFromMHtml(ossInputStream);
             Worksheet sheet = wb.getWorksheets().get(0);
             PicturesCollection pictures = sheet.getPictures();
-            if(pictures!=null && pictures.size()>=1){
-                for (int i=0 ; i<pictures.size() ; i++){
+            if (pictures != null && pictures.size() >= 1) {
+                for (int i = 0; i < pictures.size(); i++) {
                     ExcelPicture pic = pictures.get(i);
                     int x = pic.getLeftColumn();
                     int y = pic.getBottomRow();
                     Elements select = doc.select("el-input[x1=" + x + "][y1=" + y + "]");
-                    System.out.println("xx=--"+x);
-                    System.out.println("yy=--"+y);
-                    if(select!=null && select.size()>=1){
+                    System.out.println("xx=--" + x);
+                    System.out.println("yy=--" + y);
+                    if (select != null && select.size() >= 1) {
                         Element element = select.get(0);
                         Element elementP = element.parent();
                         element.remove();
@@ -3565,17 +3249,94 @@ public class ExcelTabController extends BladeController {
         WbsTreeContract wbsInfo = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
                 .eq(WbsTreeContract::getPKeyId, pkeyId));
 
-        if(wbsInfo!=null){
+        if (wbsInfo != null) {
             String tabName = wbsInfo.getInitTableName();
-            if(StringUtils.isNotEmpty(tabName)){
-                String delSql = "delete from "+tabName+" where p_key_id = " + pkeyId;
+            if (StringUtils.isNotEmpty(tabName)) {
+                String delSql = "delete from " + tabName + " where p_key_id = " + pkeyId;
                 jdbcTemplate.execute(delSql);
-            }else{
-                return   R.fail("获取InitTableName失败!");
+            } else {
+                return R.fail("获取InitTableName失败!");
             }
-        }else{
-            return   R.fail("获取数据失败!");
+        } else {
+            return R.fail("获取数据失败!");
         }
         return R.data("成功!");
     }
+
+    @GetMapping("/batchUploadExcelTab")
+    @ApiOperationSupport(order = 39)
+    @ApiOperation(value = "批量上传清表", notes = "传入ExcelTabBatchUploadDTO")
+    public R<Object> batchUploadExcelTab(@RequestBody ExcelTabBatchUploadDTO dto) throws IOException {
+        if (ObjectUtil.isEmpty(dto.getId())) {
+            throw new ServiceException("获取节点信息失败");
+        }
+        if (ObjectUtil.isEmpty(dto.getFileList()) || dto.getFileList().size() <= 0) {
+            throw new ServiceException("未获取到需要上传的文件信息");
+        }
+        ExcelTab excelTabParentNode = excelTabService.getBaseMapper().selectById(dto.getId());
+        List<ExcelTab> excelTabs = excelTabService.getBaseMapper().selectList(Wrappers.<ExcelTab>lambdaQuery().select(ExcelTab::getSort).eq(ExcelTab::getParentId, excelTabParentNode.getId()));
+        Optional<Integer> maxSort = excelTabs.stream().map(ExcelTab::getSort).max(Integer::compare);
+        int maxValue = 1;
+        if (maxSort.isPresent()) {
+            maxValue = maxSort.get();
+        }
+        for (ExcelTabFileDTO fileDTO : dto.getFileList()) {
+            if (ObjectUtil.isEmpty(fileDTO.getFileName())) {
+                throw new ServiceException("文件名不能为空");
+            }
+            if (!this.isExcelFormat(fileDTO.getFileName())) {
+                throw new ServiceException("文件名后缀不是.xlsx或者.xls格式,请重新填写");
+            }
+            if (!this.isExcelFile(fileDTO.getFile())) {
+                throw new ServiceException("【" + fileDTO.getFileName() + "】文件不是excel格式文件,上传终止");
+            }
+            try {
+                R<BladeFile> bladeFile = iossClient.addFileInfo(fileDTO.getFile());
+                if (ObjectUtil.isNotEmpty(bladeFile.getData())) {
+                    //创建节点,并上传excel文件到节点上
+                    ExcelTab excelTabNode = new ExcelTab();
+                    excelTabNode.setId(SnowFlakeUtil.getId());
+                    excelTabNode.setParentId(excelTabParentNode.getId());
+                    excelTabNode.setFileType(excelTabParentNode.getFileType());
+                    excelTabNode.setName(fileDTO.getFileName().split(".xls")[0]);
+                    excelTabNode.setAlias(excelTabParentNode.getAlias() + "," + excelTabParentNode.getId());
+                    excelTabNode.setFileUrl(bladeFile.getData().getLink());
+                    excelTabNode.setExtension(fileDTO.getFileName());
+                    excelTabNode.setCreateTime(new Date());
+                    excelTabNode.setUpdateTime(new Date());
+                    excelTabNode.setCreateUser(SecureUtil.getUserId());
+                    excelTabNode.setUpdateUser(SecureUtil.getUserId());
+                    excelTabNode.setCreateDept(SecureUtil.getUser().getDeptId().contains(",") ? Long.parseLong(SecureUtil.getUser().getDeptId().split(",")[0]) : Long.parseLong(SecureUtil.getUser().getDeptId()));
+                    excelTabNode.setStatus(1);
+                    excelTabNode.setIsDeleted(0);
+                    excelTabNode.setTabType(excelTabParentNode.getTabType());
+                    excelTabNode.setTenantId(SecureUtil.getTenantId());
+                    excelTabNode.setSort(maxValue++);
+                    excelTabService.save(excelTabNode);
+                }
+            } catch (Exception e) {
+                throw new ServiceException("【" + fileDTO.getFileName() + "】文件上传失败,上传终止" + e.getMessage());
+            }
+        }
+        return R.success("操作成功");
+    }
+
+    private boolean isExcelFormat(String filename) {
+        return filename.toLowerCase().endsWith(".xlsx") || filename.toLowerCase().endsWith(".xls");
+    }
+
+    private boolean isExcelFile(MultipartFile file) throws IOException {
+        org.apache.poi.ss.usermodel.Workbook workbook = null;
+        try (InputStream inputStream = file.getInputStream()) {
+            workbook = WorkbookFactory.create(inputStream);
+            return ObjectUtil.isNotEmpty(workbook);
+        } catch (Exception e) {
+            return false;
+        } finally {
+            if (workbook != null) {
+                workbook.close();
+            }
+        }
+    }
+
 }

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

@@ -401,7 +401,6 @@
         set excel_id= #{aPrivate.excelId},
             node_name = #{aPrivate.nodeName},
             full_name = #{aPrivate.fullName},
-            init_table_name = #{aPrivate.initTableName},
             is_link_table = 2,
             html_url = #{aPrivate.htmlUrl}
         where type = 2

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

@@ -595,7 +595,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             try {
                 //获取onlyOffice缓存中的文件流
                 URL url = new URL(downloadUri);
-                String file_path = FileUtils.getSysLocalFileUrl();
+                String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
                 String filecode = SnowFlakeUtil.getId() + "";
                 String dataUrl = file_path + "/excel/" + filecode + ".pdf";
                 java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
@@ -615,6 +615,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 ExcelTab excelTab = baseMapper.selectById(Long.parseLong(tabId));
                 //上传新文件到文件服务器
                 byte[] officeByte = IoUtil.readToByteArray(inputStream);
+
                 FileOutputStream fs = new FileOutputStream(dataUrl);
                 fs.write(officeByte);
                 fs.flush();
@@ -629,6 +630,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 if (file.exists()) {
                     file.delete();
                 }
+                System.out.println("123456");
             } catch (Exception e) {
                 editCallback.setError(1);
                 e.printStackTrace();
@@ -1488,17 +1490,11 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                             if(StringUtils.isNotEmpty(dataJson)){
                                                 JSONArray jsonArray = JSONArray.parseArray(dataJson);
                                                 List<Integer> idList = Func.toIntList(myData);
-                                                String dataInfo = "";//jsonArray.getJSONObject(idList.get(0)-1).getString("name");
-                                                for(int inx=0 ; inx<idList.size() ; inx++){
-                                                    int index = idList.get(inx);
-                                                    if(index>=1){
-                                                        dataInfo = dataInfo+jsonArray.getJSONObject(index).getString("name")+",";
-                                                    }
-                                                }
-                                                if (StringUtils.isNotEmpty(dataInfo)){
-                                                    dataInfo = dataInfo.substring(0,dataInfo.lastIndexOf(","));
+                                                String dataInfo = jsonArray.getJSONObject(idList.get(0)-1).getString("name");
+                                                for(int inx=1 ; inx<idList.size() ; inx++){
+                                                   int valIndex = idList.get(inx)-1;
+                                                    dataInfo = dataInfo+","+jsonArray.getJSONObject(valIndex).getString("name");
                                                 }
-
                                                 cell.setCellValue(dataInfo);
                                             }
                                         }