diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java index ce8e31e6..bbb83eb8 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisServiceImpl.java @@ -95,6 +95,7 @@ import com.zt.plat.module.qms.common.data.dal.dataobject.DataCollectionDO; import com.zt.plat.module.qms.common.data.service.DataCollectionService; import com.zt.plat.module.qms.common.dic.controller.vo.DictionaryBusinessExtendRespVO; import com.zt.plat.module.qms.common.dic.dal.mapper.DictionaryBusinessMapper; +import com.zt.plat.module.qms.core.util.number.EffectiveNumberFormatter; import com.zt.plat.module.qms.enums.QmsCommonConstant; import cn.hutool.core.collection.CollUtil; @@ -1427,10 +1428,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessAssayProjectDataDO.setValue(value.toPlainString()); - businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessAssayProjectDataDO.setValue(value); + businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); @@ -1452,10 +1454,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessAssayParameterDataDO.setValue(value.toPlainString()); - businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessAssayParameterDataDO.setValue(value); + businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); @@ -1476,10 +1479,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessAssayTaskParameterDataDO.setValue(value.toPlainString()); - businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessAssayTaskParameterDataDO.setValue(value); + businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); @@ -1543,10 +1547,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessQCManagementProjectDataDO.setValue(value.toPlainString()); - businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessQCManagementProjectDataDO.setValue(value); + businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); @@ -1568,10 +1573,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessQCManagementParameterDataDO.setValue(value.toPlainString()); - businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessQCManagementParameterDataDO.setValue(value); + businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); @@ -1592,10 +1598,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessQCManagementSampleParameterDataDO.setValue(value.toPlainString()); - businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessQCManagementSampleParameterDataDO.setValue(value); + businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); @@ -1654,10 +1661,11 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService { businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue()); break; case "decimal": - BigDecimal value = new BigDecimal(pap.getValue()); - value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); - businessQCCoefficientParameterDataDO.setValue(value.toPlainString()); - businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString()); +// BigDecimal value = new BigDecimal(pap.getValue()); +// value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN); + String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit()); + businessQCCoefficientParameterDataDO.setValue(value); + businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + value); break; default: throw new IllegalArgumentException("Unexpected value: " + dataType); diff --git a/zt-module-qms/zt-module-qms-server/src/test/java/com/zt/plat/module/qms/EffectiveNumberFormatterTest.java b/zt-module-qms/zt-module-qms-server/src/test/java/com/zt/plat/module/qms/EffectiveNumberFormatterTest.java index b26a5e7a..bdaaf9ad 100644 --- a/zt-module-qms/zt-module-qms-server/src/test/java/com/zt/plat/module/qms/EffectiveNumberFormatterTest.java +++ b/zt-module-qms/zt-module-qms-server/src/test/java/com/zt/plat/module/qms/EffectiveNumberFormatterTest.java @@ -6,7 +6,6 @@ import com.zt.plat.module.qms.core.util.number.EffectiveNumberFormatter; public class EffectiveNumberFormatterTest { - @Test public void formatNumberTest() { System.out.println("=== 测试案例:测试结果 ===");