|
|
@@ -17,6 +17,8 @@ import lombok.extern.log4j.Log4j2;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
@@ -224,11 +226,35 @@ public class ReformServiceImpl implements ReformService {
|
|
|
sxsql = sxsql + conditions + sorts;
|
|
|
List<Map<String, Object>> limitLists = (List<Map<String, Object>>) commonDao.query(sxsql);
|
|
|
List<Map<String, Object>> mergedList = Stream.concat(Stream.concat(limitLists.stream(), buMenList.stream()),comList.stream()).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);
|