Commit 2d527ef7 authored by neo.wang's avatar neo.wang

Merge branch 'dev_neo' into 'dev'

[dev] fixed bb formula save formula block to db

See merge request root/atms!91
parents a0a31f33 d3e9c1b1
......@@ -7,7 +7,8 @@ public enum FormulaDataSourceDetailType {
InputInvoiceDataSourceDto(3, pwc.taxtech.atms.dto.vatdto.InputInvoiceDataSourceDto.class),
InputInvoiceDetailDataSourceDto(4, pwc.taxtech.atms.dto.vatdto.InputInvoiceDetailDataSourceDto.class),
OutputInvoiceDataSourceDto(5, pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto.class),
AssetDetailDataSourceDto(5, pwc.taxtech.atms.dto.vatdto.AssetDetailDataSourceDto.class);
AssetDetailDataSourceDto(5, pwc.taxtech.atms.dto.vatdto.AssetDetailDataSourceDto.class),
ReportCellDataSourceDto(6, pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto.class);
private Integer code;
......
......@@ -15,13 +15,22 @@ public class BBParasBo {
private Integer rowIndex;
private Integer period;
private Integer year;
private String formulaExpression;
public BBParasBo(ValueEval[] args, OperationEvaluationContext ec) throws EvaluationException {
StringBuilder expression = new StringBuilder("");
begin(expression);
reportCode = resolverString(args, ec, 0);
concatPara(expression, reportCode);
try {
columnIndex = resolverInteger(args, ec, 1);
split(expression);
concatPara(expression, columnIndex);
} catch (Exception e) {
String columnStr = resolverString(args, ec, 1);
split(expression);
concatPara(expression, columnStr);
int rtn = 0;
columnStr = columnStr.toUpperCase();
char[] excelCol = columnStr.toCharArray();
......@@ -35,8 +44,42 @@ public class BBParasBo {
columnIndex = rtn;
}
rowIndex = resolverInteger(args, ec, 2);
split(expression);
concatPara(expression, rowIndex);
period = args.length >= 4 ? resolverInteger(args, ec, 3) : 0;
year = args.length == 5 ? resolverInteger(args, ec, 4) : 0;
formulaExpression = expression.toString();
}
private StringBuilder begin(StringBuilder expression) {
return expression.append("BB(");
}
private StringBuilder end(StringBuilder expression) {
return expression.append(")");
}
private StringBuilder split(StringBuilder expression) {
return expression.append(",");
}
private StringBuilder concatPara(StringBuilder expression, String para) {
return expression.append("\"").append(para).append("\"");
}
private StringBuilder concatPara(StringBuilder expression, Integer para) {
return expression.append(para);
}
public String expression(Integer currentPeriod, Integer currentYear) {
StringBuilder builder = new StringBuilder(formulaExpression);
split(builder);
concatPara(builder, currentPeriod);
split(builder);
concatPara(builder, currentYear);
end(builder);
formulaExpression = builder.toString();
return formulaExpression;
}
public void disCount() {
......
package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.util.ArrayList;
import java.util.List;
public class CloseableFormulaDataSource implements AutoCloseable{
private List<ReportCellDataSourceDto> dataSourceList = new ArrayList<>();
private FormulaAgent agent;
public CloseableFormulaDataSource(FormulaAgent agent) {
this.agent = agent;
}
public void addDS(ReportCellDataSourceDto ds){
dataSourceList.add(ds);
}
public void addDS(List<ReportCellDataSourceDto> dss){
dataSourceList.addAll(dss);
}
public void clean(){
dataSourceList.clear();
}
@Override
public void close() throws Exception {
if(!dataSourceList.isEmpty()){
agent.save(dataSourceList);//TODO: save datasources;
}
}
}
......@@ -8,15 +8,17 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dto.vatdto.BBParasBo;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource;
import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.CellData;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class BB extends FunctionBase implements FreeRefFunction {
static final Logger LOGGER = LoggerFactory.getLogger(BB.class);
......@@ -39,58 +41,61 @@ public class BB extends FunctionBase implements FreeRefFunction {
}
public ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception {
return new NumberEval(bb(new BBParasBo(args, ec)).doubleValue());
return new NumberEval(bb(new BBParasBo(args, ec), ec).doubleValue());
}
public BigDecimal bb(BBParasBo bo) throws Exception {
try (CloseableFormulaDataSource closeDataSource = new CloseableFormulaDataSource(formulaContext.getFormulaAgent())) {
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), formulaContext.getPeriod());
curPeriod.fixedCurYear(getYear(bo.getYear()));
public BigDecimal bb(BBParasBo bo, OperationEvaluationContext ec) throws Exception {
List<Object> ds = new ArrayList<>();
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), formulaContext.getPeriod());
curPeriod.fixedCurYear(getYear(bo.getYear()));
ReportCellDataSourceDto nullCellDto = ReportCellDataSourceDto.nullDataSource(bo, curPeriod);
closeDataSource.addDS(nullCellDto);
ReportCellDataSourceDto nullCellDto = ReportCellDataSourceDto.nullDataSource(bo, curPeriod);
ds.add(nullCellDto);
CellTemplatePerGroupDto cellTemplateData = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupID(),
formulaContext.getProjectID()).stream().filter(dto -> dto.getRowIndex() == bo.getColumnIndex() - 1
&& dto.getColumnIndex() == bo.getColumnIndex() - 1).findFirst().get();
CellTemplatePerGroupDto cellTemplateData = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupID(),
formulaContext.getProjectID()).stream().filter(dto -> dto.getRowIndex() == bo.getColumnIndex() - 1
&& dto.getColumnIndex() == bo.getColumnIndex() - 1).findFirst().get();
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL);
nullCellDto.fixedWithGroup(cellTemplateData);
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL);
nullCellDto.fixedWithGroup(cellTemplateData);
// todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) {
closeDataSource.clean();
BigDecimal returnEval = defaultBigDecimal;
if (formulaContext.getPeriod() <= 1) {
return defaultBigDecimal;
}
for (int p = 1; p < formulaContext.getPeriod(); p++) {
returnEval = returnEval.add(bb(new BBParasBo(bo, p, curPeriod.getCurYear())));
}
// todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) {
ds.clear();
BigDecimal returnEval = defaultBigDecimal;
if (formulaContext.getPeriod() <= 1) {
return defaultBigDecimal;
}
return returnEval;
for (int p = 1; p < formulaContext.getPeriod(); p++) {
returnEval = returnEval.add(bb(new BBParasBo(bo, p, curPeriod.getCurYear()), ec));
}
bo.disCount();
String dbName = agent.getPastProjectDbName(curPeriod.getCurYear(),
formulaContext.getOrganizationID());
CellData cellData = agent.getCellData(dbName, cellTemplateData.getReportTemplateID(),
cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod());
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
closeDataSource.clean();
closeDataSource.addDS(nullCellDto);
// todo: fix datasource name by templateList(neo)
return returnEval;
}
MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL);
bo.disCount();
String dbName = agent.getPastProjectDbName(curPeriod.getCurYear(),
formulaContext.getOrganizationID());
CellData cellData = agent.getCellData(dbName, cellTemplateData.getReportTemplateID(),
cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod());
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
ds.clear();
ds.add(nullCellDto);
// todo: fix datasource name by templateList(neo)
MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL);
// 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 ");
return cellValue;
}
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
Long dataSourceID = saveDataSource(ec, ds, FormulaDataSourceDetailType.ReportCellDataSourceDto,
cellValue, curPeriod.getCurPeriod(), formulaContext.getReportTemplateGroupID());
saveFormulaBlock(curPeriod.getCurPeriod(), ec, bo.expression(curPeriod.getCurPeriod(), curPeriod.getCurYear()), cellValue, dataSourceID);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
return cellValue;
}
}
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