fix: 优化基本数据删除操作
This commit is contained in:
parent
82a9ce9f34
commit
85e7efd3c4
@ -42,7 +42,8 @@ public class MsOperationLog implements Serializable {
|
||||
/**
|
||||
* 操作记录的名称(瞬态字段,不持久化,由后端查询后填充)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
// @TableField(exist = false)
|
||||
@TableField("RECORD_NAME")
|
||||
private String recordName;
|
||||
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
if (engInfo == null) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),"新增", source,"01");
|
||||
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),engInfo.getEnnm(),"新增", source,"01");
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -381,7 +381,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
return;
|
||||
}
|
||||
|
||||
MsOperationLog mainLog = buildMainLog(before.getStcd(),"修改电站", source,"02");
|
||||
MsOperationLog mainLog = buildMainLog(before.getStcd(),before.getEnnm(),"修改电站", source,"02");
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -418,7 +418,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
if (engInfo == null) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),"删除电站", source,"03");
|
||||
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),engInfo.getEnnm(),"删除电站", source,"03");
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -448,14 +448,15 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
batchInsertDetails(details);
|
||||
}
|
||||
|
||||
private MsOperationLog buildMainLog(String recordId,String remark, String source,String operationType) {
|
||||
return buildMainLog(ENG_TABLE_NAME, recordId, remark, source,operationType);
|
||||
private MsOperationLog buildMainLog(String recordId, String recordName,String remark, String source,String 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();
|
||||
log.setOperator(resolveOperator());
|
||||
log.setOperateTime(new Date());
|
||||
log.setRecordName(recordName);
|
||||
log.setTableName(tableName);
|
||||
log.setRecordId(recordId);
|
||||
log.setSource(StrUtil.trimToNull(source));
|
||||
@ -548,7 +549,9 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
}
|
||||
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);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -580,6 +583,17 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
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
|
||||
public <T> void recordDeleteDetailLog(String recordId,String tableName, T entity, String source) {
|
||||
if (entity == null) {
|
||||
@ -621,7 +635,8 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
}
|
||||
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);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -664,8 +679,8 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
||||
return;
|
||||
}
|
||||
Map<String, String> codeToNameFieldMap = buildCodeToNameFieldMap(codeToNameMetaList);
|
||||
|
||||
MsOperationLog mainLog = buildMainLog(tableName, recordId, "删除", source,"03");
|
||||
String stnm = getFieldValue(entity, "stnm");
|
||||
MsOperationLog mainLog = buildMainLog(tableName, recordId,stnm, "删除", source,"03");
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user