update 多级子表的新增和保存

This commit is contained in:
2026-01-06 14:33:02 +08:00
parent 3d26c74d9a
commit 529c4720fb
5 changed files with 94 additions and 19 deletions

View File

@ -608,6 +608,9 @@ public class DataLogTools {
if(idValue2==null || idValue2 <=0) {
joinTable.setIdValue(item, IdWorker.getId());
}
System.out.println(" field:"+joinColumn.field());
System.out.println(" relatedField:"+joinColumn.relatedField());
System.out.println(" joinFieldValue:"+joinFieldValue);
joinTable.setFieldValue(item, joinColumn.relatedField(), joinFieldValue);
Set<Class<?>> joinClasses = SetUtils.ofCollection(classes);
initJoinValue(item,joinTable,joinClasses);
@ -646,12 +649,21 @@ public class DataLogTools {
if(CollectionUtils.isNotEmpty(listValue)) {
if(type==OperationType.INSERT || type==OperationType.DELETE) {
if(type==OperationType.INSERT) {
for (Object item : listValue) {
Long idValue = joinTable.getIdValue(item);
DataChangeLog datalog = createLog(join.getTargetClass(),type,parent);
mapper.insert(joinTable.toEntity(item));
saveAttrs(joinTable,item);
buildFields(datalog,joinTable,item,null);
List<LogJoinInfo> jtjoins = joinTable.getJoins();
if(CollectionUtils.isNotEmpty(jtjoins)) {
for (LogJoinInfo temp : jtjoins) {
if(temp.getJoin().caseType()==JoinCaseType.FULL) {
buildJoins(logs, datalog, OperationType.INSERT, joinTable, temp, item); // 传递父级实体
}
}
}
}
} else {
for (Object item : listValue) {
@ -660,6 +672,14 @@ public class DataLogTools {
delete(item, joinTable, mapper);
saveAttrs(joinTable,item,true);
buildFields(datalog,joinTable,item,null);
List<LogJoinInfo> jtjoins = joinTable.getJoins();
if(CollectionUtils.isNotEmpty(jtjoins)) {
for (LogJoinInfo temp : jtjoins) {
if(temp.getJoin().caseType()==JoinCaseType.FULL) {
buildJoins(logs, datalog, OperationType.DELETE, joinTable, temp, item); // 传递父级实体
}
}
}
}
}
}else {
@ -675,11 +695,28 @@ public class DataLogTools {
datalog.setOperationType(OperationType.INSERT);
mapper.insert(joinTable.toEntity(item));
buildFields(datalog,joinTable,item,null);
List<LogJoinInfo> jtjoins = joinTable.getJoins();
if(CollectionUtils.isNotEmpty(jtjoins)) {
for (LogJoinInfo temp : jtjoins) {
if(temp.getJoin().caseType()==JoinCaseType.FULL) {
buildJoins(logs, datalog, OperationType.INSERT, joinTable, temp, item); // 传递父级实体
}
}
}
continue;
}else {
datalog.setOperationType(OperationType.UPDATE);
mapper.updateById(joinTable.toEntity(item));
buildFields(datalog,joinTable,item,old);
List<LogJoinInfo> jtjoins = joinTable.getJoins();
if(CollectionUtils.isNotEmpty(jtjoins)) {
for (LogJoinInfo temp : jtjoins) {
if(temp.getJoin().caseType()==JoinCaseType.FULL) {
buildJoins(logs, datalog, OperationType.UPDATE, joinTable, temp, item); // 传递父级实体
}
}
}
}
}
//删除旧数据
@ -693,6 +730,14 @@ public class DataLogTools {
delete(pojo, joinTable, mapper);
saveAttrs(joinTable,item,true);
buildFields(datalog,joinTable,item,null);
List<LogJoinInfo> jtjoins = joinTable.getJoins();
if(CollectionUtils.isNotEmpty(jtjoins)) {
for (LogJoinInfo temp : jtjoins) {
if(temp.getJoin().caseType()==JoinCaseType.FULL) {
buildJoins(logs, datalog, OperationType.DELETE, joinTable, temp, item); // 传递父级实体
}
}
}
}
}
}
@ -709,6 +754,14 @@ public class DataLogTools {
delete(pojo, joinTable, mapper);
saveAttrs(joinTable,item,true);
buildFields(datalog,joinTable,item,null);
List<LogJoinInfo> jtjoins = joinTable.getJoins();
if(CollectionUtils.isNotEmpty(jtjoins)) {
for (LogJoinInfo temp : jtjoins) {
if(temp.getJoin().caseType()==JoinCaseType.FULL) {
buildJoins(logs, datalog, OperationType.DELETE, joinTable, temp, item); // 传递父级实体
}
}
}
}
}
}
@ -749,6 +802,7 @@ public class DataLogTools {
delete(dto, joinTable, mapper);
saveAttrs(joinTable,dto,true);
buildFields(datalog,joinTable,dto,null);
}
}
}