Quellcode durchsuchen

后管-html错误解析
1、新增根基pkeyid检验html是否错误的接口

LHB vor 2 Tagen
Ursprung
Commit
47c971017b

+ 0 - 4
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/TreeNodeVOByTabType.java

@@ -1,7 +1,6 @@
 package org.springblade.manager.vo;
 
 
-import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import org.springblade.core.tool.node.BaseNode;
@@ -21,7 +20,6 @@ public class TreeNodeVOByTabType extends BaseNode<TreeNode> {
     private String fillRate;
     private String initTableId;
     private String initTableName;
-    private String htmlUrl;
     private String excelIds;
     private String excelId;
 
@@ -29,6 +27,4 @@ public class TreeNodeVOByTabType extends BaseNode<TreeNode> {
     private String tableOwner;
     private String isLinkTable;
 
-    @ApiModelProperty("html元素是否存在错误:0-不存在,1-存在")
-    private Integer htmlElementError = 0;
 }

+ 75 - 69
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreePrivateController.java

@@ -1,6 +1,5 @@
 package org.springblade.manager.controller;
 
-import cn.hutool.core.stream.CollectorUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -31,10 +30,8 @@ import org.springblade.manager.entity.*;
 import org.springblade.manager.mapper.WbsTreeContractMapper;
 import org.springblade.manager.mapper.WbsTreePrivateMapper;
 import org.springblade.manager.service.*;
-import org.springblade.manager.utils.FileUtils;
 import org.springblade.manager.vo.*;
 import org.springblade.manager.wrapper.WbsTreePrivateWrapper;
-import org.springblade.system.cache.DictCache;
 import org.springblade.system.user.entity.User;
 import org.springframework.beans.BeanUtils;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
@@ -44,8 +41,8 @@ import org.springframework.web.bind.annotation.*;
 import javax.validation.Valid;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -516,6 +513,80 @@ public class WbsTreePrivateController extends BladeController {
         return R.fail(200, "未查询到数据");
     }
 
+    /**
+     * 根据pkeyid检验html是否存在错误细腻些
+     * @param pKeyId
+     * @return
+     */
+    @GetMapping("/getHtmlErrorByPKeyId")
+    @ApiOperationSupport(order = 3)
+    @ApiOperation(value = "根据pkeyid检验html是否存在错误细腻些", notes = "传入pKeyId")
+    public R<Boolean> getHtmlErrorByPKeyId(Long pKeyId){
+        AtomicBoolean htmlError = new AtomicBoolean(false);
+
+        WbsTreePrivate f = wbsTreePrivateService.getById(pKeyId);
+        String htmlUrl = f.getHtmlUrl();
+        String initTableId = f.getInitTableId();
+        if(StringUtil.isNotBlank(htmlUrl) && StringUtils.isNotEmpty(initTableId)){
+            //获取元素表数据
+            List<WbsFormElement> wbsFormElements = wbsFormElementService.getBaseMapper().selectList(Wrappers.<WbsFormElement>lambdaQuery()
+                    .eq(WbsFormElement::getFId, initTableId)
+                    .eq(WbsFormElement::getIsDeleted, 0)
+            );
+
+            List<String> keys = wbsFormElements.stream().map(WbsFormElement::getEKey).collect(Collectors.toList());
+
+
+            // 读取html页面信息
+            String htmlString = "";
+            //解析html
+            try {
+                R excelHtml = excelTabController.getExcelHtml(f.getPKeyId());
+                htmlString = excelHtml.getData().toString();
+            } catch (Exception e) {
+            }
+            if(StringUtil.isEmpty(htmlString)){
+                return R.data(htmlError.get());
+            }
+            // 样式集合
+            Document doc = Jsoup.parse(htmlString);
+            //获取所有input标签
+            String[] tagNames = {"el-input", "el-date-picker", "el-time-picker", "hc-form-select-search",
+                    "hc-table-form-upload", "hc-form-checkbox-group", "el-radio-group", "el-select"};
+            Elements inputs = new Elements();
+            for (String tagName : tagNames) {
+                inputs.addAll(doc.select(tagName));
+            }
+            //判断标签是否存在id属性
+            inputs.forEach(input -> {
+                String id = input.attr("id");
+                if(StringUtils.isEmpty(id)){
+                    htmlError.set(true);
+                } else {
+                    /**
+                     * 判断当前元素是否符合格式
+                     * 1、是否存在key_
+                     * 2、是否存在__
+                     * 3、key_后面是否为数字
+                     * 4、__后面是否为坐标
+                     * 5、key是否在元素库中存在
+                     */
+                    if(!id.contains("key_")
+                            || !id.contains("__")
+                            || !StringUtils.isNumber(id.split("__")[0].replace("key_",""))
+                            || !id.split("__")[1].contains("_")
+                            || !StringUtils.isNumber(id.split("__")[1].split("_")[0])
+                            || !StringUtils.isNumber(id.split("__")[1].split("_")[1])
+                            || !keys.contains(id.split("__")[0])
+                    ){
+                        htmlError.set(true);
+                    }
+                }
+            });
+        }
+        return R.data(htmlError.get());
+    }
+
     @GetMapping("/remove-table")
     @ApiOperationSupport(order = 4)
     @ApiOperation(value = "删除节点下的元素表", notes = "传入表单id、wbsId、projectId")
@@ -1229,71 +1300,6 @@ public class WbsTreePrivateController extends BladeController {
     })
     public R<IPage<TreeNodeVOByTabType>> tabTypeLazyTreeByProject(Long parentId, String projectId, String titleName, Query query) {
         IPage<TreeNodeVOByTabType> page = wbsTreePrivateService.tabTypeLazyTreeByProject(Condition.getPage(query), parentId, projectId, titleName);
-        List<TreeNodeVOByTabType> records = page.getRecords();
-        records.forEach(f->{
-            String htmlUrl = f.getHtmlUrl();
-            String initTableId = f.getInitTableId();
-            if(StringUtil.isNotBlank(htmlUrl) && StringUtils.isNotEmpty(initTableId)){
-                //获取元素表数据
-                List<WbsFormElement> wbsFormElements = wbsFormElementService.getBaseMapper().selectList(Wrappers.<WbsFormElement>lambdaQuery()
-                        .eq(WbsFormElement::getFId, initTableId)
-                        .eq(WbsFormElement::getIsDeleted, 0)
-                );
-
-                List<String> keys = wbsFormElements.stream().map(WbsFormElement::getEKey).collect(Collectors.toList());
-
-
-                // 读取html页面信息
-                String htmlString = "";
-                //解析html
-                try {
-                    R excelHtml = excelTabController.getExcelHtml(f.getPkeyId());
-                    htmlString = excelHtml.getData().toString();
-                } catch (Exception e) {
-                }
-                if(StringUtil.isEmpty(htmlString)){
-                    return;
-                }
-                // 样式集合
-                Document doc = Jsoup.parse(htmlString);
-                //获取所有input标签
-                //获取所有input标签
-                String[] tagNames = {"el-input", "el-date-picker", "el-time-picker", "hc-form-select-search",
-                        "hc-table-form-upload", "hc-form-checkbox-group", "el-radio-group", "el-select"};
-                Elements inputs = new Elements();
-                for (String tagName : tagNames) {
-                    inputs.addAll(doc.select(tagName));
-                }
-                //判断标签是否存在id属性
-                inputs.forEach(input -> {
-                    String id = input.attr("id");
-                    if(StringUtils.isEmpty(id)){
-                        f.setHtmlElementError(1);
-                        input.attr("htmlElementError", "1");
-                    } else {
-                        /**
-                         * 判断当前元素是否符合格式
-                         * 1、是否存在key_
-                         * 2、是否存在__
-                         * 3、key_后面是否为数字
-                         * 4、__后面是否为坐标
-                         * 5、key是否在元素库中存在
-                         */
-                        if(!id.contains("key_")
-                                || !id.contains("__")
-                                || !StringUtils.isNumber(id.split("__")[0].replace("key_",""))
-                                || !id.split("__")[1].contains("_")
-                                || !StringUtils.isNumber(id.split("__")[1].split("_")[0])
-                                || !StringUtils.isNumber(id.split("__")[1].split("_")[1])
-                                || !keys.contains(id.split("__")[0])
-                        ){
-                            f.setHtmlElementError(1);
-                            input.attr("htmlElementError", "1");
-                        }
-                    }
-                });
-            }
-        });
         return R.data(page);
     }
 

