Commit c8c8f041 authored by neo's avatar neo

[Bugfix] fixed use regex for psum :

parent 51d42956
......@@ -147,7 +147,7 @@ public class ReportGeneratorImpl {
List<PeriodFormulaBlock> periodFormulaBlocks = periodFormulaBlockMapper.selectByExample(periodFormulaBlockExample2);
//TODO:如果formula 为 ND(100) +ND(22) ,需要使用正则表达式拆分出自定义公式,然后根据自定义公式取formulablock 的数据进行替换
String regex = "[A-Z]*\\([\\-A-Za-z0-9\\\"\\,\\.\\u4e00-\\u9fa5\\%]*\\)";
String regex = "[A-Z]*\\([\\-A-Za-z0-9\\\"\\,\\.\\:\\u4e00-\\u9fa5\\%]*\\)";
Pattern p = Pattern.compile(regex);
String sourceFormula = StringUtils.isNotBlank(periodCellTemplateConfig.getKeyValueParsedFormula()) ?
periodCellTemplateConfig.getKeyValueParsedFormula() :
......@@ -178,60 +178,6 @@ public class ReportGeneratorImpl {
periodCellTemplateConfigMapper.updateByPrimaryKeySelective(periodCellTemplateConfig);
}
String regexNormalCell = "[A-Z]{1,2}((?!0)[0-9]{1,3})";// todo 这里原生引用计算废弃,改用BB
p = Pattern.compile(regexNormalCell);
m = p.matcher(sourceFormula);
while (m.find()) {
//如果找到普通单元格的公式,就去workbook里查找对应的格子取数据,然后放到DataSource,作为普通单元格数据源的数据
//找到一个格子就加一条数据
String findStr = m.group();//A12,A13,A15,how to get A and 12 or A and 13
String regexColumn = "[A-Z]{1,2}";
Pattern pp = Pattern.compile(regexColumn);
Matcher mm = pp.matcher(findStr);
while (mm.find()) {
String colStr = mm.group();
int colNum = FormulaHelper.excelColStrToNum(colStr, colStr.length());
int rowNum = Integer.parseInt(StringUtils.removeStart(findStr, colStr));
Row row = sheet.getRow(rowNum - 1);
if (row != null) {
Cell cell = row.getCell(colNum - 1);
if (cell != null) {
//开始取值然后存放到DataSource
PeriodDataSource dataSource = new PeriodDataSource();
dataSource.setId(distributedIdService.nextId());
dataSource.setColumnIndex(colNum - 1);
dataSource.setRowIndex(rowNum - 1);
if (((XSSFCell) cell).getRawValue() != "#VALUE!") {
dataSource.setAmount(new BigDecimal(
((XSSFCell) cell).getRawValue() != null ?
((XSSFCell) cell).getRawValue()
: (StringUtils.isNotBlank(cell.getStringCellValue())) ?
cell.getStringCellValue()
: Double.toString(cell.getNumericCellValue())));
} else {
dataSource.setAmount(new BigDecimal("0.0"));
}
dataSource.setName("ReportDataSource");
dataSource.setDescription(findStr);
dataSource.setCreateTime(new Date());
dataSource.setUpdateTime(new Date());
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setPeriod(period);
dataSource.setCellTemplateId(periodCellTemplateConfig.getCellTemplateId());
dataSource.setType(FormulaDataSourceType.Report.getCode());
dataSource.setProjectId(projectId);
periodDataSourceMapper.insertSelective(dataSource);
//这里有个问题就是DataSource的数据有了,但是celldatasource的数据没有,后面无法关联celldata和DataSource
//解决办法就是 在存DataSource的时候就先把celldata的数据加好
//然后把celldatasource的数据也加好
//然后在外面去更新celldata和celldatasource的数据
//还有就是把公式里的数据源放到内存,在所有算完之后再统一加数据源
}
}
}
}
Optional<PeriodCellTemplate> tempPeriodCellTemplate = resources.getPeriodCellTemplates().stream()
.filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId()))
.findFirst();
......
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