Commit 40dce554 authored by neo's avatar neo

[dev] bb determine target data source

parent 1bcd2fff
...@@ -78,50 +78,17 @@ public class FormulaAgent extends VatAbstractService { ...@@ -78,50 +78,17 @@ public class FormulaAgent extends VatAbstractService {
return null; 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) { public String getPastProjectDbName(int year, String orgId) {
return adminMp.getPastProjectDbName(year, orgId); return adminMp.getPastProjectDbName(year, orgId);
} }
public CellData getCellData(String dbName, String templateId,String cellId, int periodId) { public CellData getCellData( String templateId,String cellId, int periodId) {
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
try {
ShardingContextHolder.setDataSourceKey(dbName);
Report report = getReportByTemplate(templateId, periodId); Report report = getReportByTemplate(templateId, periodId);
MyAsserts.assertNotNull(report, Exceptions.BB_REPORT_NULL); MyAsserts.assertNotNull(report, Exceptions.BB_REPORT_NULL);
CellData cellData = getCellDataListByTemplate(cellId, report.getId()); CellData cellData = getCellDataListByTemplate(cellId, report.getId());
MyAsserts.assertNotNull(cellData, Exceptions.BB_CELL_DATA_NULL); MyAsserts.assertNotNull(cellData, Exceptions.BB_CELL_DATA_NULL);
return cellData; return cellData;
} finally {
ShardingContextHolder.setDataSourceKey(currentProjectDb);
}
} }
} }
...@@ -7,6 +7,7 @@ import org.apache.poi.ss.formula.eval.ValueEval; ...@@ -7,6 +7,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction; import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.common.util.MyAsserts; import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType; import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dto.vatdto.BBParasBo; import pwc.taxtech.atms.dto.vatdto.BBParasBo;
...@@ -77,8 +78,17 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -77,8 +78,17 @@ public class BB extends FunctionBase implements FreeRefFunction {
bo.disCount(); bo.disCount();
String dbName = agent.getPastProjectDbName(curPeriod.getCurYear(), String dbName = agent.getPastProjectDbName(curPeriod.getCurYear(),
formulaContext.getOrganizationID()); formulaContext.getOrganizationID());
CellData cellData = agent.getCellData(dbName, cellTemplateData.getReportTemplateID(),
cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod()); String currentProjectDb = ShardingContextHolder.getDataSourceKey();
CellData cellData = null;
try {
ShardingContextHolder.setDataSourceKey(dbName);
cellData = agent.getCellData(cellTemplateData.getReportTemplateID(),
cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod());
} finally {
ShardingContextHolder.setDataSourceKey(currentProjectDb);
}
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData); nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
ds.clear(); ds.clear();
ds.add(nullCellDto); ds.add(nullCellDto);
......
...@@ -958,7 +958,7 @@ CREATE TABLE IF NOT EXISTS `DBKeyword_ProjectDbName`.`data_source_detail` ( ...@@ -958,7 +958,7 @@ CREATE TABLE IF NOT EXISTS `DBKeyword_ProjectDbName`.`data_source_detail` (
`id` bigint(18) unsigned NOT NULL, `id` bigint(18) unsigned NOT NULL,
`data_source_id` bigint(18) unsigned NOT NULL DEFAULT '0', `data_source_id` bigint(18) unsigned NOT NULL DEFAULT '0',
`data_source_type` int(11) 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(256) NOT NULL DEFAULT '',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) 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