JAVA留言评论回复

JAVA留言评论回复

一、效果图

JAVA留言评论回复_第1张图片

二、后台代码

1、返回实体类

public class LinkRecordVo {
    @ApiModelProperty(value = "沟通记录id")
    private String id;
    @ApiModelProperty(value = "系统用户id")
    private String userId;
    @ApiModelProperty(value = "系统用户名称")
    private String userName;
    @ApiModelProperty(value = "沟通内容")
    private String content;
    @ApiModelProperty(value = "沟通对象id")
    private String linkUserId;
    @ApiModelProperty(value = "沟通对象名称")
    private String linkUserName;
    @ApiModelProperty(value = "是否有子节点")
    private String hasChild;
    private List children;
}

2、获取根节点数据

private List getRecordVos(AtPushRecord pushRecord) {
        List recordVos = new ArrayList<>();
        //获取根节点数据,根据保单id和公司id查询信息
        List newLinkRecord = linkRecordService.list(new QueryWrapper().lambda()
                .eq(AtLinkRecord::getUserId, pushRecord.getCompanyId())
                .eq(AtLinkRecord::getParentId,"0"));
        if(oConvertUtils.listIsNotEmpty(newLinkRecord)){
            newLinkRecord.forEach(e->{
                LinkRecordVo linkRecordVo = new LinkRecordVo();
                BeanUtils.copyProperties(e,linkRecordVo);
                //获取所有子节点
                List childrenList = this.getAllChildren(e);
                linkRecordVo.setChildren(childrenList);
                recordVos.add(linkRecordVo);
            });
        }
        return recordVos;
    }

3、获取子节点数据

private List getAllChildren(AtLinkRecord newLinkRecord) {
        List childrenlinkList = new ArrayList<>();
        List childrenlink = new ArrayList<>();
        //一对一,一个根节点对应一个子节点
//        AtLinkRecord linkRecord = linkRecordService.getOne(new QueryWrapper().lambda().eq(AtLinkRecord::getParentId, newLinkRecord.getId()));
//        LinkRecordVo linkRecordVo = new LinkRecordVo();
//        if(oConvertUtils.isNotEmpty(linkRecord)){
//            BeanUtils.copyProperties(linkRecord,linkRecordVo);
//            childrenlinkList.add(linkRecordVo);
//        }
        //一对多,一个根节点对应多个子节点
        List linkRecord = linkRecordService.list(new QueryWrapper().lambda().eq(AtLinkRecord::getParentId, newLinkRecord.getId()));
        if(oConvertUtils.listIsNotEmpty(linkRecord)){
            linkRecord.forEach(e->{
                LinkRecordVo linkRecordVo = new LinkRecordVo();
                BeanUtils.copyProperties(e,linkRecordVo);
                childrenlinkList.add(linkRecordVo);
            });
        }

        //递归查询
        for (LinkRecordVo recordVo : childrenlinkList) {
            AtLinkRecord record = new AtLinkRecord();
            BeanUtils.copyProperties(recordVo,record);
            childrenlink.add(record);
        }
        if(oConvertUtils.listIsNotEmpty(childrenlinkList)){
            childrenlinkList.forEach(e->{
                AtLinkRecord atLinkRecord = new AtLinkRecord();
                BeanUtils.copyProperties(e,atLinkRecord);
                e.setChildren(getAllChildren(atLinkRecord));
            });
        }
        //如果没有子节点,返回空集合,递归退出
        if(childrenlinkList.size()==0){
            return new ArrayList();
        }
        return childrenlinkList;
    }

一个在学习的开发者,勿喷,欢迎交流

你可能感兴趣的:(java,windows,开发语言)