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 { ...@@ -27,6 +27,10 @@ public class MyAsserts {
if (obj == null || obj.isEmpty()) throw exception; 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) { public static void assertNotEmpty(Collection obj, ApiException exception) {
if (obj == null || obj.isEmpty()) throw exception; if (obj == null || obj.isEmpty()) throw exception;
} }
......
...@@ -93,5 +93,6 @@ public class BBParasBo { ...@@ -93,5 +93,6 @@ public class BBParasBo {
this.rowIndex = otherBo.rowIndex; this.rowIndex = otherBo.rowIndex;
this.period = period; this.period = period;
this.year = curYear; this.year = curYear;
this.formulaExpression=otherBo.formulaExpression;
} }
} }
...@@ -5,4 +5,5 @@ public class Exceptions { ...@@ -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_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"); 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 { ...@@ -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;
...@@ -14,6 +15,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto; ...@@ -14,6 +15,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo; import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto; import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.exception.Exceptions; import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.exception.FormulaException;
import pwc.taxtech.atms.vat.entity.CellData; import pwc.taxtech.atms.vat.entity.CellData;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -34,8 +36,10 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -34,8 +36,10 @@ public class BB extends FunctionBase implements FreeRefFunction {
try { try {
return wrapExceptionEval(args, ec); return wrapExceptionEval(args, ec);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("un expect exception", e); if (e instanceof FormulaException)
e.printStackTrace(); LOGGER.warn("Formula Exception || {}", e.getMessage());
else
e.printStackTrace();
return defaultEval; return defaultEval;
} }
} }
...@@ -45,6 +49,7 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -45,6 +49,7 @@ public class BB extends FunctionBase implements FreeRefFunction {
} }
public BigDecimal bb(BBParasBo bo, OperationEvaluationContext ec) throws Exception { public BigDecimal bb(BBParasBo bo, OperationEvaluationContext ec) throws Exception {
List<Object> ds = new ArrayList<>(); List<Object> ds = new ArrayList<>();
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), formulaContext.getPeriod()); CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), formulaContext.getPeriod());
curPeriod.fixedCurYear(getYear(bo.getYear())); curPeriod.fixedCurYear(getYear(bo.getYear()));
...@@ -55,47 +60,67 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -55,47 +60,67 @@ public class BB extends FunctionBase implements FreeRefFunction {
CellTemplatePerGroupDto cellTemplateData = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupID(), CellTemplatePerGroupDto cellTemplateData = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupID(),
formulaContext.getProjectID()).stream().filter(dto -> dto.getRowIndex() == bo.getColumnIndex() - 1 formulaContext.getProjectID()).stream().filter(dto -> dto.getRowIndex() == bo.getColumnIndex() - 1
&& dto.getColumnIndex() == bo.getColumnIndex() - 1).findFirst().get(); && dto.getColumnIndex() == bo.getColumnIndex() - 1).findFirst().get();
BigDecimal cellValue = BigDecimal.ZERO;
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL); try {
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) { // todo: fix datasource name by templateList(neo)
ds.clear(); if (curPeriod.getCurPeriod() == -99) {
BigDecimal returnEval = defaultBigDecimal; ds.clear();
if (formulaContext.getPeriod() <= 1) { BigDecimal returnEval = defaultBigDecimal;
return 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++) { bo.disCount();
returnEval = returnEval.add(bb(new BBParasBo(bo, p, curPeriod.getCurYear()), ec)); 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; nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
} ds.clear();
ds.add(nullCellDto);
bo.disCount(); // todo: fix datasource name by templateList(neo)
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); MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL);
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo) // cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4, cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN); BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue);
Long dataSourceID = saveDataSource(ec, ds, FormulaDataSourceDetailType.ReportCellDataSourceDto, LOGGER.debug("cell static value ");
cellValue, curPeriod.getCurPeriod(), formulaContext.getReportTemplateGroupID()); return cellValue;
saveFormulaBlock(curPeriod.getCurPeriod(), ec, bo.expression(curPeriod.getCurPeriod(), curPeriod.getCurYear()), cellValue, dataSourceID); } finally {
nullCellDto.setAmount(cellValue); Long dataSourceID = saveDataSource(ec, ds, FormulaDataSourceDetailType.ReportCellDataSourceDto,
LOGGER.debug("cell static value "); cellValue, formulaContext.getPeriod(), formulaContext.getReportTemplateGroupID());
return cellValue; 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` ( ...@@ -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(500) 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