--修改新增时有id的时候,进行修改操作
This commit is contained in:
@ -131,22 +131,32 @@ public class DataLogTools {
|
||||
public static <T>T insert(T entity,DataOperationListener<T> listener) {
|
||||
Class<? extends Object> klazz = entity.getClass();
|
||||
List<DataChangeLog> logs = CollectionUtils.newArrayList();
|
||||
DataChangeLog datalog = createLog(klazz,OperationType.INSERT);
|
||||
LogTableInfo tabInfo = getAnnotation(klazz);
|
||||
initJoinValue(entity,tabInfo,null);
|
||||
Long idValue = tabInfo.getIdValue(entity);
|
||||
BaseMapper mapper = MybatisTools.getMapper(tabInfo.getEntityType());
|
||||
T old = findById(klazz, idValue);
|
||||
DataChangeLog datalog = old!=null ? createLog(klazz,OperationType.UPDATE) : createLog(klazz,OperationType.INSERT);
|
||||
DataOperationContent<T> content = null;
|
||||
if(listener!=null) {
|
||||
content = DataOperationContent.of(tabInfo,OperationType.INSERT,entity,null);
|
||||
if(old!=null) {
|
||||
content = DataOperationContent.of(tabInfo,OperationType.UPDATE,entity,old);
|
||||
}else {
|
||||
content = DataOperationContent.of(tabInfo,OperationType.INSERT,entity,null);
|
||||
}
|
||||
listener.before(content);
|
||||
}
|
||||
|
||||
try {
|
||||
mapper.insert(BeanUtil.toBean(entity,tabInfo.getEntityType()));
|
||||
saveAttrs(tabInfo,entity);
|
||||
datalog.setEntityId(idValue);
|
||||
buildFields(datalog,tabInfo,entity,null);
|
||||
if(old!=null) {
|
||||
buildFields(datalog,tabInfo,entity,old);
|
||||
mapper.updateById(tabInfo.toEntity(entity));
|
||||
}else {
|
||||
buildFields(datalog,tabInfo,entity,null);
|
||||
mapper.insert(tabInfo.toEntity(entity));
|
||||
}
|
||||
saveAttrs(tabInfo,entity);
|
||||
logs.add(datalog);
|
||||
List<LogJoinInfo> joins = tabInfo.getJoins();
|
||||
if(CollectionUtils.isNotEmpty(joins)) {
|
||||
@ -647,7 +657,6 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user