Commit a8a6a5e8 authored by chase's avatar chase

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

parent cf8b3128
...@@ -51,7 +51,6 @@ import pwc.taxtech.atms.vat.entity.*; ...@@ -51,7 +51,6 @@ import pwc.taxtech.atms.vat.entity.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
...@@ -1059,6 +1058,8 @@ public class DataImportService extends BaseService { ...@@ -1059,6 +1058,8 @@ public class DataImportService extends BaseService {
try { try {
InputStream inputStream = file.getInputStream(); InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream); Workbook workbook = WorkbookFactory.create(inputStream);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();
if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) { if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod); throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
} }
...@@ -1067,7 +1068,7 @@ public class DataImportService extends BaseService { ...@@ -1067,7 +1068,7 @@ public class DataImportService extends BaseService {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) { for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i); Sheet sheet = workbook.getSheetAt(i);
if (isSheetEmpty(sheet)) continue; if (isSheetEmpty(sheet)) continue;
List<AdjustmentTable> ats = generalATs(sheet); List<AdjustmentTable> ats = generalATs(sheet, evaluator);
if (ats.size() < 1) continue; if (ats.size() < 1) continue;
// 根据主体分组处理 // 根据主体分组处理
Map<String, List<AdjustmentTable>> atsGroupRes = Map<String, List<AdjustmentTable>> atsGroupRes =
...@@ -1863,7 +1864,7 @@ public class DataImportService extends BaseService { ...@@ -1863,7 +1864,7 @@ public class DataImportService extends BaseService {
return fg; return fg;
} }
private List<AdjustmentTable> generalATs(Sheet sheet) { private List<AdjustmentTable> generalATs(Sheet sheet,FormulaEvaluator evaluator) {
List<AdjustmentTable> ats = Lists.newArrayList(); List<AdjustmentTable> ats = Lists.newArrayList();
for (int j = 1; j <= sheet.getLastRowNum(); j++) { for (int j = 1; j <= sheet.getLastRowNum(); j++) {
AdjustmentTable at = new AdjustmentTable(); AdjustmentTable at = new AdjustmentTable();
...@@ -1905,9 +1906,9 @@ public class DataImportService extends BaseService { ...@@ -1905,9 +1906,9 @@ public class DataImportService extends BaseService {
at.setSegment8Name(getCellStringValue(row.getCell(18))); at.setSegment8Name(getCellStringValue(row.getCell(18)));
at.setSegment9Name(getCellStringValue(row.getCell(19))); at.setSegment9Name(getCellStringValue(row.getCell(19)));
at.setSegment10Name(getCellStringValue(row.getCell(20))); at.setSegment10Name(getCellStringValue(row.getCell(20)));
at.setPeriodDrBeq(getCellBigDecimalValue(row.getCell(21))); at.setPeriodDrBeq(getCellBigDecimalValue(row.getCell(22),evaluator));
at.setPeriodCrBeq(getCellBigDecimalValue(row.getCell(22))); at.setPeriodCrBeq(getCellBigDecimalValue(row.getCell(22),evaluator));
at.setEndBalBeq(getCellBigDecimalValue(row.getCell(23))); at.setEndBalBeq(getCellBigDecimalValue(row.getCell(23),evaluator));
ats.add(at); ats.add(at);
} }
return ats; return ats;
...@@ -2010,6 +2011,27 @@ public class DataImportService extends BaseService { ...@@ -2010,6 +2011,27 @@ public class DataImportService extends BaseService {
return null; 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) { private BigDecimal getCellBigDecimalValue(Cell cell) {
if (null == cell) { if (null == cell) {
return null; return null;
......
...@@ -744,7 +744,7 @@ ...@@ -744,7 +744,7 @@
<span class="required-tip"> * </span> <span class="required-tip"> * </span>
{{'Company Name' | translate}} {{'Company Name' | translate}}
</label> </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> <div dx-select-box="editOrgOptions"></div>
<!--<select ng-model="editFieldModel.companyName" class="form-control"--> <!--<select ng-model="editFieldModel.companyName" class="form-control"-->
<!--title="{{editFieldModel.companyName}}" required--> <!--title="{{editFieldModel.companyName}}" required-->
...@@ -987,7 +987,7 @@ ...@@ -987,7 +987,7 @@
<span class="required-tip"> * </span> <span class="required-tip"> * </span>
{{'Company Name' | translate}} {{'Company Name' | translate}}
</label> </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> <div ng-class="{'upload-fail-mark':!editFieldItem.companyName}" dx-select-box="editFieldItemOrgOptions"></div>
<!--<select ng-model="editFieldItem.companyName" class="form-control"--> <!--<select ng-model="editFieldItem.companyName" class="form-control"-->
<!--title="{{editFieldItem.companyName}}"--> <!--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