Procházet zdrojové kódy

电签系统推荐优化:根据excel_id 和col_key进行推荐

lvy před 2 měsíci
rodič
revize
b314b1b70d

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/TextdictInfoMapper.java

@@ -55,4 +55,6 @@ public interface TextdictInfoMapper extends EasyBaseMapper<TextdictInfo> {
     void updateHtmlUrl(@Param("htmlUrl") String htmlUrl,@Param("projectId") String projectId, @Param("excelId") Long pKeyId);
 
     List<TextdictInfoVO> selectTextdictInfoByExcelIdAndColKey(@Param("excelId") String excelId, @Param("colKeys") Collection<String> colKeys);
+
+    List<TextdictInfoVO> selectTextDictInfoByIdAndColKeyAndColName(@Param("list") List<TextdictInfo> textdictInfos);
 }

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

@@ -71,6 +71,12 @@
             #{key}
         </foreach>
     </select>
+    <select id="selectTextDictInfoByIdAndColKeyAndColName" resultMap="textdictInfoVoResultMap">
+        select * from m_textdict_info where is_deleted = 0
+        <foreach collection="list" item="item" separator="," open=" and (id,col_key,col_name) in ( " close=")">
+            (#{item.id},#{item.colKey},#{item.colName})
+        </foreach>
+    </select>
     <update id="updateHtmlUrl">
         update m_wbs_tree_contract set html_url = #{htmlUrl} where type = 2 and project_id = #{projectId} and is_type_private_pid = #{pKeyId};
     </update>

+ 103 - 30
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/TextdictInfoServiceImpl.java

@@ -22,6 +22,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang.StringUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -76,9 +78,18 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                 Document doc = Jsoup.parse(htmlString);
                 Elements table = doc.getElementsByAttribute("dqid");
                 List<String> dqid = new ArrayList<>();
+                Map<String, String> dqIdMap = new HashMap<>();
                 Map<String, String> keys = new HashMap<>();
                 for(Element ek:table){
-                    dqid.addAll(Func.toStrList("\\|\\|",ek.attr("dqid")));
+                    List<String> list = Func.toStrList("\\|\\|", ek.attr("dqid"));
+                    dqid.addAll(list);
+                    Elements keyname = ek.getElementsByAttributeValueStarting("keyname", "key_");
+                    if (keyname != null && !keyname.isEmpty()) {
+                        String key = keyname.get(0).attr("keyname");
+                        for (String s : list) {
+                            dqIdMap.put(s, key);
+                        }
+                    }
                 }
                 Elements keyNames = doc.getElementsByAttribute("keyname");
                 if(Func.isNotEmpty(keyNames)){
@@ -87,41 +98,15 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                     }
                 }
                 if(Func.isNotEmpty(textdictInfo.getShowType()) && textdictInfo.getShowType() == 1){
+                    List<TextdictInfo> textdictInfos = new ArrayList<>();
                     if(Func.isNotEmpty(dqid) && dqid.size() > 0){
                         textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
+                        textdict = getTextdictInfoByDqIdAndKeyName(textdict, dqIdMap, keys, textdictInfos);
                     }else {
                         textdict = new ArrayList<>();
                     }
                     if (!keys.isEmpty()) {
-                        // 根据excel_id 和col_key 查询
-                        List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelIdAndColKey(textdictInfo.getExcelId(),keys.keySet());
-                        if (textdictList != null) {
-                            Map<String, TextdictInfoVO> map = textdictList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
-                            textdictList = new ArrayList<>(map.values());
-                        }
-                        if (textdict == null || textdict.isEmpty()) {
-                            textdict = textdictList;
-                            if (textdict != null) {
-                                textdict.forEach(textdictInfoVO -> textdictInfoVO.setIsSystem(2));
-                            }
-                            addSign(textdict, doc, privateInfo, dqid, textdict);
-                        } else if (textdictList != null && !textdictList.isEmpty()) {
-                            Map<String, Map<String, TextdictInfoVO>> map = textdict.stream().filter(vo -> vo.getColKey() != null && vo.getColKey().contains("__")).collect(Collectors.groupingBy(vo -> vo.getColKey().split("__")[1], Collectors.toMap(TextdictInfoVO::getSigRoleId, v -> v, (v1, v2) -> v1)));
-                            List<TextdictInfoVO> collect = textdictList.stream().filter(textdictInfoVO -> {
-                                if (textdictInfoVO.getColKey() == null || !textdictInfoVO.getColKey().contains("__")) {
-                                    return true;
-                                }
-                                Map<String, TextdictInfoVO> voMap = map.get(textdictInfoVO.getColKey().split("__")[1]);
-                                textdictInfoVO.setIsSystem(2);
-                                if (voMap != null && !voMap.isEmpty() ) {
-                                    return voMap.get(textdictInfoVO.getSigRoleId()) == null;
-                                }
-                                return true;
-                            }).collect(Collectors.toList());
-                            textdict.addAll(collect);
-                            addSign(collect, doc, privateInfo, dqid,textdict);
-                        }
-
+                        textdict = getTextDictInfoBySystem(textdictInfo, keys, textdictInfos, textdict, doc, privateInfo, dqid);
                         TextdictInfoVO temp = null;
                         if (textdict != null && !textdict.isEmpty()) {
                             temp = textdict.get(0);
@@ -171,6 +156,94 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
         }
         return page.setRecords(textdict);
     }
+
+    /**
+     * 系统推荐
+     */
+    @Nullable
+    private List<TextdictInfoVO> getTextDictInfoBySystem(TextdictInfoVO textdictInfo, Map<String, String> keys, List<TextdictInfo> textdictInfos, List<TextdictInfoVO> textdict, Document doc, WbsTreePrivate privateInfo, List<String> dqid) {
+        // 根据excel_id 和col_key 查询
+        List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelIdAndColKey(textdictInfo.getExcelId(), keys.keySet());
+        if (textdictList != null) {
+            Map<String, TextdictInfoVO> map = textdictList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
+            textdictList = new ArrayList<>(map.values());
+            if (!textdictInfos.isEmpty()) {
+                // 保存到数据库,从系统推荐中获取roleId
+                Map<String, TextdictInfo> collect = textdictInfos.stream().collect(Collectors.toMap(info -> info.getColKey() + info.getColName(), v -> v, (v1, v2) -> v1));
+                for (TextdictInfoVO vo : textdictList) {
+                    TextdictInfo info = collect.get(vo.getColKey() + vo.getColName());
+                    if (info != null) {
+                        vo.setId(info.getId());
+                        vo.setProjectId("0");
+                        BeanUtil.copyProperties(vo, info);
+                    }
+                }
+                List<TextdictInfo> list = textdictInfos.stream().filter(info -> StringUtil.hasText(info.getSigRoleId())).collect(Collectors.toList());
+                this.saveBatch( list);
+            }
+        }
+        if (textdict.isEmpty()) {
+            textdict = textdictList;
+            if (textdict != null) {
+                textdict.forEach(textdictInfoVO -> textdictInfoVO.setIsSystem(2));
+            }
+            addSign(textdict, doc, privateInfo, dqid, textdict);
+        } else if (textdictList != null && !textdictList.isEmpty()) {
+            Map<String, Map<String, TextdictInfoVO>> map = textdict.stream().filter(vo -> vo.getColKey() != null && vo.getColKey().contains("__")).collect(Collectors.groupingBy(vo -> vo.getColKey().split("__")[1], Collectors.toMap(TextdictInfoVO::getSigRoleId, v -> v, (v1, v2) -> v1)));
+            List<TextdictInfoVO> collect = textdictList.stream().filter(textdictInfoVO -> {
+                if (textdictInfoVO.getColKey() == null || !textdictInfoVO.getColKey().contains("__")) {
+                    return true;
+                }
+                Map<String, TextdictInfoVO> voMap = map.get(textdictInfoVO.getColKey().split("__")[1]);
+                textdictInfoVO.setIsSystem(2);
+                if (voMap != null && !voMap.isEmpty() ) {
+                    return voMap.get(textdictInfoVO.getSigRoleId()) == null;
+                }
+                return true;
+            }).collect(Collectors.toList());
+            textdict.addAll(collect);
+            addSign(collect, doc, privateInfo, dqid, textdict);
+        }
+        return textdict;
+    }
+
+    @NotNull
+    private List<TextdictInfoVO> getTextdictInfoByDqIdAndKeyName(List<TextdictInfoVO> textdict, Map<String, String> dqIdMap, Map<String, String> keys, List<TextdictInfo> textdictInfos) {
+        if (textdict == null) {
+            textdict = new ArrayList<>();
+        }
+        Map<String, TextdictInfoVO> map = textdict.stream().collect(Collectors.toMap(item -> item.getId() + "", v -> v, (v1, v2) -> v2));
+        dqIdMap.forEach((k, v) -> {
+            if (map.containsKey(k)) {
+                return;
+            }
+            Long id = null;
+            try {
+                id = Long.parseLong(k);
+            } catch (Exception e) {
+                log.warn(e.getMessage());
+            }
+            String colName = keys.get(v);
+            if (id == null || v == null || colName == null) {
+                return;
+            }
+            TextdictInfo info = new TextdictInfo();
+            info.setId(id);
+            info.setColKey(v);
+            info.setColName(colName);
+            textdictInfos.add(info);
+        });
+        if (!textdictInfos.isEmpty()) {
+            List<TextdictInfoVO> list = baseMapper.selectTextDictInfoByIdAndColKeyAndColName(textdictInfos);
+            Map<String, TextdictInfoVO> voMap = list.stream().collect(Collectors.toMap(item -> item.getId() + item.getColKey() + item.getColName(), item -> item, (v1, v2) -> v1));
+            Collection<TextdictInfoVO> values = voMap.values();
+            values.forEach(item -> item.setIsSystem(2));
+            textdict.addAll(values);
+            textdictInfos.removeIf(item -> voMap.containsKey(item.getId() + item.getColKey() + item.getColName()));
+        }
+        return textdict;
+    }
+
     private void addSign(List<TextdictInfoVO> collect, Document doc, WbsTreePrivate privateInfo, List<String> dqid,List<TextdictInfoVO> allTextdict) {
         if (collect == null || collect.isEmpty()) {
             return;