From 4953cfa2836b62d71750a28b98ef0e8ec3a4e1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A6=8F=E8=B4=A2?= <1471584931@qq.com> Date: Wed, 14 Jan 2026 17:43:05 +0800 Subject: [PATCH] =?UTF-8?q?--=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9E=E6=97=B6?= =?UTF-8?q?=E6=9C=89id=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BF=AE=E6=94=B9=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/pictc/utils/DataLogTools.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/itc-pcitc-dependencies/itc-pcitc-dependencies-service/src/main/java/com/pictc/utils/DataLogTools.java b/itc-pcitc-dependencies/itc-pcitc-dependencies-service/src/main/java/com/pictc/utils/DataLogTools.java index 475d69a..dff5a6b 100644 --- a/itc-pcitc-dependencies/itc-pcitc-dependencies-service/src/main/java/com/pictc/utils/DataLogTools.java +++ b/itc-pcitc-dependencies/itc-pcitc-dependencies-service/src/main/java/com/pictc/utils/DataLogTools.java @@ -131,22 +131,32 @@ public class DataLogTools { public static T insert(T entity,DataOperationListener listener) { Class klazz = entity.getClass(); List 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 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 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);