@Override public List<TaskApproveVo> taskApprove(TaskApproveDTO taskApproveDTO) { List<TaskApproveVo> voList = approveLogMapper.getTaskApprove(taskApproveDTO); // 将名称与部门名称拼接 voList.forEach(taskApproveVo -> { String userName = taskApproveVo.getUserName(); String orgName = taskApproveVo.getOrgName(); taskApproveVo.setUserNameAndOrgName(userName + "-" + orgName); }); // 如果当前节点有多个代办的话 将同一级别的代办展示为一条 并将名字拼接 List<TaskApproveVo> list = voList.stream().filter(a -> a.getStatus() == 0).collect(Collectors.toList()); // 过滤 获取同一节点所有代办 if (list.size() > 1){ List<String> newList = list.stream().map(TaskApproveVo::getUserNameAndOrgName).collect(Collectors.toList()); // 获取指定属性转换为集合 获取所有的userNameAndOrgName 转化为集合 String names = newList.stream().collect(Collectors.joining(",")); // 逗号拼接字符串 // 将原始集合中的代办剔除 创建一个新的代办对象 voList.removeIf(vo -> vo.getStatus() == 0); TaskApproveVo taskApproveVo = new TaskApproveVo(); taskApproveVo.setStatus(0); taskApproveVo.setBillId(voList.get(0).getBillId()); taskApproveVo.setInstanceId(voList.get(0).getInstanceId()); taskApproveVo.setUserNameAndOrgName(names); voList.add(taskApproveVo); } return voList; }
过滤
List<TaskApproveVo> list = voList.stream().filter(a -> a.getStatus() == 0).collect(Collectors.toList());
获取指定属性转换为集合
List<String> newList = list.stream().map(TaskApproveVo::getUserNameAndOrgName).collect(Collectors.toList());
逗号拼接字符串
String names = newList.stream().collect(Collectors.joining(","));
根据条件移除集合中的某个对象
voList.removeIf(vo -> vo.getStatus() == 0);
通过某个字段对集合中的数据进行去重
List<WorkflowCirculation> circulationList = workflowCirculationMapper.queryListByPressesKeyAndBindVersion("Process_1646718515566", "version1"); List<WorkflowCirculation> list = circulationList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WorkflowCirculation::getName)) ), ArrayList::new));
文章持续更新,可以关注下方公众号或者微信搜一搜「 最后一支迷迭香 」第一时间阅读,获取更完整的链路资料。