Commit 26e11df2 authored by chase's avatar chase

修复 导入数据无法导入公式

parent f0b88d69
package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -739,6 +738,8 @@ public class DataImportService extends BaseService {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();
if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
}
......@@ -842,34 +843,34 @@ public class DataImportService extends BaseService {
iData.setSpecialInvoiceAmount4(getCellLongDecimalValue(cell5));
Cell cell6 = sheet.getRow(6).getCell(j);
iData.setSpecialInvoiceSalesAmount1(getCellBigDecimalValue(cell6));
iData.setSpecialInvoiceSalesAmount1(getCellBigDecimalValue(cell6,evaluator));
Cell cell7 = sheet.getRow(7).getCell(j);
iData.setSpecialInvoiceSalesAmount2(getCellBigDecimalValue(cell7));
iData.setSpecialInvoiceSalesAmount2(getCellBigDecimalValue(cell7,evaluator));
Cell cell8 = sheet.getRow(8).getCell(j);
iData.setSpecialInvoiceSalesAmount3(getCellBigDecimalValue(cell8));
iData.setSpecialInvoiceSalesAmount3(getCellBigDecimalValue(cell8,evaluator));
Cell cell9 = sheet.getRow(9).getCell(j);
iData.setSpecialInvoiceSalesAmount4(getCellBigDecimalValue(cell9));
iData.setSpecialInvoiceSalesAmount4(getCellBigDecimalValue(cell9,evaluator));
Cell cell10 = sheet.getRow(10).getCell(j);
iData.setSpecialInvoiceSalesAmount5(getCellBigDecimalValue(cell10));
iData.setSpecialInvoiceSalesAmount5(getCellBigDecimalValue(cell10,evaluator));
Cell cell11 = sheet.getRow(11).getCell(j);
iData.setSpecialInvoiceTaxAmount1(getCellBigDecimalValue(cell11));
iData.setSpecialInvoiceTaxAmount1(getCellBigDecimalValue(cell11,evaluator));
Cell cell12 = sheet.getRow(12).getCell(j);
iData.setSpecialInvoiceTaxAmount2(getCellBigDecimalValue(cell12));
iData.setSpecialInvoiceTaxAmount2(getCellBigDecimalValue(cell12,evaluator));
Cell cell13 = sheet.getRow(13).getCell(j);
iData.setSpecialInvoiceTaxAmount3(getCellBigDecimalValue(cell13));
iData.setSpecialInvoiceTaxAmount3(getCellBigDecimalValue(cell13,evaluator));
Cell cell14 = sheet.getRow(14).getCell(j);
iData.setSpecialInvoiceTaxAmount4(getCellBigDecimalValue(cell14));
iData.setSpecialInvoiceTaxAmount4(getCellBigDecimalValue(cell14,evaluator));
Cell cell15 = sheet.getRow(15).getCell(j);
iData.setSpecialInvoiceTaxAmount5(getCellBigDecimalValue(cell15));
iData.setSpecialInvoiceTaxAmount5(getCellBigDecimalValue(cell15,evaluator));
Cell cell16 = sheet.getRow(16).getCell(j);
iData.setInvoiceAmount1(getCellLongDecimalValue(cell16));
......@@ -884,34 +885,34 @@ public class DataImportService extends BaseService {
iData.setInvoiceAmount4(getCellLongDecimalValue(cell19));
Cell cell20 = sheet.getRow(20).getCell(j);
iData.setInvoiceSalesAmount1(getCellBigDecimalValue(cell20));
iData.setInvoiceSalesAmount1(getCellBigDecimalValue(cell20,evaluator));
Cell cell21 = sheet.getRow(21).getCell(j);
iData.setInvoiceSalesAmount2(getCellBigDecimalValue(cell21));
iData.setInvoiceSalesAmount2(getCellBigDecimalValue(cell21,evaluator));
Cell cell22 = sheet.getRow(22).getCell(j);
iData.setInvoiceSalesAmount3(getCellBigDecimalValue(cell22));
iData.setInvoiceSalesAmount3(getCellBigDecimalValue(cell22,evaluator));
Cell cell23 = sheet.getRow(23).getCell(j);
iData.setInvoiceSalesAmount4(getCellBigDecimalValue(cell23));
iData.setInvoiceSalesAmount4(getCellBigDecimalValue(cell23,evaluator));
Cell cell24 = sheet.getRow(24).getCell(j);
iData.setInvoiceSalesAmount5(getCellBigDecimalValue(cell24));
iData.setInvoiceSalesAmount5(getCellBigDecimalValue(cell24,evaluator));
Cell cell25 = sheet.getRow(25).getCell(j);
iData.setInvoiceTaxAmount1(getCellBigDecimalValue(cell25));
iData.setInvoiceTaxAmount1(getCellBigDecimalValue(cell25,evaluator));
Cell cell26 = sheet.getRow(26).getCell(j);
iData.setInvoiceTaxAmount2(getCellBigDecimalValue(cell26));
iData.setInvoiceTaxAmount2(getCellBigDecimalValue(cell26,evaluator));
Cell cell27 = sheet.getRow(27).getCell(j);
iData.setInvoiceTaxAmount3(getCellBigDecimalValue(cell27));
iData.setInvoiceTaxAmount3(getCellBigDecimalValue(cell27,evaluator));
Cell cell28 = sheet.getRow(28).getCell(j);
iData.setInvoiceTaxAmount4(getCellBigDecimalValue(cell28));
iData.setInvoiceTaxAmount4(getCellBigDecimalValue(cell28,evaluator));
Cell cell29 = sheet.getRow(29).getCell(j);
iData.setInvoiceTaxAmount5(getCellBigDecimalValue(cell29));
iData.setInvoiceTaxAmount5(getCellBigDecimalValue(cell29,evaluator));
iDatas.add(iData);
}
......@@ -951,6 +952,8 @@ public class DataImportService extends BaseService {
OperationResultDto operationResultDto = new OperationResultDto();
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();
if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
}
......@@ -959,7 +962,7 @@ public class DataImportService extends BaseService {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
if (isSheetEmpty(sheet)) continue;
List<RedLetterInfoTable> rlits = generalRLITs(sheet);
List<RedLetterInfoTable> rlits = generalRLITs(sheet,evaluator);
if (rlits.size() < 1) continue;
// 根据主体分组处理
Map<String, List<RedLetterInfoTable>> atsGroupRes =
......@@ -1167,6 +1170,8 @@ public class DataImportService extends BaseService {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();
if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
}
......@@ -1175,7 +1180,7 @@ public class DataImportService extends BaseService {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
if (isSheetEmpty(sheet)) continue;
List<CoupaPurchasingReport> ats = generalCPRs(sheet);
List<CoupaPurchasingReport> ats = generalCPRs(sheet,evaluator);
if (ats.size() < 1) continue;
// 根据主体分组处理
Map<String, List<CoupaPurchasingReport>> atsGroupRes =
......@@ -1286,6 +1291,8 @@ public class DataImportService extends BaseService {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();
if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
}
......@@ -1406,10 +1413,10 @@ public class DataImportService extends BaseService {
cil.setSalespersonName(getCellStringValue(cell6));
Cell cell7 = row.getCell(6);
cil.setAmount(getCellBigDecimalValue(cell7));
cil.setAmount(getCellBigDecimalValue(cell7,evaluator));
Cell cell8 = row.getCell(7);
cil.setTaxAmount(getCellBigDecimalValue(cell8));
cil.setTaxAmount(getCellBigDecimalValue(cell8,evaluator));
Cell cell9 = row.getCell(8);
......@@ -1566,6 +1573,8 @@ public class DataImportService extends BaseService {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();
if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
}
......@@ -1575,7 +1584,7 @@ public class DataImportService extends BaseService {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
if (isSheetEmpty(sheet)) continue;
DataImportResponseDto<InvoiceRecord> dataImportResponseDto= generalIRs(sheet);
DataImportResponseDto<InvoiceRecord> dataImportResponseDto= generalIRs(sheet,evaluator);
dataImportResponseDto1.addAll(dataImportResponseDto.getDataImportErrorDtos());
//List<InvoiceRecord> irs = generalIRs(sheet);
List<InvoiceRecord> irs=dataImportResponseDto.getObjectList();
......@@ -1737,7 +1746,7 @@ public class DataImportService extends BaseService {
dataImportLogs.add(dataImportLog);
}
private List<RedLetterInfoTable> generalRLITs(Sheet sheet) {
private List<RedLetterInfoTable> generalRLITs(Sheet sheet,FormulaEvaluator evaluator) {
List<RedLetterInfoTable> rlits = Lists.newArrayList();
for (int j = 1; j <= sheet.getLastRowNum(); j++) {
RedLetterInfoTable rlit = new RedLetterInfoTable();
......@@ -1757,8 +1766,8 @@ public class DataImportService extends BaseService {
rlit.setFillInDate(row.getCell(3).getDateCellValue());
rlit.setSalesTaxNumber(getCellStringValue(row.getCell(4)));
rlit.setSalespersonName(getCellStringValue(row.getCell(5)));
rlit.setTotalAmount(getCellBigDecimalValue(row.getCell(6)));
rlit.setTotalTaxAmount(getCellBigDecimalValue(row.getCell(7)));
rlit.setTotalAmount(getCellBigDecimalValue(row.getCell(6),evaluator));
rlit.setTotalTaxAmount(getCellBigDecimalValue(row.getCell(7),evaluator));
rlit.setApplicationDescription(getCellStringValue(row.getCell(8)));
rlit.setApplicantManager(getCellStringValue(row.getCell(9)));
rlit.setInvoiceCode(getCellStringValue(row.getCell(10)));
......@@ -1768,7 +1777,7 @@ public class DataImportService extends BaseService {
return rlits;
}
private DataImportResponseDto<InvoiceRecord> generalIRs(Sheet sheet) {
private DataImportResponseDto<InvoiceRecord> generalIRs(Sheet sheet,FormulaEvaluator evaluator) {
List<InvoiceRecord> irs = Lists.newArrayList();
List<DataImportErrorDto> errorDtos = Lists.newArrayList();
Set<String> orgsNot = new HashSet<>();
......@@ -1816,11 +1825,11 @@ public class DataImportService extends BaseService {
ir.setCustomerCompanyName(getCellStringValue(row.getCell(2)));
ir.setInvoiceType(getCellStringValue(row.getCell(3)));
ir.setBillingContent(getCellStringValue(row.getCell(4)));
ir.setInvoiceAmount(getCellBigDecimalValue(row.getCell(5)));
ir.setInvoiceAmount(getCellBigDecimalValue(row.getCell(5),evaluator));
ir.setApplicant(getCellStringValue(row.getCell(6)));
ir.setOaApplicationNum(getCellStringValue(row.getCell(7)));
ir.setContractNo(getCellStringValue(row.getCell(8)));
ir.setContractAmount(getCellBigDecimalValue(row.getCell(9)));
ir.setContractAmount(getCellBigDecimalValue(row.getCell(9),evaluator));
ir.setDepartment(getCellStringValue(row.getCell(10)));
ir.setApplicationDate(row.getCell(11).getDateCellValue());
ir.setBillingDate(row.getCell(12).getDateCellValue());
......@@ -1832,8 +1841,8 @@ public class DataImportService extends BaseService {
ir.setInvoicesAmount(getCellIntegerValue(row.getCell(17)));
ir.setCustomerCompanyTaxNum(getCellStringValue(row.getCell(18)));
ir.setContractSourceSystem(getCellStringValue(row.getCell(19)));
ir.setTaxRate(getCellBigDecimalValue(row.getCell(20)));
ir.setTaxAmount(getCellBigDecimalValue(row.getCell(21)));
ir.setTaxRate(getCellBigDecimalValue(row.getCell(20),evaluator));
ir.setTaxAmount(getCellBigDecimalValue(row.getCell(21),evaluator));
ir.setInvoiceStatus(getCellStringValue(row.getCell(22)));
ir.setSource(getCellStringValue(row.getCell(23)));
irs.add(ir);
......@@ -1964,7 +1973,7 @@ public class DataImportService extends BaseService {
return ats;
}
private List<CoupaPurchasingReport> generalCPRs(Sheet sheet) {
private List<CoupaPurchasingReport> generalCPRs(Sheet sheet,FormulaEvaluator evaluator) {
List<CoupaPurchasingReport> cprs = Lists.newArrayList();
for (int j = 1; j <= sheet.getLastRowNum(); j++) {
CoupaPurchasingReport cpr = new CoupaPurchasingReport();
......@@ -1985,7 +1994,7 @@ public class DataImportService extends BaseService {
cpr.setDescription(getCellStringValue(row.getCell(8)));
cpr.setSupplierNum(getCellStringValue(row.getCell(9)));
cpr.setSupplier(getCellStringValue(row.getCell(10)));
cpr.setTotalAmount(getCellBigDecimalValue(row.getCell(11)));
cpr.setTotalAmount(getCellBigDecimalValue(row.getCell(11),evaluator));
cpr.setCurrency(getCellStringValue(row.getCell(12)));
String billNum = getCellStringValue(row.getCell(13));
cpr.setBillNum(billNum);
......@@ -2002,8 +2011,8 @@ public class DataImportService extends BaseService {
cpr.setPeriod(DateUtils.dateToPeriod(cpr.getBillingDate()));
cpr.setLastUpdatedDate(DateUtils.strToDate3(getCellStringValue(row.getCell(24))));
cpr.setLastUpdatedPerson(getCellStringValue(row.getCell(25)));
cpr.setTotalTaxAmount(getCellBigDecimalValue(row.getCell(26)));
cpr.setTotalTaxAmountHeader(getCellBigDecimalValue(row.getCell(27)));
cpr.setTotalTaxAmount(getCellBigDecimalValue(row.getCell(26),evaluator));
cpr.setTotalTaxAmountHeader(getCellBigDecimalValue(row.getCell(27),evaluator));
cpr.setBillingNote(getCellStringValue(row.getCell(28)));
cprs.add(cpr);
}
......@@ -2082,18 +2091,18 @@ public class DataImportService extends BaseService {
logger.warn("获取单元格数据类型未匹配");
return null;
}
private BigDecimal getCellBigDecimalValue(Cell cell) {
if (null == cell) {
return null;
}
if (cell.getCellTypeEnum().equals(CellType.STRING)) {
return new BigDecimal(cell.getStringCellValue().trim());
} else if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
return new BigDecimal(cell.getNumericCellValue());
}
logger.warn("获取单元格数据类型未匹配");
return null;
}
// private BigDecimal getCellBigDecimalValue(Cell cell) {
// if (null == cell) {
// return null;
// }
// if (cell.getCellTypeEnum().equals(CellType.STRING)) {
// return new BigDecimal(cell.getStringCellValue().trim());
// } else if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
// return new BigDecimal(cell.getNumericCellValue());
// }
// logger.warn("获取单元格数据类型未匹配");
// return null;
// }
private Long getCellLongDecimalValue(Cell cell) {
if (null == cell) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment