Commit 289e24a7 authored by neo.wang's avatar neo.wang

Merge branch 'dev_oracle_neo' into 'dev_oracle'

Dev oracle neo

See merge request root/atms!180
parents e522e8a9 f6a33be1
......@@ -85,24 +85,12 @@ 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);
String code = sheet.getSheetName();
job.setCurrentStep(code);
Optional<PeriodTemplate> periodTemplate = resources.getPeriodTemplates().stream()
.filter(a -> a.getCode().equals(code))
.findFirst();
......@@ -325,15 +313,19 @@ public class ReportGeneratorImpl {
cellData.setUpdateTime(new Date());
cellData.setProjectId(projectId);
cellData.setPeriod(period);
periodCellDataMapper.insertSelective(cellData);
//after insert celldata, insert the celldatasource for link celldata and datasource
PeriodDataSourceExample dataSourceExample = new PeriodDataSourceExample();
dataSourceExample.createCriteria().andPeriodEqualTo(period)
dataSourceExample.createCriteria().andPeriodEqualTo(period).andProjectIdEqualTo(projectId)
.andCellTemplateIdEqualTo(tempPeriodCellTemplate.get().getCellTemplateId());
List<PeriodDataSource> dataSourceList = SpringContextUtil.periodDataSourceMapper.selectByExample(dataSourceExample);
for (int ii = 0; ii < dataSourceList.size(); ii++) {
PeriodDataSource dataSource = dataSourceList.get(ii);
if (dataSource.getType().intValue() == 10) {//s手工数据源
cellData.setData(dataSource.getAmount() + "");
}
PeriodCellDataSource cellDataSource = new PeriodCellDataSource();
cellDataSource.setId(distributedIdService.nextId());
cellDataSource.setCellTemplateId(tempPeriodCellTemplate.get().getCellTemplateId());
......@@ -345,6 +337,8 @@ public class ReportGeneratorImpl {
cellDataSource.setProjectId(projectId);
SpringContextUtil.periodCellDataSourceMapper.insertSelective(cellDataSource);
}
periodCellDataMapper.insertSelective(cellData);
}
}
}
......@@ -353,9 +347,7 @@ public class ReportGeneratorImpl {
e.printStackTrace();
job.setStatus(WrapPeriodJobDto.STATUS_ERROR);
job.setErrorMsg("cacals report for code " + code + " failed");
} finally {
job.setCurrentStep(code);
periodJobMapper.updateByPrimaryKey(job);
}
}
......@@ -642,24 +634,27 @@ public class ReportGeneratorImpl {
if (!parameter.isEmpty()) {
List<PCTEntity> pctResults = periodCellDataMapper.queryByPCTs(parameter, projectId);
Map<PCTEntity, BigDecimal> pctCache = new HashMap<>();
Map<PCTEntity, PCTEntity> pctCache = new HashMap<>();
pctResults.forEach(m -> {
BigDecimal data = null;
try {
data = new BigDecimal(m.getData());
} catch (NumberFormatException e) {
logger.warn("number format ecption for parameter {}", m);
data = BigDecimal.ZERO;
}
pctCache.put(m, data);
pctCache.put(m, m);
});
configMapToPCTs.forEach((k, v) -> {
v.forEach(pctStr -> {
List<PCTEntity> entities = formulaMapToPCT.get(pctStr);
BigDecimal result = new BigDecimal("0");
StringBuilder result = new StringBuilder("0");
for (PCTEntity entity : entities) {
result = pctCache.containsKey(entity) ? result.add(pctCache.get(entity)) : result;
if(pctCache.containsKey(entity)){
PCTEntity pct= pctCache.get(entity);
if(pct.getDsCount()==1&&pct.getAmount()!=null){
result.append("+").append(pct.getAmount());
}else if(pct.getDsCount()>1&&pct.getAmount()!=null&&!StringUtils.isEmpty(pct.getFormulaExp())){
result.append("+").append(pct.getFormulaExp()).append("+").append(pct.getAmount());
}else if(pct.getAmount()==null&&!StringUtils.isNotEmpty(pct.getData())){
result.append(pct.getData());
}
}
}
k.setParsedFormula(k.getParsedFormula().replace(pctStr, result.toString()));
});
......
......@@ -201,13 +201,8 @@ public class ReportServiceImpl {
.andPeriodEqualTo(period);
List<PeriodDataSource> periodDataSources = periodDataSourceMapper.selectByExample(periodDataSourceExample);
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<>();
if (isMergeManualData) {
periodDataSources.forEach(m -> {
......@@ -218,36 +213,17 @@ public class ReportServiceImpl {
}
});
if (!periodManualDsIds.isEmpty()) {
PeriodCellDataSourceExample periodCellDataSourceExample = new PeriodCellDataSourceExample();
periodCellDataSourceExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andDataSourceIdIn(periodManualDsIds);
List<PeriodCellDataSource> manualCellDataSource = periodCellDataSourceMapper.selectByExample(periodCellDataSourceExample);
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(Lists.newArrayList(periodDsIds));
periodDataSourceDetailMapper.deleteByExample(periodDataSourceDetailExample);
PeriodCellDataSourceExample periodCellDataSourceExample = new PeriodCellDataSourceExample();
periodCellDataSourceExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andDataSourceIdIn(Lists.newArrayList(periodDsIds));
periodCellDataSourceExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period);
periodCellDataSourceMapper.deleteByExample(periodCellDataSourceExample);
......@@ -257,35 +233,31 @@ public class ReportServiceImpl {
PeriodReportExample periodReportExample = new PeriodReportExample();
periodReportExample.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period);
periodReportMapper.deleteByExample(periodReportExample);
List<PeriodReport> reports = periodReportMapper.selectByExample(periodReportExample);
List<Long> reportIds = Lists.newArrayList(Long.MAX_VALUE);
reportIds.addAll(reports.stream().map(m -> m.getId()).collect(Collectors.toList()));
PeriodCellDataExample periodCellDataExample = new PeriodCellDataExample();
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);
}
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 {
job.setStatus(WrapPeriodJobDto.STATUS_BEGIN);
List<Long> exceptTemplateIds = templateMapper.getIdsForExceptTemplate();
clearPeriodData(projectId, period, exceptTemplateIds, isMergeManualData);
copyTemplateAndConfigFromAdmin(projectId, templates, period);
} catch (Exception ex) {
job.setStatus(WrapPeriodJobDto.STATUS_ERROR);
job.setErrorMsg("error update config with projectId " + projectId + " period" + period);
periodJobMapper.updateByPrimaryKey(job);
logger.error(ex.getMessage(), ex);
}finally {
periodJobMapper.updateByPrimaryKey(job);
}
}
......@@ -515,15 +487,14 @@ public class ReportServiceImpl {
reportGenerator.updateWorkbookCaclsValueToDb(projectId, periodParam, workbook, resources, genJob);
reportGenerator.updateManaCellDataWithNewReport(projectId, periodParam);
genJob.setStatus(WrapPeriodJobDto.STATUS_END);
periodJobMapper.updateByPrimaryKey(genJob);
}catch (Exception e){
e.printStackTrace();
genJob.setStatus(WrapPeriodJobDto.STATUS_ERROR);
genJob.setErrorMsg("Server error");
}finally {
genJob.setErrorMsg("Sever error");
periodJobMapper.updateByPrimaryKey(genJob);
e.printStackTrace();
}
}
}).start();
......
......@@ -27,7 +27,15 @@ public interface FormulaAdminMapper extends MyMapper {
" JOIN " +
" cell_template ON template.id = cell_template.report_template_id " +
"WHERE " +
" template.template_group_id = #{groupId}")
" template.id IN ( " +
" SELECT " +
" ID " +
" FROM " +
" TEMPLATE " +
" WHERE " +
" TEMPLATE_GROUP_ID = #{groupId} " +
" AND IS_ACTIVE_ASSOCIATION = 1 " +
" )")
List<CellTemplatePerGroupDto> getCellTemplatePerGroupDto(@Param("groupId") Long groupId);
......
......@@ -116,50 +116,46 @@ public interface PeriodCellDataMapper extends MyVatMapper {
int batchInsert(List<PeriodCellData> list);
@Select("<script>" +
"SELECT " +
" R.PERIOD, C.CELL_TEMPLATE_ID AS CELLTEMPLATEID, DATA " +
"SELECT " +
" count( pcds.DATA_SOURCE_ID ) AS dsCount, " +
" pcd.ID as cellId, " +
" pcd.DATA as data, " +
" pcd.FORMULA_EXP as formulaExp, " +
" pcd.CELL_TEMPLATE_ID as cellTemplateId, " +
" pcd.PERIOD as period, " +
" temp.AMOUNT as amount " +
"FROM " +
" PERIOD_CELL_DATA C, " +
" PERIOD_REPORT R " +
" PERIOD_CELL_DATA pcd " +
" JOIN PERIOD_CELL_DATA_SOURCE pcds ON pcd.ID = pcds.CELL_DATA_ID " +
" LEFT JOIN ( " +
" SELECT " +
" pcd.ID, " +
" pds.TYPE, " +
" pds.AMOUNT, " +
" pds.PERIOD, " +
" pds.PROJECT_ID " +
" FROM " +
" PERIOD_CELL_DATA pcd " +
" JOIN PERIOD_CELL_DATA_SOURCE pcds ON pcd.ID = pcds.CELL_DATA_ID " +
" JOIN PERIOD_DATA_SOURCE pds ON pcds.DATA_SOURCE_ID = pds.ID " +
" WHERE " +
" pcd.PROJECT_ID = #{projectId} " +
" AND pds.TYPE = 10 " +
" ) temp ON pcd.ID = temp.ID AND pcd.PROJECT_ID = temp.PROJECT_ID and pcd.PERIOD = temp.period " +
"WHERE " +
" C.REPORT_ID = R.ID" +
" AND C.PROJECT_ID = #{projectId} AND " +
" " +
" pcd.PERIOD = 10 " +
" AND pcd.PROJECT_ID = #{projectId} AND " +
" <foreach item=\"item\" index=\"index\" collection=\"list\"" +
" open=\"(\" separator=\"OR\" close=\")\">" +
" ( R.PERIOD=#{item.period} AND C.CELL_TEMPLATE_ID=#{item.cellTemplateId} )" +
" ( pcd.PERIOD=#{item.period} AND pcd.CELL_TEMPLATE_ID=#{item.cellTemplateId} )" +
" </foreach>" +
"GROUP BY " +
" pcd.ID, " +
" pcd.DATA, " +
" pcd.FORMULA_EXP, " +
" pcd.CELL_TEMPLATE_ID, " +
" pcd.PERIOD, " +
" temp.AMOUNT" +
"</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
......@@ -4,6 +4,10 @@ public class PCTEntity {
Integer period;
Long cellTemplateId;
String data;
String formulaExp;
Long cellId;
String amount;
Integer dsCount;
public PCTEntity() {
}
......@@ -49,4 +53,36 @@ public class PCTEntity {
public void setData(String data) {
this.data = data;
}
public String getFormulaExp() {
return formulaExp;
}
public void setFormulaExp(String formulaExp) {
this.formulaExp = formulaExp;
}
public Long getCellId() {
return cellId;
}
public void setCellId(Long cellId) {
this.cellId = cellId;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public Integer getDsCount() {
return dsCount;
}
public void setDsCount(Integer dsCount) {
this.dsCount = dsCount;
}
}
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