From b8dbd91e4a1552a1e11cd5fe4eef09f296cf656b Mon Sep 17 00:00:00 2001
From: shicf <shi_chongfu@163.com>
Date: 星期一, 04 八月 2025 16:13:21 +0800
Subject: [PATCH] 综合搜索,多表且有别名,报错

---
 src/main/java/com/product/face/entity/FaceListEntity.java |  149 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 146 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/product/face/entity/FaceListEntity.java b/src/main/java/com/product/face/entity/FaceListEntity.java
index c846e53..fb791e2 100644
--- a/src/main/java/com/product/face/entity/FaceListEntity.java
+++ b/src/main/java/com/product/face/entity/FaceListEntity.java
@@ -14,7 +14,6 @@
 import com.product.core.entity.FieldSetEntity;
 import com.product.core.spring.context.SpringBeanUtil;
 import com.product.core.spring.context.SpringMVCContextHolder;
-import com.product.face.config.FaceConst;
 import com.product.module.sys.entity.SystemUser;
 import com.product.util.BaseUtil;
 
@@ -108,8 +107,9 @@
 	 * @param columnWidth    鍒楀
 	 * @param sequence       鎺掑簭
 	 * @param fieldReference 鍙傜収
+	 * @param search        鏄惁鎼滅储
 	 */
-	public void addField(String fieldName, String faceUuid, String columnName, String columnWidth, Integer sequence, String fieldReference) {
+	public void addField(String fieldName, String faceUuid, String columnName, String columnWidth, Integer sequence, String fieldReference, boolean search) {
 		FaceField faceField = new FaceField();
 		faceField.setFieldName(fieldName);
 		faceField.setFieldUuid(faceUuid);
@@ -117,6 +117,7 @@
 		faceField.setColumnWidth(columnWidth);
 		faceField.setSequence(sequence);
 		faceField.setFieldReference(fieldReference);
+		faceField.setSearch(search);
 		if (this.faceFields == null) {
 			this.faceFields = Lists.newArrayList();
 		}
@@ -252,7 +253,6 @@
 		}
 		return filter.toString();
 	}
