111
whywhyo
2023-05-05 e3e5d863f7da346e8beaed4fb6ed4a4fca0cb22b
zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java
@@ -250,6 +250,7 @@
    }
    private void checkAuthorization(String familyId, String destinationFamilyId,boolean flag) {
        String text=null;
        if(flag){
@@ -283,8 +284,6 @@
        return familyId;
    }
    private String getFinalStr(String destinationFamilyId, List<String> authorityList) {
        String authorityListStr = authorityList.stream().collect(Collectors.joining(" ", "{", "}"));
        String finalStr= destinationFamilyId +authorityListStr;  //3{2007 1988 1004}
@@ -292,4 +291,96 @@
    }
    /**
     * 获取家根网
     * @return
     */
    @Override
    public AjaxResult listWithTree(Integer depth) {
        List<ZInfoUser> allPeopleList = list();
        List<ZInfoUser> result = null;
        try {
            result = allPeopleList.stream().filter(people -> people.getUserId()!=1&&(people.getFatherId() == 0||people.getMomId()==0))
                    .map(people -> {
                        people.setChildList(fillChildren(people, allPeopleList));
                        return people;
                    }).collect(Collectors.toList());
        } catch (NullPointerException e) {
            throw new RuntimeException("您在加入成员的时候没有指定该成员的父亲或者母亲");
        }
        return AjaxResult.success(result);
    }
    /**
     * 为了家根网、新增或者修改父子关系
     * @param fatherId
     * @param motherId
     * @return
     */
    @Override
    public AjaxResult addParent(Long fatherId, Long motherId) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        LambdaQueryWrapper<ZInfoUser> zInfoUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId,userId);
        ZInfoUser zInfoUser = getOne(zInfoUserLambdaQueryWrapper);
        zInfoUser.setFatherId(fatherId);
        zInfoUser.setMomId(motherId);
        updateById(zInfoUser);
        return AjaxResult.success();
    }
    @Override
    public AjaxResult listAllExceptAdmin() {
        List<ZInfoUser> collect = list().stream().filter(zInfoUser -> zInfoUser.getUserId() != 1).collect(Collectors.toList());
        return AjaxResult.success(collect);
    }
    @Override
    public AjaxResult listMySelfAndSpouse(Long id) {
        LambdaQueryWrapper<ZInfoUser> lqw1 = new LambdaQueryWrapper<>();
        lqw1.eq(ZInfoUser::getUserId,id);
        ZInfoUser myself = getOne(lqw1);
        Long spouseId = myself.getSpouseId();
        LambdaQueryWrapper<ZInfoUser> lqw2 = new LambdaQueryWrapper<>();
        lqw2.eq(ZInfoUser::getUserId,spouseId);
        ZInfoUser spouse = getOne(lqw2);
        ArrayList<ZInfoUser> zInfoUsers = new ArrayList<>();
        zInfoUsers.add(myself);
        zInfoUsers.add(spouse);
        return AjaxResult.success(zInfoUsers);
    }
    /**
     * 递归算法
     * @param people
     * @param allPeopleList
     * @return
     */
    private List<ZInfoUser> fillChildren(ZInfoUser people, List<ZInfoUser> allPeopleList) {
        // TODO: 2023-05-05 控制递归的次数
        List<ZInfoUser> collect = allPeopleList.stream().filter(
                one -> one.getFatherId() == people.getUserId() || one.getMomId() == people.getUserId()
        ).map(
                one -> {
                    one.setChildList(fillChildren(one, allPeopleList));
                    return one;
                }
        ).collect(Collectors.toList());
        return collect;
    }
}