先把想要copy的去平铺
//平铺树形结构
List<AhseH0002AssessmentLibEntity> outList = new ArrayList<>();
for (AhseH0002AssessmentLibEntity tTreeStructure : baseBean) {
if (tTreeStructure.getZAhseH0002AssessmentEntity() != null) {
List<AhseH0002AssessmentLibEntity> treeStructureList = tTreeStructure.getZAhseH0002AssessmentEntity();
outList.add(tTreeStructure);
convertChildrenToTileList(treeStructureList, outList);
//若不需要字节点,则可设置为空
// tTreeStructure.setChildren(null);
} else {
outList.add(tTreeStructure);
}
}
//递归实现
private static void convertChildrenToTileList(List<AhseH0002AssessmentLibEntity> source , List<AhseH0002AssessmentLibEntity> outList){
if(outList==null){
outList = new ArrayList<>();
}
for (AhseH0002AssessmentLibEntity tTreeStructure : source) {
if (tTreeStructure.getZAhseH0002AssessmentEntity() != null) {
List<AhseH0002AssessmentLibEntity> treeStructureList = tTreeStructure.getZAhseH0002AssessmentEntity();
outList.add(tTreeStructure);
convertChildrenToTileList(treeStructureList, outList);
//若不需要字节点,则可设置为空
// tTreeStructure.setChildren(null);
} else {
outList.add(tTreeStructure);
}
}
}
将父id子id 分别存入
//传入链表不变
ArrayList<AhseH0002AssessmentLibEntity> oldlist = new ArrayList<>(16);
for (AhseH0002AssessmentLibEntity ahseH0002AssessmentLibEntity : outList) {
AhseH0002AssessmentLibEntity ahseH0002AssessmentLibEntity1 = new AhseH0002AssessmentLibEntity();
BeanUtils.copyProperties(ahseH0002AssessmentLibEntity, ahseH0002AssessmentLibEntity1);
oldlist.add(ahseH0002AssessmentLibEntity1);
}
// id列表篇存Map
HashMap<String, String> map = new HashMap<String, String>(16);
for (AhseH0002AssessmentLibEntity assessmentEntity : outList) {
String s = IdUtil.randomUUID();
map.put(assessmentEntity.getId(), s);
assessmentEntity.setId(s);
}
//循环链表保存修改后的值
for (AhseH0002AssessmentLibEntity assessmentEntity : outList) {
if (map.get(assessmentEntity.getFid()) != null) {
//重置父级ID
assessmentEntity.setFid(map.get(assessmentEntity.getFid()));
} else {
//查不到父级拿取前端传来Idd
assessmentEntity.setFid(idd);
}
ahseH0002AssessmentMapper.add(assessmentEntity);
}
//循环旧链表将关联的内容表查出并新建如另一张表
for (AhseH0002AssessmentLibEntity ahseH0002AssessmentLibEntity : oldlist) {
AhseH0002AssessmentlistEntity ahseH0002AssessmentlistEntity = new AhseH0002AssessmentlistEntity();
ahseH0002AssessmentlistEntity.setAssessmentid(ahseH0002AssessmentLibEntity.getId());
// 拿旧对象的
List<AhseH0002AssessmentlistEntity> list = ahseH0002AssessmentlistMapper.getList(ahseH0002AssessmentlistEntity);
if (list!=null&&list.size()>0){
for (AhseH0002AssessmentlistEntity h0002AssessmentlistEntity : list) {
// 将查出来的数据链表转换成另一张表内容
AhseH0002AssessmentLiblistEntity copylist = new AhseH0002AssessmentLiblistEntity();
copylist.setContent(h0002AssessmentlistEntity.getContent());
copylist.setFraction(h0002AssessmentlistEntity.getFraction());
copylist.setLrr(h0002AssessmentlistEntity.getLrr());
copylist.setLrsj(h0002AssessmentlistEntity.getLrsj());
copylist.setName(h0002AssessmentlistEntity.getName());
copylist.setScoringCriteria(h0002AssessmentlistEntity.getScoringCriteria());
// BeanUtils.copyProperties(copylist, h0002AssessmentlistEntity);
//生成新的id 并把新的关联id 传入新表
copylist.setId(IdUtil.randomUUID());
if (map.get(h0002AssessmentlistEntity.getAssessmentid())!=null){
copylist.setAssessmentid(map.get(h0002AssessmentlistEntity.getAssessmentid()));
}
ahseH0002AssessmentLibListMapper.add(copylist);
}
}
}