Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
9b65181c
Commit
9b65181c
authored
Jul 19, 2018
by
frank.xa.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add parse formula function in the cell_template_config table
parent
014ec32d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
ReportGeneratorImpl.java
...wc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
+24
-5
RegexTest.java
atms-api/src/test/java/pwc/taxtech/atms/RegexTest.java
+21
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
View file @
9b65181c
...
...
@@ -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
()
...
...
atms-api/src/test/java/pwc/taxtech/atms/RegexTest.java
0 → 100644
View file @
9b65181c
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
++;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment