Commit 9b65181c authored by frank.xa.zhang's avatar frank.xa.zhang

add parse formula function in the cell_template_config table

parent 014ec32d
......@@ -180,15 +180,34 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
periodFormulaBlockMapper.updateReportId(reportID, cellTemplateConfigIds, period);
}
PeriodFormulaBlockExample periodFormulaBlockExample2 = new PeriodFormulaBlockExample();
periodFormulaBlockExample2.createCriteria().andCellTemplateIdEqualTo(templateID);
List<PeriodFormulaBlock> periodFormulaBlocks = periodFormulaBlockMapper.selectByExample(periodFormulaBlockExample2);
for (PeriodCellTemplateConfig periodCellTemplateConfig : periodCellTemplateConfigs) {
//TODO:如果formula 为 ND(100) +ND(22) ,需要使用正则表达式拆分出自定义公式,然后根据自定义公式取formulablock 的数据进行替换
String regex = "[A-Z]*\\([A-Za-z0-9\\\"\\,\\.\\u4e00-\\u9fa5\\%]*\\)";
Pattern p = Pattern.compile( regex );
Matcher m = p.matcher(periodCellTemplateConfig.getFormula());
while( m.find() )
{
Pattern p = Pattern.compile(regex);
String sourceFormula = periodCellTemplateConfig.getFormula();
String resultFormula = periodCellTemplateConfig.getFormula();
Matcher m = p.matcher(sourceFormula);
Boolean isFind = false;
while (m.find()) {
isFind = true;
//如果有些公式无法用正则匹配,可以做特殊处理
//System.out.println( "匹配项" + count+":" + m.group() ); //group方法返回由以前匹配操作所匹配的输入子序列。
String findStr = m.group();
Optional<PeriodFormulaBlock> formulaBlock = periodFormulaBlocks.stream()
.filter(a -> a.getFormulaExpression().equals(findStr))
.findFirst();
if (formulaBlock.isPresent()) {
resultFormula.replace(findStr, formulaBlock.get().getData());
}
}
//如果有正则匹配就进行更新公式解析
if (isFind) {
periodCellTemplateConfig.setParsedFormula(resultFormula);
periodCellTemplateConfigMapper.updateByPrimaryKey(periodCellTemplateConfig);
}
Optional<PeriodCellTemplate> tempPeriodCellTemplate = periodCellTemplateList.stream()
......
package pwc.taxtech.atms;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static void main(String[] args) {
String regex = "[A-Z]*\\([A-Za-z0-9\\\"\\,\\.\\u4e00-\\u9fa5\\%\\-]*\\)";
String forumula = "ND(2) +ND(1) +A2";
int count = 0;
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(forumula);
while (m.find()) {
//如果有些公式无法用正则匹配,可以做特殊处理
System.out.println("匹配项" + count + ":" + m.group()); //group方法返回由以前匹配操作所匹配的输入子序列。
count++;
}
}
}
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