fix: 优化站点修改来源日志
This commit is contained in:
parent
49466f3990
commit
57699cc5ef
@ -18,4 +18,18 @@ public interface IMsOperationLogService {
|
|||||||
* @param source 操作来源
|
* @param source 操作来源
|
||||||
*/
|
*/
|
||||||
void recordOperationLog(String tableName, String recordId, String operation, String source);
|
void recordOperationLog(String tableName, String recordId, String operation, String source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用修改操作详情日志(含字段级变更详情)
|
||||||
|
* <p>
|
||||||
|
* 通过反射遍历实体所有字段,对比修改前后的值差异,
|
||||||
|
* 将每个变更字段记录为一条操作日志详情。
|
||||||
|
* </p>
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param before 修改前的实体
|
||||||
|
* @param after 修改后的实体
|
||||||
|
* @param source 操作来源
|
||||||
|
* @param <T> 实体类型
|
||||||
|
*/
|
||||||
|
<T> void recordModifyDetailLog(String tableName, T before, T after, String source);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -399,6 +399,45 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
|||||||
msOperationLogMapper.insert(log);
|
msOperationLogMapper.insert(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> void recordModifyDetailLog(String tableName, T before, T after, String source) {
|
||||||
|
if (before == null || after == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String recordId = getStcd(before);
|
||||||
|
MsOperationLog mainLog = buildMainLog(tableName, recordId, "修改", source);
|
||||||
|
msOperationLogMapper.insert(mainLog);
|
||||||
|
|
||||||
|
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||||
|
Set<String> processedColumns = new HashSet<>();
|
||||||
|
Class<?> entityClass = before.getClass();
|
||||||
|
|
||||||
|
for (Field field : entityClass.getDeclaredFields()) {
|
||||||
|
if (shouldSkipField(field)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
field.setAccessible(true);
|
||||||
|
String columnName = resolveColumnName(field);
|
||||||
|
if (processedColumns.contains(columnName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object oldValue = getFieldValue(field, before);
|
||||||
|
Object newValue = getFieldValue(field, after);
|
||||||
|
|
||||||
|
//如果新值是null,则不记录
|
||||||
|
if(newValue == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (equalsValue(oldValue, newValue)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
details.add(buildGenericDetail(mainLog.getId(), tableName, recordId, columnName,
|
||||||
|
oldValue, newValue, "修改字段值"));
|
||||||
|
processedColumns.add(columnName);
|
||||||
|
}
|
||||||
|
batchInsertDetails(details);
|
||||||
|
}
|
||||||
|
|
||||||
private MsOperationLogDetail buildDetail(String mainId,
|
private MsOperationLogDetail buildDetail(String mainId,
|
||||||
String stationCode,
|
String stationCode,
|
||||||
String fieldCode,
|
String fieldCode,
|
||||||
@ -422,9 +461,41 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void batchInsertDetails(List<MsOperationLogDetail> details) {
|
private void batchInsertDetails(List<MsOperationLogDetail> details) {
|
||||||
|
if (details == null || details.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
msOperationLogDetailMapper.insert(details);
|
msOperationLogDetailMapper.insert(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过反射获取实体的 stcd(记录ID)
|
||||||
|
*/
|
||||||
|
private <T> String getStcd(T entity) {
|
||||||
|
try {
|
||||||
|
return (String) entity.getClass().getMethod("getStcd").invoke(entity);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建通用的操作日志详情(不含字典名称解析)
|
||||||
|
*/
|
||||||
|
private MsOperationLogDetail buildGenericDetail(String mainId, String tableName,
|
||||||
|
String stationCode, String fieldCode,
|
||||||
|
Object oldValue, Object newValue, String remark) {
|
||||||
|
MsOperationLogDetail detail = new MsOperationLogDetail();
|
||||||
|
detail.setMainId(mainId);
|
||||||
|
detail.setTableName(tableName);
|
||||||
|
detail.setStationCode(stationCode);
|
||||||
|
detail.setFieldCode(fieldCode);
|
||||||
|
detail.setFieldMeaning(fieldCode);
|
||||||
|
detail.setOldValueCode(formatValue(oldValue));
|
||||||
|
detail.setNewValueCode(formatValue(newValue));
|
||||||
|
detail.setRemark(remark);
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldSkipField(Field field) {
|
private boolean shouldSkipField(Field field) {
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -80,7 +80,7 @@ public class SdAiboxBHServiceImpl extends ServiceImpl<SdAiboxBHMapper, SdAiboxBH
|
|||||||
SdAiboxBH before = this.getById(entity.getStcd());
|
SdAiboxBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class SdArtsgBHServiceImpl extends ServiceImpl<SdArtsgBHMapper, SdArtsgBH
|
|||||||
SdArtsgBH before = this.getById(entity.getStcd());
|
SdArtsgBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class SdDwBHServiceImpl extends ServiceImpl<SdDwBHMapper, SdDwBH> impleme
|
|||||||
SdDwBH before = this.getById(entity.getStcd());
|
SdDwBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class SdEqBHServiceImpl extends ServiceImpl<SdEqBHMapper, SdEqBH> impleme
|
|||||||
SdEqBH before = this.getById(entity.getStcd());
|
SdEqBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class SdFbrdBHServiceImpl extends ServiceImpl<SdFbrdBHMapper, SdFbrdBH> i
|
|||||||
SdFbrdBH before = this.getById(entity.getStcd());
|
SdFbrdBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class SdFhbtBHServiceImpl extends ServiceImpl<SdFhbtBHMapper, SdFhbtBH> i
|
|||||||
SdFhbtBH before = this.getById(entity.getStcd());
|
SdFhbtBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class SdOpinfoBHServiceImpl extends ServiceImpl<SdOpinfoBHMapper, SdOpinf
|
|||||||
SdOpinfoBH before = this.getById(entity.getStcd());
|
SdOpinfoBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class SdOtteBHServiceImpl extends ServiceImpl<SdOtteBHMapper, SdOtteBH> i
|
|||||||
SdOtteBH before = this.getById(entity.getStcd());
|
SdOtteBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class SdOtweBHServiceImpl extends ServiceImpl<SdOtweBHMapper, SdOtweBH> i
|
|||||||
SdOtweBH before = this.getById(entity.getStcd());
|
SdOtweBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class SdSonarBHServiceImpl extends ServiceImpl<SdSonarBHMapper, SdSonarBH
|
|||||||
SdSonarBH before = this.getById(entity.getStcd());
|
SdSonarBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class SdTeBHServiceImpl extends ServiceImpl<SdTeBHMapper, SdTeBH> impleme
|
|||||||
SdTeBH before = this.getById(entity.getStcd());
|
SdTeBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public class SdVaBHServiceImpl extends ServiceImpl<SdVaBHMapper, SdVaBH> impleme
|
|||||||
SdVaBH before = this.getById(entity.getStcd());
|
SdVaBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public class SdVpBHServiceImpl extends ServiceImpl<SdVpBHMapper, SdVpBH> impleme
|
|||||||
SdVpBH before = this.getById(entity.getStcd());
|
SdVpBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,7 +77,7 @@ public class SdWeBHServiceImpl extends ServiceImpl<SdWeBHMapper, SdWeBH> impleme
|
|||||||
SdWeBH before = this.getById(entity.getStcd());
|
SdWeBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,7 +80,7 @@ public class SdWqBHServiceImpl extends ServiceImpl<SdWqBHMapper, SdWqBH> impleme
|
|||||||
SdWqBH before = this.getById(entity.getStcd());
|
SdWqBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public class SdWtBHServiceImpl extends ServiceImpl<SdWtBHMapper, SdWtBH> impleme
|
|||||||
SdWtBH before = this.getById(entity.getStcd());
|
SdWtBH before = this.getById(entity.getStcd());
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
if (result && before != null) {
|
if (result && before != null) {
|
||||||
msOperationLogService.recordOperationLog(TABLE_NAME, entity.getStcd(), "修改", source);
|
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -626,6 +626,13 @@ public class WeFishServiceImpl implements WeFishService {
|
|||||||
queryWeEnvmAutoMonitorCount(buildWeEnvmZjWqSql(baseId, rstcds)),
|
queryWeEnvmAutoMonitorCount(buildWeEnvmZjWqSql(baseId, rstcds)),
|
||||||
3, "WQ", "ENV,ENVM,WQ,", "水质监测"
|
3, "WQ", "ENV,ENVM,WQ,", "水质监测"
|
||||||
));
|
));
|
||||||
|
if (showIds.isEmpty() || showIds.contains("4")) {
|
||||||
|
// 气象监测
|
||||||
|
rows.add(buildWeEnvmAutoMonitorVo(
|
||||||
|
queryWeEnvmAutoMonitorCount(buildWeEnvmMmSql(baseId, hbrvcds)),
|
||||||
|
4, "MM", "MM,", "气象监测"
|
||||||
|
));
|
||||||
|
}
|
||||||
rows.add(buildWeEnvmAutoMonitorVo(
|
rows.add(buildWeEnvmAutoMonitorVo(
|
||||||
queryWeEnvmAutoMonitorCount(buildWeEnvmStGjSql(baseId)),
|
queryWeEnvmAutoMonitorCount(buildWeEnvmStGjSql(baseId)),
|
||||||
5, null, "ST,ZQ-ST,ZZ", "国家水文站"
|
5, null, "ST,ZQ-ST,ZZ", "国家水文站"
|
||||||
@ -5346,6 +5353,19 @@ public class WeFishServiceImpl implements WeFishService {
|
|||||||
return new SqlAndParams(sql.toString(), paramMap);
|
return new SqlAndParams(sql.toString(), paramMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SqlAndParams buildWeEnvmMmSql(String baseId, List<String> hbrvcds) {
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
sql.append("SELECT COUNT(1) AS cnt FROM SD_MM_B_H mm ")
|
||||||
|
.append("LEFT JOIN SD_ENGINFO_B_H eng ON eng.STCD = mm.RSTCD AND NVL(eng.IS_DELETED, 0) = 0 ")
|
||||||
|
.append("WHERE NVL(mm.IS_DELETED, 0) = 0 ")
|
||||||
|
.append("AND mm.STTP = 'MM' ")
|
||||||
|
.append("AND NVL(mm.MWAY, 0) = 2 ");
|
||||||
|
appendWeEnvmBaseIdCondition(sql, paramMap, "eng.BASE_ID", baseId);
|
||||||
|
appendWeEnvmExactInCondition(sql, paramMap, "eng.HBRVCD", "hbrvcd", hbrvcds);
|
||||||
|
return new SqlAndParams(sql.toString(), paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
private void appendWeEnvmBaseIdCondition(StringBuilder sql, Map<String, Object> paramMap, String column, String baseId) {
|
private void appendWeEnvmBaseIdCondition(StringBuilder sql, Map<String, Object> paramMap, String column, String baseId) {
|
||||||
if (StrUtil.isBlank(baseId)) {
|
if (StrUtil.isBlank(baseId)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user