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
7f336aed
Commit
7f336aed
authored
Jul 03, 2018
by
frank.xa.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add function SGSR method
parent
b3ec20cc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
0 deletions
+170
-0
FormulaContext.java
...tms/vat/service/impl/report/functions/FormulaContext.java
+22
-0
FormulaHelper.java
...atms/vat/service/impl/report/functions/FormulaHelper.java
+75
-0
SGSRFunction.java
.../atms/vat/service/impl/report/functions/SGSRFunction.java
+73
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FormulaContext.java
0 → 100644
View file @
7f336aed
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
.
report
.
functions
;
public
class
FormulaContext
{
private
Integer
period
;
private
Integer
year
;
public
Integer
getPeriod
()
{
return
period
;
}
public
void
setPeriod
(
Integer
period
)
{
this
.
period
=
period
;
}
public
Integer
getYear
()
{
return
year
;
}
public
void
setYear
(
Integer
year
)
{
this
.
year
=
year
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FormulaHelper.java
0 → 100644
View file @
7f336aed
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
.
report
.
functions
;
public
class
FormulaHelper
{
/**
* Excel column index begin 1
*
* @param colStr
* @param length
* @return
*/
public
static
int
excelColStrToNum
(
String
colStr
,
int
length
)
{
int
num
=
0
;
int
result
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
char
ch
=
colStr
.
charAt
(
length
-
i
-
1
);
num
=
(
int
)
(
ch
-
'A'
+
1
);
num
*=
Math
.
pow
(
26
,
i
);
result
+=
num
;
}
return
result
;
}
/**
* Excel column index begin 1
*
* @param columnIndex
* @return
*/
public
static
String
excelColIndexToStr
(
int
columnIndex
)
{
if
(
columnIndex
<=
0
)
{
return
null
;
}
String
columnStr
=
""
;
columnIndex
--;
do
{
if
(
columnStr
.
length
()
>
0
)
{
columnIndex
--;
}
columnStr
=
((
char
)
(
columnIndex
%
26
+
(
int
)
'A'
))
+
columnStr
;
columnIndex
=
(
int
)
((
columnIndex
-
columnIndex
%
26
)
/
26
);
}
while
(
columnIndex
>
0
);
return
columnStr
;
}
public
static
int
getPeriod
(
int
parameterPeriod
,
int
[]
yearOffset
,
FormulaContext
formulaFunctionContext
)
{
yearOffset
[
0
]
=
0
;
if
(
parameterPeriod
==
-
99
)
{
return
parameterPeriod
;
}
else
if
(
parameterPeriod
<=
-
1
)
{
int
period
=
parameterPeriod
+
formulaFunctionContext
.
getPeriod
();
while
(
period
<=
0
)
{
yearOffset
[
0
]--;
period
+=
12
;
//throw new NotImplementedException();
}
return
period
;
}
else
if
(
parameterPeriod
==
0
)
{
return
formulaFunctionContext
.
getPeriod
();
}
else
{
return
parameterPeriod
;
}
}
public
static
int
getYear
(
int
parameterYear
,
FormulaContext
formulaContext
)
{
if
(
parameterYear
<=
-
1
)
{
return
parameterYear
+
formulaContext
.
getYear
();
}
else
if
(
parameterYear
==
0
)
{
return
formulaContext
.
getYear
();
}
else
{
return
parameterYear
;
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/SGSRFunction.java
0 → 100644
View file @
7f336aed
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
.
report
.
functions
;
import
org.apache.poi.ss.formula.OperationEvaluationContext
;
import
org.apache.poi.ss.formula.eval.EvaluationException
;
import
org.apache.poi.ss.formula.eval.OperandResolver
;
import
org.apache.poi.ss.formula.eval.ValueEval
;
import
org.apache.poi.ss.formula.functions.FreeRefFunction
;
public
class
SGSRFunction
implements
FreeRefFunction
{
private
FormulaContext
formulaContext
;
public
SGSRFunction
(
FormulaContext
formulaContext
){
this
.
formulaContext
=
formulaContext
;
}
@Override
public
ValueEval
evaluate
(
ValueEval
[]
valueEvals
,
OperationEvaluationContext
operationEvaluationContext
)
{
try
{
int
period
,
year
,
colIndex
,
rowIndex
;
String
reportCode
;
if
(
valueEvals
.
length
>
4
)
{
ValueEval
v5
=
OperandResolver
.
getSingleValue
(
valueEvals
[
4
],
operationEvaluationContext
.
getRowIndex
(),
operationEvaluationContext
.
getColumnIndex
());
year
=
OperandResolver
.
coerceValueToInt
(
v5
);
}
else
{
year
=
0
;
}
ValueEval
v1
=
OperandResolver
.
getSingleValue
(
valueEvals
[
0
],
operationEvaluationContext
.
getRowIndex
(),
operationEvaluationContext
.
getColumnIndex
());
reportCode
=
OperandResolver
.
coerceValueToString
(
v1
);
ValueEval
v2
=
OperandResolver
.
getSingleValue
(
valueEvals
[
1
],
operationEvaluationContext
.
getRowIndex
(),
operationEvaluationContext
.
getColumnIndex
());
String
cIndex
=
OperandResolver
.
coerceValueToString
(
v2
);
colIndex
=
FormulaHelper
.
excelColStrToNum
(
cIndex
,
cIndex
.
length
());
ValueEval
v3
=
OperandResolver
.
getSingleValue
(
valueEvals
[
2
],
operationEvaluationContext
.
getRowIndex
(),
operationEvaluationContext
.
getColumnIndex
());
rowIndex
=
OperandResolver
.
coerceValueToInt
(
v3
);
ValueEval
v4
=
OperandResolver
.
getSingleValue
(
valueEvals
[
3
],
operationEvaluationContext
.
getRowIndex
(),
operationEvaluationContext
.
getColumnIndex
());
period
=
OperandResolver
.
coerceValueToInt
(
v4
);
int
curYear
,
curPeriod
;
if
(
reportCode
.
startsWith
(
"VAT"
)){
int
[]
yearOffSet
=
{};
curPeriod
=
FormulaHelper
.
getPeriod
(
period
,
yearOffSet
,
formulaContext
);
curYear
=
FormulaHelper
.
getYear
(
year
,
formulaContext
)+
yearOffSet
[
0
];
}
else
if
(
reportCode
.
startsWith
(
"CIT."
)){
curYear
=
FormulaHelper
.
getYear
(
year
,
formulaContext
);
curPeriod
=
0
;
}
else
{
}
}
catch
(
EvaluationException
e
)
{
e
.
printStackTrace
();
}
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