Commit 63c4e918 authored by neo's avatar neo

[DEV] delete exclude aop config use mapper directly in formula agent

parent 900b46ef
package pwc.taxtech.atms.vat.service.impl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dto.GroupId;
......@@ -9,6 +14,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entitiy.ProjectServiceType;
import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.service.impl.DistributedIDService;
import pwc.taxtech.atms.vat.dao.CellDataMapper;
import pwc.taxtech.atms.vat.dao.FormulaProjectMapper;
......@@ -25,7 +31,7 @@ import java.util.List;
import static pwc.taxtech.atms.constant.Constant.FIRST_OR_DEFAULT;
@Repository
@Service
public class FormulaAgent extends VatAbstractService {
@Autowired
public FormulaAdminMapper adminMp;
......@@ -38,6 +44,8 @@ public class FormulaAgent extends VatAbstractService {
@Autowired
public DistributedIDService distributedIDService;
@Qualifier("dynamicSqlSessionTemplate")
public SqlSessionTemplate jdbcTemplate;
public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId) {
ProjectServiceTypeExample pst = new ProjectServiceTypeExample();
......@@ -59,7 +67,7 @@ public class FormulaAgent extends VatAbstractService {
return cellTemplates;
}
public Report getReportByTemplate(String templateId, Integer periodId) {
private Report getReportByTemplate(String templateId, Integer periodId) {
ReportExample example = new ReportExample();
example.createCriteria().andTemplateIdEqualTo(Long.valueOf(templateId))
.andPeriodEqualTo(periodId);
......@@ -69,7 +77,7 @@ public class FormulaAgent extends VatAbstractService {
return null;
}
public CellData getCellDataListByTemplate(String templateId, Long reportId) {
private CellData getCellDataListByTemplate(String templateId, Long reportId) {
CellDataExample dataExample = new CellDataExample();
dataExample.createCriteria().andCellTemplateIdEqualTo(Long.valueOf(templateId));
List<CellData> cellDataList = cellDataMapper.selectByExample(dataExample);
......@@ -91,7 +99,7 @@ public class FormulaAgent extends VatAbstractService {
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.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());
......@@ -102,4 +110,24 @@ public class FormulaAgent extends VatAbstractService {
}
public String getPastProjectDbName(int year, String orgId) {
return adminMp.getPastProjectDbName(year, orgId);
}
public CellData getCellData(String dbName, String templateId, int periodId) {
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
try {
ShardingContextHolder.setDataSourceKey(dbName);
Report report = getReportByTemplate(templateId, periodId);
MyAsserts.assertNotNull(report, Exceptions.BB_REPORT_NULL);
CellData cellData = getCellDataListByTemplate(templateId, report.getId());
MyAsserts.assertNotNull(cellData, Exceptions.BB_CELL_DATA_NULL);
return cellData;
} finally {
ShardingContextHolder.setDataSourceKey(currentProjectDb);
}
}
}
......@@ -7,9 +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.common.util.SpringContextUtil;
import pwc.taxtech.atms.dto.vatdto.BBParasBo;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource;
......@@ -17,7 +15,6 @@ 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 pwc.taxtech.atms.vat.entity.Report;
import java.math.BigDecimal;
......@@ -57,9 +54,7 @@ public class BB extends FunctionBase implements FreeRefFunction {
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)
......@@ -78,37 +73,22 @@ public class BB extends FunctionBase implements FreeRefFunction {
}
bo.disCount();
String dbName = SpringContextUtil.formulaAdminMapper.getPastProjectDbName(curPeriod.getCurYear(),
String dbName = agent.getPastProjectDbName(curPeriod.getCurYear(),
formulaContext.getOrganizationID());
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
ShardingContextHolder.setDataSourceKey(dbName);
try {
Report report = agent.getReportByTemplate(cellTemplateData.getReportTemplateID(), curPeriod.getCurPeriod());
MyAsserts.assertNotNull(report, Exceptions.BB_REPORT_NULL);
CellData cellData = agent.getCellDataListByTemplate(cellTemplateData.getCellTemplateID(), report.getId());
MyAsserts.assertNotNull(cellData, Exceptions.BB_CELL_DATA_NULL);
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
closeDataSource.clean();
closeDataSource.addDS(nullCellDto);
// todo: fix datasource name by templateList(neo)
CellData cellData = agent.getCellData(dbName, cellTemplateData.getReportTemplateID(), curPeriod.getCurPeriod());
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
closeDataSource.clean();
closeDataSource.addDS(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);
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;
}
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
return cellValue;
}
}
......
......@@ -60,8 +60,8 @@
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut id="txPointcut2" expression="execution(public * pwc.taxtech.atms..*.*(..)) &amp;&amp; @target(org.springframework.stereotype.Service)
and !execution(* pwc.taxtech.atms.vat.service.impl.FormulaAgent.*(..))" />
<aop:pointcut id="txPointcut2" expression="execution(public * pwc.taxtech.atms..*.*(..)) &amp;&amp;
@target(org.springframework.stereotype.Service)" />
<aop:advisor pointcut-ref="txPointcut2" advice-ref="txAdvice" />
</aop:config>
......
package pwc.taxtech.atms;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.vat.dao.ReportMapper;
import pwc.taxtech.atms.vat.entity.Report;
import pwc.taxtech.atms.vat.entity.ReportExample;
import java.util.List;
public class DataSourceSwitch extends CommonIT {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private ReportMapper reportMapper;
@Test
public void insertChieseCharacter() {
ShardingContextHolder.setDataSourceKey("a1700000");
ReportExample example = new ReportExample();
example.createCriteria().andTemplateIdEqualTo(Long.valueOf("9951852766564352"))
.andPeriodEqualTo(1);
List<Report> reports = reportMapper.selectByExample(example);
System.out.println(reports.size());
ShardingContextHolder.setDataSourceKey("a1800013");
System.out.println(reportMapper.selectByExample(example).size());
ShardingContextHolder.setDataSourceKey("a1700000");
System.out.println(reportMapper.selectByExample(example).size());
}
}
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