复制树形
复制红框里的内容,让其变为橘黄框里的内容
selectByPpidNotNull这个方法是用来查询红框里的所有内容的,pid为主表的id,最父级的name需要自己再写其他的方法来让前端调用进行修改
/**所启用的简报pid*/
@ApiOperation(value = "启动电子表内容", notes = "简报电子化")
@PostMapping("/startMessage/{pid}")
@SysLog(value = "自动编制简报电子化启动电子表内容", type = LogTypeEnum.INSERT)
public ApiResult<List<BulletinDzh>> insertAuthor(@PathVariable("pid") Integer pid) {
List<BulletinDzh> list = bulletinDzhMapper.selectByPpidNotNull(pid);
List<BulletinDzh> collect = list.stream().filter(ele -> ele.getPpid() == null).collect(Collectors.toList());
if (collect.isEmpty()){
return ApiResult.ok(list);
}else {
dataProcess(list,collect.get(0));
return ApiResult.ok(list);
}
}
public void dataProcess(List<BulletinDzh> list,BulletinDzh data){
Integer oldId = data.getId();
data.setId(null);
bulletinDzhMapper.insert(data);
Integer newId = data.getId();
List<BulletinDzh> collect = list.stream().filter(ele -> ele.getPpid()!=null&&ele.getPpid().equals(oldId)).collect(Collectors.toList());
if (!collect.isEmpty()){
collect.forEach(ele->{
ele.setPpid(newId);
ele.setPid(data.getPid());
dataProcess(list,ele);
});
}
}