fix: 优化垂向水温修改不显示日志

This commit is contained in:
tangwei 2026-08-20 11:42:04 +08:00
parent 6dd7437bf1
commit dd48776d91
3 changed files with 76 additions and 35 deletions

View File

@ -47,6 +47,7 @@ import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper;
import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper;
import com.yfd.platform.qgc_env.wq.entity.vo.MsWarnRuleDetailBVo;
import com.yfd.platform.qgc_env.wt.utils.SiteAvoidanceUtils;
import com.yfd.platform.utils.LogValueUtils;
import com.yfd.platform.utils.QgcQueryWrapperUtil;
import com.yfd.platform.utils.SecurityUtils;
import jakarta.annotation.Resource;
@ -6845,7 +6846,7 @@ public class EngEqDataServiceImpl implements EngEqDataService {
Object oldValue = beforeHour == null ? null : beforeHour.get(entry.getKey());
Object newValue = updateData.get(entry.getKey());
// 数值类型按数值大小比较忽略精度差异133.0000 == 133.00
if (sameLogValue(oldValue, newValue)) {
if (LogValueUtils.sameLogValue(oldValue, newValue)) {
continue;
}
details.add(buildQecDetail(null, QEC_HOUR_TABLE_NAME, stcd, column,
@ -6865,24 +6866,6 @@ public class EngEqDataServiceImpl implements EngEqDataService {
batchInsertQecLogDetails(details);
}
private boolean sameLogValue(Object oldValue, Object newValue) {
if (oldValue == null && newValue == null) {
return true;
}
if (oldValue == null || newValue == null) {
return false;
}
// BigDecimal/Double 等数值类型按数值大小比较忽略精度差异133.0000 == 133.00
if (oldValue instanceof Number && newValue instanceof Number) {
try {
return new BigDecimal(oldValue.toString()).compareTo(new BigDecimal(newValue.toString())) == 0;
} catch (NumberFormatException e) {
return false;
}
}
return StrUtil.equals(formatLogValue(oldValue), formatLogValue(newValue));
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeKendoByIds(BatchDeleteAo batchDeleteAo) {
@ -7182,10 +7165,10 @@ public class EngEqDataServiceImpl implements EngEqDataService {
detail.setStationCode(stationCode);
detail.setFieldCode(fieldCode);
detail.setFieldMeaning(QEC_FIELD_MEANING_MAP.getOrDefault(fieldCode, fieldCode));
detail.setOldValueCode(formatLogValue(oldValueCode));
detail.setOldValueName(formatLogValue(oldValueName));
detail.setNewValueCode(formatLogValue(newValueCode));
detail.setNewValueName(formatLogValue(newValueName));
detail.setOldValueCode(LogValueUtils.formatLogValue(oldValueCode));
detail.setOldValueName(LogValueUtils.formatLogValue(oldValueName));
detail.setNewValueCode(LogValueUtils.formatLogValue(newValueCode));
detail.setNewValueName(LogValueUtils.formatLogValue(newValueName));
detail.setRemark(remark);
return detail;
}
@ -7203,7 +7186,7 @@ public class EngEqDataServiceImpl implements EngEqDataService {
}
private Object resolveQecDisplayValue(String fieldCode, Object rawValue) {
String text = formatLogValue(rawValue);
String text = LogValueUtils.formatLogValue(rawValue);
if (StrUtil.isBlank(text)) {
return rawValue;
}
@ -7232,16 +7215,6 @@ public class EngEqDataServiceImpl implements EngEqDataService {
}
}
private String formatLogValue(Object value) {
if (value == null) {
return null;
}
if (value instanceof Date date) {
return DateUtil.formatDateTime(date);
}
return String.valueOf(value);
}
private Integer parseInteger(Object value) {
if (value == null) {
return null;

View File

@ -16,6 +16,7 @@ import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper;
import com.yfd.platform.qgc_env.wt.entity.vo.SdWtvtYearVo;
import com.yfd.platform.qgc_env.wt.mapper.SdWtvtRMapper;
import com.yfd.platform.qgc_env.wt.service.SdWtvtRService;
import com.yfd.platform.utils.LogValueUtils;
import com.yfd.platform.utils.QgcQueryWrapperUtil;
import com.yfd.platform.utils.SecurityUtils;
import jakarta.annotation.Resource;
@ -237,7 +238,7 @@ public class SdWtvtRServiceImpl extends ServiceImpl<SdWtvtRMapper, SdWtvtYearVo>
Map<String, Object> beforeRow = beforeRowMap.get(depthKey);
Object oldValue = beforeRow == null ? null : beforeRow.get("VWT");
Object newValue = item.get("vwt");
if (StringUtils.equals(formatWtvtLogValue(oldValue), formatWtvtLogValue(newValue))) {
if (LogValueUtils.sameLogValue(oldValue, newValue)) {
return;
}
logDetails.add(buildWtvtDetail(null, stcd, "VWT",

View File

@ -0,0 +1,67 @@
package com.yfd.platform.utils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import java.math.BigDecimal;
import java.util.Date;
/**
* 日志值比较与格式化工具类供各业务模块(生态流量垂向水温等)操作日志记录时共用
*
* @author supeng
*/
public class LogValueUtils {
private LogValueUtils() {
}
/**
* 比较新旧两个值是否相同用于判断字段值是否发生变化
* <p>
* 规则
* <ul>
* <li>两者都为 null 视为相同</li>
* <li>一者为 null 视为不同</li>
* <li>BigDecimal/Double 等数值类型按数值大小比较忽略精度差异133.0000 == 133.00</li>
* <li>其余类型按 {@link #formatLogValue(Object)} 格式化后字符串比较</li>
* </ul>
*
* @param oldValue 旧值
* @param newValue 新值
* @return true 表示相同
*/
public static boolean sameLogValue(Object oldValue, Object newValue) {
if (oldValue == null && newValue == null) {
return true;
}
if (oldValue == null || newValue == null) {
return false;
}
// BigDecimal/Double 等数值类型按数值大小比较忽略精度差异133.0000 == 133.00
if (oldValue instanceof Number && newValue instanceof Number) {
try {
return new BigDecimal(oldValue.toString()).compareTo(new BigDecimal(newValue.toString())) == 0;
} catch (NumberFormatException e) {
return false;
}
}
return StrUtil.equals(formatLogValue(oldValue), formatLogValue(newValue));
}
/**
* 格式化日志中的值Date 格式化为日期时间字符串其余直接转字符串
*
* @param value 原始值
* @return 格式化后的字符串
*/
public static String formatLogValue(Object value) {
if (value == null) {
return null;
}
if (value instanceof Date date) {
return DateUtil.formatDateTime(date);
}
return String.valueOf(value);
}
}