Commit 7c46546f authored by frank.xa.zhang's avatar frank.xa.zhang

Merge branch 'dev' into dev_frank

parents 69c03978 56496b35
package pwc.taxtech.atms.vat.service.impl; package pwc.taxtech.atms.vat.service.impl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dao.FormulaAdminMapper; import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dto.GroupId; import pwc.taxtech.atms.dto.GroupId;
...@@ -9,7 +11,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto; ...@@ -9,7 +11,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto; import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entitiy.ProjectServiceType; import pwc.taxtech.atms.entitiy.ProjectServiceType;
import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample; import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample;
import pwc.taxtech.atms.service.impl.DistributedIDService; import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.dao.CellDataMapper; import pwc.taxtech.atms.vat.dao.CellDataMapper;
import pwc.taxtech.atms.vat.dao.FormulaProjectMapper; import pwc.taxtech.atms.vat.dao.FormulaProjectMapper;
import pwc.taxtech.atms.vat.dao.ReportMapper; import pwc.taxtech.atms.vat.dao.ReportMapper;
...@@ -25,7 +27,7 @@ import java.util.List; ...@@ -25,7 +27,7 @@ import java.util.List;
import static pwc.taxtech.atms.constant.Constant.FIRST_OR_DEFAULT; import static pwc.taxtech.atms.constant.Constant.FIRST_OR_DEFAULT;
@Repository @Service
public class FormulaAgent extends VatAbstractService { public class FormulaAgent extends VatAbstractService {
@Autowired @Autowired
public FormulaAdminMapper adminMp; public FormulaAdminMapper adminMp;
...@@ -35,9 +37,6 @@ public class FormulaAgent extends VatAbstractService { ...@@ -35,9 +37,6 @@ public class FormulaAgent extends VatAbstractService {
public ReportMapper reportMapper; public ReportMapper reportMapper;
@Autowired @Autowired
public CellDataMapper cellDataMapper; public CellDataMapper cellDataMapper;
@Autowired
public DistributedIDService distributedIDService;
public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId) { public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId) {
ProjectServiceTypeExample pst = new ProjectServiceTypeExample(); ProjectServiceTypeExample pst = new ProjectServiceTypeExample();
...@@ -59,7 +58,7 @@ public class FormulaAgent extends VatAbstractService { ...@@ -59,7 +58,7 @@ public class FormulaAgent extends VatAbstractService {
return cellTemplates; return cellTemplates;
} }
public Report getReportByTemplate(String templateId, Integer periodId) { private Report getReportByTemplate(String templateId, Integer periodId) {
ReportExample example = new ReportExample(); ReportExample example = new ReportExample();
example.createCriteria().andTemplateIdEqualTo(Long.valueOf(templateId)) example.createCriteria().andTemplateIdEqualTo(Long.valueOf(templateId))
.andPeriodEqualTo(periodId); .andPeriodEqualTo(periodId);
...@@ -69,7 +68,7 @@ public class FormulaAgent extends VatAbstractService { ...@@ -69,7 +68,7 @@ public class FormulaAgent extends VatAbstractService {
return null; return null;
} }
public CellData getCellDataListByTemplate(String templateId, Long reportId) { private CellData getCellDataListByTemplate(String templateId, Long reportId) {
CellDataExample dataExample = new CellDataExample(); CellDataExample dataExample = new CellDataExample();
dataExample.createCriteria().andCellTemplateIdEqualTo(Long.valueOf(templateId)); dataExample.createCriteria().andCellTemplateIdEqualTo(Long.valueOf(templateId));
List<CellData> cellDataList = cellDataMapper.selectByExample(dataExample); List<CellData> cellDataList = cellDataMapper.selectByExample(dataExample);
...@@ -91,7 +90,7 @@ public class FormulaAgent extends VatAbstractService { ...@@ -91,7 +90,7 @@ public class FormulaAgent extends VatAbstractService {
ds.setUpdateBy(m.getUpdater() == null ? "Admin" : m.getUpdater()); ds.setUpdateBy(m.getUpdater() == null ? "Admin" : m.getUpdater());
ds.setUpdateTime(m.getUpdateTime() == null ? new Date() : m.getUpdateTime()); ds.setUpdateTime(m.getUpdateTime() == null ? new Date() : m.getUpdateTime());
ds.setId(distributedIDService.nextId()); 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.setRowName(m.getRowName() == null ? "" : m.getRowName());
ds.setColumnName(m.getColumnName() == null ? "" : m.getColumnName()); ds.setColumnName(m.getColumnName() == null ? "" : m.getColumnName());
ds.setRowIndex(m.getRowIndex()); ds.setRowIndex(m.getRowIndex());
...@@ -102,4 +101,24 @@ public class FormulaAgent extends VatAbstractService { ...@@ -102,4 +101,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);
}
}
} }
...@@ -38,6 +38,9 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen ...@@ -38,6 +38,9 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
@Autowired @Autowired
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Autowired
private FormulaAgent formulaAgent;
@Override @Override
public String generateData(String projectId, List<Long> templateIds, Boolean ifDeleteManualDataSource, public String generateData(String projectId, List<Long> templateIds, Boolean ifDeleteManualDataSource,
List<String> exceptCellTemplates, Integer periodParam, String generator) { List<String> exceptCellTemplates, Integer periodParam, String generator) {
......
...@@ -78,8 +78,6 @@ public class VatAbstractService { ...@@ -78,8 +78,6 @@ public class VatAbstractService {
@Autowired @Autowired
public ModifiedReportCellMapper modifiedReportCellMapper; public ModifiedReportCellMapper modifiedReportCellMapper;
@Autowired @Autowired
public FormulaAgent formulaAgent;
@Autowired
public CellCommentMapper cellCommentMapper; public CellCommentMapper cellCommentMapper;
@Autowired @Autowired
public KeyValueConfigMapper keyValueConfigMapper; public KeyValueConfigMapper keyValueConfigMapper;
......
...@@ -7,9 +7,7 @@ import org.apache.poi.ss.formula.eval.ValueEval; ...@@ -7,9 +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.common.util.SpringContextUtil;
import pwc.taxtech.atms.dto.vatdto.BBParasBo; import pwc.taxtech.atms.dto.vatdto.BBParasBo;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto; import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource; import pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource;
...@@ -17,7 +15,6 @@ import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo; ...@@ -17,7 +15,6 @@ 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.vat.entity.CellData; import pwc.taxtech.atms.vat.entity.CellData;
import pwc.taxtech.atms.vat.entity.Report;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -57,9 +54,7 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -57,9 +54,7 @@ public class BB extends FunctionBase implements FreeRefFunction {
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();
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL); MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL);
nullCellDto.fixedWithGroup(cellTemplateData); nullCellDto.fixedWithGroup(cellTemplateData);
// todo: fix datasource name by templateList(neo) // todo: fix datasource name by templateList(neo)
...@@ -78,37 +73,22 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -78,37 +73,22 @@ public class BB extends FunctionBase implements FreeRefFunction {
} }
bo.disCount(); bo.disCount();
String dbName = SpringContextUtil.formulaAdminMapper.getPastProjectDbName(curPeriod.getCurYear(), String dbName = agent.getPastProjectDbName(curPeriod.getCurYear(),
formulaContext.getOrganizationID()); formulaContext.getOrganizationID());
String currentProjectDb = ShardingContextHolder.getDataSourceKey(); CellData cellData = agent.getCellData(dbName, cellTemplateData.getReportTemplateID(), curPeriod.getCurPeriod());
ShardingContextHolder.setDataSourceKey(dbName); nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
closeDataSource.clean();
try { closeDataSource.addDS(nullCellDto);
Report report = agent.getReportByTemplate(cellTemplateData.getReportTemplateID(), curPeriod.getCurPeriod()); // todo: fix datasource name by templateList(neo)
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)
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, BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN); BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue); nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value "); LOGGER.debug("cell static value ");
ShardingContextHolder.setDataSourceKey(currentProjectDb); return cellValue;
return cellValue;
} catch (Exception e) {
LOGGER.warn("un support exception", e);
ShardingContextHolder.setDataSourceKey(currentProjectDb);
throw e;
}
} }
} }
......
...@@ -60,8 +60,8 @@ ...@@ -60,8 +60,8 @@
</tx:advice> </tx:advice>
<aop:config proxy-target-class="true"> <aop:config proxy-target-class="true">
<aop:pointcut id="txPointcut2" expression="execution(public * pwc.taxtech.atms..*.*(..)) &amp;&amp; @target(org.springframework.stereotype.Service) <aop:pointcut id="txPointcut2" expression="execution(public * pwc.taxtech.atms..*.*(..)) &amp;&amp;
and !execution(* pwc.taxtech.atms.vat.service.impl.FormulaAgent.*(..))" /> @target(org.springframework.stereotype.Service)" />
<aop:advisor pointcut-ref="txPointcut2" advice-ref="txAdvice" /> <aop:advisor pointcut-ref="txPointcut2" advice-ref="txAdvice" />
</aop:config> </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