/**
*
*
* @Author: wang-junjie
* @Description: list排序
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static List<LogDTO> sortList(List<LogDTO> list, String propertyName, boolean isAsc) {
//借助commons-collections包的ComparatorUtils
//BeanComparator,ComparableComparator和ComparatorChain都是实现了Comparator这个接口
Comparator<?> mycmp = ComparableComparator.getInstance();
mycmp = ComparatorUtils.nullLowComparator(mycmp); //允许null
if(isAsc){
mycmp = ComparatorUtils.reversedComparator(mycmp); //逆序
}
Comparator<LogDTO> cmp = new BeanComparator(propertyName, mycmp);
Collections.sort(list, cmp);
return list;
}
@Transactional
public JSONObject getIntimeLogInfo(Integer draw, Integer start, Integer length, String search,String startTime,String endTime) throws Exception {
Map<String, Object> jsonMap = new HashMap<String, Object>();
try {
int count = 0;
List<TbLog> listLogBean = this.logDAO.getIntimeLogInfo(start, length,startTime,endTime);
// 数据传输对象处理
List<LogDTO> listLogDTO = new ArrayList<LogDTO>();
Iterator<TbLog> itrLogBean = listLogBean.iterator();
while (itrLogBean.hasNext()) {
TbLog objLogBean = (TbLog) itrLogBean.next();
Integer logcount = this.logDAO.getLogCount(objLogBean.getUserLoginName(), startTime, endTime);
System.out.println("--"+objLogBean.getUserLoginName()+"--"+objLogBean.getTbUser().getUserLoginName());
objLogBean.setLogcount(logcount);
listLogDTO.add(objLogBean.toDTO());
count++;
}
//listLogDTO.;
listLogDTO=sortList(listLogDTO,"userDTO.userLoginUpdate",true);//true按照userDTO.userLoginUpdate降序
jsonMap.put("draw", draw);
jsonMap.put("recordsTotal", count);
jsonMap.put("recordsFiltered", count);
jsonMap.put("data", listLogDTO);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(JSONObject.fromObject(jsonMap).toString(1));
return JSONObject.fromObject(jsonMap);
}
list排序
最新推荐文章于 2023-05-25 14:27:34 发布