fix: 优化基本数据删除操作

This commit is contained in:
tangwei 2026-09-01 18:00:17 +08:00
parent 82a9ce9f34
commit 85e7efd3c4
2 changed files with 27 additions and 11 deletions

View File

@ -42,7 +42,8 @@ public class MsOperationLog implements Serializable {
/** /**
* 操作记录的名称瞬态字段不持久化由后端查询后填充 * 操作记录的名称瞬态字段不持久化由后端查询后填充
*/ */
@TableField(exist = false) // @TableField(exist = false)
@TableField("RECORD_NAME")
private String recordName; private String recordName;
} }

View File

@ -345,7 +345,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
if (engInfo == null) { if (engInfo == null) {
return; return;
} }
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),"新增", source,"01"); MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),engInfo.getEnnm(),"新增", source,"01");
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>(); List<MsOperationLogDetail> details = new ArrayList<>();
@ -381,7 +381,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
return; return;
} }
MsOperationLog mainLog = buildMainLog(before.getStcd(),"修改电站", source,"02"); MsOperationLog mainLog = buildMainLog(before.getStcd(),before.getEnnm(),"修改电站", source,"02");
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>(); List<MsOperationLogDetail> details = new ArrayList<>();
@ -418,7 +418,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
if (engInfo == null) { if (engInfo == null) {
return; return;
} }
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),"删除电站", source,"03"); MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),engInfo.getEnnm(),"删除电站", source,"03");
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>(); List<MsOperationLogDetail> details = new ArrayList<>();
@ -448,14 +448,15 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
batchInsertDetails(details); batchInsertDetails(details);
} }
private MsOperationLog buildMainLog(String recordId,String remark, String source,String operationType) { private MsOperationLog buildMainLog(String recordId, String recordName,String remark, String source,String operationType) {
return buildMainLog(ENG_TABLE_NAME, recordId, remark, source,operationType); return buildMainLog(ENG_TABLE_NAME, recordId,recordName, remark, source,operationType);
} }
private MsOperationLog buildMainLog(String tableName, String recordId, String remark, String source,String operationType) { private MsOperationLog buildMainLog(String tableName, String recordId, String recordName, String remark, String source,String operationType) {
MsOperationLog log = new MsOperationLog(); MsOperationLog log = new MsOperationLog();
log.setOperator(resolveOperator()); log.setOperator(resolveOperator());
log.setOperateTime(new Date()); log.setOperateTime(new Date());
log.setRecordName(recordName);
log.setTableName(tableName); log.setTableName(tableName);
log.setRecordId(recordId); log.setRecordId(recordId);
log.setSource(StrUtil.trimToNull(source)); log.setSource(StrUtil.trimToNull(source));
@ -548,7 +549,9 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
} }
Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList); Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList);
MsOperationLog mainLog = buildMainLog(tableName, recordId, "新增", source,"01"); // 调用示例尝试获取 name如果没有则尝试获取 code
String stnm = getFieldValue(entity, "stnm");
MsOperationLog mainLog = buildMainLog(tableName, recordId, stnm, "新增", source,"01");
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>(); List<MsOperationLogDetail> details = new ArrayList<>();
@ -580,6 +583,17 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
batchInsertDetails(details); batchInsertDetails(details);
} }
public static String getFieldValue(Object obj, String fieldName) {
try {
Field field = obj.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
Object value = field.get(obj);
return value == null ? null : value.toString();
} catch (NoSuchFieldException | IllegalAccessException e) {
return null;
}
}
@Override @Override
public <T> void recordDeleteDetailLog(String recordId,String tableName, T entity, String source) { public <T> void recordDeleteDetailLog(String recordId,String tableName, T entity, String source) {
if (entity == null) { if (entity == null) {
@ -621,7 +635,8 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
} }
Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList); Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList);
MsOperationLog mainLog = buildMainLog(tableName, recordId, "修改", source,"02"); String stnm = getFieldValue(after, "stnm");
MsOperationLog mainLog = buildMainLog(tableName, recordId,stnm, "修改", source,"02");
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>(); List<MsOperationLogDetail> details = new ArrayList<>();
@ -664,8 +679,8 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
return; return;
} }
Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList); Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList);
String stnm = getFieldValue(entity, "stnm");
MsOperationLog mainLog = buildMainLog(tableName, recordId, "删除", source,"03"); MsOperationLog mainLog = buildMainLog(tableName, recordId,stnm, "删除", source,"03");
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>(); List<MsOperationLogDetail> details = new ArrayList<>();