bug 修改

This commit is contained in:
jiang 2025-11-28 16:42:06 +08:00
parent 65248c920a
commit 44952ad1bf
1 changed files with 11 additions and 11 deletions

View File

@ -23,10 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;
/**
* @author 黑子
@ -200,15 +197,18 @@ public class CarBalanceServiceImpl implements CarBalanceService {
try {
String tonType;
Integer tonValue = Integer.valueOf(vo.getTon()); // 先获取值避免重复调用方法
if (tonValue == null) {
// 处理 null 情况根据业务需求可选默认值 1/2/3 或抛出异常
// 1. 先获取值并做 null 防护避免 NPE
BigDecimal tonValue = Optional.ofNullable(vo.getTon())
.map(BigDecimal::new) // vo.getTon() String 类型需确保格式正确如数字字符串
// vo.getTon() 已为 BigDecimal直接用 .orElse(BigDecimal.ZERO)
.orElse(BigDecimal.ZERO); // null 时默认 0符合 "小于2" 逻辑对应 tonType="1"
// 2. BigDecimal 必须用 compareTo 比较不能直接用 < > ==
if (tonValue.compareTo(new BigDecimal("2")) < 0) { // tonValue < 2包含 null/0/1
tonType = "1";
} else if (tonValue < 2) {
tonType = "1";
} else if (tonValue < 5) { // 隐含条件2 tonValue < 5
} else if (tonValue.compareTo(new BigDecimal("5")) < 0) { // 2 tonValue < 5
tonType = "2";
} else { // 隐含条件tonValue 5原逻辑写的 >5这里包含等于需确认是否需要调整
} else { // tonValue 5明确包含等于5的情况
tonType = "3";
}
BigDecimal days = new BigDecimal(day);