解决导入明细接口的数值精度的bug

This commit is contained in:
jishenghua
2025-06-06 20:49:20 +08:00
parent 953507839e
commit d32a8ff517
3 changed files with 21 additions and 4 deletions

View File

@@ -1023,7 +1023,7 @@ public class DepotItemController {
if("CGDD".equals(prefixNo) || "XSDD".equals(prefixNo)) {
barCode = ExcelUtils.getContent(src, i, 0);
num = ExcelUtils.getContent(src, i, 2);
unitPrice = ExcelUtils.getContent(src, i, 3);
unitPrice = ExcelUtils.getContentNumber(src, i, 3);
taxRate = ExcelUtils.getContent(src, i, 4);
remark = ExcelUtils.getContent(src, i, 5);
}
@@ -1031,7 +1031,7 @@ public class DepotItemController {
depotName = ExcelUtils.getContent(src, i, 0);
barCode = ExcelUtils.getContent(src, i, 1);
num = ExcelUtils.getContent(src, i, 3);
unitPrice = ExcelUtils.getContent(src, i, 4);
unitPrice = ExcelUtils.getContentNumber(src, i, 4);
taxRate = ExcelUtils.getContent(src, i, 5);
remark = ExcelUtils.getContent(src, i, 6);
}
@@ -1039,7 +1039,7 @@ public class DepotItemController {
depotName = ExcelUtils.getContent(src, i, 0);
barCode = ExcelUtils.getContent(src, i, 1);
num = ExcelUtils.getContent(src, i, 3);
unitPrice = ExcelUtils.getContent(src, i, 4);
unitPrice = ExcelUtils.getContentNumber(src, i, 4);
remark = ExcelUtils.getContent(src, i, 5);
}
Map<String, String> materialMap = new HashMap<>();

View File

@@ -1371,7 +1371,7 @@ public class DepotItemService {
item.put("unitPrice", unitPrice);
BigDecimal allPrice = BigDecimal.ZERO;
if(unitPrice!=null && unitPrice.compareTo(BigDecimal.ZERO)!=0) {
allPrice = unitPrice.multiply(operNumber);
allPrice = unitPrice.multiply(operNumber).setScale(2, BigDecimal.ROUND_HALF_UP);
}
BigDecimal taxMoney = BigDecimal.ZERO;
if(taxRate.compareTo(BigDecimal.ZERO) != 0) {

View File

@@ -2,6 +2,7 @@ package com.jsh.erp.utils;
import java.io.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import jxl.*;
@@ -184,6 +185,22 @@ public class ExcelUtils {
}
}
public static String getContentNumber(Sheet src, int rowNum, int colNum) {
if(colNum < src.getRow(rowNum).length) {
Cell cell = src.getCell(colNum, rowNum);
if(cell.getType() == CellType.NUMBER) {
NumberCell numCell = (NumberCell)cell;
double value = numCell.getValue(); // 获取完整精度的数值
DecimalFormat df = new DecimalFormat("#.######"); // 设置足够多的小数位
return df.format(value);
} else {
return cell.getContents().trim(); // 获取原始字符串内容
}
} else {
return null;
}
}
/**
* 获取真实的行数,剔除掉空白行
* @param src