|
|
@@ -267,11 +267,37 @@ public class ReformServiceImpl implements ReformService {
|
|
|
.filter(Optional::isPresent)
|
|
|
.map(Optional::get)
|
|
|
.collect(Collectors.toList());
|
|
|
+ //重新排序,数据量超过一万可能耗时长一点,超过十万或许有性能问题
|
|
|
+ sortData(order,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");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//发布时间格式必须是2025-05-02,不然排序失败
|
|
|
+ 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 1; // null 排最后
|
|
|
+ if (date2 == null) return -1; // null 排最后
|
|
|
+
|
|
|
+ return isDescending ? date2.compareTo(date1) : date1.compareTo(date2);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
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);
|