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

Merge branch 'dev_neo' into 'dev'

Dev neo

See merge request root/atms!92
parents 2d527ef7 2175262a
......@@ -27,6 +27,10 @@ public class MyAsserts {
if (obj == null || obj.isEmpty()) throw exception;
}
public static void assertNotEmpty(String obj, FormulaException exception) {
if (obj == null || obj.isEmpty()) throw exception;
}
public static void assertNotEmpty(Collection obj, ApiException exception) {
if (obj == null || obj.isEmpty()) throw exception;
}
......
......@@ -93,5 +93,6 @@ public class BBParasBo {
this.rowIndex = otherBo.rowIndex;
this.period = period;
this.year = curYear;
this.formulaExpression=otherBo.formulaExpression;
}
}
......@@ -5,4 +5,5 @@ public class Exceptions {
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");
public static final FormulaException BB_EMPTY = new FormulaException("db name is empty");
}
......@@ -78,50 +78,17 @@ public class FormulaAgent extends VatAbstractService {
return null;
}
public void save(List<ReportCellDataSourceDto> dataSourceDtos) {
dataSourceDtos.forEach(m -> {
DataSource ds = new DataSource();
ds.setAmount(m.getAmount() == null ? new BigDecimal(0) : m.getAmount());
ds.setCreateBy(m.getCreator() == null ? "Admin" : m.getCreator());
ds.setCreateTime(m.getCreateTime() == null ? new Date() : m.getCreateTime());
ds.setDescription(m.getDescription() == null ? "" : m.getDescription());
ds.setKeyValueDataId(m.getKeyValueDataID());
ds.setName(m.getName());
ds.setType(m.type);
ds.setUpdateBy(m.getUpdater() == null ? "Admin" : m.getUpdater());
ds.setUpdateTime(m.getUpdateTime() == null ? new Date() : m.getUpdateTime());
ds.setId(distributedIDService.nextId());
ds.setKeyValueDataId(m.getDescription() == null ? "" : m.getDescription());//TODO: tobe fixed
ds.setRowName(m.getRowName() == null ? "" : m.getRowName());
ds.setColumnName(m.getColumnName() == null ? "" : m.getColumnName());
ds.setRowIndex(m.getRowIndex());
ds.setColumnIndex(m.getColumnIndex());
ds.setRemapBatchId("0");//TODO: tobe fixed
ds.setCellTemplateId(Long.parseLong(m.getCellTemplateID()));
ds.setPeriod(m.getPeriod());
dataSourceMapper.insert(ds);
});
}
public String getPastProjectDbName(int year, String orgId) {
return adminMp.getPastProjectDbName(year, orgId);
}
public CellData getCellData(String dbName, String templateId,String cellId, int periodId) {
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
try {
ShardingContextHolder.setDataSourceKey(dbName);
public CellData getCellData( String templateId,String cellId, int periodId) {
Report report = getReportByTemplate(templateId, periodId);
MyAsserts.assertNotNull(report, Exceptions.BB_REPORT_NULL);
CellData cellData = getCellDataListByTemplate(cellId, report.getId());
MyAsserts.assertNotNull(cellData, Exceptions.BB_CELL_DATA_NULL);
return cellData;
} finally {
ShardingContextHolder.setDataSourceKey(currentProjectDb);
}
}
}
......@@ -7,6 +7,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dto.vatdto.BBParasBo;
......@@ -14,6 +15,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.exception.FormulaException;
import pwc.taxtech.atms.vat.entity.CellData;
import java.math.BigDecimal;
......@@ -34,8 +36,10 @@ public class BB extends FunctionBase implements FreeRefFunction {
try {
return wrapExceptionEval(args, ec);
} catch (Exception e) {
LOGGER.warn("un expect exception", e);
e.printStackTrace();
if (e instanceof FormulaException)
LOGGER.warn("Formula Exception || {}", e.getMessage());
else
e.printStackTrace();
return defaultEval;
}
}
......@@ -45,6 +49,7 @@ public class BB extends FunctionBase implements FreeRefFunction {
}
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()));
......@@ -55,47 +60,67 @@ public class BB extends FunctionBase implements FreeRefFunction {
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);
// todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) {
ds.clear();
BigDecimal returnEval = defaultBigDecimal;
if (formulaContext.getPeriod() <= 1) {
return defaultBigDecimal;
BigDecimal cellValue = BigDecimal.ZERO;
try {
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL);
nullCellDto.fixedWithGroup(cellTemplateData);
// todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) {
ds.clear();
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()), ec));
}
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());
MyAsserts.assertNotEmpty(dbName, Exceptions.BB_EMPTY);
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
CellData cellData = null;
if (currentProjectDb.equals(dbName)) {
cellData = agent.getCellData(cellTemplateData.getReportTemplateID(),
cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod());
} else {
try {
ShardingContextHolder.setDataSourceKey(dbName);
cellData = agent.getCellData(cellTemplateData.getReportTemplateID(),
cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod());
} catch (Exception e) {
LOGGER.warn("get data exception with dbName{} currentDb {}", dbName, currentProjectDb, e);
throw e;
} finally {
ShardingContextHolder.setDataSourceKey(currentProjectDb);
}
}
return returnEval;
}
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)
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);
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);
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;
cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
return cellValue;
} finally {
Long dataSourceID = saveDataSource(ec, ds, FormulaDataSourceDetailType.ReportCellDataSourceDto,
cellValue, formulaContext.getPeriod(), formulaContext.getReportTemplateGroupID());
saveFormulaBlock(formulaContext.getPeriod(), ec, bo.expression(curPeriod.getCurPeriod(), curPeriod.getCurYear()), cellValue, dataSourceID);
}
}
}
......@@ -958,7 +958,7 @@ CREATE TABLE IF NOT EXISTS `DBKeyword_ProjectDbName`.`data_source_detail` (
`id` bigint(18) unsigned NOT NULL,
`data_source_id` bigint(18) unsigned NOT NULL DEFAULT '0',
`data_source_type` int(11) unsigned NOT NULL DEFAULT '0',
`item_value` varchar(128) NOT NULL DEFAULT '',
`item_value` varchar(500) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
......
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