Commit c53634a9 authored by neo.wang's avatar neo.wang

Merge branch 'dev_neo' into 'dev'

[DEV] dbb formula for -99 logic

See merge request root/atms!50
parents 3d324f46 34358d83
......@@ -29,4 +29,11 @@ public class BBParasBo {
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 {
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_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;
import com.github.pagehelper.util.StringUtil;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
......@@ -26,6 +25,7 @@ import java.math.BigDecimal;
public class ReportFormulaFactory {
static final Logger LOGGER = LoggerFactory.getLogger(ReportFormulaFactory.class);
final static ValueEval defaultEval = new StringEval("0");
final static BigDecimal defaultBigDecimal = new BigDecimal("0");
public static abstract class ReportBaseFormula implements FreeRefFunction {
final FormulaContext context;
......@@ -68,8 +68,11 @@ public class ReportFormulaFactory {
@Override
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())) {
BBParasBo bo = new BBParasBo(args, ec);
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), context.getPeriod());
curPeriod.fixedCurYear(getYear(curPeriod.getCurYear()));
......@@ -88,13 +91,13 @@ public class ReportFormulaFactory {
// todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) {
closeDataSource.clean();
ValueEval returnEval = null;
BigDecimal returnEval = defaultBigDecimal;
if (context.getPeriod() <= 1) {
return defaultEval;
return defaultBigDecimal;
}
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;
......@@ -114,25 +117,25 @@ public class ReportFormulaFactory {
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
// todo: fix datasource name by templateList(neo)
if (!StringUtil.isEmpty(cellData.getData())) {
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
ShardingContextHolder.setDataSourceKey(currentProjectDb);
return new NumberEval(cellValue.doubleValue());
}
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
ShardingContextHolder.setDataSourceKey(currentProjectDb);
return cellValue;
} catch (Exception e) {
LOGGER.warn("un support exception", e);
ShardingContextHolder.setDataSourceKey(currentProjectDb);
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