From dd48776d91f612bcfed64f9df64510fc17ebc02a Mon Sep 17 00:00:00 2001 From: tangwei Date: Thu, 20 Aug 2026 11:42:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=9E=82=E5=90=91?= =?UTF-8?q?=E6=B0=B4=E6=B8=A9=E4=BF=AE=E6=94=B9=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eq/service/impl/EngEqDataServiceImpl.java | 41 ++---------- .../wt/service/impl/SdWtvtRServiceImpl.java | 3 +- .../com/yfd/platform/utils/LogValueUtils.java | 67 +++++++++++++++++++ 3 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 backend/src/main/java/com/yfd/platform/utils/LogValueUtils.java diff --git a/backend/src/main/java/com/yfd/platform/qgc_eng/eq/service/impl/EngEqDataServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_eng/eq/service/impl/EngEqDataServiceImpl.java index 4df52a05..7ea2d5cf 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_eng/eq/service/impl/EngEqDataServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_eng/eq/service/impl/EngEqDataServiceImpl.java @@ -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; diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/wt/service/impl/SdWtvtRServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_env/wt/service/impl/SdWtvtRServiceImpl.java index 810fdda9..e6631b27 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/wt/service/impl/SdWtvtRServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/wt/service/impl/SdWtvtRServiceImpl.java @@ -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 Map 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", diff --git a/backend/src/main/java/com/yfd/platform/utils/LogValueUtils.java b/backend/src/main/java/com/yfd/platform/utils/LogValueUtils.java new file mode 100644 index 00000000..cd97a15f --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/utils/LogValueUtils.java @@ -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() { + } + + /** + * 比较新旧两个值是否相同,用于判断字段值是否发生变化。 + *

+ * 规则: + *

    + *
  • 两者都为 null 视为相同
  • + *
  • 一者为 null 视为不同
  • + *
  • BigDecimal/Double 等数值类型按数值大小比较,忽略精度差异(133.0000 == 133.00)
  • + *
  • 其余类型按 {@link #formatLogValue(Object)} 格式化后字符串比较
  • + *
+ * + * @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); + } +}