Commit 4e073be0 authored by neo's avatar neo

[DEV] fixed mualt bb with manula value

parent 649519d1
...@@ -85,19 +85,6 @@ public class ReportGeneratorImpl { ...@@ -85,19 +85,6 @@ public class ReportGeneratorImpl {
return periodResources; 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 @Transactional
public void updateWorkbookCaclsValueToDb(String projectId, Integer period, Workbook workbook, PeriodResources resources, PeriodJob job) { public void updateWorkbookCaclsValueToDb(String projectId, Integer period, Workbook workbook, PeriodResources resources, PeriodJob job) {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) { for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
...@@ -647,55 +634,29 @@ public class ReportGeneratorImpl { ...@@ -647,55 +634,29 @@ public class ReportGeneratorImpl {
if (!parameter.isEmpty()) { if (!parameter.isEmpty()) {
List<PCTEntity> pctResults = periodCellDataMapper.queryByPCTs(parameter, projectId); List<PCTEntity> pctResults = periodCellDataMapper.queryByPCTs(parameter, projectId);
List<PCTEntity> manuaPctResults = periodCellDataMapper.queryManualPCTs(parameter, projectId);
Map<PCTEntity, BigDecimal> pctCache = new HashMap<>(); Map<PCTEntity, PCTEntity> pctCache = new HashMap<>();
Map<PCTEntity, PCTEntity> pctCachePCT = new HashMap<>();
pctResults.forEach(m -> { pctResults.forEach(m -> {
BigDecimal data = null; pctCache.put(m, m);
try {
data = new BigDecimal(m.getData());
} catch (NumberFormatException e) {
logger.warn("number format ecption for parameter {}", m);
data = BigDecimal.ZERO;
}
pctCache.put(m, data);
pctCachePCT.put(m, m);
}); });
configMapToPCTs.forEach((k, v) -> { configMapToPCTs.forEach((k, v) -> {
v.forEach(pctStr -> { v.forEach(pctStr -> {
List<PCTEntity> entities = formulaMapToPCT.get(pctStr); List<PCTEntity> entities = formulaMapToPCT.get(pctStr);
List<PCTEntity> manualEntities = new ArrayList<>(); StringBuilder result = new StringBuilder("0");
BigDecimal result = new BigDecimal("0");
String resultStr = "";
for (PCTEntity entity : entities) { for (PCTEntity entity : entities) {
if (manuaPctResults != null && !manuaPctResults.isEmpty() && manuaPctResults.contains(entity)) { if(pctCache.containsKey(entity)){
for (PCTEntity manual : manuaPctResults) { PCTEntity pct= pctCache.get(entity);
if (manual.equals(entity)) { if(pct.getDsCount()==1&&pct.getAmount()!=null){
manualEntities.add(manual); 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 { }else if(pct.getAmount()==null&&!StringUtils.isNotEmpty(pct.getData())){
result = pctCache.containsKey(entity) ? result.add(pctCache.get(entity)) : result; result.append(pct.getData());
}
}
resultStr = result.toString();
if (!manualEntities.isEmpty()) {
for (PCTEntity m : manualEntities) {
if (pctCachePCT.containsKey(m)) {
if (!StringUtils.isEmpty(pctCachePCT.get(m).getFormulaExp())) {
resultStr += ("+" + pctCachePCT.get(m).getFormulaExp() + "+" + m.getData());
} else {
if (!StringUtils.isEmpty(m.getData()))
resultStr += ("+" + m.getData());
}
} }
} }
} }
k.setParsedFormula(k.getParsedFormula().replace(pctStr, resultStr)); k.setParsedFormula(k.getParsedFormula().replace(pctStr, result.toString()));
}); });
}); });
......
...@@ -115,66 +115,48 @@ public interface PeriodCellDataMapper extends MyVatMapper { ...@@ -115,66 +115,48 @@ public interface PeriodCellDataMapper extends MyVatMapper {
int batchInsert(List<PeriodCellData> list); int batchInsert(List<PeriodCellData> list);
@Select("<script>" +
"SELECT " +
" R.PERIOD as period, C.CELL_TEMPLATE_ID AS cellTemplateId, DATA as data ,FORMULA_EXP as formulaExp " +
"FROM " +
" PERIOD_CELL_DATA C, " +
" PERIOD_REPORT R " +
"WHERE " +
" C.REPORT_ID = R.ID" +
" AND C.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} )" +
" </foreach>" +
"</script>")
List<PCTEntity> queryByPCTs(@Param("list") Set<PCTEntity> parameter, @Param("projectId") String projectId);
@Select("<script>" + @Select("<script>" +
"SELECT " + "SELECT " +
" p.PERIOD AS period, " + " count( pcds.DATA_SOURCE_ID ) AS dsCount, " +
" p.CELL_TEMPLATE_ID AS cellTemplateId, " + " pcd.ID as cellId, " +
" p.AMOUNT AS data " + " pcd.DATA as data, " +
" pcd.FORMULA_EXP as formulaExp, " +
" pcd.CELL_TEMPLATE_ID as cellTemplateId, " +
" pcd.PERIOD as period, " +
" temp.AMOUNT as amount " +
"FROM " + "FROM " +
" PERIOD_DATA_SOURCE p " + " 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 " + "WHERE " +
" PROJECT_ID = #{projectId} AND p.TYPE = 10 AND " + " pcd.PERIOD = 10 " +
" AND pcd.PROJECT_ID = #{projectId} " +
" AND p.TYPE = 10 AND " +
" <foreach item=\"item\" index=\"index\" collection=\"list\"" + " <foreach item=\"item\" index=\"index\" collection=\"list\"" +
" open=\"(\" separator=\"OR\" close=\")\">" + " open=\"(\" separator=\"OR\" close=\")\">" +
" ( p.PERIOD=#{item.period} AND p.CELL_TEMPLATE_ID=#{item.cellTemplateId} )" + " ( pcd.PERIOD=#{item.period} AND pcd.CELL_TEMPLATE_ID=#{item.cellTemplateId} )" +
" </foreach>" + " </foreach>" +
"GROUP BY " +
" pcd.ID, " +
" pcd.DATA, " +
" pcd.FORMULA_EXP, " +
" pcd.CELL_TEMPLATE_ID, " +
" pcd.PERIOD, " +
" temp.AMOUNT;" +
"</script>") "</script>")
List<PCTEntity> queryManualPCTs(@Param("list") Set<PCTEntity> parameter, @Param("projectId") String projectId); 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
...@@ -5,6 +5,9 @@ public class PCTEntity { ...@@ -5,6 +5,9 @@ public class PCTEntity {
Long cellTemplateId; Long cellTemplateId;
String data; String data;
String formulaExp; String formulaExp;
Long cellId;
String amount;
Integer dsCount;
public PCTEntity() { public PCTEntity() {
} }
...@@ -58,4 +61,28 @@ public class PCTEntity { ...@@ -58,4 +61,28 @@ public class PCTEntity {
public void setFormulaExp(String formulaExp) { public void setFormulaExp(String formulaExp) {
this.formulaExp = 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