|  | @@ -230,6 +230,7 @@ public class SharePathServiceImpl implements SharePathService {
 | 
	
		
			
				|  |  |                  .deep(k.getDepth())
 | 
	
		
			
				|  |  |                  .parentId(k.getAncestor())
 | 
	
		
			
				|  |  |                  .userId(k.getDescendant())
 | 
	
		
			
				|  |  | +                .sort(k.getSort())
 | 
	
		
			
				|  |  |                  .nickname(k.getDescNickName()).build()).collect(Collectors.toList());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -271,7 +272,10 @@ public class SharePathServiceImpl implements SharePathService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public List<OrderCalcDO> selectSons(Long userId, List<Long> userIds) {
 | 
	
		
			
				|  |  | -        List<Long> allDescendants = sharePathMapper.findAllDescendants(userId);
 | 
	
		
			
				|  |  | +        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
 | 
	
		
			
				|  |  | +                .eq(SharePathDO::getAncestor, userId));
 | 
	
		
			
				|  |  | +        List<Long> allDescendants = sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +//        List<Long> allDescendants = sharePathMapper.findAllDescendants(userId);
 | 
	
		
			
				|  |  |          if (allDescendants.isEmpty()) {
 | 
	
		
			
				|  |  |              return Collections.emptyList();
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -292,14 +296,28 @@ public class SharePathServiceImpl implements SharePathService {
 | 
	
		
			
				|  |  |          LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT); // 今天的开始时间,即午夜12点
 | 
	
		
			
				|  |  |          LocalDateTime todayEnd = todayStart.plusDays(1);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        return orderCalcService.queryTodayCalcByUserIds(todayStart, todayEnd);
 | 
	
		
			
				|  |  | +        return orderCalcService.queryTodayCalcByUserIds(todayStart, todayEnd, unionList);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public List<OrderCalcDO> selectBrothers(Long userId, List<Long> userIds) {
 | 
	
		
			
				|  |  | +        List<Long> sortedSiblings = new ArrayList<>();
 | 
	
		
			
				|  |  | +        // 先查询出他的父亲
 | 
	
		
			
				|  |  | +        SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getDepth, 1).eq(SharePathDO::getDescendant, userId));
 | 
	
		
			
				|  |  | +        if (sharePathDO == null) {
 | 
	
		
			
				|  |  | +            sortedSiblings = sharePathMapper.findLessSortedSiblings(userId);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            // 再根据父亲查询他的所有儿子
 | 
	
		
			
				|  |  | +            List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
 | 
	
		
			
				|  |  | +                    .eq(SharePathDO::getDepth, 1)
 | 
	
		
			
				|  |  | +                    .eq(SharePathDO::getAncestor, sharePathDO.getAncestor()));
 | 
	
		
			
				|  |  | +            //最后再进行排序
 | 
	
		
			
				|  |  | +            sortedSiblings = filterByDescendant(sharePathDOS, userId);
 | 
	
		
			
				|  |  | +            // 查询兄弟的所有儿子
 | 
	
		
			
				|  |  | +            sortedSiblings.addAll(findSons(sortedSiblings));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<Long> sortedSiblings = sharePathMapper.findLessSortedSiblings(userId);
 | 
	
		
			
				|  |  |          if (sortedSiblings.isEmpty()) {
 | 
	
		
			
				|  |  |              return Collections.emptyList();
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -312,6 +330,40 @@ public class SharePathServiceImpl implements SharePathService {
 | 
	
		
			
				|  |  |          return calcQuota(unionList);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private List<Long> findSons(List<Long> sortedSiblings) {
 | 
	
		
			
				|  |  | +        List<Long> longs = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (Long sortedSibling : sortedSiblings) {
 | 
	
		
			
				|  |  | +            List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
 | 
	
		
			
				|  |  | +                    .eq(SharePathDO::getAncestor, sortedSibling));
 | 
	
		
			
				|  |  | +            if (sharePathDOS.isEmpty()) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            List<Long> collect = sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            longs.addAll(collect);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return longs.stream().distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public List<Long> filterByDescendant(List<SharePathDO> sharePaths, Long descendantId) {
 | 
	
		
			
				|  |  | +        // 首先,找到特定 descendantId 的 sort 值
 | 
	
		
			
				|  |  | +        SharePathDO reference = sharePaths.stream()
 | 
	
		
			
				|  |  | +                .filter(sharePath -> sharePath.getDescendant().equals(descendantId))
 | 
	
		
			
				|  |  | +                .findFirst()
 | 
	
		
			
				|  |  | +                .orElse(null);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (reference == null) {
 | 
	
		
			
				|  |  | +            throw new IllegalArgumentException("Descendant with ID " + descendantId + " not found");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 过滤出所有 sort 值大于找到的 sort 值的记录
 | 
	
		
			
				|  |  | +        return sharePaths.stream()
 | 
	
		
			
				|  |  | +                .filter(sharePath -> sharePath.getSort() > reference.getSort())
 | 
	
		
			
				|  |  | +                .map(SharePathDO::getDescendant)
 | 
	
		
			
				|  |  | +                .collect(Collectors.toList());
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Long queryParentBySonUserId(Long userId) {
 | 
	
		
			
				|  |  |  
 |