Explorar el Código

后管表单关联优化保留原有配置

lvy hace 1 semana
padre
commit
6c46c05592

+ 7 - 15
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -739,37 +739,29 @@ public class ExcelTabController extends BladeController {
         {
             IPage<TextdictInfoVO> result = textdictInfoService.analysisHtmlDefault(wbsTreePrivate.getPKeyId() + "");
             if (result != null && result.getRecords() != null && !result.getRecords().isEmpty()) {
-                result.getRecords().forEach(config -> {
-                    if (config.getId() == null || config.getId() <= 0) {
-                        defaultConfigs.add(config);
-                    }
-                });
+                defaultConfigs.addAll(result.getRecords());
             }
         }
         // 将原配置信息写入到新的html中,先通过colKey匹配,再通过colName匹配。如果匹配不上,则保存到数据库。后续手动配置、修改
         defaultConfigs.removeIf(config -> {
             String colKey = config.getColKey();
             Element element = null;
+            String colName = config.getColName();
             if (colKey != null && !colKey.isEmpty()) {
                 element = doc.select("[keyname='" + config.getColKey() + "']").first();
-                if (element == null && colKey.contains("__")) {
-                    element = doc.select("[keyname*='" + colKey.split("__")[0] + "']").first();
-                    String point = colKey.split("__")[1];
-                    if (element == null && point.contains("_")) {
-                        String[] split = point.split("_");
-                        element = doc.select("[trindex='" + split[0] + "'],[tdindex='" + split[1] + "']").first();
+                if (element != null && colName != null) {
+                    String placeholder = element.attr("placeholder");
+                    if (!StringCNUtils.compareStringIgnoreSpaceAndSymbols(placeholder, colName)) {
+                        element = null;
                     }
                 }
             }
-            if (element == null) {
-                element = doc.select("[placeholder='" + config.getColName() + "']").first();
-            }
             if (element != null) {
                 element.removeAttr("defText");
                 element.attr("defText", config.getSigRoleName());
                 return true;
             }
-            return false;
+            return config.getId() != null && config.getId() > 0;
         });
         if (!defaultConfigs.isEmpty()) {
             List<TextdictInfo> saves = new ArrayList<>();

+ 2 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -710,12 +710,13 @@ public class TextdictInfoController extends BladeController {
 
             String[] trtd = key.split("__")[1].split("_");
             Element element;
+            String colKey;
             try {
                 element = trs.get(Integer.parseInt(trtd[0])).select("td").get(Integer.parseInt(trtd[1]));
+                colKey = element.children().get(0).attr("keyname");
             } catch (Exception e) {
                 throw new ServiceException(String.format("【%s】元素位置与表单不匹配,请重新编辑后保存", textdictInfo.getColName()));
             }
-            String colKey = element.children().get(0).attr("keyname");
             textdictInfo.setColKey(colKey);
 
             TextdictInfo info = oldTextDictInfoMap.get(wbsTreePrivate.getProjectId() + wbsTreePrivate.getExcelId() + (colKey != null && colKey.contains("__") ? colKey.split("__")[0] : colKey) + sigRoleId);

+ 9 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/TextdictInfoServiceImpl.java

@@ -270,10 +270,16 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                 textdictInfos.add(textdictInfo);
             }
             List<TextdictInfo> list = this.list(Wrappers.<TextdictInfo>lambdaQuery().eq(TextdictInfo::getTabId, tabId).eq(TextdictInfo::getType, 4));
+            Map<String, TextdictInfoVO> map = textdictInfos.stream().collect(Collectors.toMap(vo -> vo.getColKey() + vo.getColName() + vo.getSigRoleName(), vo -> vo, (vo1, vo2) -> vo1));
             list.forEach(textdictInfo -> {
-                TextdictInfoVO vo = new TextdictInfoVO();
-                BeanUtil.copyProperties(textdictInfo, vo);
-                textdictInfos.add(vo);
+                if (!map.containsKey(textdictInfo.getColKey() + textdictInfo.getColName() + textdictInfo.getSigRoleName())) {
+                    TextdictInfoVO vo = new TextdictInfoVO();
+                    BeanUtil.copyProperties(textdictInfo, vo);
+                    map.put(textdictInfo.getColKey() + textdictInfo.getColName() + textdictInfo.getSigRoleName(), vo);
+                    textdictInfos.add(vo);
+                } else {
+                    baseMapper.delete(Wrappers.<TextdictInfo>lambdaQuery().eq(TextdictInfo::getId, textdictInfo.getId()).eq(TextdictInfo::getProjectId, textdictInfo.getProjectId()).eq(TextdictInfo::getType, 4));
+                }
             });
             textdictInfoPage.setRecords(textdictInfos);
             return textdictInfoPage;