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
b22c475a
Commit
b22c475a
authored
Jul 05, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DEV] bb formula impl
parent
8d258f2d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
156 additions
and
9 deletions
+156
-9
EnumOperationType.java
...va/pwc/taxtech/atms/constant/enums/EnumOperationType.java
+21
-0
FormulaAdminMapper.java
...rc/main/java/pwc/taxtech/atms/dao/FormulaAdminMapper.java
+14
-0
DataSourceAmount.java
...in/java/pwc/taxtech/atms/dto/vatdto/DataSourceAmount.java
+8
-0
ReportCellDataSourceDto.java
.../pwc/taxtech/atms/dto/vatdto/ReportCellDataSourceDto.java
+21
-2
FormulaProjectMapper.java
...n/java/pwc/taxtech/atms/vat/dao/FormulaProjectMapper.java
+16
-0
ReportFormulaFactory.java
...c/taxtech/atms/vat/service/impl/ReportFormulaFactory.java
+70
-7
FormulaAgent.java
.../atms/vat/service/impl/report/functions/FormulaAgent.java
+6
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/constant/enums/EnumOperationType.java
0 → 100644
View file @
b22c475a
package
pwc
.
taxtech
.
atms
.
constant
.
enums
;
public
enum
EnumOperationType
{
Single
(
0
),
Add
(
1
),
Sub
(
2
),
Mul
(
3
),
Div
(
4
);
private
int
code
;
EnumOperationType
(
int
code
)
{
this
.
code
=
code
;
}
public
int
getCode
()
{
return
code
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/dao/FormulaAdminMapper.java
View file @
b22c475a
...
...
@@ -46,4 +46,18 @@ public interface FormulaAdminMapper extends MyMapper {
" AND p.ID = #{projectId}"
)
List
<
GroupId
>
getTemplateGroupId
(
@Param
(
"projectId"
)
String
projectId
);
@Select
(
"SELECT "
+
" p.DbName "
+
"FROM "
+
" Project p "
+
" JOIN "
+
" ProjectServiceType ps ON p.id = ps.ProjectID "
+
"WHERE "
+
" ps.ServiceTypeID IN ('2' , '3') "
+
" AND p.Year = #{year} "
+
" AND p.OrganizationID = #{orgId} "
+
" AND p.IsActive = 1 "
+
"ORDER BY ps.ServiceTypeID "
+
"LIMIT 0 , 1"
)
String
getPastProjectDbName
(
@Param
(
"year"
)
int
year
,
@Param
(
"orgId"
)
String
organizationID
);
}
atms-api/src/main/java/pwc/taxtech/atms/dto/vatdto/DataSourceAmount.java
0 → 100644
View file @
b22c475a
package
pwc
.
taxtech
.
atms
.
dto
.
vatdto
;
import
java.math.BigDecimal
;
public
class
DataSourceAmount
{
public
BigDecimal
amount
;
public
Integer
operationType
;
}
atms-api/src/main/java/pwc/taxtech/atms/dto/vatdto/ReportCellDataSourceDto.java
View file @
b22c475a
...
...
@@ -3,6 +3,8 @@ package pwc.taxtech.atms.dto.vatdto;
import
pwc.taxtech.atms.constant.Constant
;
import
pwc.taxtech.atms.constant.DataSourceName
;
import
pwc.taxtech.atms.constant.enums.FormulaDataSourceType
;
import
pwc.taxtech.atms.dto.CellTemplateDto
;
import
pwc.taxtech.atms.vat.entity.CellData
;
public
class
ReportCellDataSourceDto
extends
FormulaDataSourceDto
{
Integer
year
;
...
...
@@ -22,7 +24,7 @@ public class ReportCellDataSourceDto extends FormulaDataSourceDto {
this
.
type
=
FormulaDataSourceType
.
Report
.
getCode
();
}
public
static
ReportCellDataSourceDto
nullDataSource
(
BBParasBo
bbParasBo
,
CurrentPeriodBo
currentPeriodBo
)
{
public
static
ReportCellDataSourceDto
nullDataSource
(
BBParasBo
bbParasBo
,
CurrentPeriodBo
currentPeriodBo
)
{
ReportCellDataSourceDto
nulDataSource
=
new
ReportCellDataSourceDto
();
nulDataSource
.
name
=
DataSourceName
.
ReportDataSource
;
nulDataSource
.
reportTemplateID
=
bbParasBo
.
getReportCode
();
...
...
@@ -34,7 +36,24 @@ public class ReportCellDataSourceDto extends FormulaDataSourceDto {
return
nulDataSource
;
}
public
void
fixedWithGroup
(
CellTemplatePerGroupDto
dto
){
public
static
ReportCellDataSourceDto
extractFromGroup
(
BBParasBo
bbParasBo
,
CurrentPeriodBo
currentPeriodBo
,
CellData
cellData
,
CellTemplatePerGroupDto
cellTemplateData
)
{
ReportCellDataSourceDto
dataSource
=
new
ReportCellDataSourceDto
();
dataSource
.
year
=
currentPeriodBo
.
curYear
;
dataSource
.
period
=
currentPeriodBo
.
curPeriod
;
dataSource
.
columnIndex
=
bbParasBo
.
getColumnIndex
();
dataSource
.
columnName
=
cellTemplateData
.
getColumnName
();
dataSource
.
rowIndex
=
bbParasBo
.
getRowIndex
();
dataSource
.
rowName
=
cellTemplateData
.
getRowName
();
dataSource
.
reportTemplateID
=
cellTemplateData
.
getReportTemplateID
();
dataSource
.
cellDataID
=
cellData
.
getId
()
+
""
;
dataSource
.
cellTemplateID
=
cellData
.
getCellTemplateId
()
+
""
;
dataSource
.
resultType
=
cellTemplateData
.
getResultType
();
dataSource
.
isOnlyManualInput
=
false
;
return
dataSource
;
}
public
void
fixedWithGroup
(
CellTemplatePerGroupDto
dto
)
{
cellTemplateID
=
dto
.
getCellTemplateID
();
rowName
=
dto
.
getRowName
();
columnName
=
dto
.
getColumnName
();
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/dao/FormulaProjectMapper.java
View file @
b22c475a
package
pwc
.
taxtech
.
atms
.
vat
.
dao
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
pwc.taxtech.atms.MyVatMapper
;
import
pwc.taxtech.atms.dto.vatdto.DataSourceAmount
;
import
java.util.List
;
@Mapper
public
interface
FormulaProjectMapper
extends
MyVatMapper
{
@Select
(
"SELECT "
+
" ds.amount, cds.operation_type AS operationType "
+
"FROM "
+
" data_source ds "
+
" JOIN "
+
" cell_data_source cds ON ds.id = cds.data_source_id "
+
"WHERE "
+
" cds.cell_data_id = #{cellId} "
+
" AND ds.type != #{code} "
+
" AND ds.amount IS NOT NULL "
)
List
<
DataSourceAmount
>
queryDsAmount
(
@Param
(
"cellId"
)
Long
dataId
,
@Param
(
"code"
)
Integer
code
);
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportFormulaFactory.java
View file @
b22c475a
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
;
import
com.github.pagehelper.util.StringUtil
;
import
org.apache.poi.ss.formula.OperationEvaluationContext
;
import
org.apache.poi.ss.formula.eval.EvaluationException
;
import
org.apache.poi.ss.formula.eval.NumberEval
;
import
org.apache.poi.ss.formula.eval.OperandResolver
;
import
org.apache.poi.ss.formula.eval.StringEval
;
import
org.apache.poi.ss.formula.eval.StringValueEval
;
...
...
@@ -9,20 +11,33 @@ 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.constant.Constant
;
import
pwc.taxtech.atms.constant.enums.CellDataSourceType
;
import
pwc.taxtech.atms.constant.enums.EnumOperationType
;
import
pwc.taxtech.atms.constant.enums.EnumServiceType
;
import
pwc.taxtech.atms.dto.GroupId
;
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.DataSourceAmount
;
import
pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto
;
import
pwc.taxtech.atms.entitiy.ProjectExample
;
import
pwc.taxtech.atms.entitiy.ProjectServiceType
;
import
pwc.taxtech.atms.entitiy.ProjectServiceTypeExample
;
import
pwc.taxtech.atms.vat.entity.CellData
;
import
pwc.taxtech.atms.vat.entity.CellDataExample
;
import
pwc.taxtech.atms.vat.entity.Report
;
import
pwc.taxtech.atms.vat.entity.ReportExample
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FormulaAgent
;
import
pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
FIRST_OR_DEFAULT
;
public
class
ReportFormulaFactory
{
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ReportFormulaFactory
.
class
);
final
static
ValueEval
defaultEval
=
new
StringEval
(
"0"
);
...
...
@@ -81,7 +96,7 @@ public class ReportFormulaFactory {
}
CellTemplatePerGroupDto
cellTemplateData
=
cellTemplates
.
stream
().
filter
(
dto
->
dto
.
getRowIndex
()
==
bo
.
getColumnIndex
()
-
1
&&
dto
.
getColumnIndex
()==
bo
.
getColumnIndex
()-
1
)
dto
.
getRowIndex
()
==
bo
.
getColumnIndex
()
-
1
&&
dto
.
getColumnIndex
()
==
bo
.
getColumnIndex
()
-
1
)
.
findFirst
().
get
();
if
(
cellTemplateData
==
null
)
{
...
...
@@ -90,15 +105,15 @@ public class ReportFormulaFactory {
}
nullCellDto
.
fixedWithGroup
(
cellTemplateData
);
// todo: fix datasource name by templateList(neo)
if
(
curPeriod
.
getCurPeriod
()==-
99
)
{
// todo: fix datasource name by templateList(neo)
if
(
curPeriod
.
getCurPeriod
()
==
-
99
)
{
closeDataSource
.
clean
();
ValueEval
returnEval
=
null
;
if
(
context
.
getPeriod
()<=
1
)
{
return
defaultEval
;
ValueEval
returnEval
=
null
;
if
(
context
.
getPeriod
()
<=
1
)
{
return
defaultEval
;
}
for
(
int
p
=
1
;
p
<
context
.
getPeriod
();
p
++)
{
for
(
int
p
=
1
;
p
<
context
.
getPeriod
();
p
++)
{
// returnEval=And(returnEval,BB)//TODO: to impl add vormular
}
...
...
@@ -106,8 +121,56 @@ public class ReportFormulaFactory {
}
bo
.
disCount
();
String
dbName
=
agent
.
adminMp
.
getPastProjectDbName
(
curPeriod
.
getCurYear
(),
context
.
getOrganizationID
());
String
currentProjectDb
=
ShardingContextHolder
.
getDataSourceKey
();
ShardingContextHolder
.
setDataSourceKey
(
dbName
);
ReportExample
example
=
new
ReportExample
();
example
.
createCriteria
().
andTemplateIdEqualTo
(
Long
.
valueOf
(
cellTemplateData
.
getCellTemplateID
()))
.
andPeriodEqualTo
(
curPeriod
.
getCurPeriod
());
List
<
Report
>
reports
=
agent
.
reportMapper
.
selectByExample
(
example
);
if
(
reports
==
null
||
reports
.
isEmpty
())
{
LOGGER
.
warn
(
"report data is empty"
);
return
defaultEval
;
}
CellDataExample
dataExample
=
new
CellDataExample
();
dataExample
.
createCriteria
().
andCellTemplateIdEqualTo
(
Long
.
valueOf
(
cellTemplateData
.
getCellTemplateID
()))
.
andReportIdEqualTo
(
reports
.
get
(
FIRST_OR_DEFAULT
).
getId
());
List
<
CellData
>
cellDatas
=
agent
.
cellDataMapper
.
selectByExample
(
dataExample
);
if
(
cellDatas
==
null
||
cellDatas
.
isEmpty
())
{
LOGGER
.
warn
(
"cell data is empty"
);
return
defaultEval
;
}
CellData
cellData
=
cellDatas
.
get
(
FIRST_OR_DEFAULT
);
nullCellDto
=
ReportCellDataSourceDto
.
extractFromGroup
(
bo
,
curPeriod
,
cellData
,
cellTemplateData
);
// todo: fix datasource name by templateList(neo)
if
(!
StringUtil
.
isEmpty
(
cellData
.
getData
()))
{
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal
decimal
=
new
BigDecimal
(
cellData
.
getData
());
BigDecimal
cellValue
=
decimal
.
setScale
(
4
,
BigDecimal
.
ROUND_HALF_DOWN
);
nullCellDto
.
setAmount
(
cellValue
);
LOGGER
.
debug
(
"cell static value "
);
return
new
NumberEval
(
cellValue
.
doubleValue
());
}
ShardingContextHolder
.
setDataSourceKey
(
currentProjectDb
);
// Boolean hasValuedDataSource = false;//TODO: Calculate other referenced formula
// BigDecimal dataSourceAmount = new BigDecimal(0);
// List<DataSourceAmount> amounts = agent.projectMp.queryDsAmount(cellData.getId(),
// CellDataSourceType.Formula.getCode());
// if (amounts != null || !amounts.isEmpty())
// for (DataSourceAmount m : amounts)
// if (m.operationType.intValue() == EnumOperationType.Sub.getCode())
// dataSourceAmount = dataSourceAmount.subtract(m.amount);
// else dataSourceAmount = dataSourceAmount.add(m.amount);
//
// if (!StringUtil.isEmpty(cellTemplateData.getFormula())) {
//
// }
}
catch
(
EvaluationException
e
)
{
LOGGER
.
warn
(
"resole args some exception"
,
e
);
...
...
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FormulaAgent.java
View file @
b22c475a
...
...
@@ -3,7 +3,9 @@ package pwc.taxtech.atms.vat.service.impl.report.functions;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
pwc.taxtech.atms.dao.FormulaAdminMapper
;
import
pwc.taxtech.atms.vat.dao.CellDataMapper
;
import
pwc.taxtech.atms.vat.dao.FormulaProjectMapper
;
import
pwc.taxtech.atms.vat.dao.ReportMapper
;
import
pwc.taxtech.atms.vat.service.impl.VatAbstractService
;
@Service
...
...
@@ -12,4 +14,8 @@ public class FormulaAgent extends VatAbstractService {
public
FormulaAdminMapper
adminMp
;
@Autowired
public
FormulaProjectMapper
projectMp
;
@Autowired
public
ReportMapper
reportMapper
;
@Autowired
public
CellDataMapper
cellDataMapper
;
}
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