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
63c4e918
Commit
63c4e918
authored
Jul 17, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DEV] delete exclude aop config use mapper directly in formula agent
parent
900b46ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
38 deletions
+80
-38
FormulaAgent.java
.../java/pwc/taxtech/atms/vat/service/impl/FormulaAgent.java
+32
-4
BB.java
...wc/taxtech/atms/vat/service/impl/report/functions/BB.java
+12
-32
applicationContext.xml
atms-api/src/main/resources/applicationContext.xml
+2
-2
DataSourceSwitch.java
...-api/src/test/java/pwc/taxtech/atms/DataSourceSwitch.java
+34
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/FormulaAgent.java
View file @
63c4e918
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Service
;
import
pwc.taxtech.atms.common.datasource.ShardingContextHolder
;
import
pwc.taxtech.atms.common.util.MyAsserts
;
import
pwc.taxtech.atms.constant.enums.EnumServiceType
;
import
pwc.taxtech.atms.dao.FormulaAdminMapper
;
import
pwc.taxtech.atms.dto.GroupId
;
...
...
@@ -9,6 +14,7 @@ import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import
pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto
;
import
pwc.taxtech.atms.entitiy.ProjectServiceType
;
import
pwc.taxtech.atms.entitiy.ProjectServiceTypeExample
;
import
pwc.taxtech.atms.exception.Exceptions
;
import
pwc.taxtech.atms.service.impl.DistributedIDService
;
import
pwc.taxtech.atms.vat.dao.CellDataMapper
;
import
pwc.taxtech.atms.vat.dao.FormulaProjectMapper
;
...
...
@@ -25,7 +31,7 @@ import java.util.List;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
FIRST_OR_DEFAULT
;
@
Repository
@
Service
public
class
FormulaAgent
extends
VatAbstractService
{
@Autowired
public
FormulaAdminMapper
adminMp
;
...
...
@@ -38,6 +44,8 @@ public class FormulaAgent extends VatAbstractService {
@Autowired
public
DistributedIDService
distributedIDService
;
@Qualifier
(
"dynamicSqlSessionTemplate"
)
public
SqlSessionTemplate
jdbcTemplate
;
public
List
<
CellTemplatePerGroupDto
>
getCellTemplateGroupDto
(
Long
templateGroupId
,
String
projectId
)
{
ProjectServiceTypeExample
pst
=
new
ProjectServiceTypeExample
();
...
...
@@ -59,7 +67,7 @@ public class FormulaAgent extends VatAbstractService {
return
cellTemplates
;
}
p
ublic
Report
getReportByTemplate
(
String
templateId
,
Integer
periodId
)
{
p
rivate
Report
getReportByTemplate
(
String
templateId
,
Integer
periodId
)
{
ReportExample
example
=
new
ReportExample
();
example
.
createCriteria
().
andTemplateIdEqualTo
(
Long
.
valueOf
(
templateId
))
.
andPeriodEqualTo
(
periodId
);
...
...
@@ -69,7 +77,7 @@ public class FormulaAgent extends VatAbstractService {
return
null
;
}
p
ublic
CellData
getCellDataListByTemplate
(
String
templateId
,
Long
reportId
)
{
p
rivate
CellData
getCellDataListByTemplate
(
String
templateId
,
Long
reportId
)
{
CellDataExample
dataExample
=
new
CellDataExample
();
dataExample
.
createCriteria
().
andCellTemplateIdEqualTo
(
Long
.
valueOf
(
templateId
));
List
<
CellData
>
cellDataList
=
cellDataMapper
.
selectByExample
(
dataExample
);
...
...
@@ -91,7 +99,7 @@ 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
.
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
());
...
...
@@ -102,4 +110,24 @@ public class FormulaAgent extends VatAbstractService {
}
public
String
getPastProjectDbName
(
int
year
,
String
orgId
)
{
return
adminMp
.
getPastProjectDbName
(
year
,
orgId
);
}
public
CellData
getCellData
(
String
dbName
,
String
templateId
,
int
periodId
)
{
String
currentProjectDb
=
ShardingContextHolder
.
getDataSourceKey
();
try
{
ShardingContextHolder
.
setDataSourceKey
(
dbName
);
Report
report
=
getReportByTemplate
(
templateId
,
periodId
);
MyAsserts
.
assertNotNull
(
report
,
Exceptions
.
BB_REPORT_NULL
);
CellData
cellData
=
getCellDataListByTemplate
(
templateId
,
report
.
getId
());
MyAsserts
.
assertNotNull
(
cellData
,
Exceptions
.
BB_CELL_DATA_NULL
);
return
cellData
;
}
finally
{
ShardingContextHolder
.
setDataSourceKey
(
currentProjectDb
);
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/BB.java
View file @
63c4e918
...
...
@@ -7,9 +7,7 @@ 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
;
...
...
@@ -17,7 +15,6 @@ 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
;
...
...
@@ -57,9 +54,7 @@ public class BB extends FunctionBase implements FreeRefFunction {
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)
...
...
@@ -78,37 +73,22 @@ public class BB extends FunctionBase implements FreeRefFunction {
}
bo
.
disCount
();
String
dbName
=
SpringContextUtil
.
formulaAdminMapper
.
getPastProjectDbName
(
curPeriod
.
getCurYear
(),
String
dbName
=
agent
.
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)
CellData
cellData
=
agent
.
getCellData
(
dbName
,
cellTemplateData
.
getReportTemplateID
(),
curPeriod
.
getCurPeriod
());
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
);
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
;
}
BigDecimal
cellValue
=
new
BigDecimal
(
cellData
.
getData
()).
setScale
(
4
,
BigDecimal
.
ROUND_HALF_DOWN
);
nullCellDto
.
setAmount
(
cellValue
);
LOGGER
.
debug
(
"cell static value "
);
return
cellValue
;
}
}
...
...
atms-api/src/main/resources/applicationContext.xml
View file @
63c4e918
...
...
@@ -60,8 +60,8 @@
</tx:advice>
<aop:config
proxy-target-class=
"true"
>
<aop:pointcut
id=
"txPointcut2"
expression=
"execution(public * pwc.taxtech.atms..*.*(..)) &&
@target(org.springframework.stereotype.Service)
and !execution(* pwc.taxtech.atms.vat.service.impl.FormulaAgent.*(..)
)"
/>
<aop:pointcut
id=
"txPointcut2"
expression=
"execution(public * pwc.taxtech.atms..*.*(..)) &&
@target(org.springframework.stereotype.Service
)"
/>
<aop:advisor
pointcut-ref=
"txPointcut2"
advice-ref=
"txAdvice"
/>
</aop:config>
...
...
atms-api/src/test/java/pwc/taxtech/atms/DataSourceSwitch.java
0 → 100644
View file @
63c4e918
package
pwc
.
taxtech
.
atms
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
pwc.taxtech.atms.common.datasource.ShardingContextHolder
;
import
pwc.taxtech.atms.vat.dao.ReportMapper
;
import
pwc.taxtech.atms.vat.entity.Report
;
import
pwc.taxtech.atms.vat.entity.ReportExample
;
import
java.util.List
;
public
class
DataSourceSwitch
extends
CommonIT
{
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
ReportMapper
reportMapper
;
@Test
public
void
insertChieseCharacter
()
{
ShardingContextHolder
.
setDataSourceKey
(
"a1700000"
);
ReportExample
example
=
new
ReportExample
();
example
.
createCriteria
().
andTemplateIdEqualTo
(
Long
.
valueOf
(
"9951852766564352"
))
.
andPeriodEqualTo
(
1
);
List
<
Report
>
reports
=
reportMapper
.
selectByExample
(
example
);
System
.
out
.
println
(
reports
.
size
());
ShardingContextHolder
.
setDataSourceKey
(
"a1800013"
);
System
.
out
.
println
(
reportMapper
.
selectByExample
(
example
).
size
());
ShardingContextHolder
.
setDataSourceKey
(
"a1700000"
);
System
.
out
.
println
(
reportMapper
.
selectByExample
(
example
).
size
());
}
}
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