+ 4 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreePrivateMapper.xml

@@ -1007,7 +1007,7 @@
     <!-- 项目级 表单类型分类 wbs树 -->
     <select id="tabTypeLazyTreeByProject" resultMap="treeNodeResultMapTabType">
         SELECT a.exceIds AS excelIds,initTableName,a.exceIds as excelId,table_type, table_owner,is_link_table,
-        p_key_id as id,p_key_id as primaryKeyId,title,parent_id,fill_rate as fillRate,initTableId, html_url,p_key_id as pkeyId,
+        p_key_id as id,p_key_id as primaryKeyId,title,parent_id,fill_rate as fillRate,initTableId,p_key_id as pkeyId,
         (SELECT dict_value from blade_dict where code='table_type' and dict_key not in(-1,0) and dict_key=table_type )
         as tabType,
         (SELECT count(1) FROM m_wbs_form_element WHERE f_id = initTableId and is_deleted=0) AS "elementTotal",
@@ -1033,12 +1033,12 @@
         ) AS "has_children"
         from (
         SELECT '12345678910' as p_key_id , '表单类型' as title, 0 as parent_id,0 as table_type,0 as fill_rate,0 as
-        table_owner,0 as initTableId,0 as exceIds,0 as initTableName,null as html_url,0 as is_link_table
+        table_owner,0 as initTableId,0 as exceIds,0 as initTableName,0 as is_link_table
         union all
         SELECT dict_key as p_key_id ,dict_value as title,'12345678910' as parent_id,0 as table_type,0 as fill_rate,0 as
-        table_owner,0 as initTableId,0 as exceIsd,0 as initTableName,null as html_url,0 as is_link_table from blade_dict where code='table_type' and dict_key not in(-1,0)
+        table_owner,0 as initTableId,0 as exceIsd,0 as initTableName,0 as is_link_table from blade_dict where code='table_type' and dict_key not in(-1,0)
         union all
-        SELECT p_key_id,node_name as title,table_type as parent_id,table_type,fill_rate,table_owner,init_table_id as initTableId,excel_id AS excelIds,init_table_name as  initTableName, html_url,is_link_table
+        SELECT p_key_id,node_name as title,table_type as parent_id,table_type,fill_rate,table_owner,init_table_id as initTableId,excel_id AS excelIds,init_table_name as  initTableName,is_link_table
         from m_wbs_tree_private WHERE project_id=#{projectId} and type in(2,10) and
         is_deleted=0 and table_type is not NULL GROUP BY node_name
         ) a where 1=1