Browse Source

feature 解决数据字典没有替换的问题

xiahan 1 năm trước cách đây
mục cha
commit
a152f2ed5d

+ 7 - 1
cx-knowledge-base/cx-knowledge-base-common/src/main/java/com/rongwei/bscommon/sys/service/impl/KnowledgeBaseServiceImpl.java

@@ -12,7 +12,9 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * KnowledgeBaseServiceImpl class
@@ -64,8 +66,11 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
             // 设置下拉选的搜索条件
             searchBasicInfo.forEach(info -> {
                 if (SELECT.equals(info.getControlType()) && (DICT.equals(info.getEnumType()) || SQL.equals(info.getEnumType()))) {
-                    String searchValue = selectInfo.stream().filter(data -> (data.getDictKey().equals(String.format(STR, info.getTableName(), info.getColumnName()))) && data.getLabel().contains(searchContent)).map(KBDictDataVo::getValue).collect(Collectors.joining(","));
+                    List<KBDictDataVo> collect = selectInfo.stream().filter(data -> (data.getDictKey().equals(String.format(STR, info.getTableName(), info.getColumnName())))).collect(Collectors.toList());
+                    List<KBDictDataVo> kbDictDataVoList = collect.stream().filter(dictData -> dictData.getLabel().contains(searchContent)).collect(Collectors.toList());
+                    String searchValue = kbDictDataVoList.stream().map(KBDictDataVo::getValue).collect(Collectors.joining(","));
                     info.setSearchValue(StringUtils.isBlank(searchValue) ? "" : searchValue);
+                    info.setDictData(collect.stream().collect(Collectors.toMap(KBDictDataVo::getValue, KBDictDataVo::getLabel)));
                 } else {
                     info.setSearchValue(searchContent);
                 }
@@ -88,6 +93,7 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
                 columnInfo.setColumnDesc(data.getColumnDesc());
                 columnInfo.setColumnType(data.getColumnType());
                 columnInfo.setSearchValue(data.getSearchValue());
+                columnInfo.setDictData(data.getDictData());
                 return columnInfo;
             }).collect(Collectors.toList()));
             if (!vo.getColumnInfoList().isEmpty()) {

+ 31 - 23
cx-knowledge-base/cx-knowledge-base-common/src/main/resources/mybatis/KbKnowledgebaseSearchKeywordsDao.xml

@@ -29,7 +29,7 @@
     <select id="getSelectInfo" resultType="com.rongwei.bsentity.vo.KBDictDataVo">
         <foreach collection="datas" separator="union all" item="data" >
             <if test="data.enumType=='dict'">
-                select name as label ,value as value,concat(#{data.tableName},"-;-",#{data.columnName}) as dictKey from sys_dict where DELETED='0' AND DICTTYPE=#{data.enumContent}
+                select name as label ,value as value,concat(#{data.tableName},"-;-",#{data.columnName}) as dictKey from sys_dict where DELETED='0' and PID != -1 AND DICTTYPE=#{data.enumContent}
             </if>
             <if test="data.enumType=='sql'">
                 select label,value,concat(#{data.tableName},"-;-",#{data.columnName}) as dictKey from (${data.enumContent}) a
@@ -76,7 +76,23 @@
                     '' AS systemName,
                     <foreach collection="searchVo.columnInfoList" item="columnInfo" separator=', "-@-",' open="CONCAT("
                              close=")">
-                        #{columnInfo.columnDesc},": ",ifnull(a.${columnInfo.columnName},"")
+                        <choose>
+                            <when test="columnInfo.dictData != null and columnInfo.dictData.size() > 0">
+                                #{columnInfo.columnDesc},": ",
+                                ifnull(
+                                <foreach collection="columnInfo.dictData.keys" item="key">
+                                    REPLACE(
+                                </foreach>
+                                a.${columnInfo.columnName}
+                                <foreach collection="columnInfo.dictData.entrySet()" index="key" item="val" separator=")" close=")" >
+                                    ,#{key},#{val}
+                                </foreach>
+                                    ,"")
+                            </when>
+                            <otherwise>
+                                #{columnInfo.columnDesc},": ",ifnull(a.${columnInfo.columnName},"")
+                            </otherwise>
+                        </choose>
                     </foreach>
                     as searchResult
                     from (${searchVo.tableSql}) a
@@ -85,24 +101,25 @@
                         AND
                         <foreach collection="searchVo.columnInfoList" item="columnInfo" separator=' or ' open="("
                                  close=")">
-                            <bind name="pattern" value="'%' + columnInfo.searchValue + '%'"/>
                             <choose>
                                 <when test="columnInfo.columnType=='DATETIME'">
-                                    CAST(a.${columnInfo.columnName}  AS CHAR) LIKE #{pattern}
+                                    CAST(a.${columnInfo.columnName} AS CHAR) LIKE "%"#{columnInfo.searchValue}"%"
                                 </when>
                                 <otherwise>
-                                    a.${columnInfo.columnName} LIKE #{pattern}
+                                    a.${columnInfo.columnName} LIKE "%"#{columnInfo.searchValue}"%"
                                 </otherwise>
                             </choose>
 
                         </foreach>
                     </where>
                 </foreach>
-                union all
-                <include refid="kbSQL"></include>
+                <if test="systemId=='all'">
+                    union all
+                    <include refid="kbSQL"></include>
+                </if>
             </otherwise>
         </choose>
-                )b where b.searchResult is not null order by b.createDate ${orderRules} limit #{pageNum},#{pageSize}
+        )b where b.searchResult is not null order by b.createDate ${orderRules} limit #{pageNum},#{pageSize}
     </select>
     <select id="getKbDataLength" resultType="java.lang.Integer">
         select COUNT(*) from (
@@ -113,18 +130,7 @@
             <otherwise>
                 <foreach collection="searchVos" item="searchVo" separator="union all">
                     select
-                    ID as dataId,
-                    #{searchVo.menuId} AS menuId,
-                    #{searchVo.menuName} AS menuName,
-                    #{searchVo.menuPid} AS systemId,
-                    #{searchVo.pagePartId} as pagePartId,
-                    a.CREATEDATE as createDate,
-                    '' AS systemName,
-                    <foreach collection="searchVo.columnInfoList" item="columnInfo" separator=', "-@-",' open="CONCAT("
-                             close=")">
-                        #{columnInfo.columnDesc},": ",ifnull(a.${columnInfo.columnName},"")
-                    </foreach>
-                    as searchResult
+                    ID as dataId
                     from (${searchVo.tableSql}) a
                     <where>
                         AND DELETED ='0'
@@ -144,10 +150,12 @@
                         </foreach>
                     </where>
                 </foreach>
-                union all
-                <include refid="kbSQL"></include>
+                <if test="systemId=='all'">
+                    union all
+                    <include refid="kbSQL"></include>
+                </if>
             </otherwise>
         </choose>
-        )b where b.searchResult is not null
+        )b where b.dataId is not null
     </select>
 </mapper>

+ 3 - 0
cx-knowledge-base/cx-knowledge-base-entity/src/main/java/com/rongwei/bsentity/vo/KBSearchVo.java

@@ -2,7 +2,9 @@ package com.rongwei.bsentity.vo;
 
 import lombok.Data;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * KBSearchVo class
@@ -33,5 +35,6 @@ public class KBSearchVo {
         private String columnDesc;
         private String columnType;
         private String searchValue;
+        private Map<String,String> dictData = new HashMap<>();
     }
 }

+ 5 - 0
cx-knowledge-base/cx-knowledge-base-entity/src/main/java/com/rongwei/bsentity/vo/KnowledgeBaseVo.java

@@ -2,6 +2,9 @@ package com.rongwei.bsentity.vo;
 
 import lombok.Data;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * KnowledgeBaseVo class
  *
@@ -38,4 +41,6 @@ public class KnowledgeBaseVo {
     private String searchValue;
     // 列表查询条件
     private String tablesql;
+
+    private Map<String,String> dictData;
 }