Pu Zhibing
2025-02-25 49e96cc15baf35d710fe3a049fb97aff6a1af132
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -863,5 +863,65 @@
        return R.ok(map);
    }
    /**
     * 获取指定用户的服务商
     * @param userId
     * @return
     */
    @GetMapping("/getServiceProvider")
    public R<Shop> getServiceProvider(Long userId){
        //向上找获取第一个开店的门店
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1));
        AppUser appUser = appUserClient.getAppUserById(userId);
        //上级集合,防止循环关联
        Set<Long> pid = new HashSet<>();
        Shop shop = getSuperiorStore(appUser, list, 1, 1, pid);
        return R.ok(shop);
    }
    public Shop getSuperiorStore(AppUser appUser, List<Shop> list, Integer hierarchy, Integer num, Set<Long> pid){
        if(null == appUser.getInviteUserId()){
            return null;
        }
        if(pid.contains(appUser.getInviteUserId())){
            return null;
        }
        AppUser appUser1 = appUserClient.getAppUserById(appUser.getInviteUserId());
        if(null != appUser1){
            Optional<Shop> first = list.stream().filter(shop -> shop.getAppUserId().equals(appUser1.getId())).findFirst();
            if(first.isPresent()){
                if(hierarchy.equals(num)){
                    return first.get();
                }
                num++;
            }
        }
        return getSuperiorStore(appUser1, list, hierarchy, num, pid);
    }
    /**
     * 获取指定用户的高级服务商
     * @return
     */
    @GetMapping("/getSuperiorServiceProvider")
    public R<Shop> getSuperiorServiceProvider(Long userId){
        //向上找获取第一个开店的门店
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1));
        AppUser appUser = appUserClient.getAppUserById(userId);
        //上级集合,防止循环关联
        Set<Long> pid = new HashSet<>();
        Shop shop = getSuperiorStore(appUser, list, 2, 1, pid);
        return R.ok(shop);
    }
}