Jelajahi Sumber

后管表单关联优化

lvy 3 hari lalu
induk
melakukan
c6d4bcf399

+ 115 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.google.gson.Gson;
 import com.spire.xls.*;
@@ -686,7 +687,7 @@ public class ExcelTabController extends BladeController {
                 }
             }
         }
-
+        saveOldHtmlConfig(aPrivate, htmlString);
         File writefile = new File(thmlUrl);
         FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
 
@@ -732,6 +733,119 @@ public class ExcelTabController extends BladeController {
         return R.success("关联成功");
     }
 
+    public void saveOldHtmlConfig(WbsTreePrivate wbsTreePrivate, String htmlString){
+        // 获取原默认值配置
+        List<TextdictInfoVO> defaultConfigs = new ArrayList<>();
+        {
+            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);
+                    }
+                });
+            }
+        }
+        // 读取新的html内容
+        Document doc = Jsoup.parse(htmlString);
+        // 将原配置信息写入到新的html中,先通过colKey匹配,再通过colName匹配。如果匹配不上,则保存到数据库。后续手动配置、修改
+        defaultConfigs.removeIf(config -> {
+            String colKey = config.getColKey();
+            Element element = null;
+            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) {
+                element = doc.select("[placeholder='" + config.getColName() + "']").first();
+            }
+            if (element != null) {
+                element.removeAttr("defText");
+                element.attr("defText", config.getSigRoleName());
+                return true;
+            }
+            return false;
+        });
+        if (!defaultConfigs.isEmpty()) {
+            List<TextdictInfo> saves = new ArrayList<>();
+            defaultConfigs.forEach(config -> {
+                TextdictInfo info = new TextdictInfo();
+                info.setId(SnowFlakeUtil.getId());
+                info.setTabId(wbsTreePrivate.getPKeyId() + "");
+                info.setExcelId(wbsTreePrivate.getExcelId() == null ? null : wbsTreePrivate.getExcelId() + "");
+                info.setType(config.getType());
+                info.setColKey(config.getColKey());
+                info.setColName(config.getColName());
+                info.setSigRoleName(config.getSigRoleName());
+                info.setProjectId(wbsTreePrivate.getProjectId());
+                info.setName("编辑默认值");
+                saves.add( info);
+            });
+            textdictInfoService.saveOrUpdateBatch(saves);
+        }
+        // 获取原电签配置
+        TextdictInfoVO textdictInfo = new TextdictInfoVO();
+        textdictInfo.setProjectId(wbsTreePrivate.getProjectId());
+        textdictInfo.setTabId(wbsTreePrivate.getPKeyId() + "");
+        textdictInfo.setShowType(1);
+        textdictInfo.setType(2);
+        IPage<TextdictInfoVO> signConfigs = textdictInfoService.selectTextdictInfoPage(new Page<>(1, 1000), textdictInfo);
+        if (signConfigs != null && signConfigs.getRecords() != null && !signConfigs.getRecords().isEmpty()) {
+            List<TextdictInfoVO> signConfigList = signConfigs.getRecords();
+            signConfigList.removeIf(config -> {
+                String colKey = config.getColKey();
+                Element element = null;
+                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) {
+                    element = doc.select("[placeholder='" + config.getColName() + "']").first();
+                }
+                if (element != null) {
+                    int i = 5;
+                    Element parent = element.parent();
+                    while (i > 0 && parent != null) {
+                        if (parent.hasAttr("title")) {
+                            element.attr("dqid", config.getId() + "");
+                            return true;
+                        }
+                        parent = parent.parent();
+                        i--;
+                    }
+                }
+                return false;
+            });
+            if (!signConfigList.isEmpty()) {
+                String ids = signConfigList.stream().map(config -> config.getId() + "").collect(Collectors.joining("||"));
+                Element table = doc.select("table").first();
+                if (table != null) {
+                    Element tr = table.select("tr").last();
+                    if (tr != null) {
+                        Element td = tr.select("td").last();
+                        if (td != null) {
+                            td.attr("dqid", ids);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
 
     /**
      * 质检 获取html接口

+ 28 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -165,6 +165,21 @@ public class TextdictInfoController extends BladeController {
                     String colKey,
                     Integer type) throws FileNotFoundException {
         if(type != null && type == 4){
+            if (ids != null && !ids.isEmpty()) {
+                String[] split = ids.split(",");
+                List<Long> removeIds = new ArrayList<>();
+                for (String id : split) {
+                    if (StringUtil.isNumeric(id)) {
+                        long lid = Long.parseLong(id);
+                        if (lid > 0) {
+                            removeIds.add(lid);
+                        }
+                    }
+                }
+                if (!removeIds.isEmpty()) {
+                    textdictInfoService.remove(Wrappers.<TextdictInfo>lambdaQuery().in(TextdictInfo::getId, removeIds).eq(TextdictInfo::getTabId, tabId).eq(TextdictInfo::getType, 4));
+                }
+            }
             textdictInfoService.removeHtmlDefault(tabId,colKey);
             return R.success("删除成功");
         }
@@ -629,8 +644,8 @@ public class TextdictInfoController extends BladeController {
         }
 
         // 查询历史数据
-        String querySql = String.format("SELECT * from m_textdict_info WHERE project_id = %d and excel_id = %d and type in (2, 6) and (SELECT 1 from m_wbs_tree_private WHERE p_key_id = tab_id and html_url = '%s' ) = 1"
-                    , Long.parseLong(wbsTreePrivate.getProjectId()), wbsTreePrivate.getExcelId(), wbsTreePrivate.getHtmlUrl());
+        String querySql = String.format("select * from m_textdict_info where project_id = %d and tab_id = %d and type in (2,6) and is_deleted = 0"
+                    , Long.parseLong(wbsTreePrivate.getProjectId()), wbsTreePrivate.getPKeyId());
         List<TextdictInfo> oldTextDictInfos = jdbcTemplate.query(querySql, new BeanPropertyRowMapper<>(TextdictInfo.class));
         Map<String, TextdictInfo> oldTextDictInfoMap;
         if (!oldTextDictInfos.isEmpty()) {
@@ -638,7 +653,16 @@ public class TextdictInfoController extends BladeController {
                     + (item.getColKey() != null && item.getColKey().contains("__") ? item.getColKey().split("__")[0] : item.getColKey())
                     + item.getSigRoleId(), textdictInfo -> textdictInfo));
         } else {
-            oldTextDictInfoMap = new HashMap<>();
+            querySql = String.format("SELECT * from m_textdict_info WHERE project_id = %d and excel_id = %d and type in (2, 6) and exists (SELECT 1 from m_wbs_tree_private WHERE p_key_id = tab_id and html_url = '%s' )"
+                    , Long.parseLong(wbsTreePrivate.getProjectId()), wbsTreePrivate.getExcelId(), wbsTreePrivate.getHtmlUrl());
+            oldTextDictInfos = jdbcTemplate.query(querySql, new BeanPropertyRowMapper<>(TextdictInfo.class));
+            if (!oldTextDictInfos.isEmpty()) {
+                oldTextDictInfoMap = oldTextDictInfos.stream().collect(Collectors.toMap(item -> item.getProjectId() + item.getExcelId()
+                        + (item.getColKey() != null && item.getColKey().contains("__") ? item.getColKey().split("__")[0] : item.getColKey())
+                        + item.getSigRoleId(), textdictInfo -> textdictInfo));
+            } else {
+                oldTextDictInfoMap = new HashMap<>();
+            }
         }
         // 由于要实现电签 一对多(1个key 对应多个电签Id)
         Map<String,String> keyMap = new HashMap<>();
@@ -694,6 +718,7 @@ public class TextdictInfoController extends BladeController {
                 textdictInfo.setId(info.getId());
                 updateList.add(textdictInfo);
             } else {
+                textdictInfo.setId(SnowFlakeUtil.getId());
                 addList.add(textdictInfo);
             }
             newTextDictInfos.add(textdictInfo);

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

@@ -74,9 +74,6 @@ import java.util.stream.Collectors;
 public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, TextdictInfo> implements ITextdictInfoService {
     @Resource
     private WbsTreePrivateMapper wbsTreePrivateMapper;
-
-    @Resource
-    private ISignConfigService iSignConfigService;
     @Override
     public IPage<TextdictInfoVO> selectTextdictInfoPage(IPage<TextdictInfoVO> page, TextdictInfoVO textdictInfo) {
         List<TextdictInfoVO> textdict = new ArrayList<>();
@@ -84,21 +81,40 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
             WbsTreePrivate privateInfo = wbsTreePrivateMapper.getByPKeyId(Func.toLong(textdictInfo.getTabId() + ""));
             String htmlUrl = privateInfo.getHtmlUrl();
             try {
+                InputStream fileInputStream = FileUtils.getInputStreamByUrl(htmlUrl);
+                String htmlString = IoUtil.readToString(fileInputStream);
+                Document doc = Jsoup.parse(htmlString);
+                Elements table = doc.getElementsByAttribute("dqid");
+                List<String> dqid = new ArrayList<>();
+                for(Element ek:table){
+                    dqid.addAll(Func.toStrList("\\|\\|",ek.attr("dqid")));
+                }
                 if(Func.isNotEmpty(textdictInfo.getShowType()) && textdictInfo.getShowType() == 1){
-                    textdict = baseMapper.selectTextDictInfoByProjectIdAndTabId(page, privateInfo);
+                    if (!dqid.isEmpty()) {
+                        textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
+                    }
                     if (textdict == null || textdict.isEmpty()) {
-                        textdict = baseMapper.selectTextdictInfoByExcelIdAndProjectIdAndHtmlUrl(page, privateInfo);
+                        textdict = baseMapper.selectTextDictInfoByProjectIdAndTabId(page, privateInfo);
+                        if (textdict == null || textdict.isEmpty()) {
+                            textdict = baseMapper.selectTextdictInfoByExcelIdAndProjectIdAndHtmlUrl(page, privateInfo);
+                        }
                     }
                     if (textdict != null && !textdict.isEmpty()) {
-                        Map<String, TextdictInfoVO> map = textdict.stream().collect(Collectors.toMap(item -> item.getProjectId() + item.getTabId() + item.getColKey() + item.getColName(), item -> item, (v1, v2) -> v1));
+                        Map<String, TextdictInfoVO> map = textdict.stream().collect(Collectors.toMap(item -> item.getProjectId() + item.getTabId() + item.getColKey() + item.getColName(), item -> item, (v1, v2) -> dqid.contains(v2.getId() + "") ? v2 : v1));
                         textdict = new ArrayList<>(map.values());
-                        InputStream fileInputStream = FileUtils.getInputStreamByUrl(htmlUrl);
-                        String htmlString = IoUtil.readToString(fileInputStream);
-                        Document doc = Jsoup.parse(htmlString);
                         for (TextdictInfoVO vo : textdict) {
                             Elements keyName = doc.getElementsByAttributeValue("keyname", vo.getColKey());
                             if (keyName ==  null || keyName.isEmpty()) {
                                 vo.setIsMatch(0);
+                            } else {
+                                for (Element ek : keyName) {
+                                    Elements placeholder = ek.getElementsByAttributeValue("placeholder", vo.getColName());
+                                    if (placeholder != null && !placeholder.isEmpty()) {
+                                        vo.setIsMatch(1);
+                                        break;
+                                    }
+                                    vo.setIsMatch(0);
+                                }
                             }
                         }
                     }
@@ -253,6 +269,12 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                 textdictInfo.setId(-1L);
                 textdictInfos.add(textdictInfo);
             }
+            List<TextdictInfo> list = this.list(Wrappers.<TextdictInfo>lambdaQuery().eq(TextdictInfo::getTabId, tabId).eq(TextdictInfo::getType, 4));
+            list.forEach(textdictInfo -> {
+                TextdictInfoVO vo = new TextdictInfoVO();
+                BeanUtil.copyProperties(textdictInfo, vo);
+                textdictInfos.add(vo);
+            });
             textdictInfoPage.setRecords(textdictInfos);
             return textdictInfoPage;
         } catch (FileNotFoundException e) {