Commit a8a6a5e8 authored by chase's avatar chase

fix 导入报表中有公式无法导入bug

parent cf8b3128
......@@ -51,7 +51,6 @@ import pwc.taxtech.atms.vat.entity.*;
import javax.annotation.Resource;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
......@@ -1059,6 +1058,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);
}
......@@ -1067,7 +1068,7 @@ public class DataImportService extends BaseService {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
if (isSheetEmpty(sheet)) continue;
List<AdjustmentTable> ats = generalATs(sheet);
List<AdjustmentTable> ats = generalATs(sheet, evaluator);
if (ats.size() < 1) continue;
// 根据主体分组处理
Map<String, List<AdjustmentTable>> atsGroupRes =
......@@ -1863,7 +1864,7 @@ public class DataImportService extends BaseService {
return fg;
}
private List<AdjustmentTable> generalATs(Sheet sheet) {
private List<AdjustmentTable> generalATs(Sheet sheet,FormulaEvaluator evaluator) {
List<AdjustmentTable> ats = Lists.newArrayList();
for (int j = 1; j <= sheet.getLastRowNum(); j++) {
AdjustmentTable at = new AdjustmentTable();
......@@ -1905,9 +1906,9 @@ public class DataImportService extends BaseService {
at.setSegment8Name(getCellStringValue(row.getCell(18)));
at.setSegment9Name(getCellStringValue(row.getCell(19)));
at.setSegment10Name(getCellStringValue(row.getCell(20)));
at.setPeriodDrBeq(getCellBigDecimalValue(row.getCell(21)));
at.setPeriodCrBeq(getCellBigDecimalValue(row.getCell(22)));
at.setEndBalBeq(getCellBigDecimalValue(row.getCell(23)));
at.setPeriodDrBeq(getCellBigDecimalValue(row.getCell(22),evaluator));
at.setPeriodCrBeq(getCellBigDecimalValue(row.getCell(22),evaluator));
at.setEndBalBeq(getCellBigDecimalValue(row.getCell(23),evaluator));
ats.add(at);
}
return ats;
......@@ -2010,6 +2011,27 @@ public class DataImportService extends BaseService {
return null;
}
private BigDecimal getCellBigDecimalValue(Cell cell,FormulaEvaluator evaluator) {
if (null == cell) {
return null;
}
if(cell.getCellTypeEnum().equals(CellType.FORMULA)){
CellValue cellValue = evaluator.evaluate(cell);
if (cellValue.getCellTypeEnum().equals(CellType.STRING)) {
return new BigDecimal(cellValue.getStringValue().trim());
} else if (cellValue.getCellTypeEnum().equals(CellType.NUMERIC)) {
return new BigDecimal(cellValue.getNumberValue());
}
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;
......
......@@ -744,7 +744,7 @@
<span class="required-tip"> * </span>
{{'Company Name' | translate}}
</label>
<div class="col-sm-11" style="width:61.67%" id="companyNameOptionsMap">
<div class="col-sm-11" style="width:61.67%;height: 13px" id="companyNameOptionsMap">
<div dx-select-box="editOrgOptions"></div>
<!--<select ng-model="editFieldModel.companyName" class="form-control"-->
<!--title="{{editFieldModel.companyName}}" required-->
......@@ -987,7 +987,7 @@
<span class="required-tip"> * </span>
{{'Company Name' | translate}}
</label>
<div class="col-sm-11" style="width:61.67%">
<div class="col-sm-11" style="width:61.67%;height: 13px">
<div ng-class="{'upload-fail-mark':!editFieldItem.companyName}" dx-select-box="editFieldItemOrgOptions"></div>
<!--<select ng-model="editFieldItem.companyName" class="form-control"-->
<!--title="{{editFieldItem.companyName}}"-->
......
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