Commit 16727cac by 林冲

bugfix:解决定金尾款导入无法处理中文

1 parent 672f0018
......@@ -34,6 +34,7 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
......@@ -145,19 +146,25 @@ public class EvalElectronicContractService {
// 阶段2: 数据校验和转换
for (int i = 0; i < excelRows.size(); i++) {
ContractImportRow row = excelRows.get(i);
List<String> errors = new ArrayList<>();
validateRow(row, errors);
EvalElectronicContractImportDTO dto = convertToImportDTO(row, accountInfo);
boolean exist = toImportList.stream().anyMatch(item -> item.getPlateNo().equals(dto.getPlateNo()));
if (exist) {
errors.add("已存在相同车牌号的导入数据");
}
if (!errors.isEmpty()) {
// 只抛出第一个错误
failList.add(buildFailDTO(dto, errors.get(0)));
continue;
try {
List<String> errors = new ArrayList<>();
validateRow(row, errors);
EvalElectronicContractImportDTO dto = convertToImportDTO(row, accountInfo);
boolean exist = toImportList.stream().anyMatch(item -> item.getPlateNo().equals(dto.getPlateNo()));
if (exist) {
errors.add("已存在相同车牌号的导入数据");
}
if (!errors.isEmpty()) {
// 只抛出第一个错误
failList.add(buildFailDTO(dto, errors.get(0)));
continue;
}
toImportList.add(dto);
} catch (BusinessException e) {
log.error("导入合同校验数据异常", e);
failList.add(buildFailDTO(row, e.getMessage()));
}
toImportList.add(dto);
}
// 阶段3: 并行导入操作
List<CompletableFuture<Void>> importFutures = toImportList.stream()
......@@ -312,8 +319,13 @@ public class EvalElectronicContractService {
dto.setBrand(StringUtils.trimToNull(row.getBrand()));
dto.setCarCategory(StringUtils.trimToNull(row.getCarCategory()));
dto.setPayType(StringUtils.trimToNull(row.getPayType()));
dto.setDepositAmount(row.getDepositAmount());
dto.setFinalAmount(row.getFinalAmount());
try {
dto.setDepositAmount(new BigDecimal(row.getDepositAmount()));
dto.setFinalAmount(new BigDecimal(row.getFinalAmount()));
} catch (Exception e) {
log.error("数值转换异常", e);
}
dto.setPayeeName(StringUtils.trimToNull(row.getPayeeName()));
dto.setBankName(StringUtils.trimToNull(row.getBankName()));
dto.setBankAccountNo(StringUtils.trimToNull(row.getBankAccountNo()));
......@@ -327,7 +339,7 @@ public class EvalElectronicContractService {
return dto;
}
private EvalElectronicContractImportFailDTO buildFailDTO(EvalElectronicContractImportDTO source, String reason) {
private EvalElectronicContractImportFailDTO buildFailDTO(ContractImportRow source, String reason) {
EvalElectronicContractImportFailDTO dto = new EvalElectronicContractImportFailDTO();
dto.setMerchantNo(source.getMerchantNo());
dto.setPlateNo(source.getPlateNo());
......@@ -340,10 +352,26 @@ public class EvalElectronicContractService {
dto.setPayeeName(source.getPayeeName());
dto.setBankName(source.getBankName());
dto.setBankAccountNo(source.getBankAccountNo());
dto.setOperator(source.getOperator());
dto.setOperatorAccount(source.getOperatorAccount());
dto.setOperatorUuid(source.getOperatorUuid());
dto.setOperatorPhone(source.getOperatorPhone());
dto.setReason(StringUtils.defaultIfBlank(reason, "unknown failure reason"));
return dto;
}
private EvalElectronicContractImportFailDTO buildFailDTO(EvalElectronicContractImportDTO source, String reason) {
EvalElectronicContractImportFailDTO dto = new EvalElectronicContractImportFailDTO();
dto.setMerchantNo(source.getMerchantNo());
dto.setPlateNo(source.getPlateNo());
dto.setVin(source.getVin());
dto.setBrand(source.getBrand());
dto.setCarCategory(source.getCarCategory());
dto.setPayType(source.getPayType());
if (source.getDepositAmount() != null) {
dto.setDepositAmount(source.getDepositAmount().toString());
}
if (source.getFinalAmount() != null) {
dto.setFinalAmount(source.getFinalAmount().toString());
}
dto.setPayeeName(source.getPayeeName());
dto.setBankName(source.getBankName());
dto.setBankAccountNo(source.getBankAccountNo());
dto.setReason(StringUtils.defaultIfBlank(reason, "unknown failure reason"));
return dto;
}
......@@ -355,36 +383,47 @@ public class EvalElectronicContractService {
}
if (StringUtils.isBlank(row.getMerchantNo())) {
errors.add("商户号必填");
return;
}
if (StringUtils.isBlank(row.getPlateNo())) {
errors.add("车牌号必填");
return;
}
if (StringUtils.isBlank(row.getVin())) {
errors.add("车架号必填");
return;
}
if (StringUtils.isBlank(row.getBrand())) {
errors.add("品牌必填");
return;
}
if (StringUtils.isBlank(row.getCarCategory())) {
errors.add("车辆类别必填");
return;
}
if (StringUtils.isBlank(row.getPayType())) {
errors.add("支付方式必填");
return;
}
if (row.getDepositAmount() == null) {
errors.add("定金金额必填");
return;
}
if (row.getFinalAmount() == null) {
errors.add("尾款金额必填");
return;
}
if (StringUtils.isBlank(row.getPayeeName())) {
errors.add("收款人必填");
return;
}
if (StringUtils.isBlank(row.getBankName())) {
errors.add("开户行必填");
return;
}
if (StringUtils.isBlank(row.getBankAccountNo())) {
errors.add("收款银行账号必填");
return;
}
// 校验4s店编号必须都是数字
......@@ -418,30 +457,9 @@ public class EvalElectronicContractService {
}
// 定金金额校验:最多10位数,不包含小数
if (row.getDepositAmount() != null) {
String depositAmountStr = row.getDepositAmount().toString();
if (depositAmountStr.contains(".")) {
errors.add("定金金额不能包含小数");
}
// 去除可能的负号再检查位数
String absDepositAmount = depositAmountStr.replace("-", "").replace(".", "");
if (absDepositAmount.length() > 10) {
errors.add("定金金额最多10位数");
}
}
NumberUtil.validatePositiveIntegerRegex(row.getDepositAmount());
// 尾款金额校验:最多10位数,不包含小数
if (row.getFinalAmount() != null) {
String finalAmountStr = row.getFinalAmount().toString();
if (finalAmountStr.contains(".")) {
errors.add("尾款金额不能包含小数");
}
// 去除可能的负号再检查位数
String absFinalAmount = finalAmountStr.replace("-", "").replace(".", "");
if (absFinalAmount.length() > 10) {
errors.add("尾款金额最多10位数");
}
}
NumberUtil.validatePositiveIntegerRegex(row.getFinalAmount());
// 收款人校验:1-20字符
if (StringUtils.isNotBlank(row.getPayeeName())) {
......
package com.gsc4cloud.gsc.facade.vpcweb.utils;
import com.gsc4cloud.gsc.vpc.api.exception.BusinessException;
public class NumberUtil {
public static boolean isAllDigits(String str) {
return str != null && str.matches("^[0-9]+$");
}
/**
* 非公共方法
*/
public static void validatePositiveIntegerRegex(String str) {
if (str == null) {
throw new BusinessException("输入不能为null");
}
if (str.isEmpty()) {
throw new BusinessException("输入不能为空字符串");
}
// 检查是否全为数字
if (!str.matches("\\d+")) {
throw new BusinessException("输入包含非数字字符");
}
// 检查前导零和长度
if (str.matches("0[0-9]+")) {
throw new BusinessException("数字不能有前导零(除了0本身)");
}
if (str.length() > 10) {
throw new BusinessException("数字长度不能超过10位");
}
// 检查数值范围
if (str.length() == 10) {
if (str.compareTo("9999999999") > 0) {
throw new BusinessException("数字不能超过10位");
}
}
}
}
......@@ -30,10 +30,10 @@ public class ContractImportRow {
private String payType;
@ExcelProperty(index = 6) // *定金金额
private BigDecimal depositAmount;
private String depositAmount;
@ExcelProperty(index = 7) // *尾款金额
private BigDecimal finalAmount;
private String finalAmount;
@ExcelProperty(index = 8) // *收款人
private String payeeName;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!