|
|
@@ -267,11 +267,84 @@ public class ReformServiceImpl implements ReformService {
|
|
|
.filter(Optional::isPresent)
|
|
|
.map(Optional::get)
|
|
|
.collect(Collectors.toList());
|
|
|
+ //重新排序,数据量超过一万可能耗时长一点,超过十万或许有性能问题
|
|
|
+ sortData(order.trim(),mergedList);
|
|
|
Map<String, Object> map = paginate(mergedList, pageNo , limit);
|
|
|
result.setVariables(map);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void sortData(String order, List<Map<String, Object>> mergedList) {
|
|
|
+ if (BeanUtils.isNotEmpty(order)) {
|
|
|
+ boolean isDescending = order.contains("DESC");
|
|
|
+
|
|
|
+ if (order.startsWith("FA_FANG_SHI_JIAN")) {
|
|
|
+ // 按发布时间排序
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ mergedList.sort((m1, m2) -> {
|
|
|
+ try {
|
|
|
+ String dateStr1 = (String) m1.get("fa_bu_shi_jian_");
|
|
|
+ String dateStr2 = (String) m2.get("fa_bu_shi_jian_");
|
|
|
+
|
|
|
+ Date date1 = dateStr1 != null ? sdf.parse(dateStr1) : null;
|
|
|
+ Date date2 = dateStr2 != null ? sdf.parse(dateStr2) : null;
|
|
|
+
|
|
|
+ if (date1 == null && date2 == null) return 0;
|
|
|
+ if (date1 == null) return isDescending ? -1 : 1; // null 排最后
|
|
|
+ if (date2 == null) return isDescending ? 1 : -1; // null 排最后
|
|
|
+
|
|
|
+ return isDescending ? date2.compareTo(date1) : date1.compareTo(date2);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (order.startsWith("WEN_JIAN_BIAN_HAO")) {
|
|
|
+ // 按文件编号排序
|
|
|
+ mergedList.sort((m1, m2) -> {
|
|
|
+ String code1 = (String) m1.get("wen_jian_bian_hao");
|
|
|
+ String code2 = (String) m2.get("wen_jian_bian_hao");
|
|
|
+
|
|
|
+ if (code1 == null && code2 == null) return 0;
|
|
|
+ if (code1 == null) return isDescending ? -1 : 1; // null 排最后
|
|
|
+ if (code2 == null) return isDescending ? 1 : -1; // null 排最后
|
|
|
+
|
|
|
+ // 使用自然排序比较器
|
|
|
+ Comparator<String> naturalComparator = Comparator.naturalOrder();
|
|
|
+ Comparator<String> comparator = isDescending ? naturalComparator.reversed() : naturalComparator;
|
|
|
+
|
|
|
+ // 如果包含数字部分,使用自然排序
|
|
|
+ return compareNatural(code1, code2, isDescending);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private int compareNatural(String a, String b, boolean descending) {
|
|
|
+ // 实现一个简单的自然排序比较
|
|
|
+ String[] parts1 = a.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
|
|
+ String[] parts2 = b.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
|
|
+
|
|
|
+ int length = Math.min(parts1.length, parts2.length);
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
+ String part1 = parts1[i];
|
|
|
+ String part2 = parts2[i];
|
|
|
+
|
|
|
+ if (part1.matches("\\d+") && part2.matches("\\d+")) {
|
|
|
+ int num1 = Integer.parseInt(part1);
|
|
|
+ int num2 = Integer.parseInt(part2);
|
|
|
+ if (num1 != num2) {
|
|
|
+ return descending ? Integer.compare(num2, num1) : Integer.compare(num1, num2);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int cmp = part1.compareTo(part2);
|
|
|
+ if (cmp != 0) {
|
|
|
+ return descending ? -cmp : cmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return descending ? Integer.compare(parts2.length, parts1.length)
|
|
|
+ : Integer.compare(parts1.length, parts2.length);
|
|
|
+ }
|
|
|
+
|
|
|
public static Map<String, Object> paginate(List<Map<String, Object>> dataList, int currentPage, int pageSize) {
|
|
|
int totalCount = dataList.size();
|
|
|
int totalPage = (int) Math.ceil((double) totalCount / pageSize);
|