Pārlūkot izejas kodu

修改客户端计量单的小数点末尾0的问题

cr 1 dienu atpakaļ
vecāks
revīzija
28cab94a99

+ 86 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/ChangeFormVO2.java

@@ -1,6 +1,7 @@
 package org.springblade.meter.vo;
 
 import com.alibaba.excel.annotation.ExcelIgnore;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -42,32 +43,117 @@ public class ChangeFormVO2 {
     private String formName;
 
     @ApiModelProperty(value = "当前单价")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal currentPrice;
 
     @ApiModelProperty(value = "合同数量(变更前)")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal contractTotal;
 
     @ApiModelProperty(value = "数量变更增减")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal currentChangeTotal;
 
     @ApiModelProperty(value = "合同变更后数量(变更后)")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal changeTotal;
 
     @ApiModelProperty(value = "合同金额(变更前)")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal contractMoney;
 
     @ApiModelProperty(value = "金额变更增减")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal currentChangeMoney;
 
     @ApiModelProperty(value = "变更后金额(变更后)")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal changeMoney;
 
     @ApiModelProperty(value = "最新变更后数量")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal newestChangeTotal;
 
     @ApiModelProperty(value = "最新变更后金额")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private BigDecimal newestChangeMoney;
 
     @ApiModelProperty(value = "需要修改的中间计量申请ids")
     private String applyIds;
+    /**
+     * 设置当前单价,自动去除末尾的0
+     */
+    public void setCurrentPrice(BigDecimal currentPrice) {
+        this.currentPrice = trimTrailingZeros(currentPrice);
+    }
+
+    /**
+     * 设置合同数量(变更前),自动去除末尾的0
+     */
+    public void setContractTotal(BigDecimal contractTotal) {
+        this.contractTotal = trimTrailingZeros(contractTotal);
+    }
+
+    /**
+     * 设置数量变更增减,自动去除末尾的0
+     */
+    public void setCurrentChangeTotal(BigDecimal currentChangeTotal) {
+        this.currentChangeTotal = trimTrailingZeros(currentChangeTotal);
+    }
+
+    /**
+     * 设置合同变更后数量,自动去除末尾的0
+     */
+    public void setChangeTotal(BigDecimal changeTotal) {
+        this.changeTotal = trimTrailingZeros(changeTotal);
+    }
+
+    /**
+     * 设置合同金额(变更前),自动去除末尾的0
+     */
+    public void setContractMoney(BigDecimal contractMoney) {
+        this.contractMoney = trimTrailingZeros(contractMoney);
+    }
+
+    /**
+     * 设置金额变更增减,自动去除末尾的0
+     */
+    public void setCurrentChangeMoney(BigDecimal currentChangeMoney) {
+        this.currentChangeMoney = trimTrailingZeros(currentChangeMoney);
+    }
+
+    /**
+     * 设置变更后金额,自动去除末尾的0
+     */
+    public void setChangeMoney(BigDecimal changeMoney) {
+        this.changeMoney = trimTrailingZeros(changeMoney);
+    }
+
+    /**
+     * 设置最新变更后数量,自动去除末尾的0
+     */
+    public void setNewestChangeTotal(BigDecimal newestChangeTotal) {
+        this.newestChangeTotal = trimTrailingZeros(newestChangeTotal);
+    }
+
+    /**
+     * 设置最新变更后金额,自动去除末尾的0
+     */
+    public void setNewestChangeMoney(BigDecimal newestChangeMoney) {
+        this.newestChangeMoney = trimTrailingZeros(newestChangeMoney);
+    }
+
+    /**
+     * 去除BigDecimal末尾的0
+     * @param value 需要处理的值
+     * @return 去除末尾0后的值,如果输入为null则返回null
+     */
+    private BigDecimal trimTrailingZeros(BigDecimal value) {
+        if (value == null) {
+            return null;
+        }
+        // 先去除末尾零,然后使用普通字符串表示避免科学计数法
+        BigDecimal stripped = value.stripTrailingZeros();
+        return new BigDecimal(stripped.toPlainString());
+    }
 }