Ver Fonte

chore(日报): 提交 2026-11-28 代码变更(6 个文件)

harper há 16 horas atrás
pai
commit
d68ac07d47

+ 22 - 7
src/ss/fts/Fts.java

@@ -30,6 +30,8 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.ElasticsearchException;
 import co.elastic.clients.elasticsearch._types.FieldValue;
 import co.elastic.clients.elasticsearch._types.SearchType;
+import co.elastic.clients.elasticsearch._types.SortOptions;
+import co.elastic.clients.elasticsearch._types.SortOrder;
 import co.elastic.clients.elasticsearch._types.mapping.Property;
 import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
 import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
@@ -53,6 +55,7 @@ import co.elastic.clients.json.JsonData;
 
 import ss.AppB;
 import ss.log.SsLog;
+import ss.obj.ObjB;
 
 
 public class Fts implements AutoCloseable {
@@ -99,6 +102,13 @@ public class Fts implements AutoCloseable {
 
 
 		final String indexName = rdIdxName(objectName);
+		// 唯一性排序兜底:按对象主键倒序,保证 ES 的 from/size 分页跨页稳定,并与首页 DB 的 order by id desc 保持一致。Lin
+		final List<SortOptions> sortOpts = new ArrayList<>();
+		if (StringUtils.isNotBlank(objectName)) {
+			ObjB sortObj = AppB.objMap.get(objectName);
+			if (sortObj != null && StringUtils.isNotBlank(sortObj.idName))
+				sortOpts.add(SortOptions.of(s -> s.field(f -> f.field(sortObj.idName).order(SortOrder.Desc))));
+		}
 		try {
 //			index = index.toLowerCase();	// 去掉 appName(index),不支持多个应用。Lin
 
@@ -793,13 +803,18 @@ public class Fts implements AutoCloseable {
 	                .from((pageNumber -1) * rowCountPerPage)
 	                .size(rowCountPerPage), HashMap.class);
 			} else {
-			response = client.search(searchRequestBuilder -> searchRequestBuilder
-	                .index(indexName)
-	                .query(queryBuilder -> queryBuilder.bool(boolQueryBuilder.build()))
-//	                .highlight(hl)
-	                .searchType(SearchType.QueryThenFetch)
-	                .from((pageNumber -1) * rowCountPerPage)
-	                .size(rowCountPerPage), HashMap.class);
+			response = client.search(searchRequestBuilder -> {
+				searchRequestBuilder
+		                .index(indexName)
+		                .query(queryBuilder -> queryBuilder.bool(boolQueryBuilder.build()))
+//		                .highlight(hl)
+		                .searchType(SearchType.QueryThenFetch)
+		                .from((pageNumber -1) * rowCountPerPage)
+		                .size(rowCountPerPage);
+				if (!(sortOpts.isEmpty()))
+					searchRequestBuilder.sort(sortOpts);
+				return searchRequestBuilder;
+			}, HashMap.class);
 			}
 
 /* ES5 > ES8。Lin

+ 3 - 10
src/ss/search/SearchServ.java

@@ -4732,15 +4732,7 @@ public class SearchServ extends Serv {
 */
 ///// start,再改,支持查询条件 <serv filter=。Lin
 /// 来自 SearchU.makeSqlCmd(。Lin
-			SqlCmd sqlCmd = new SqlCmd();
-			String sql = SearchU.makeMainSql(cache);    // basesql()。Lin
-			String where = SearchU.makeWhereSql(cache, sqlCmd);
-			if (where != null)
-				sql += " and ("+ where +")";
-/* 改,第一次时列表按 对象ID 倒排序。Lin
-			sql += makeOrderSql(cache);    // baseorderby()。Lin
-*/			sql += " order by "+ viewob.idName +" desc";
-			sqlCmd.init(sql);    // setNameSql()。Lin
+			SqlCmd sqlCmd = SearchU.makeSqlCmd(cache);    // 与列表接口一致:按对象 order 配置 + 主键兜底排序,避免首页与后续页顺序不一致。Lin
 ///
 			list = gdba.doSelMapListByPagingByC(sqlCmd, page);	// .selectAsMapList()。Lin
 			// gdba.doSelMapListByPagingByC( 里的 page(Po),只用到 .rowNumPer、.pageNo,并返回 .rowNum(写入)。Lin
@@ -5649,7 +5641,8 @@ public class SearchServ extends Serv {
 /* 再改 managementOption(String) 为 int -- Request."management"(String) 改为 Request."scopeType"(int) 了。Lin
 		boolean bdOption = !(StringUtils.isBlank(managementOption)) && (!"0".equals(managementOption));
 */		boolean bdOption = (managementOption != SearchC.SCOPE_all);	// 所有,原为 "0"。Lin
-		isFulltext = !bdOption;
+		// 无关键词时走 DB(与首页一致),仅在“所有 + 有关键词”时走全文检索,避免 ES 为空导致列表空白/翻页不承接。Lin
+		isFulltext = !bdOption && StringUtils.isNotBlank(requestParam.get(SearchC.FIELD_ssKeywordName));
 //		boolean isReady = "1".equals(requestParam.get("isReady"));	// 再去掉,去掉 isReady = true -- 拆分 searchObj() -- 新查询页。Lin
 
 		Map<String, Object> dataMap = new HashMap<>();	// 再增加 -- 改为 ajax。Lin

+ 7 - 1
src/ss/search/SearchU.java

@@ -134,7 +134,13 @@ public class SearchU {
 /* 再改,IDEA:String concatenation '+=' in loop。Lin
  * 不转来转去,直接 return
 			sql = sql.substring(0, sql.length() - 1);
-*/			return sql.substring(0, sql.length() -1);
+*/
+			// 唯一性兜底:追加主键排序,保证相同排序键时 rownum 分页跨页稳定,避免翻页重复/跳行。Lin
+			if (StringUtils.isNotBlank(cache.obj.idName))
+				sql.append(cache.obj.tabName).append(".").append(cache.obj.idName).append(" desc");
+			else
+				return sql.substring(0, sql.length() -1);
+			return sql.toString();
 		}
 
 /* sql 移到上面的 if 里了。Lin

+ 15 - 7
web/js/vue/ss-components.js

@@ -9498,9 +9498,17 @@ import { EVEN_VAR } from "./EventBus.js";
       },
     },
     setup(props) {
-      const totalItems = ref(props.total); // 总条目数
-      const totalPages = ref(Math.ceil(props.total / props.size));
-      const currentPage = ref(props.page); // 当前页码
+      // 功能说明:total/size 响应式化,并对 size<=0 兜底,避免 totalPages 变成 Infinity 后无限翻页、把 rowNumPer=0 发后端导致空白 by xu 20261128
+      const sizeSafe = computed(() => (Number(props.size) > 0 ? Number(props.size) : 1));
+      const totalItems = computed(() => Number(props.total) || 0); // 总条目数
+      const totalPages = computed(() => Math.ceil(totalItems.value / sizeSafe.value));
+      const currentPage = ref(Number(props.page) || 1); // 当前页码
+      watch(
+        () => props.page,
+        (v) => {
+          currentPage.value = Number(v) || 1;
+        }
+      );
 
       // 计算显示的信息
       const pageInfo = ref(
@@ -9515,8 +9523,8 @@ import { EVEN_VAR } from "./EventBus.js";
           updatePageInfo();
           props.onChange?.({
             pageNo: currentPage.value, // 当前页码
-            rowNumPer: props.size, // 每页条数
-            rowNum: props.total, // 总记录数
+            rowNumPer: sizeSafe.value, // 每页条数
+            rowNum: totalItems.value, // 总记录数
           });
         }
       };
@@ -9529,8 +9537,8 @@ import { EVEN_VAR } from "./EventBus.js";
           updatePageInfo();
           props.onChange?.({
             pageNo: currentPage.value, // 当前页码
-            rowNumPer: props.size, // 每页条数
-            rowNum: props.total, // 总记录数
+            rowNumPer: sizeSafe.value, // 每页条数
+            rowNum: totalItems.value, // 总记录数
           });
         }
       };

+ 10 - 3
web/page/env/objList.jsp

@@ -2219,9 +2219,16 @@
                 handlePageChange({pageNo, rowNumPer, rowNum}) {
                     // 翻页:调用列表接口刷新(不刷新右侧栏)
                     if (this.loadingList) return;
-                    this.ssPaging.pageNo = pageNo;
-                    this.ssPaging.rowNumPer = rowNumPer;
-                    this.ssPaging.rowNum = rowNum;
+                    // 功能说明:rowNumPer<=0 兜底、pageNo 越界钳制,避免把 0 或超界页码发给后端导致空白 by xu 20261128
+                    const safeSize = Number(rowNumPer) > 0 ? Number(rowNumPer) : (Number(this.ssPaging?.rowNumPer) > 0 ? Number(this.ssPaging.rowNumPer) : 12);
+                    const safeTotal = Number(rowNum) > 0 ? Number(rowNum) : Number(this.ssPaging?.rowNum || 0);
+                    const maxPage = Math.max(1, Math.ceil(safeTotal / safeSize));
+                    let nextPageNo = Number(pageNo) || 1;
+                    if (nextPageNo < 1) nextPageNo = 1;
+                    if (nextPageNo > maxPage) nextPageNo = maxPage;
+                    this.ssPaging.pageNo = nextPageNo;
+                    this.ssPaging.rowNumPer = safeSize;
+                    this.ssPaging.rowNum = safeTotal;
                     this.userInteracted = true;
                     this.loadPobjList({ source: "page", lockRowNumPer: true });
                 },

+ 10 - 3
web/page/objList.jsp

@@ -2254,9 +2254,16 @@
                 handlePageChange({pageNo, rowNumPer, rowNum}) {
                     // 翻页:调用列表接口刷新(不刷新右侧栏)
                     if (this.loadingList) return;
-                    this.ssPaging.pageNo = pageNo;
-                    this.ssPaging.rowNumPer = rowNumPer;
-                    this.ssPaging.rowNum = rowNum;
+                    // 功能说明:rowNumPer<=0 兜底、pageNo 越界钳制,避免把 0 或超界页码发给后端导致空白 by xu 20261128
+                    const safeSize = Number(rowNumPer) > 0 ? Number(rowNumPer) : (Number(this.ssPaging?.rowNumPer) > 0 ? Number(this.ssPaging.rowNumPer) : 12);
+                    const safeTotal = Number(rowNum) > 0 ? Number(rowNum) : Number(this.ssPaging?.rowNum || 0);
+                    const maxPage = Math.max(1, Math.ceil(safeTotal / safeSize));
+                    let nextPageNo = Number(pageNo) || 1;
+                    if (nextPageNo < 1) nextPageNo = 1;
+                    if (nextPageNo > maxPage) nextPageNo = maxPage;
+                    this.ssPaging.pageNo = nextPageNo;
+                    this.ssPaging.rowNumPer = safeSize;
+                    this.ssPaging.rowNum = safeTotal;
                     this.userInteracted = true;
                     this.loadPobjList({ source: "page", lockRowNumPer: true });
                 },