fix: 优化逻辑
This commit is contained in:
parent
19bacb996b
commit
5034ebd1f7
@ -6,6 +6,7 @@ import com.yfd.platform.common.DataSourceRequest;
|
|||||||
import com.yfd.platform.qgc_base.domain.MsOperationLog;
|
import com.yfd.platform.qgc_base.domain.MsOperationLog;
|
||||||
import com.yfd.platform.qgc_base.domain.MsOperationLogDetail;
|
import com.yfd.platform.qgc_base.domain.MsOperationLogDetail;
|
||||||
import com.yfd.platform.qgc_base.domain.SdEngInfoBH;
|
import com.yfd.platform.qgc_base.domain.SdEngInfoBH;
|
||||||
|
import com.yfd.platform.utils.CodeToNameMetadataBo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -53,6 +54,21 @@ public interface IMsOperationLogService extends IService<MsOperationLog> {
|
|||||||
*/
|
*/
|
||||||
<T> void recordAddDetailLog(String recordId,String tableName, T entity, String source);
|
<T> void recordAddDetailLog(String recordId,String tableName, T entity, String source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用新增操作详情日志(含字段级详情,支持代码-名称映射)
|
||||||
|
* <p>
|
||||||
|
* 与 {@link #recordAddDetailLog(String, String, Object, String)} 功能相同,
|
||||||
|
* 额外支持将实体中 code 字段对应的 name 字段值填充到 newValueName。
|
||||||
|
* </p>
|
||||||
|
* @param recordId 记录ID(stcd)
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param entity 新增的实体
|
||||||
|
* @param source 操作来源
|
||||||
|
* @param codeToNameMetaList 代码-名称映射元数据列表(可为null)
|
||||||
|
* @param <T> 实体类型
|
||||||
|
*/
|
||||||
|
<T> void recordAddDetailLog(String recordId, String tableName, T entity, String source, List<CodeToNameMetadataBo> codeToNameMetaList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用删除操作详情日志(含字段级详情)
|
* 通用删除操作详情日志(含字段级详情)
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import com.yfd.platform.qgc_base.domain.SdEngInfoBH;
|
|||||||
import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper;
|
import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper;
|
||||||
import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper;
|
import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper;
|
||||||
import com.yfd.platform.qgc_base.service.IMsOperationLogService;
|
import com.yfd.platform.qgc_base.service.IMsOperationLogService;
|
||||||
|
import com.yfd.platform.utils.CodeToNameMetadataBo;
|
||||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||||
import com.yfd.platform.utils.SecurityUtils;
|
import com.yfd.platform.utils.SecurityUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@ -471,6 +472,64 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
|
|||||||
batchInsertDetails(details);
|
batchInsertDetails(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> void recordAddDetailLog(String recordId, String tableName, T entity, String source, List<CodeToNameMetadataBo> codeToNameMetaList) {
|
||||||
|
if (entity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 构建 codeFieldName -> nameFieldName 映射
|
||||||
|
Map<String, String> codeToNameFieldMap = new HashMap<>();
|
||||||
|
if (codeToNameMetaList != null) {
|
||||||
|
for (CodeToNameMetadataBo meta : codeToNameMetaList) {
|
||||||
|
if (StrUtil.isNotBlank(meta.getCodeProperty()) && StrUtil.isNotBlank(meta.getModifyProperty())) {
|
||||||
|
codeToNameFieldMap.put(meta.getCodeProperty(), meta.getModifyProperty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MsOperationLog mainLog = buildMainLog(tableName, recordId, "新增", source);
|
||||||
|
msOperationLogMapper.insert(mainLog);
|
||||||
|
|
||||||
|
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||||
|
Set<String> processedColumns = new HashSet<>();
|
||||||
|
Class<?> entityClass = entity.getClass();
|
||||||
|
|
||||||
|
for (Field field : entityClass.getDeclaredFields()) {
|
||||||
|
if (shouldSkipField(field)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
field.setAccessible(true);
|
||||||
|
String columnName = resolveColumnName(field);
|
||||||
|
if (processedColumns.contains(columnName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String fieldMeaning = resolveFieldChinese(field);
|
||||||
|
Object newValue = getFieldValue(field, entity);
|
||||||
|
|
||||||
|
MsOperationLogDetail detail = buildGenericDetail(mainLog.getId(), tableName, recordId, columnName,
|
||||||
|
fieldMeaning, null, newValue, "新增字段值");
|
||||||
|
|
||||||
|
// 如果当前字段是 code 字段,且存在对应的 name 字段映射,则填充 newValueName
|
||||||
|
String nameFieldName = codeToNameFieldMap.get(field.getName());
|
||||||
|
if (nameFieldName != null) {
|
||||||
|
try {
|
||||||
|
Field nameField = entityClass.getDeclaredField(nameFieldName);
|
||||||
|
nameField.setAccessible(true);
|
||||||
|
Object nameValue = nameField.get(entity);
|
||||||
|
if (nameValue != null) {
|
||||||
|
detail.setNewValueName(formatValue(nameValue));
|
||||||
|
}
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
// 忽略找不到 name 字段的情况
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
details.add(detail);
|
||||||
|
processedColumns.add(columnName);
|
||||||
|
}
|
||||||
|
batchInsertDetails(details);
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
|
|||||||
@ -68,7 +68,7 @@ public class SdDwBHServiceImpl extends ServiceImpl<SdDwBHMapper, SdDwBH> impleme
|
|||||||
public boolean add(SdDwBH entity, String source) {
|
public boolean add(SdDwBH entity, String source) {
|
||||||
boolean result = this.save(entity);
|
boolean result = this.save(entity);
|
||||||
if (result) {
|
if (result) {
|
||||||
msOperationLogService.recordAddDetailLog(entity.getStcd(),TABLE_NAME, entity, source);
|
msOperationLogService.recordAddDetailLog(entity.getStcd(), TABLE_NAME, entity, source, CODE_TO_NAME_META_LIST);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,8 @@ public class SdWeBHServiceImpl extends ServiceImpl<SdWeBHMapper, SdWeBH> impleme
|
|||||||
public boolean add(SdWeBH entity, String source) {
|
public boolean add(SdWeBH entity, String source) {
|
||||||
boolean result = this.save(entity);
|
boolean result = this.save(entity);
|
||||||
if (result) {
|
if (result) {
|
||||||
msOperationLogService.recordAddDetailLog(entity.getStcd(),TABLE_NAME, entity, source); }
|
msOperationLogService.recordAddDetailLog(entity.getStcd(), TABLE_NAME, entity, source, CODE_TO_NAME_META_LIST);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ public class SdWeBHServiceImpl extends ServiceImpl<SdWeBHMapper, SdWeBH> impleme
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean update(SdWeBH entity, String source) {
|
public boolean update(SdWeBH entity, String source) {
|
||||||
SdWeBH before = this.getById(entity.getStcd());
|
SdWeBH before = this.getById(entity.getStcd());
|
||||||
|
dictCodeToNameConverter.convertCodeToName(before, CODE_TO_NAME_META_LIST);
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordModifyDetailLog(entity.getStcd(),TABLE_NAME, before, entity, source);
|
msOperationLogService.recordModifyDetailLog(entity.getStcd(),TABLE_NAME, before, entity, source);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user