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
ef7e84a6
Commit
ef7e84a6
authored
May 28, 2018
by
frank.xa.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed report display issue
parent
c9e60f8f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
272 additions
and
8 deletions
+272
-8
RegexMatchType.java
.../java/pwc/taxtech/atms/constant/enums/RegexMatchType.java
+17
-0
TemplateController.java
.../java/pwc/taxtech/atms/controller/TemplateController.java
+1
-1
TemplateFormulaController.java
...wc/taxtech/atms/controller/TemplateFormulaController.java
+31
-0
RegexMatchObject.java
.../src/main/java/pwc/taxtech/atms/dto/RegexMatchObject.java
+96
-0
TemplateFormulaService.java
...java/pwc/taxtech/atms/service/TemplateFormulaService.java
+7
-0
CellConfigTranslater.java
...a/pwc/taxtech/atms/service/impl/CellConfigTranslater.java
+7
-7
FormulaHelper.java
...ain/java/pwc/taxtech/atms/service/impl/FormulaHelper.java
+72
-0
TemplateFormulaServiceImpl.java
...taxtech/atms/service/impl/TemplateFormulaServiceImpl.java
+41
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/constant/enums/RegexMatchType.java
0 → 100644
View file @
ef7e84a6
package
pwc
.
taxtech
.
atms
.
constant
.
enums
;
public
enum
RegexMatchType
{
CellNumber
(
1
),
KeyValue
(
2
),
Equal
(
3
);
private
Integer
code
;
RegexMatchType
(
Integer
code
)
{
this
.
code
=
code
;
}
public
Integer
getCode
()
{
return
code
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/controller/TemplateController.java
View file @
ef7e84a6
...
...
@@ -21,7 +21,7 @@ import java.util.List;
@RestController
@RequestMapping
(
value
=
"api/v1/template"
)
public
class
TemplateController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Account
Controller
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Template
Controller
.
class
);
@Autowired
TemplateService
templateService
;
...
...
atms-api/src/main/java/pwc/taxtech/atms/controller/TemplateFormulaController.java
0 → 100644
View file @
ef7e84a6
package
pwc
.
taxtech
.
atms
.
controller
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
pwc.taxtech.atms.dto.OperationResultDto
;
import
pwc.taxtech.atms.service.TemplateFormulaService
;
@RestController
@RequestMapping
(
value
=
"api/v1/templateFormula"
)
public
class
TemplateFormulaController
{
@Autowired
TemplateFormulaService
templateFormulaService
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TemplateFormulaController
.
class
);
@RequestMapping
(
value
=
"validate"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
@ResponseBody
OperationResultDto
Validate
(
@RequestBody
(
required
=
false
)
String
fromula
)
{
try
{
return
templateFormulaService
.
Validate
(
fromula
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"TemplateFormulaController Valdate"
,
e
);
OperationResultDto
result
=
new
OperationResultDto
();
result
.
setResult
(
false
);
return
result
;
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/dto/RegexMatchObject.java
0 → 100644
View file @
ef7e84a6
package
pwc
.
taxtech
.
atms
.
dto
;
import
org.apache.commons.lang3.StringUtils
;
import
pwc.taxtech.atms.constant.enums.RegexMatchType
;
import
java.util.AbstractMap
;
public
class
RegexMatchObject
{
/**
* GET(int columnIndex, int rowIndex);
*/
private
String
formularTemplate
=
"GET({0},{1})"
;
private
String
keyValueTemplate
=
"KeyValue(\"{0}\")"
;
private
int
index
;
private
int
length
;
private
RegexMatchType
matchType
;
private
AbstractMap
.
SimpleEntry
<
String
,
Integer
>
parameters
;
private
String
expression
;
private
int
fromNumberSystem26
(
String
s
)
{
if
(
StringUtils
.
isEmpty
(
s
))
{
return
0
;
}
int
n
=
0
;
for
(
int
i
=
s
.
length
()
-
1
,
j
=
1
;
i
>=
0
;
i
--,
j
*=
26
)
{
char
c
=
Character
.
toUpperCase
(
s
.
charAt
(
i
));
if
(
c
<
'A'
||
c
>
'Z'
)
{
return
0
;
}
n
+=
((
int
)
c
-
64
)
*
j
;
}
return
n
;
}
public
String
getFormularTemplate
()
{
return
formularTemplate
;
}
public
void
setFormularTemplate
(
String
formularTemplate
)
{
this
.
formularTemplate
=
formularTemplate
;
}
public
String
getKeyValueTemplate
()
{
return
keyValueTemplate
;
}
public
void
setKeyValueTemplate
(
String
keyValueTemplate
)
{
this
.
keyValueTemplate
=
keyValueTemplate
;
}
public
int
getIndex
()
{
return
index
;
}
public
void
setIndex
(
int
index
)
{
this
.
index
=
index
;
}
public
int
getLength
()
{
return
length
;
}
public
void
setLength
(
int
length
)
{
this
.
length
=
length
;
}
public
RegexMatchType
getMatchType
()
{
return
matchType
;
}
public
void
setMatchType
(
RegexMatchType
matchType
)
{
this
.
matchType
=
matchType
;
}
public
AbstractMap
.
SimpleEntry
<
String
,
Integer
>
getParameters
()
{
return
parameters
;
}
public
void
setParameters
(
AbstractMap
.
SimpleEntry
<
String
,
Integer
>
parameters
)
{
this
.
parameters
=
parameters
;
}
public
String
getExpression
()
{
if
(
this
.
matchType
.
equals
(
RegexMatchType
.
CellNumber
.
getCode
()))
{
return
String
.
format
(
formularTemplate
,
fromNumberSystem26
(
this
.
parameters
.
getKey
())
-
1
,
parameters
.
getValue
()
-
1
);
}
else
if
(
this
.
matchType
.
equals
(
RegexMatchType
.
KeyValue
.
getCode
()))
{
return
String
.
format
(
keyValueTemplate
,
this
.
parameters
.
getKey
().
substring
(
1
));
}
else
if
(
this
.
matchType
.
equals
(
RegexMatchType
.
Equal
.
getCode
()))
{
return
"=="
;
}
return
expression
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/service/TemplateFormulaService.java
0 → 100644
View file @
ef7e84a6
package
pwc
.
taxtech
.
atms
.
service
;
import
pwc.taxtech.atms.dto.OperationResultDto
;
public
interface
TemplateFormulaService
{
OperationResultDto
Validate
(
String
formula
);
}
atms-api/src/main/java/pwc/taxtech/atms/service/impl/CellConfigTranslater.java
View file @
ef7e84a6
...
...
@@ -42,7 +42,7 @@ public final class CellConfigTranslater {
cellTemplateConfigDto
.
setIsReadOnly
(
isReadOnly
);
cellTemplateConfigDto
.
setFormulaDescription
(
description
);
Optional
<
CellTemplateConfig
>
formulaItem
=
configList
.
stream
().
filter
(
a
->
a
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"Formula"
))).
findFirst
();
Optional
<
CellTemplateConfig
>
formulaItem
=
configList
.
stream
().
filter
(
a
->
a
.
getDataSourceType
().
equals
(
CellDataSourceType
.
Formula
.
getCode
(
))).
findFirst
();
if
(
formulaItem
.
isPresent
())
{
cellTemplateConfigDto
.
setHasFormula
(
true
);
cellTemplateConfigDto
.
setFormula
(
formulaItem
.
get
().
getFormula
());
...
...
@@ -54,7 +54,7 @@ public final class CellConfigTranslater {
cellTemplateConfigDto
.
setCellTemplateID
(
formulaItem
.
get
().
getCellTemplateID
());
}
Optional
<
CellTemplateConfig
>
voucherItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"Voucher"
))).
findFirst
();
Optional
<
CellTemplateConfig
>
voucherItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
Voucher
.
getCode
(
))).
findFirst
();
if
(
voucherItem
.
isPresent
())
{
cellTemplateConfigDto
.
setHasVoucher
(
true
);
cellTemplateConfigDto
.
setVoucherKeyword
(
voucherItem
.
get
().
getVoucherKeyword
()
==
null
?
""
:
voucherItem
.
get
().
getVoucherKeyword
());
...
...
@@ -63,7 +63,7 @@ public final class CellConfigTranslater {
}
}
Optional
<
CellTemplateConfig
>
invoiceItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"OutputInvoice"
))
||
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"InputInvoice"
))
||
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"CustomInvoice"
))).
findFirst
();
Optional
<
CellTemplateConfig
>
invoiceItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
OutputInvoice
.
getCode
())
||
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
InputInvoice
.
getCode
())
||
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
CustomInvoice
.
getCode
(
))).
findFirst
();
if
(
invoiceItem
.
isPresent
())
{
cellTemplateConfigDto
.
setHasInvoice
(
true
);
cellTemplateConfigDto
.
setInvoiceType
(
invoiceItem
.
get
().
getInvoiceType
());
...
...
@@ -84,18 +84,18 @@ public final class CellConfigTranslater {
}
}
Optional
<
CellTemplateConfig
>
keyInItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"KeyIn"
))).
findFirst
();
Optional
<
CellTemplateConfig
>
keyInItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
KeyIn
.
getCode
(
))).
findFirst
();
if
(
keyInItem
.
isPresent
())
{
cellTemplateConfigDto
.
setHasKeyIn
(
true
);
}
Optional
<
CellTemplateConfig
>
modelItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"RelatedModel"
))).
findFirst
();
Optional
<
CellTemplateConfig
>
modelItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
RelatedModel
.
getCode
(
))).
findFirst
();
if
(
modelItem
.
isPresent
())
{
cellTemplateConfigDto
.
setHasModel
(
true
);
cellTemplateConfigDto
.
setModelIDs
(
GetList
(
modelItem
.
get
().
getModelIDs
()));
}
Optional
<
CellTemplateConfig
>
validationItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
valueOf
(
"Validation"
))).
findFirst
();
Optional
<
CellTemplateConfig
>
validationItem
=
configList
.
stream
().
filter
(
x
->
x
.
getDataSourceType
().
equals
(
CellDataSourceType
.
Validation
.
getCode
(
))).
findFirst
();
if
(
validationItem
.
isPresent
())
{
cellTemplateConfigDto
.
setHasValidation
(
true
);
cellTemplateConfigDto
.
setValidation
(
validationItem
.
get
().
getValidation
());
...
...
@@ -110,6 +110,6 @@ public final class CellConfigTranslater {
return
null
;
}
return
Arrays
.
asList
(
joinString
.
split
(
Constant
.
Comma
));
return
new
ArrayList
<>(
Arrays
.
asList
(
joinString
.
split
(
Constant
.
Comma
)
));
}
}
atms-api/src/main/java/pwc/taxtech/atms/service/impl/FormulaHelper.java
0 → 100644
View file @
ef7e84a6
package
pwc
.
taxtech
.
atms
.
service
.
impl
;
import
org.apache.commons.lang3.StringUtils
;
import
pwc.taxtech.atms.constant.enums.RegexMatchType
;
import
pwc.taxtech.atms.dto.RegexMatchObject
;
import
java.util.AbstractMap
;
import
java.util.Stack
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
final
class
FormulaHelper
{
private
Pattern
regexPattern
,
equalPattern
,
keyValuePattern
;
private
String
strPattern
=
"(?=\\+|-|\\*|/|,|\\(|$|)(?!\")(((?<columnNumber>[A-Z]{1,3})(?<rowNumber>[0-9]{1,7}))|(?<keyCode>@[a-zA-Z0-9.]{1,}))(?=\\+|-|\\*|/| |,|\\)|>|=|<|$|^)(?!\")"
;
private
String
strKeyValuePattern
=
"(?=\\+|-|\\*|/|,|\\(|$|)(?!\")(?<keyCode>@[a-zA-Z0-9.]{1,})(?=\\+|-|\\*|/| |,|\\)|>|=|<|$|^)(?!\")"
;
private
String
strEqualPattern
=
"(?<![<>])(?<equal>=)"
;
public
FormulaHelper
()
{
regexPattern
=
Pattern
.
compile
(
strPattern
);
equalPattern
=
Pattern
.
compile
(
strEqualPattern
);
keyValuePattern
=
Pattern
.
compile
(
strKeyValuePattern
);
}
public
String
FormatFormula
(
String
formula
)
{
Matcher
equalMatchResult
=
equalPattern
.
matcher
(
formula
);
Stack
<
RegexMatchObject
>
equalMatchObjectStack
=
new
Stack
<>();
while
(
equalMatchResult
.
find
())
{
if
(
StringUtils
.
isNotBlank
(
equalMatchResult
.
group
(
"equal"
)))
{
RegexMatchObject
object
=
new
RegexMatchObject
();
object
.
setIndex
(
equalMatchResult
.
start
());
object
.
setLength
(
equalMatchResult
.
end
()
-
equalMatchResult
.
start
()
+
1
);
object
.
setMatchType
(
RegexMatchType
.
Equal
);
object
.
setParameters
(
new
AbstractMap
.
SimpleEntry
<>(
equalMatchResult
.
group
(
"equal"
),
-
1
));
equalMatchObjectStack
.
push
(
object
);
}
}
while
(
equalMatchObjectStack
.
size
()
>
0
)
{
RegexMatchObject
obj
=
equalMatchObjectStack
.
pop
();
formula
=
formula
.
substring
(
0
,
obj
.
getIndex
())
+
obj
.
getExpression
()
+
formula
.
substring
(
obj
.
getIndex
()
+
obj
.
getLength
());
}
Matcher
regexResult
=
regexPattern
.
matcher
(
formula
);
Stack
<
RegexMatchObject
>
regexMatchObjectStack
=
new
Stack
<>();
while
(
regexResult
.
find
())
{
if
(
StringUtils
.
isNotBlank
(
regexResult
.
group
(
"columnNumber"
))
&&
StringUtils
.
isNotBlank
(
regexResult
.
group
(
"rowNumber"
)))
{
RegexMatchObject
object
=
new
RegexMatchObject
();
object
.
setIndex
(
regexResult
.
start
());
object
.
setLength
(
regexResult
.
end
()
-
regexResult
.
start
()
+
1
);
object
.
setMatchType
(
RegexMatchType
.
CellNumber
);
object
.
setParameters
(
new
AbstractMap
.
SimpleEntry
<>(
regexResult
.
group
(
"columnNumber"
),
Integer
.
parseInt
(
regexResult
.
group
(
"rowNumber"
))));
regexMatchObjectStack
.
push
(
object
);
}
if
(
StringUtils
.
isNotBlank
(
regexResult
.
group
(
"keyCode"
)))
{
RegexMatchObject
object
=
new
RegexMatchObject
();
object
.
setIndex
(
regexResult
.
start
());
object
.
setLength
(
regexResult
.
end
()
-
regexResult
.
start
()
+
1
);
object
.
setMatchType
(
RegexMatchType
.
CellNumber
);
object
.
setParameters
(
new
AbstractMap
.
SimpleEntry
<>(
regexResult
.
group
(
"keyCode"
),
-
1
));
regexMatchObjectStack
.
push
(
object
);
}
}
while
(!
regexMatchObjectStack
.
empty
())
{
RegexMatchObject
obj
=
regexMatchObjectStack
.
pop
();
formula
=
formula
.
substring
(
0
,
obj
.
getIndex
())
+
obj
.
getExpression
()
+
formula
.
substring
(
obj
.
getIndex
(),
obj
.
getLength
());
}
return
formula
.
trim
();
}
}
atms-api/src/main/java/pwc/taxtech/atms/service/impl/TemplateFormulaServiceImpl.java
0 → 100644
View file @
ef7e84a6
package
pwc
.
taxtech
.
atms
.
service
.
impl
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
pwc.taxtech.atms.dto.OperationResultDto
;
import
pwc.taxtech.atms.service.TemplateFormulaService
;
@Service
public
class
TemplateFormulaServiceImpl
extends
AbstractService
implements
TemplateFormulaService
{
private
FormulaHelper
_formulaHelper
=
new
FormulaHelper
();
//private static ScriptEngine m_engine = Python.CreateEngine();
@Override
public
OperationResultDto
Validate
(
String
formula
)
{
OperationResultDto
result
=
new
OperationResultDto
();
if
(
StringUtils
.
isBlank
(
formula
))
{
result
.
setResult
(
true
);
return
result
;
}
try
{
String
tidyFormula
=
_formulaHelper
.
FormatFormula
(
formula
);
/*todo: find the replace solution for here to check formual is correct or not
//var sourceCode = m_engine.CreateScriptSourceFromString(tidyFormula, SourceCodeKind.AutoDetect);
//var compileCode = sourceCode.Compile();
rtn.Result = compileCode != null;*/
result
.
setResult
(
true
);
return
result
;
}
catch
(
Exception
e
)
{
result
.
setResult
(
false
);
result
.
setResultMsg
(
e
.
getMessage
());
}
return
null
;
}
}
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