Commit 34358d83 authored by neo's avatar neo

[DEV] dbb formula for -99 logic

parent 729b3949
...@@ -29,4 +29,11 @@ public class BBParasBo { ...@@ -29,4 +29,11 @@ public class BBParasBo {
columnIndex--; columnIndex--;
} }
public BBParasBo(BBParasBo otherBo,int period,int curYear) {
this.reportCode = otherBo.reportCode;
this.columnIndex = otherBo.getColumnIndex();
this.rowIndex = otherBo.rowIndex;
this.period = period;
this.year = curYear;
}
} }
...@@ -4,4 +4,5 @@ public class Exceptions { ...@@ -4,4 +4,5 @@ public class Exceptions {
public static final FormulaException BB_CELL_TEMP_NULL = new FormulaException("cell template data is null"); public static final FormulaException BB_CELL_TEMP_NULL = new FormulaException("cell template data is null");
public static final FormulaException BB_REPORT_NULL = new FormulaException("cell report is null"); public static final FormulaException BB_REPORT_NULL = new FormulaException("cell report is null");
public static final FormulaException BB_CELL_DATA_NULL = new FormulaException("cell data is null"); public static final FormulaException BB_CELL_DATA_NULL = new FormulaException("cell data is null");
public static final FormulaException BB_CELL_DATA_EMPTY = new FormulaException("cell data is empty");
} }
package pwc.taxtech.atms.vat.service.impl; package pwc.taxtech.atms.vat.service.impl;
import com.github.pagehelper.util.StringUtil;
import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.StringEval;
...@@ -26,6 +25,7 @@ import java.math.BigDecimal; ...@@ -26,6 +25,7 @@ import java.math.BigDecimal;
public class ReportFormulaFactory { public class ReportFormulaFactory {
static final Logger LOGGER = LoggerFactory.getLogger(ReportFormulaFactory.class); static final Logger LOGGER = LoggerFactory.getLogger(ReportFormulaFactory.class);
final static ValueEval defaultEval = new StringEval("0"); final static ValueEval defaultEval = new StringEval("0");
final static BigDecimal defaultBigDecimal = new BigDecimal("0");
public static abstract class ReportBaseFormula implements FreeRefFunction { public static abstract class ReportBaseFormula implements FreeRefFunction {
final FormulaContext context; final FormulaContext context;
...@@ -68,8 +68,11 @@ public class ReportFormulaFactory { ...@@ -68,8 +68,11 @@ public class ReportFormulaFactory {
@Override @Override
public ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception { public ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception {
return new NumberEval(bb(new BBParasBo(args, ec)).doubleValue());
}
public BigDecimal bb(BBParasBo bo) throws Exception {
try (CloseableFormulaDataSource closeDataSource = new CloseableFormulaDataSource(context.getFormulaAgent())) { try (CloseableFormulaDataSource closeDataSource = new CloseableFormulaDataSource(context.getFormulaAgent())) {
BBParasBo bo = new BBParasBo(args, ec);
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), context.getPeriod()); CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), context.getPeriod());
curPeriod.fixedCurYear(getYear(curPeriod.getCurYear())); curPeriod.fixedCurYear(getYear(curPeriod.getCurYear()));
...@@ -88,13 +91,13 @@ public class ReportFormulaFactory { ...@@ -88,13 +91,13 @@ public class ReportFormulaFactory {
// todo: fix datasource name by templateList(neo) // todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) { if (curPeriod.getCurPeriod() == -99) {
closeDataSource.clean(); closeDataSource.clean();
ValueEval returnEval = null; BigDecimal returnEval = defaultBigDecimal;
if (context.getPeriod() <= 1) { if (context.getPeriod() <= 1) {
return defaultEval; return defaultBigDecimal;
} }
for (int p = 1; p < context.getPeriod(); p++) { for (int p = 1; p < context.getPeriod(); p++) {
// returnEval=And(returnEval,BB)//TODO: to impl add vormular returnEval = returnEval.add(bb(new BBParasBo(bo, p, curPeriod.getCurYear())));
} }
return returnEval; return returnEval;
...@@ -114,25 +117,25 @@ public class ReportFormulaFactory { ...@@ -114,25 +117,25 @@ public class ReportFormulaFactory {
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData); nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
// todo: fix datasource name by templateList(neo) // todo: fix datasource name by templateList(neo)
if (!StringUtil.isEmpty(cellData.getData())) {
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo) MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL);
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue); // cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
LOGGER.debug("cell static value "); BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
ShardingContextHolder.setDataSourceKey(currentProjectDb); BigDecimal.ROUND_HALF_DOWN);
return new NumberEval(cellValue.doubleValue()); nullCellDto.setAmount(cellValue);
} LOGGER.debug("cell static value ");
ShardingContextHolder.setDataSourceKey(currentProjectDb);
return cellValue;
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("un support exception", e); LOGGER.warn("un support exception", e);
ShardingContextHolder.setDataSourceKey(currentProjectDb); ShardingContextHolder.setDataSourceKey(currentProjectDb);
throw e; throw e;
} }
} }
return defaultEval;
} }
} }
} }
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