Prechádzať zdrojové kódy

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

lvy 3 týždňov pred
rodič
commit
59348d6be9

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

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.data.repository.query.Param;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -52,4 +53,8 @@ public interface TextdictInfoMapper extends EasyBaseMapper<TextdictInfo> {
     TextdictInfo selectTextdictInfoOne(@Param("id") String id,@Param("sigRoleId") String sigRoleId,@Param("projectId") String projectId);
 
     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);
 }

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

@@ -65,6 +65,18 @@
             and sig_role_id = #{sigRoleId}
             and project_id= #{projectId}
     </select>
+    <select id="selectTextdictInfoByExcelIdAndColKey" resultMap="textdictInfoVoResultMap">
+        SELECT * from m_textdict_info where is_deleted = 0 and type in('2','6') and excel_id = #{excelId} and is_deleted = 0
+        <foreach collection="colKeys" item="key" separator="," open=" and col_key in ( " close=" )" >
+            #{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>

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

@@ -12,6 +12,7 @@ import org.springblade.manager.vo.WbsFormElementVO3;
 import org.springblade.system.vo.RoleVO;
 import org.springblade.system.vo.RoleVO2;
 
+import java.util.Collection;
 import java.util.List;
 
 public interface ISignConfigService extends BaseService<SignConfig> {
@@ -30,5 +31,5 @@ public interface ISignConfigService extends BaseService<SignConfig> {
 
     List<TableInfo> tableList(Integer tableType, String name);
 
-    List<TextdictInfoVO> hasSignConfig(String initTableName, List<String> keys, TextdictInfoVO vo);
+    List<TextdictInfoVO> hasSignConfig(String initTableName, Collection<String> keys, TextdictInfoVO vo);
 }

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/SignConfigServiceImpl.java

@@ -293,7 +293,7 @@ public class SignConfigServiceImpl extends BaseServiceImpl<SignConfigMapper, Sig
     }
 
     @Override
-    public List<TextdictInfoVO> hasSignConfig(String initTableName, List<String> keyNames, TextdictInfoVO vo) {
+    public List<TextdictInfoVO> hasSignConfig(String initTableName, Collection<String> keyNames, TextdictInfoVO vo) {
         List<TextdictInfoVO> textdictInfoVOS = new ArrayList<>();
         if (keyNames == null || keyNames.isEmpty()) {
             return textdictInfoVOS;

+ 115 - 28
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,46 +78,35 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                 Document doc = Jsoup.parse(htmlString);
                 Elements table = doc.getElementsByAttribute("dqid");
                 List<String> dqid = new ArrayList<>();
-                List<String> keys = 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)){
                     for(Element keyName:keyNames){
-                        keys.add(keyName.attr("keyname"));
+                        keys.put(keyName.attr("keyname"), keyName.attr("placeholder"));
                     }
                 }
                 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<>();
                     }
-                    List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelId(page, textdictInfo);
-                    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);
-                    }
                     if (!keys.isEmpty()) {
+                        textdict = getTextDictInfoBySystem(textdictInfo, keys, textdictInfos, textdict, doc, privateInfo, dqid);
                         TextdictInfoVO temp = null;
                         if (textdict != null && !textdict.isEmpty()) {
                             temp = textdict.get(0);
@@ -128,7 +119,7 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                             temp.setType(2);
                         }
                         // 查询电签库配置
-                        List<TextdictInfoVO> textdictConfigList = iSignConfigService.hasSignConfig(privateInfo.getInitTableName(), keys, temp);
+                        List<TextdictInfoVO> textdictConfigList = iSignConfigService.hasSignConfig(privateInfo.getInitTableName(), keys.keySet(), temp);
                         if (textdict == null || textdict.isEmpty()) {
                             textdict = textdictConfigList;
                         } else {
@@ -147,7 +138,15 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                         }
                     }
                 }else{
-                    textdict = baseMapper.selectTextdictInfoByExcelId(page, textdictInfo);
+                    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));
+                            textdict = new ArrayList<>(map.values());
+                        }
+                    }
                 }
             } catch (Exception e) {
                 throw new RuntimeException(e);
@@ -157,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;