fix(wms): 解决材料厚度预警中的精度比较问题

- 统一将理论厚度和规格厚度四舍五入到3位小数后再进行比较
- 避免因高精度尾数导致的比较结果与存储值不一致问题
- 对阈值也进行相同的精度处理确保比较逻辑正确
- 修复偏差值计算中重复精度转换的问题
- 优化偏差率计算中的除法精度控制
This commit is contained in:
2026-06-13 10:22:22 +08:00
parent 9c7d2dca65
commit f0656b57d4

View File

@@ -285,16 +285,19 @@ public class WmsMaterialWarningServiceImpl implements IWmsMaterialWarningService
}
// 理论厚度 - 规格厚度 > 阈值 → 触发
BigDecimal diff = theoreticalThickness.subtract(specThickness);
if (diff.compareTo(threshold) > 0) {
// 先统一 round 到 3 位小数再比较,避免理论厚度公式计算引入的高精度尾数
// 导致比较结果与存储值不一致(如 diff=-0.0096 > -0.01 触发,但存储时都 round 成 -0.010
BigDecimal diff = theoreticalThickness.subtract(specThickness).setScale(3, RoundingMode.HALF_UP);
BigDecimal scaledThreshold = threshold.setScale(3, RoundingMode.HALF_UP);
if (diff.compareTo(scaledThreshold) > 0) {
WmsMaterialWarning warning = new WmsMaterialWarning();
warning.setCoilId(coil.getCoilId());
warning.setWarningType("THICKNESS");
warning.setTheoreticalVal(theoreticalThickness.setScale(3, RoundingMode.HALF_UP));
warning.setActualVal(specThickness.setScale(3, RoundingMode.HALF_UP));
warning.setAllowDeviation(threshold.setScale(3, RoundingMode.HALF_UP));
warning.setDeviationValue(theoreticalThickness.subtract(specThickness).setScale(3, RoundingMode.HALF_UP));
BigDecimal rate = diff.divide(specThickness, 10, RoundingMode.HALF_UP)
warning.setAllowDeviation(scaledThreshold);
warning.setDeviationValue(diff);
BigDecimal rate = diff.divide(specThickness.setScale(3, RoundingMode.HALF_UP), 10, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP);
warning.setDeviationRate(rate);
warning.setWarningLevel("WARNING");