Commit a913acb5 authored by eddie.woo's avatar eddie.woo

Merge branch 'dev_oracle' of http://code.tech.tax.asia.pwcinternal.com/root/atms into dev_oracle

parents 252ed411 1f52b42a
......@@ -14,6 +14,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.CellDataSourceType;
......@@ -26,6 +27,7 @@ import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.service.impl.DistributedIdService;
import pwc.taxtech.atms.service.impl.HttpFileService;
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.dpo.MergerManaualCellData;
import pwc.taxtech.atms.vat.dpo.PeriodCellTemplateConfigExtendDto;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.impl.report.functions.*;
......@@ -83,6 +85,20 @@ public class ReportGeneratorImpl {
return periodResources;
}
@Transactional
public void updateManaCellDataWithNewReport(String projectId, Integer period) {
List<MergerManaualCellData> result = periodCellDataMapper.selectManualToBeMerged(projectId, period);
if (!result.isEmpty()) {
result.forEach(m -> {
PeriodCellData pcd = new PeriodCellData();
pcd.setId(m.getId());
pcd.setReportId(m.getNewReportId());
periodCellDataMapper.updateByPrimaryKeySelective(pcd);
});
}
}
@Transactional
public void updateWorkbookCaclsValueToDb(String projectId, Integer period, Workbook workbook, PeriodResources resources, PeriodJob job) {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
......@@ -336,9 +352,9 @@ public class ReportGeneratorImpl {
} catch (Exception e) {
e.printStackTrace();
job.setStatus(WrapPeriodJobDto.STATUS_ERROR);
job.setErrorMsg("cacals report for code "+code +" failed");
job.setErrorMsg("cacals report for code " + code + " failed");
}finally {
} finally {
job.setCurrentStep(code);
periodJobMapper.updateByPrimaryKey(job);
}
......
......@@ -2,6 +2,7 @@ package pwc.taxtech.atms.vat.service.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
......@@ -10,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.common.util.SpringContextUtil;
......@@ -198,7 +200,12 @@ public class ReportServiceImpl {
periodDataSourceExample.createCriteria().andProjectIdEqualTo(projectId)
.andPeriodEqualTo(period);
List<PeriodDataSource> periodDataSources = periodDataSourceMapper.selectByExample(periodDataSourceExample);
List<Long> periodDsIds = Lists.newArrayList(Long.MAX_VALUE);
PeriodCellDataSourceExample allMappingExample = new PeriodCellDataSourceExample();
allMappingExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period);
List<PeriodCellDataSource> allPcds = periodCellDataSourceMapper.selectByExample(allMappingExample);
Set<Long> periodDsIds = Sets.newHashSet(Long.MAX_VALUE);
List<Long> periodManualDsIds = new ArrayList<>();
List<Long> periodManualCellDataIds = new ArrayList<>();
......@@ -216,27 +223,36 @@ public class ReportServiceImpl {
periodCellDataSourceExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andDataSourceIdIn(periodManualDsIds);
List<PeriodCellDataSource> manualCellDataSource = periodCellDataSourceMapper.selectByExample(periodCellDataSourceExample);
if (!manualCellDataSource.isEmpty())
if (!manualCellDataSource.isEmpty()) {
periodManualCellDataIds.addAll(manualCellDataSource.stream().map(PeriodCellDataSource::getCellDataId)
.collect(Collectors.toList()));
}
}
if (!allPcds.isEmpty()) {
List<Long> allPcdsIds = allPcds.stream().map(m -> m.getDataSourceId()).collect(Collectors.toList());
allPcdsIds.removeAll(periodManualDsIds);
periodDsIds.addAll(allPcdsIds);
}
} else {
periodDsIds.addAll(periodDataSources.stream().map(m -> m.getId()).collect(Collectors.toList()));
if (!allPcds.isEmpty())
periodDsIds.addAll(allPcds.stream().map(m -> m.getDataSourceId()).collect(Collectors.toList()));
}
PeriodDataSourceDetailExample periodDataSourceDetailExample = new PeriodDataSourceDetailExample();
periodDataSourceDetailExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andDataSourceIdIn(periodDsIds);
.andDataSourceIdIn(Lists.newArrayList(periodDsIds));
periodDataSourceDetailMapper.deleteByExample(periodDataSourceDetailExample);
PeriodCellDataSourceExample periodCellDataSourceExample = new PeriodCellDataSourceExample();
periodCellDataSourceExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andDataSourceIdIn(periodDsIds);
.andDataSourceIdIn(Lists.newArrayList(periodDsIds));
periodCellDataSourceMapper.deleteByExample(periodCellDataSourceExample);
PeriodDataSourceExample periodDataSourceDeleteExample = new PeriodDataSourceExample();
periodDataSourceDeleteExample.createCriteria().andIdIn(periodDsIds);
periodDataSourceDeleteExample.createCriteria().andIdIn(Lists.newArrayList(periodDsIds));
periodDataSourceMapper.deleteByExample(periodDataSourceDeleteExample);
PeriodReportExample periodReportExample = new PeriodReportExample();
......@@ -247,18 +263,18 @@ public class ReportServiceImpl {
reportIds.addAll(reports.stream().map(m -> m.getId()).collect(Collectors.toList()));
PeriodCellDataExample periodCellDataExample = new PeriodCellDataExample();
if (!periodManualCellDataIds.isEmpty()) {
periodCellDataExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period).andReportIdIn(
reportIds).andIdNotIn(periodManualCellDataIds);
if (isMergeManualData) {
if (periodManualCellDataIds.isEmpty()) periodManualCellDataIds.add(Long.MAX_VALUE);
periodCellDataExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period).andIdNotIn(periodManualCellDataIds);
} else {
periodCellDataExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period).andReportIdIn(
reportIds);
periodCellDataExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period);
}
periodCellDataMapper.deleteByExample(periodCellDataExample);
periodReportMapper.deleteByExample(periodReportExample);
}
@Transactional
private void updateConfig(String projectId, Integer period, Boolean isMergeManualData, List<Template> templates, PeriodJob job) {
try {
List<Long> exceptTemplateIds = templateMapper.getIdsForExceptTemplate();
......@@ -482,6 +498,8 @@ public class ReportServiceImpl {
new Thread(new Runnable() {
@Override
public void run() {
try {
updateConfig(projectId, periodParam, isMergeManualData, templates, genJob);
PeriodResources resources = reportGenerator.getPeriodResources(projectId, periodParam,
......@@ -496,9 +514,18 @@ public class ReportServiceImpl {
evaluator.evaluateAll();
reportGenerator.updateWorkbookCaclsValueToDb(projectId, periodParam, workbook, resources, genJob);
reportGenerator.updateManaCellDataWithNewReport(projectId, periodParam);
genJob.setStatus(WrapPeriodJobDto.STATUS_END);
}catch (Exception e){
e.printStackTrace();
genJob.setStatus(WrapPeriodJobDto.STATUS_ERROR);
genJob.setErrorMsg("Server error");
}finally {
periodJobMapper.updateByPrimaryKey(genJob);
}
}
}).start();
operationResultDto.setData(genJob);
operationResultDto.setResult(true);
......
......@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.vat.dpo.MergerManaualCellData;
import pwc.taxtech.atms.vat.entity.PCTEntity;
import pwc.taxtech.atms.vat.entity.PeriodCellData;
import pwc.taxtech.atms.vat.entity.PeriodCellDataExample;
......@@ -130,4 +131,35 @@ public interface PeriodCellDataMapper extends MyVatMapper {
" </foreach>" +
"</script>")
List<PCTEntity> queryByPCTs(@Param("list") Set<PCTEntity> parameter, @Param("projectId") String projectId);
@Select("" +
"SELECT " +
" d.ID AS id, " +
" d.REPORT_ID AS reportId, " +
" d.CELL_TEMPLATE_ID AS cellTemplateId, " +
" p.REPORT_TEMPLATE_ID AS templateId, " +
" t.ID AS newReportId " +
"FROM " +
" PERIOD_CELL_DATA d " +
" JOIN PERIOD_CELL_TEMPLATE p ON d.CELL_TEMPLATE_ID = p.CELL_TEMPLATE_ID " +
" LEFT JOIN PERIOD_REPORT t ON p.REPORT_TEMPLATE_ID = t.TEMPLATE_ID " +
"WHERE " +
" d.PROJECT_ID = #{projectId} " +
" AND p.PROJECT_ID = #{projectId} " +
" AND t.PROJECT_ID = #{projectId} " +
" AND d.PERIOD = #{period} " +
" AND p.PERIOD = #{period} " +
" AND t.PERIOD = #{period} " +
" AND d.REPORT_ID NOT IN ( " +
" SELECT " +
" ID " +
" FROM " +
" PERIOD_REPORT " +
" WHERE " +
" PROJECT_ID = #{projectId} " +
" AND PERIOD = #{period} " +
" )" +
"")
List<MergerManaualCellData> selectManualToBeMerged(@Param("projectId") String projectId, @Param("period") Integer period);
}
\ No newline at end of file
package pwc.taxtech.atms.vat.dpo;
public class MergerManaualCellData {
private Long id;
private Long reportId;
private Long cellTemplateId;
private Long templateId;
private Long newReportId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getReportId() {
return reportId;
}
public void setReportId(Long reportId) {
this.reportId = reportId;
}
public Long getCellTemplateId() {
return cellTemplateId;
}
public void setCellTemplateId(Long cellTemplateId) {
this.cellTemplateId = cellTemplateId;
}
public Long getTemplateId() {
return templateId;
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public Long getNewReportId() {
return newReportId;
}
public void setNewReportId(Long newReportId) {
this.newReportId = newReportId;
}
}
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