|
|
@@ -102,6 +102,34 @@ public class StoreServiceFeeRuleServiceImpl implements StoreServiceFeeRuleServic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 排序规则(按桌号聚合):
|
|
|
+ // 1) 先按“桌号组的最新时间”倒序(哪个桌号刚创建/更新,整组置顶);
|
|
|
+ // 2) 组内按单条 updatedTime 倒序;
|
|
|
+ // 3) 最后用桌号(名称)保证同名相邻。
|
|
|
+ Map<String, Date> tableMaxUpdated = new HashMap<>();
|
|
|
+ for (StoreServiceFeeRuleListVo vo : records) {
|
|
|
+ String tableName = (vo.getTableNameList() == null || vo.getTableNameList().isEmpty())
|
|
|
+ ? null
|
|
|
+ : vo.getTableNameList().get(0);
|
|
|
+ Date ts = vo.getUpdatedTime();
|
|
|
+ if (tableName == null) continue;
|
|
|
+ Date cur = tableMaxUpdated.get(tableName);
|
|
|
+ if (cur == null || (ts != null && ts.after(cur))) {
|
|
|
+ tableMaxUpdated.put(tableName, ts);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ records.sort((a, b) -> {
|
|
|
+ String at = (a.getTableNameList() == null || a.getTableNameList().isEmpty()) ? null : a.getTableNameList().get(0);
|
|
|
+ String bt = (b.getTableNameList() == null || b.getTableNameList().isEmpty()) ? null : b.getTableNameList().get(0);
|
|
|
+ Date ag = tableMaxUpdated.get(at);
|
|
|
+ Date bg = tableMaxUpdated.get(bt);
|
|
|
+ int cmpGroup = Comparator.nullsLast(Date::compareTo).reversed().compare(ag, bg);
|
|
|
+ if (cmpGroup != 0) return cmpGroup;
|
|
|
+ int cmpInner = Comparator.nullsLast(Date::compareTo).reversed().compare(a.getUpdatedTime(), b.getUpdatedTime());
|
|
|
+ if (cmpInner != 0) return cmpInner;
|
|
|
+ return Comparator.nullsFirst(String::compareTo).compare(at, bt);
|
|
|
+ });
|
|
|
+
|
|
|
Page<StoreServiceFeeRuleListVo> result = new Page<>(pn, ps, records.size());
|
|
|
result.setRecords(records);
|
|
|
return R.data(result);
|