!561 使用封装好的StreamUtils工具类代替项目中的部分stream操作
* refactor : 使用封装好的StreamUtils工具类代替项目中的部分stream操作
| | |
| | | import org.dromara.common.core.enums.UserStatus; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.exception.user.UserException; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.dromara.common.core.utils.ValidatorUtils; |
| | | import org.dromara.common.json.utils.JsonUtils; |
| | | import org.dromara.common.satoken.utils.LoginHelper; |
| | |
| | | } |
| | | SysSocialVo social; |
| | | if (TenantHelper.isEnable()) { |
| | | Optional<SysSocialVo> opt = list.stream().filter(x -> x.getTenantId().equals(loginBody.getTenantId())).findAny(); |
| | | Optional<SysSocialVo> opt = StreamUtils.findAny(list, x -> x.getTenantId().equals(loginBody.getTenantId())); |
| | | if (opt.isEmpty()) { |
| | | throw new ServiceException("对不起,你没有权限登录当前租户!"); |
| | | } |
| | |
| | | |
| | | import java.util.*; |
| | | import java.util.function.BiFunction; |
| | | import java.util.function.Consumer; |
| | | import java.util.function.Function; |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 找到流中满足条件的第一个元素 |
| | | * |
| | | * @param collection 需要查询的集合 |
| | | * @param function 过滤方法 |
| | | * @return 找到符合条件的第一个元素,没有则返回null |
| | | */ |
| | | public static <E> E findFirst(Collection<E> collection, Predicate<E> function) { |
| | | if (CollUtil.isEmpty(collection)) { |
| | | return null; |
| | | } |
| | | return collection.stream().filter(function).findFirst().orElse(null); |
| | | } |
| | | |
| | | /** |
| | | * 找到流中任意一个满足条件的元素 |
| | | * |
| | | * @param collection 需要查询的集合 |
| | | * @param function 过滤方法 |
| | | * @return 找到符合条件的任意一个元素,没有则返回null |
| | | */ |
| | | public static <E> Optional<E> findAny(Collection<E> collection, Predicate<E> function) { |
| | | if (CollUtil.isEmpty(collection)) { |
| | | return Optional.empty(); |
| | | } |
| | | return collection.stream().filter(function).findAny(); |
| | | } |
| | | |
| | | /** |
| | | * 将collection拼接 |
| | | * |
| | | * @param collection 需要转化的集合 |
| | |
| | | import io.swagger.v3.oas.models.tags.Tag; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.springdoc.core.customizers.OpenApiBuilderCustomizer; |
| | | import org.springdoc.core.customizers.ServerBaseUrlCustomizer; |
| | | import org.springdoc.core.properties.SpringDocConfigProperties; |
| | |
| | | .flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet()); |
| | | methodTags.addAll(AnnotatedElementUtils.findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.tags.Tag.class)); |
| | | if (!CollectionUtils.isEmpty(methodTags)) { |
| | | tagsStr.addAll(methodTags.stream().map(tag -> propertyResolverUtils.resolve(tag.name(), locale)).collect(Collectors.toSet())); |
| | | tagsStr.addAll(StreamUtils.toSet(methodTags, tag -> propertyResolverUtils.resolve(tag.name(), locale))); |
| | | List<io.swagger.v3.oas.annotations.tags.Tag> allTags = new ArrayList<>(methodTags); |
| | | addTags(allTags, tags, locale); |
| | | } |
| | |
| | | import org.apache.ibatis.logging.Log; |
| | | import org.apache.ibatis.logging.LogFactory; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Collection; |
| | |
| | | * @return 查询到的符合条件的对象列表,经过转换为指定类型的对象后返回 |
| | | */ |
| | | default <C> List<C> selectObjs(Wrapper<T> wrapper, Function<? super Object, C> mapper) { |
| | | return this.selectObjs(wrapper).stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList()); |
| | | return StreamUtils.toList(this.selectObjs(wrapper), mapper); |
| | | } |
| | | |
| | | } |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 角色 业务层处理 |
| | |
| | | List<SysRoleVo> userRoles = baseMapper.selectRolesByUserId(userId); |
| | | List<SysRoleVo> roles = selectRoleAll(); |
| | | // 使用HashSet提高查找效率 |
| | | Set<Long> userRoleIds = userRoles.stream().map(SysRoleVo::getRoleId).collect(Collectors.toSet()); |
| | | Set<Long> userRoleIds = StreamUtils.toSet(userRoles, SysRoleVo::getRoleId); |
| | | for (SysRoleVo role : roles) { |
| | | if (userRoleIds.contains(role.getRoleId())) { |
| | | role.setFlag(true); |
| | |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.AllArgsConstructor; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.flowable.common.engine.impl.interceptor.Command; |
| | | import org.flowable.common.engine.impl.interceptor.CommandContext; |
| | | import org.flowable.engine.impl.persistence.entity.ExecutionEntity; |
| | |
| | | } |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | userIds.forEach(e -> { |
| | | Long userId = assignees.stream().filter(id -> ObjectUtil.equals(id, e)).findFirst().orElse(null); |
| | | Long userId = StreamUtils.findFirst(assignees, id -> ObjectUtil.equals(id, e)); |
| | | if (userId == null) { |
| | | userIdList.add(e); |
| | | } |
| | |
| | | } |
| | | ProcessInstance processInstance = QueryUtils.instanceQuery(processInstanceId).singleResult(); |
| | | if (processInstance != null) { |
| | | taskList = taskList.stream().filter(e -> !e.get("activityType").equals(FlowConstant.END_EVENT)).collect(Collectors.toList()); |
| | | taskList = StreamUtils.filter(taskList, e -> !e.get("activityType").equals(FlowConstant.END_EVENT)); |
| | | } |
| | | //查询出运行中节点 |
| | | List<Map<String, Object>> runtimeNodeList = taskList.stream().filter(e -> !(Boolean) e.get("completed")).collect(Collectors.toList()); |
| | | List<Map<String, Object>> runtimeNodeList = StreamUtils.filter(taskList, e -> !(Boolean) e.get("completed")); |
| | | if (CollUtil.isNotEmpty(runtimeNodeList)) { |
| | | Iterator<Map<String, Object>> iterator = taskList.iterator(); |
| | | while (iterator.hasNext()) { |
| | |
| | | } |
| | | //附件 |
| | | if (CollUtil.isNotEmpty(attachmentList)) { |
| | | List<Attachment> attachments = attachmentList.stream().filter(e -> e.getTaskId().equals(historicTaskInstance.getId())).collect(Collectors.toList()); |
| | | List<Attachment> attachments = StreamUtils.filter(attachmentList, e -> e.getTaskId().equals(historicTaskInstance.getId())); |
| | | if (CollUtil.isNotEmpty(attachments)) { |
| | | actHistoryInfoVo.setAttachmentList(attachments); |
| | | } |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.satoken.utils.LoginHelper; |
| | | import org.dromara.workflow.domain.WfTaskBackNode; |
| | |
| | | wfTaskBackNode.setOrderNo(0); |
| | | wfTaskBackNodeMapper.insert(wfTaskBackNode); |
| | | } else { |
| | | WfTaskBackNode taskNode = list.stream().filter(e -> e.getNodeId().equals(wfTaskBackNode.getNodeId()) && e.getOrderNo() == 0).findFirst().orElse(null); |
| | | WfTaskBackNode taskNode = StreamUtils.findFirst(list, e -> e.getNodeId().equals(wfTaskBackNode.getNodeId()) && e.getOrderNo() == 0); |
| | | if (ObjectUtil.isEmpty(taskNode)) { |
| | | wfTaskBackNode.setOrderNo(list.get(0).getOrderNo() + 1); |
| | | WfTaskBackNode node = getListByInstanceIdAndNodeId(wfTaskBackNode.getInstanceId(), wfTaskBackNode.getNodeId()); |