美文网首页
java8进行集合排序

java8进行集合排序

作者: 大风过岗 | 来源:发表于2020-07-23 15:19 被阅读0次

    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;
        }
    

    相关文章

      网友评论

          本文标题:java8进行集合排序

          本文链接:https://www.haomeiwen.com/subject/zhrhlktx.html