-
 	/**
 	 * 鑾峰彇鏉′欢
 	 *
@@ -274,6 +274,9 @@
 		maps.put("filter", filters);
 		for (int i = 0; i < faceFields.size(); i++) {
 			FaceField faceField = faceFields.get(i);
+			if (!faceField.isSearch()) {
+				continue;
+			}
 			if (StringUtils.isEmpty(faceField.getFieldName()) || StringUtils.isEmpty(faceField.getFieldReference())) {
 				if (poolCache == null) {
 					poolCache = DataPoolCacheImpl.getInstance();
@@ -335,11 +338,142 @@
 		RedisUtil.set(faceListKey + getUuid(), JSON.parseObject(JSON.toJSONString(this), com.product.admin.entity.FaceListEntity.class));
 		return maps;
 	}
+	/**
+	 * 鏂扮殑鏂规硶锛屾牴鎹煡璇㈣鍙ョ殑涓殑琛ㄥ埆鍚嶏紝鐢熸垚鏌ヨ鏉′欢
+	 *
+	 * @param tableAlias 琛ㄥ埆鍚�
+	 * @param aliasField 瀛楁鍒悕
+	 * @param  tableAndField 琛ㄤ腑瀛楁
+	 * @return
+	 */
+	public Map<String, List<String>> getFilters(Map<String, List<String>> tableAlias, Map<String, List<String>> aliasField,Map<String, List<String>> tableAndField) {
+		DataPoolCacheImpl poolCache = null;
+		//鎵�鏈夊瓧娈甸泦鍚�
+		List<FaceField> faceFields = this.getFaceFields();
+		//鏅�氭ā绯婃煡璇㈠瓧娈甸泦鍚�
+		List<String> fieldNames = Lists.newArrayList();
+		//鍙傜収妯$硦鏌ヨ鏉′欢闆嗗悎
+		List<String> filters = Lists.newArrayList();
+		//杩斿洖鐨勭粨鏋滈泦
+		Map<String, List<String>> maps = Maps.newHashMap();
+		maps.put("fields", fieldNames);
+		maps.put("filter", filters);
+		for (int i = 0; i < faceFields.size(); i++) {
+			FaceField faceField = faceFields.get(i);
+			
+			if (!faceField.isSearch()) {
+				continue;
+			}
+			if (StringUtils.isEmpty(faceField.getFieldName()) || StringUtils.isEmpty(faceField.getFieldReference())) {
+				if (poolCache == null) {
+					poolCache = DataPoolCacheImpl.getInstance();
+				}
+				DataTableEntity dt = poolCache.getCacheData("琛ㄥ瓧娈典俊鎭�", new String[]{getTableUuid(), faceField.getFieldName()});
+				if (BaseUtil.dataTableIsEmpty(dt)) {
+				} else {
+					FieldSetEntity f = dt.getFieldSetEntity(0);
+					faceField.setFieldName(f.getString(CmnConst.FIELD_NAME));
+					faceField.setFieldReference(f.getString("field_reference"));
+				}
+			}
+			//瀛楁鍚嶇О
+			String fieldName = faceField.getFieldName();
+			if (!StringUtils.isEmpty(fieldName)) {
+				fieldName.trim();
+			}
+			if (aliasField != null && !StringUtils.isEmpty(fieldName)) {
+				List<String> fieldAlias = aliasField.get(getTableName() + "." + fieldName);
+				if (fieldAlias != null && fieldAlias.size() > 0) {
+					String alias = fieldAlias.get(0);
+					if (!StringUtils.isEmpty(alias)) {
+						fieldName = alias.trim();
+					}
+				}
+			}
+			//鍙傜収澶勭悊
+			String field_reference = faceField.getFieldReference();
+			if (!StringUtils.isEmpty(field_reference)) {
+				if (field_reference.indexOf("銆�") == 0 && field_reference.indexOf("銆�") > 0) {
+					//鏅�氬弬鐓�
+					filters.add(getDictFilter(getFieldName(tableAlias,aliasField, tableAndField, fieldName), field_reference.replace("銆�", "").replace("銆�", "")));
+					continue;
+				} else {
+					if (poolCache == null) {
+						poolCache = DataPoolCacheImpl.getInstance();
+					}
+					//楂樼骇鍙傜収
+					DataTableEntity prompt = poolCache.getCacheData("楂樼骇鍙傜収閰嶇疆淇℃伅", new String[]{field_reference});
+					if (BaseUtil.dataTableIsEmpty(prompt)) {
+						continue;
+					}
+					FieldSetEntity ff = prompt.getFieldSetEntity(0);
+					StringBuilder p = new StringBuilder();
+					p.append(getFieldName(tableAlias,aliasField, tableAndField, fieldName)).append(" in ").append(" ( SELECT ").append(ff.getString("value_field")).append(" FROM ").append(ff.getString("source_table"));
+					p.append(" WHERE ").append(ff.getString("view_fields")).append(" like concat('%','~val~','%') )");
+					filters.add(p.toString());
+					continue;
+				}
+			}
+
+			if (!StringUtils.isEmpty(faceField.getFieldName())) {
+				fieldNames.add(getFieldName(tableAlias,aliasField, tableAndField, fieldName));
+			}
+		}
+		//鑾峰彇redis 璧峰key
+		String faceListKey = SystemFaceService.FACE_LIST_KEY;
+		//閲嶆柊鏀惧叆redis
+		RedisUtil.set(faceListKey + getUuid(), JSON.parseObject(JSON.toJSONString(this), com.product.admin.entity.FaceListEntity.class));
+		return maps;
+	}
 
 	private String getFieldName(String tableAlias, String fieldName) {
 		fieldName = "`" + fieldName + "`";
 		if (!StringUtils.isEmpty(tableAlias)) {
 			return "`" + tableAlias + "`." + fieldName;
+		}
+		return fieldName;
+	}
+	//鏂版柟娉�
+	private String getFieldName(Map<String, List<String>> tableAlias,Map<String, List<String>> aliasField, Map<String, List<String>> tableAndField, String fieldName) {	
+		String table=null;
+		boolean b=false;
+		if(!tableAndField.isEmpty()) {
+			for(String key:tableAndField.keySet()) {
+				for(String field:tableAndField.get(key)) {
+					if(fieldName.equals(field)) {
+						
+						List<String>alias=tableAlias.get(key);
+						if(!alias.isEmpty()) {
+							table=alias.get(0);//鍙栫涓�涓埆鍚�
+						}
+						b=true;
+						break;
+					}
+				}
+				if(b)break;
+			}
+		}
+		b=false;
+		//鎵惧埌瀛楁鐨勭湡瀹炲悕瀛�
+		for(String f:aliasField.keySet()) {
+			List<String> fs=aliasField.get(f);
+			if(!fs.isEmpty()) {
+				for(String af:fs) {
+					//瀛楁鍒悕鏈夊彲鑳芥槸甯� 琛ㄥ埆鍚�
+					int c=af.indexOf('.');
+					if(c>0)af=af.substring(c+1);
+					if(fieldName.equals(af)) {
+						fieldName=f;
+						b=true;
+						break;
+					}
+				}
+			}
+			if(b)break;
+		}
+		
+		if (fieldName.indexOf('.')<0 && !StringUtils.isEmpty(table)) {
+			return "`" + table + "`." + fieldName;
 		}
 		return fieldName;
 	}
@@ -374,6 +508,8 @@
 		 * 瀛楁鍙傜収
 		 */
 		private String fieldReference;
+
+		private boolean search;
 
 		public String getFieldReference() {
 			return fieldReference;
@@ -423,6 +559,13 @@
 			this.sequence = sequence;
 		}
 
+		public boolean isSearch() {
+			return search;
+		}
+
+		public void setSearch(boolean search) {
+			this.search = search;
+		}
 	}
 
 

--
Gitblit v1.9.2