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
ca1d2cdd
Commit
ca1d2cdd
authored
Jul 13, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DEV] delete formula factory and use formula base
parent
f1d87ace
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
149 deletions
+135
-149
FormulaAgent.java
.../java/pwc/taxtech/atms/vat/service/impl/FormulaAgent.java
+3
-4
ReportFormulaFactory.java
...c/taxtech/atms/vat/service/impl/ReportFormulaFactory.java
+0
-143
ReportGeneratorImpl.java
...wc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
+3
-2
BB.java
...wc/taxtech/atms/vat/service/impl/report/functions/BB.java
+115
-0
FunctionBase.java
.../atms/vat/service/impl/report/functions/FunctionBase.java
+14
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/FormulaAgent.java
View file @
ca1d2cdd
...
...
@@ -6,7 +6,6 @@ import pwc.taxtech.atms.constant.enums.EnumServiceType;
import
pwc.taxtech.atms.dao.FormulaAdminMapper
;
import
pwc.taxtech.atms.dto.GroupId
;
import
pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto
;
import
pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto
;
import
pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto
;
import
pwc.taxtech.atms.entitiy.ProjectServiceType
;
import
pwc.taxtech.atms.entitiy.ProjectServiceTypeExample
;
...
...
@@ -92,9 +91,9 @@ public class FormulaAgent extends VatAbstractService {
ds
.
setUpdateBy
(
m
.
getUpdater
()
==
null
?
"Admin"
:
m
.
getUpdater
());
ds
.
setUpdateTime
(
m
.
getUpdateTime
()
==
null
?
new
Date
()
:
m
.
getUpdateTime
());
ds
.
setId
(
distributedIDService
.
nextId
());
ds
.
setKeyValueDataId
(
m
.
getDescription
()
==
null
""
:
m
.
getDescription
());
//TODO: tobe fixed
ds
.
setRowName
(
m
.
getRowName
()
==
null
?
""
:
m
.
getRowName
());
ds
.
setColumnName
(
m
.
getColumnName
()
==
null
?
""
:
m
.
getColumnName
());
ds
.
setKeyValueDataId
(
m
.
getDescription
()
==
null
?
""
:
m
.
getDescription
());
//TODO: tobe fixed
ds
.
setRowName
(
m
.
getRowName
()
==
null
?
""
:
m
.
getRowName
());
ds
.
setColumnName
(
m
.
getColumnName
()
==
null
?
""
:
m
.
getColumnName
());
ds
.
setRowIndex
(
m
.
getRowIndex
());
ds
.
setColumnIndex
(
m
.
getColumnIndex
());
dataSourceMapper
.
insert
(
ds
);
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportFormulaFactory.java
deleted
100644 → 0
View file @
f1d87ace
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
;
import
org.apache.poi.ss.formula.OperationEvaluationContext
;
import
org.apache.poi.ss.formula.eval.NumberEval
;
import
org.apache.poi.ss.formula.eval.StringEval
;
import
org.apache.poi.ss.formula.eval.ValueEval
;
import
org.apache.poi.ss.formula.functions.FreeRefFunction
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
pwc.taxtech.atms.common.datasource.ShardingContextHolder
;
import
pwc.taxtech.atms.common.util.MyAsserts
;
import
pwc.taxtech.atms.common.util.SpringContextUtil
;
import
pwc.taxtech.atms.dto.vatdto.BBParasBo
;
import
pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto
;
import
pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource
;
import
pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo
;
import
pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto
;
import
pwc.taxtech.atms.exception.Exceptions
;
import
pwc.taxtech.atms.vat.entity.CellData
;
import
pwc.taxtech.atms.vat.entity.Report
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext
;
import
java.math.BigDecimal
;
public
class
ReportFormulaFactory
{
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ReportFormulaFactory
.
class
);
final
static
ValueEval
defaultEval
=
new
StringEval
(
"0"
);
final
static
BigDecimal
defaultBigDecimal
=
new
BigDecimal
(
"0"
);
public
static
abstract
class
ReportBaseFormula
implements
FreeRefFunction
{
final
FormulaContext
context
;
final
FormulaAgent
agent
;
protected
ReportBaseFormula
(
FormulaContext
context
)
{
this
.
context
=
context
;
this
.
agent
=
context
.
getFormulaAgent
();
}
public
int
getYear
(
int
parameterYear
)
{
if
(
parameterYear
<=
-
1
)
{
return
parameterYear
+
context
.
getYear
();
}
else
if
(
parameterYear
==
0
)
{
return
context
.
getYear
();
}
else
{
return
parameterYear
;
}
}
@Override
public
ValueEval
evaluate
(
ValueEval
[]
args
,
OperationEvaluationContext
ec
)
{
try
{
return
wrapExceptionEval
(
args
,
ec
);
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"un expect exception"
,
e
);
e
.
printStackTrace
();
return
defaultEval
;
}
}
public
abstract
ValueEval
wrapExceptionEval
(
ValueEval
[]
args
,
OperationEvaluationContext
ec
)
throws
Exception
;
}
public
static
class
BB
extends
ReportBaseFormula
{
protected
BB
(
FormulaContext
context
)
{
super
(
context
);
}
@Override
public
ValueEval
wrapExceptionEval
(
ValueEval
[]
args
,
OperationEvaluationContext
ec
)
throws
Exception
{
return
new
NumberEval
(
bb
(
new
BBParasBo
(
args
,
ec
)).
doubleValue
());
}
public
BigDecimal
bb
(
BBParasBo
bo
)
throws
Exception
{
try
(
CloseableFormulaDataSource
closeDataSource
=
new
CloseableFormulaDataSource
(
context
.
getFormulaAgent
()))
{
CurrentPeriodBo
curPeriod
=
CurrentPeriodBo
.
getPeriod
(
bo
.
getPeriod
().
intValue
(),
context
.
getPeriod
());
curPeriod
.
fixedCurYear
(
getYear
(
curPeriod
.
getCurYear
()));
ReportCellDataSourceDto
nullCellDto
=
ReportCellDataSourceDto
.
nullDataSource
(
bo
,
curPeriod
);
closeDataSource
.
addDS
(
nullCellDto
);
CellTemplatePerGroupDto
cellTemplateData
=
agent
.
getCellTemplateGroupDto
(
context
.
getReportTemplateGroupID
(),
context
.
getProjectID
()).
stream
().
filter
(
dto
->
dto
.
getRowIndex
()
==
bo
.
getColumnIndex
()
-
1
&&
dto
.
getColumnIndex
()
==
bo
.
getColumnIndex
()
-
1
).
findFirst
().
get
();
MyAsserts
.
assertNotNull
(
cellTemplateData
,
Exceptions
.
BB_CELL_TEMP_NULL
);
nullCellDto
.
fixedWithGroup
(
cellTemplateData
);
// todo: fix datasource name by templateList(neo)
if
(
curPeriod
.
getCurPeriod
()
==
-
99
)
{
closeDataSource
.
clean
();
BigDecimal
returnEval
=
defaultBigDecimal
;
if
(
context
.
getPeriod
()
<=
1
)
{
return
defaultBigDecimal
;
}
for
(
int
p
=
1
;
p
<
context
.
getPeriod
();
p
++)
{
returnEval
=
returnEval
.
add
(
bb
(
new
BBParasBo
(
bo
,
p
,
curPeriod
.
getCurYear
())));
}
return
returnEval
;
}
bo
.
disCount
();
String
dbName
=
SpringContextUtil
.
formulaAdminMapper
.
getPastProjectDbName
(
curPeriod
.
getCurYear
(),
context
.
getOrganizationID
());
String
currentProjectDb
=
ShardingContextHolder
.
getDataSourceKey
();
ShardingContextHolder
.
setDataSourceKey
(
dbName
);
try
{
Report
report
=
agent
.
getReportByTemplate
(
cellTemplateData
.
getReportTemplateID
(),
curPeriod
.
getCurPeriod
());
MyAsserts
.
assertNotNull
(
report
,
Exceptions
.
BB_REPORT_NULL
);
CellData
cellData
=
agent
.
getCellDataListByTemplate
(
cellTemplateData
.
getCellTemplateID
(),
report
.
getId
());
MyAsserts
.
assertNotNull
(
cellData
,
Exceptions
.
BB_CELL_DATA_NULL
);
nullCellDto
=
ReportCellDataSourceDto
.
extractFromGroup
(
bo
,
curPeriod
,
cellData
,
cellTemplateData
);
closeDataSource
.
clean
();
closeDataSource
.
addDS
(
nullCellDto
);
// todo: fix datasource name by templateList(neo)
MyAsserts
.
assertNotNull
(
cellData
.
getData
(),
Exceptions
.
BB_CELL_DATA_NULL
);
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal
cellValue
=
new
BigDecimal
(
cellData
.
getData
()).
setScale
(
4
,
BigDecimal
.
ROUND_HALF_DOWN
);
nullCellDto
.
setAmount
(
cellValue
);
LOGGER
.
debug
(
"cell static value "
);
ShardingContextHolder
.
setDataSourceKey
(
currentProjectDb
);
return
cellValue
;
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"un support exception"
,
e
);
ShardingContextHolder
.
setDataSourceKey
(
currentProjectDb
);
throw
e
;
}
}
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
View file @
ca1d2cdd
...
...
@@ -33,6 +33,7 @@ import pwc.taxtech.atms.vat.entity.PeriodTemplate;
import
pwc.taxtech.atms.vat.entity.PeriodTemplateExample
;
import
pwc.taxtech.atms.vat.entity.Report
;
import
pwc.taxtech.atms.vat.service.ReportGenerator
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.BB
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FSJZ
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.ND
;
...
...
@@ -138,7 +139,7 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
cell
=
row
.
getCell
(
k
.
getColumnIndex
());
//todo:后面单独处理kv的公式
if
(
StringUtils
.
isNotBlank
(
v
.
getFormula
())
&&
!
v
.
getFormula
().
contains
(
"@"
))
{
if
(
StringUtils
.
isNotBlank
(
v
.
getFormula
())
&&
!
v
.
getFormula
().
contains
(
"@"
))
{
cell
.
setCellFormula
(
v
.
getFormula
());
}
});
...
...
@@ -257,7 +258,7 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
private
void
addFunctionsToWorkbook
(
Workbook
workbook
,
FormulaContext
formulaContext
)
{
String
[]
functionNames
=
{
"SGSR"
,
"FSJZ"
,
"ND"
,
"BB"
};
FreeRefFunction
[]
functionImpls
=
{
new
SGSR
(
formulaContext
),
new
FSJZ
(
formulaContext
),
new
ND
(
formulaContext
),
new
ReportFormulaFactory
.
BB
(
formulaContext
)};
new
BB
(
formulaContext
)};
UDFFinder
udfs
=
new
DefaultUDFFinder
(
functionNames
,
functionImpls
);
UDFFinder
udfToolpack
=
new
AggregatingUDFFinder
(
udfs
);
workbook
.
addToolPack
(
udfToolpack
);
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/BB.java
0 → 100644
View file @
ca1d2cdd
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
.
report
.
functions
;
import
org.apache.poi.ss.formula.OperationEvaluationContext
;
import
org.apache.poi.ss.formula.eval.NumberEval
;
import
org.apache.poi.ss.formula.eval.StringEval
;
import
org.apache.poi.ss.formula.eval.ValueEval
;
import
org.apache.poi.ss.formula.functions.FreeRefFunction
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
pwc.taxtech.atms.common.datasource.ShardingContextHolder
;
import
pwc.taxtech.atms.common.util.MyAsserts
;
import
pwc.taxtech.atms.common.util.SpringContextUtil
;
import
pwc.taxtech.atms.dto.vatdto.BBParasBo
;
import
pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto
;
import
pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource
;
import
pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo
;
import
pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto
;
import
pwc.taxtech.atms.exception.Exceptions
;
import
pwc.taxtech.atms.vat.entity.CellData
;
import
pwc.taxtech.atms.vat.entity.Report
;
import
java.math.BigDecimal
;
public
class
BB
extends
FunctionBase
implements
FreeRefFunction
{
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
BB
.
class
);
final
static
ValueEval
defaultEval
=
new
StringEval
(
"0"
);
final
static
BigDecimal
defaultBigDecimal
=
new
BigDecimal
(
"0"
);
public
BB
(
FormulaContext
context
)
{
super
(
context
);
}
@Override
public
ValueEval
evaluate
(
ValueEval
[]
args
,
OperationEvaluationContext
ec
)
{
try
{
return
wrapExceptionEval
(
args
,
ec
);
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"un expect exception"
,
e
);
e
.
printStackTrace
();
return
defaultEval
;
}
}
public
ValueEval
wrapExceptionEval
(
ValueEval
[]
args
,
OperationEvaluationContext
ec
)
throws
Exception
{
return
new
NumberEval
(
bb
(
new
BBParasBo
(
args
,
ec
)).
doubleValue
());
}
public
BigDecimal
bb
(
BBParasBo
bo
)
throws
Exception
{
try
(
CloseableFormulaDataSource
closeDataSource
=
new
CloseableFormulaDataSource
(
formulaContext
.
getFormulaAgent
()))
{
CurrentPeriodBo
curPeriod
=
CurrentPeriodBo
.
getPeriod
(
bo
.
getPeriod
().
intValue
(),
formulaContext
.
getPeriod
());
curPeriod
.
fixedCurYear
(
getYear
(
curPeriod
.
getCurYear
()));
ReportCellDataSourceDto
nullCellDto
=
ReportCellDataSourceDto
.
nullDataSource
(
bo
,
curPeriod
);
closeDataSource
.
addDS
(
nullCellDto
);
CellTemplatePerGroupDto
cellTemplateData
=
agent
.
getCellTemplateGroupDto
(
formulaContext
.
getReportTemplateGroupID
(),
formulaContext
.
getProjectID
()).
stream
().
filter
(
dto
->
dto
.
getRowIndex
()
==
bo
.
getColumnIndex
()
-
1
&&
dto
.
getColumnIndex
()
==
bo
.
getColumnIndex
()
-
1
).
findFirst
().
get
();
MyAsserts
.
assertNotNull
(
cellTemplateData
,
Exceptions
.
BB_CELL_TEMP_NULL
);
nullCellDto
.
fixedWithGroup
(
cellTemplateData
);
// todo: fix datasource name by templateList(neo)
if
(
curPeriod
.
getCurPeriod
()
==
-
99
)
{
closeDataSource
.
clean
();
BigDecimal
returnEval
=
defaultBigDecimal
;
if
(
formulaContext
.
getPeriod
()
<=
1
)
{
return
defaultBigDecimal
;
}
for
(
int
p
=
1
;
p
<
formulaContext
.
getPeriod
();
p
++)
{
returnEval
=
returnEval
.
add
(
bb
(
new
BBParasBo
(
bo
,
p
,
curPeriod
.
getCurYear
())));
}
return
returnEval
;
}
bo
.
disCount
();
String
dbName
=
SpringContextUtil
.
formulaAdminMapper
.
getPastProjectDbName
(
curPeriod
.
getCurYear
(),
formulaContext
.
getOrganizationID
());
String
currentProjectDb
=
ShardingContextHolder
.
getDataSourceKey
();
ShardingContextHolder
.
setDataSourceKey
(
dbName
);
try
{
Report
report
=
agent
.
getReportByTemplate
(
cellTemplateData
.
getReportTemplateID
(),
curPeriod
.
getCurPeriod
());
MyAsserts
.
assertNotNull
(
report
,
Exceptions
.
BB_REPORT_NULL
);
CellData
cellData
=
agent
.
getCellDataListByTemplate
(
cellTemplateData
.
getCellTemplateID
(),
report
.
getId
());
MyAsserts
.
assertNotNull
(
cellData
,
Exceptions
.
BB_CELL_DATA_NULL
);
nullCellDto
=
ReportCellDataSourceDto
.
extractFromGroup
(
bo
,
curPeriod
,
cellData
,
cellTemplateData
);
closeDataSource
.
clean
();
closeDataSource
.
addDS
(
nullCellDto
);
// todo: fix datasource name by templateList(neo)
MyAsserts
.
assertNotNull
(
cellData
.
getData
(),
Exceptions
.
BB_CELL_DATA_NULL
);
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal
cellValue
=
new
BigDecimal
(
cellData
.
getData
()).
setScale
(
4
,
BigDecimal
.
ROUND_HALF_DOWN
);
nullCellDto
.
setAmount
(
cellValue
);
LOGGER
.
debug
(
"cell static value "
);
ShardingContextHolder
.
setDataSourceKey
(
currentProjectDb
);
return
cellValue
;
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"un support exception"
,
e
);
ShardingContextHolder
.
setDataSourceKey
(
currentProjectDb
);
throw
e
;
}
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FunctionBase.java
View file @
ca1d2cdd
...
...
@@ -6,14 +6,17 @@ import org.apache.poi.ss.formula.eval.OperandResolver;
import
org.apache.poi.ss.formula.eval.ValueEval
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
pwc.taxtech.atms.vat.service.impl.FormulaAgent
;
public
class
FunctionBase
{
protected
final
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
protected
FormulaContext
formulaContext
;
final
FormulaAgent
agent
;
public
FunctionBase
(
FormulaContext
formulaContext
){
this
.
formulaContext
=
formulaContext
;
this
.
agent
=
formulaContext
.
getFormulaAgent
();
}
public
String
getStringParam
(
ValueEval
valueEval
,
OperationEvaluationContext
ec
)
{
...
...
@@ -44,4 +47,15 @@ public class FunctionBase {
return
FormulaHelper
.
getCellTemplateIDWithTemplateCodeAndColumnIndexAndRowIndex
(
ec
.
getWorkbook
().
getSheetName
(
ec
.
getSheetIndex
()),
ec
.
getColumnIndex
(),
ec
.
getRowIndex
(),
period
,
formulaContext
);
}
public
int
getYear
(
int
parameterYear
)
{
if
(
parameterYear
<=
-
1
)
{
return
parameterYear
+
formulaContext
.
getYear
();
}
else
if
(
parameterYear
==
0
)
{
return
formulaContext
.
getYear
();
}
else
{
return
parameterYear
;
}
}
}
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