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
70f45dc3
Commit
70f45dc3
authored
Apr 01, 2019
by
frank.xa.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add report validation function code --frank
parent
a90aea4e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
176 additions
and
9 deletions
+176
-9
CitReportServiceImpl.java
...a/pwc/taxtech/atms/service/impl/CitReportServiceImpl.java
+0
-0
ReportGeneratorImpl.java
...wc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
+16
-6
ReportServiceImpl.java
.../pwc/taxtech/atms/vat/service/impl/ReportServiceImpl.java
+2
-2
FunctionBase.java
.../atms/vat/service/impl/report/functions/FunctionBase.java
+1
-1
BB.java
...atms/vat/service/impl/report/functions/validation/BB.java
+157
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/service/impl/CitReportServiceImpl.java
View file @
70f45dc3
This diff is collapsed.
Click to expand it.
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
View file @
70f45dc3
...
...
@@ -591,16 +591,26 @@ public class ReportGeneratorImpl {
*
* @param workbook 工作簿
*/
public
void
addFunctionsAndContext
(
Workbook
workbook
,
String
[]
functions
,
FormulaContext
formulaContext
)
{
FreeRefFunction
[]
functionImpls
=
{
new
SGSR
(
formulaContext
),
new
FSJZ
(
formulaContext
),
new
ND
(
formulaContext
),
new
BB
(
formulaContext
),
new
XXFP
(
formulaContext
),
new
GZSD
(
formulaContext
),
new
PC
(
formulaContext
)
,
new
JXFPMX
(
formulaContext
),
new
JXFP
(
formulaContext
),
new
PSUM
(
formulaContext
),
new
DFFS
(
formulaContext
),
new
JFFS
(
formulaContext
),
new
WPSR
(
formulaContext
),
new
WPNAME
(
formulaContext
),
new
WPTYPE
(
formulaContext
),
new
SUM2
(
formulaContext
),
new
RSUMIF
(
formulaContext
),
new
SUM
(
formulaContext
),
new
KPSR
(
formulaContext
),
new
TBM
(
formulaContext
)};
public
void
addFunctionsAndContext
(
Workbook
workbook
,
String
[]
functions
,
FormulaContext
formulaContext
,
Boolean
isValidate
)
{
FreeRefFunction
[]
functionImpls
=
new
FreeRefFunction
[
0
];
if
(!
isValidate
)
{
functionImpls
=
new
FreeRefFunction
[]{
new
SGSR
(
formulaContext
),
new
FSJZ
(
formulaContext
),
new
ND
(
formulaContext
),
new
BB
(
formulaContext
),
new
XXFP
(
formulaContext
),
new
GZSD
(
formulaContext
),
new
PC
(
formulaContext
)
,
new
JXFPMX
(
formulaContext
),
new
JXFP
(
formulaContext
),
new
PSUM
(
formulaContext
),
new
DFFS
(
formulaContext
),
new
JFFS
(
formulaContext
),
new
WPSR
(
formulaContext
),
new
WPNAME
(
formulaContext
),
new
WPTYPE
(
formulaContext
),
new
SUM2
(
formulaContext
),
new
RSUMIF
(
formulaContext
),
new
SUM
(
formulaContext
),
new
KPSR
(
formulaContext
)};
}
else
{
functionImpls
=
new
FreeRefFunction
[]{
new
SGSR
(
formulaContext
),
new
FSJZ
(
formulaContext
),
new
ND
(
formulaContext
),
new
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
.
report
.
functions
.
validation
.
BB
(
formulaContext
),
new
XXFP
(
formulaContext
),
new
GZSD
(
formulaContext
),
new
PC
(
formulaContext
)
,
new
JXFPMX
(
formulaContext
),
new
JXFP
(
formulaContext
),
new
PSUM
(
formulaContext
),
new
DFFS
(
formulaContext
),
new
JFFS
(
formulaContext
),
new
WPSR
(
formulaContext
),
new
WPNAME
(
formulaContext
),
new
WPTYPE
(
formulaContext
),
new
SUM2
(
formulaContext
),
new
RSUMIF
(
formulaContext
),
new
SUM
(
formulaContext
),
new
KPSR
(
formulaContext
)};
}
UDFFinder
udfs
=
new
DefaultUDFFinder
(
functions
,
functionImpls
);
UDFFinder
udfToolpack
=
new
AggregatingUDFFinder
(
udfs
);
workbook
.
addToolPack
(
udfToolpack
);
}
/**
* 为CIT复制的一份注册自定义公式,和上面的addFunctionsAndContext方法基本相同
* CIT 注册所有的自定义方法到工作簿
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportServiceImpl.java
View file @
70f45dc3
...
...
@@ -981,7 +981,7 @@ public class ReportServiceImpl extends BaseService {
Workbook
workbook
=
reportGenerator
.
createWorkBookByPeriodTemplate
(
resources
.
getPeriodTemplates
(),
genJob
);
reportGenerator
.
addFunctionsAndContext
(
workbook
,
functions
,
reportGenerator
.
initContext
(
resources
,
periodParam
));
reportGenerator
.
addFunctionsAndContext
(
workbook
,
functions
,
reportGenerator
.
initContext
(
resources
,
periodParam
)
,
false
);
reportGenerator
.
setConfigAndDataToWorkBook
(
workbook
,
resources
);
FormulaEvaluator
evaluator
=
workbook
.
getCreationHelper
().
createFormulaEvaluator
();
...
...
@@ -1023,7 +1023,7 @@ public class ReportServiceImpl extends BaseService {
periodCellTemplateConfigDtos
.
forEach
(
a
->
{
workbook4Validate
.
getSheetAt
(
a
.
getSheetNumber
()
-
1
).
getRow
(
a
.
getRowNumber
()).
getCell
(
a
.
getColNumber
()).
setCellFormula
(
a
.
getParsedValidation
());
});
reportGenerator
.
addFunctionsAndContext
(
workbook4Validate
,
functions
,
reportGenerator
.
initContext
(
resources
,
periodParam
));
reportGenerator
.
addFunctionsAndContext
(
workbook4Validate
,
functions
,
reportGenerator
.
initContext
(
resources
,
periodParam
)
,
true
);
FormulaEvaluator
validateEvaluator
=
workbook4Validate
.
getCreationHelper
().
createFormulaEvaluator
();
validateEvaluator
.
evaluateAll
();
//todo: 4.then save the validation result to cellData table
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FunctionBase.java
View file @
70f45dc3
...
...
@@ -24,7 +24,7 @@ public class FunctionBase {
,
new
BigDecimal
(
"0.11"
),
new
BigDecimal
(
"0.06"
),
new
BigDecimal
(
"0.05"
),
new
BigDecimal
(
"0.03"
)};
protected
FormulaContext
formulaContext
;
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
FunctionBase
.
class
);
final
FormulaAgent
agent
;
public
final
FormulaAgent
agent
;
public
FunctionBase
(
FormulaContext
formulaContext
)
{
this
.
formulaContext
=
formulaContext
;
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/validation/BB.java
0 → 100644
View file @
70f45dc3
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
.
report
.
functions
.
validation
;
import
org.apache.commons.collections.CollectionUtils
;
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.util.MyAsserts
;
import
pwc.taxtech.atms.dpo.CellTemplatePerGroupDto
;
import
pwc.taxtech.atms.dto.vatdto.BBParasBo
;
import
pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo
;
import
pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto
;
import
pwc.taxtech.atms.entity.Project
;
import
pwc.taxtech.atms.exception.Exceptions
;
import
pwc.taxtech.atms.exception.FormulaException
;
import
pwc.taxtech.atms.vat.entity.PeriodCellData
;
import
pwc.taxtech.atms.vat.entity.PeriodDataSource
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FunctionBase
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.List
;
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
)
{
if
(
e
instanceof
FormulaException
)
LOGGER
.
warn
(
"Formula Exception || {}"
,
e
.
getMessage
());
e
.
printStackTrace
();
return
defaultEval
;
}
}
public
ValueEval
wrapExceptionEval
(
ValueEval
[]
args
,
OperationEvaluationContext
ec
)
throws
Exception
{
List
<
Object
>
ds
=
new
ArrayList
<>();
return
new
NumberEval
(
bb
(
new
BBParasBo
(
args
,
ec
),
ec
,
ds
,
null
).
doubleValue
());
}
public
BigDecimal
bb
(
BBParasBo
bo
,
OperationEvaluationContext
ec
,
List
<
Object
>
dataSource
,
BBParasBo
rootBo
)
throws
Exception
{
CurrentPeriodBo
curPeriod
=
CurrentPeriodBo
.
getPeriod
(
bo
.
getPeriod
().
intValue
(),
formulaContext
.
getPeriod
());
curPeriod
.
fixedCurYear
(
getYear
(
bo
.
getYear
()));
ReportCellDataSourceDto
nullCellDto
=
ReportCellDataSourceDto
.
nullDataSource
(
bo
,
curPeriod
);
dataSource
.
add
(
nullCellDto
);
BigDecimal
cellValue
=
BigDecimal
.
ZERO
;
try
{
if
(
bo
.
getPeriod
().
intValue
()
==
99
)
{
dataSource
.
clear
();
BigDecimal
returnEval
=
defaultBigDecimal
;
if
(
formulaContext
.
getPeriod
()
<=
1
)
{
return
defaultBigDecimal
;
}
//如果是当年取到当期截至,往年取12期
for
(
int
p
=
1
;
p
<=
(
curPeriod
.
getCurYear
()==
formulaContext
.
getYear
()?
formulaContext
.
getPeriod
():
12
);
p
++)
{
try
{
returnEval
=
returnEval
.
add
(
bb
(
new
BBParasBo
(
bo
,
p
,
curPeriod
.
getCurYear
()),
ec
,
dataSource
,
bo
));
}
catch
(
Exception
e
)
{
if
(
e
instanceof
FormulaException
)
{
LOGGER
.
warn
(
"Formula Exception || {}"
,
e
.
getMessage
());
}
}
}
cellValue
=
returnEval
;
return
cellValue
;
}
List
<
CellTemplatePerGroupDto
>
cellTemplateDataList
;
Project
project
=
null
;
if
(
curPeriod
.
getCurYear
()
!=
formulaContext
.
getYear
())
{
project
=
agent
.
getFixedProject
(
formulaContext
.
getProjectId
(),
curPeriod
.
getCurYear
());
// MyAsserts.assertNotNull(project, Exceptions.PROJECT_NOT_FOUND);
if
(
project
==
null
){
return
cellValue
;
}
cellTemplateDataList
=
agent
.
getCellTemplateGroupDto
(
formulaContext
.
getReportTemplateGroupId
(),
project
.
getId
(),
bo
.
getReportCode
(),
bo
.
getRowIndex
()
-
1
,
bo
.
getColumnIndex
()
-
1
,
curPeriod
.
getCurPeriod
());
}
else
{
cellTemplateDataList
=
agent
.
getCellTemplateGroupDto
(
formulaContext
.
getReportTemplateGroupId
(),
formulaContext
.
getProjectId
(),
bo
.
getReportCode
(),
bo
.
getRowIndex
()
-
1
,
bo
.
getColumnIndex
()
-
1
,
curPeriod
.
getCurPeriod
());
}
// MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.BB_CELL_TEMP_NULL);
if
(
CollectionUtils
.
isEmpty
(
cellTemplateDataList
)){
return
cellValue
;
}
CellTemplatePerGroupDto
cellTemplateData
=
cellTemplateDataList
.
get
(
0
);
nullCellDto
.
fixedWithGroup
(
cellTemplateData
);
//当年当期
if
((
bo
.
getPeriod
().
intValue
()
==
0
&&
bo
.
getYear
().
intValue
()
==
0
)||
(
bo
.
getYear
().
equals
(
formulaContext
.
getYear
())&&
bo
.
getPeriod
().
equals
(
formulaContext
.
getPeriod
())))
{
int
index
=
ec
.
getWorkbook
().
getSheetIndex
(
bo
.
getReportCode
());
cellValue
=
getCellValue
(
index
,
ec
,
formulaContext
,
agent
,
bo
.
getRowIndex
()
-
1
,
bo
.
getColumnIndex
()
-
1
,
Long
.
parseLong
(
cellTemplateData
.
getCellTemplateId
()));
nullCellDto
.
extractFromGroup
(
bo
,
formulaContext
.
getPeriod
(),
formulaContext
.
getYear
(),
cellTemplateData
);
nullCellDto
.
setAmount
(
cellValue
);
return
cellValue
;
}
PeriodCellData
cellData
=
null
;
String
projectId
=
agent
.
getPastProjectId
(
curPeriod
.
getCurYear
(),
formulaContext
.
getOrganizationId
());
MyAsserts
.
assertNotEmpty
(
projectId
,
Exceptions
.
PROJECT_EMPTY
);
cellData
=
agent
.
getCellData
(
cellTemplateData
.
getReportTemplateId
(),
cellTemplateData
.
getCellTemplateId
(),
curPeriod
.
getCurPeriod
(),
project
==
null
?
formulaContext
.
getProjectId
():
project
.
getId
());
List
<
PeriodDataSource
>
dss
=
agent
.
queryManualDataSource
(
Long
.
parseLong
(
cellTemplateData
.
getCellTemplateId
()),
project
==
null
?
formulaContext
.
getProjectId
():
project
.
getId
(),
bo
.
getPeriod
());
nullCellDto
.
extractFromGroup
(
bo
,
curPeriod
,
cellData
,
cellTemplateData
);
if
(
cellData
.
getData
()
==
null
&&
!
dss
.
isEmpty
())
{
cellValue
=
dss
.
get
(
0
).
getAmount
();
}
else
if
(
cellData
.
getData
()
!=
null
&&
dss
.
isEmpty
())
{
cellValue
=
new
BigDecimal
(
cellData
.
getData
()).
setScale
(
4
,
BigDecimal
.
ROUND_HALF_DOWN
);
}
else
if
(
cellData
.
getData
()
!=
null
&&
!
dss
.
isEmpty
())
{
cellValue
=
dss
.
get
(
0
).
getAmount
().
add
(
new
BigDecimal
(
cellData
.
getData
()).
setScale
(
4
,
BigDecimal
.
ROUND_HALF_DOWN
));
}
else
throw
Exceptions
.
BB_CELL_DATA_NULL
;
nullCellDto
.
setAmount
(
cellValue
);
if
(
rootBo
!=
null
)
{
rootBo
.
putPeriodCellTempate
(
curPeriod
.
getCurPeriod
(),
Long
.
parseLong
(
cellTemplateData
.
getCellTemplateId
()));
}
else
{
bo
.
putPeriodCellTempate
(
curPeriod
.
getCurPeriod
(),
Long
.
parseLong
(
cellTemplateData
.
getCellTemplateId
()));
}
LOGGER
.
debug
(
"cell static value "
);
return
cellValue
;
}
catch
(
Exception
e
)
{
logger
.
warn
(
"[BB_Exception] some error {}"
,
bo
.
toString
());
throw
e
;
}
finally
{
if
(
rootBo
==
null
)
{
LOGGER
.
warn
(
"[BB_Exception] error for bb cacls for {} and current for {}"
,
bo
.
toString
(),
curPeriod
.
toString
());
// Long dataSourceId = saveDataSource(ec, dataSource, FormulaDataSourceDetailType.ReportCellDataSourceDto,
// cellValue, formulaContext.getPeriod(),
// formulaContext.getReportTemplateGroupId(), bo.getColumnIndex() - 1, bo.getRowIndex() - 1,
// formulaContext.getProjectId());
// saveFormulaBlock(formulaContext.getPeriod(), ec,
// bo.expression(), cellValue, dataSourceId, formulaContext.getProjectId());
}
}
}
}
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