java8进行集合排序
代码如下:
@Override
public GenericPage<SystemMsgOrganizationReceiveRecordVO> getPage(Integer pageNo, Integer pageSize, SystemMsgPushRecordPO po, LoginData loginData) throws HerculesException {
List<SystemMsgOrganizationReceiveRecordVO> attributesVOList= Lists.newArrayList();
List<SystemMsgOrganizationReceiveRecordVO> sortedList=null;
SystemMsgOrganizationReceiveRecord condition=new SystemMsgOrganizationReceiveRecord();
Optional.ofNullable(po).ifPresent(aq->BeanUtils.copyProperties(aq,condition));
condition.setOrganizationId(loginData.getOrganizationId());
Page<SystemMsgOrganizationReceiveRecord> pageInfo = PageHelper.startPage(pageNo, pageSize);
List<SystemMsgOrganizationReceiveRecord> deviceTelemetries = systemMsgOrganizationReceiveRecordMapper.selectByCondition(condition);
Optional.ofNullable(deviceTelemetries).ifPresent(a->{
deviceTelemetries.forEach(e->{
SystemMsgOrganizationReceiveRecordVO avo=new SystemMsgOrganizationReceiveRecordVO();
BeanUtils.copyProperties(e,avo);
attributesVOList.add(avo);
});
});
//进行排序
if(!ObjectUtils.isEmpty(attributesVOList)){
sortedList = attributesVOList.stream().sorted(Comparator.comparing(SystemMsgOrganizationReceiveRecordVO::getReadStatus)
.thenComparing(SystemMsgOrganizationReceiveRecordVO::getCreateTime).reversed())
.collect(Collectors.toList());
}
sortedList= sortedList==null ? attributesVOList: sortedList;
GenericPage<SystemMsgOrganizationReceiveRecordVO> genericPage = new GenericPage<SystemMsgOrganizationReceiveRecordVO>(pageSize,pageInfo.getTotal(),sortedList);
return genericPage;
}
网友评论