Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tron-explore
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张建华@五瓣科技
tron-explore
Commits
fe3aaee6
Commit
fe3aaee6
authored
Nov 17, 2020
by
jianhua.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
波场浏览器JAVA版
parent
dee5d47e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
103 deletions
+21
-103
pom.xml
pom.xml
+1
-0
BlockDayCensusRepository.java
.../com/wuban/tron/explore/dao/BlockDayCensusRepository.java
+7
-0
AccountBalanceTask.java
...java/com/wuban/tron/explore/fetch/AccountBalanceTask.java
+0
-102
TransactionServiceImpl.java
...ban/tron/explore/service/impl/TransactionServiceImpl.java
+13
-1
No files found.
pom.xml
View file @
fe3aaee6
...
...
@@ -124,6 +124,7 @@
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<fork>
true
</fork>
<includeSystemScope>
true
</includeSystemScope>
</configuration>
</plugin>
<plugin>
...
...
src/main/java/com/wuban/tron/explore/dao/BlockDayCensusRepository.java
View file @
fe3aaee6
...
...
@@ -23,6 +23,13 @@ public interface BlockDayCensusRepository {
*/
int
insert
(
@Param
(
"record"
)
BlockDayCensus
record
);
/**
* 删除记录
* @param id
* @return
*/
void
deleteById
(
@Param
(
"id"
)
Long
id
);
/**
* 按照时间统计区块信息
*
...
...
src/main/java/com/wuban/tron/explore/fetch/AccountBalanceTask.java
deleted
100644 → 0
View file @
dee5d47e
package
com
.
wuban
.
tron
.
explore
.
fetch
;
import
com.wuban.tron.explore.domain.TronAccount
;
import
com.wuban.tron.explore.entity.Address
;
import
com.wuban.tron.explore.service.AddressService
;
import
com.wuban.tron.explore.service.TronService
;
import
com.wuban.tron.explore.util.SpringContextUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Set
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* <core>账户余额处理者服务接口方法实现类</core>
*
* @author sky
* @date 2020/11/04
*/
@Slf4j
@Deprecated
public
class
AccountBalanceTask
extends
AbstractJob
{
private
AddressService
addressService
=
SpringContextUtil
.
getBean
(
AddressService
.
class
);
private
static
final
int
SIZE
=
2
;
private
String
name
=
"账户余额持久化线程池"
;
private
static
ThreadPoolExecutor
threadPool
;
private
TronService
tronService
=
SpringContextUtil
.
getBean
(
TronService
.
class
);
private
Set
<
String
>
dataSet
;
public
AccountBalanceTask
()
{
initPool
();
}
public
AccountBalanceTask
(
Set
<
String
>
dataSet
)
{
this
.
dataSet
=
dataSet
;
}
public
void
fetch
(
String
address
)
{
TronAccount
tronAccount
=
this
.
tronService
.
getAccount
(
address
);
if
(
tronAccount
!=
null
)
{
if
(
tronAccount
.
getBalance
()
!=
null
)
{
Address
obj
=
new
Address
();
obj
.
setAddress
(
address
);
obj
.
setBalance
(
tronAccount
.
getBalance
());
this
.
addressService
.
updateById
(
obj
);
log
.
info
(
"更新账户余额 account:{}"
,
obj
.
toString
());
}
}
}
@Override
public
boolean
execute
()
{
if
(!
CollectionUtils
.
isEmpty
(
dataSet
))
{
dataSet
.
forEach
(
o
->
threadPool
.
execute
(()
->
fetch
(
o
)));
}
return
true
;
}
public
synchronized
void
initPool
()
{
if
(
threadPool
==
null
)
{
threadPool
=
new
ThreadPoolExecutor
(
SIZE
,
SIZE
*
2
,
10L
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<>(),
new
ExecutorThreadFactory
());
log
.
info
(
"初始化线程池 name:{} coreSize:{} maxSize:{}"
,
name
,
SIZE
,
SIZE
*
2
);
}
}
/**
* The match engine thread factory
*/
private
class
ExecutorThreadFactory
implements
ThreadFactory
{
private
final
ThreadGroup
group
;
private
final
AtomicInteger
threadNumber
=
new
AtomicInteger
(
1
);
private
final
String
namePrefix
;
ExecutorThreadFactory
()
{
final
SecurityManager
s
=
System
.
getSecurityManager
();
this
.
group
=
(
s
!=
null
)
?
s
.
getThreadGroup
()
:
Thread
.
currentThread
().
getThreadGroup
();
this
.
namePrefix
=
"excutor-"
+
AccountBalanceTask
.
this
.
name
+
"-thread-"
;
}
@Override
public
Thread
newThread
(
final
Runnable
r
)
{
final
Thread
t
=
new
Thread
(
this
.
group
,
r
,
this
.
namePrefix
+
this
.
threadNumber
.
getAndIncrement
(),
0
);
if
(
t
.
isDaemon
())
{
t
.
setDaemon
(
false
);
}
if
(
t
.
getPriority
()
!=
Thread
.
NORM_PRIORITY
)
{
t
.
setPriority
(
Thread
.
NORM_PRIORITY
);
}
return
t
;
}
}
}
src/main/java/com/wuban/tron/explore/service/impl/TransactionServiceImpl.java
View file @
fe3aaee6
...
...
@@ -7,6 +7,7 @@ import com.wuban.tron.explore.constant.PageConstant;
import
com.wuban.tron.explore.dao.*
;
import
com.wuban.tron.explore.domain.*
;
import
com.wuban.tron.explore.entity.*
;
import
com.wuban.tron.explore.entity.example.BlockDayCensusExample
;
import
com.wuban.tron.explore.entity.example.TransactionExample
;
import
com.wuban.tron.explore.service.TransactionService
;
import
com.wuban.tron.explore.util.BigDecimalUtil
;
...
...
@@ -401,11 +402,22 @@ public class TransactionServiceImpl implements TransactionService {
BigDecimal
averBlockBytes
=
BigDecimalUtil
.
getDevide
(
new
BigDecimal
(
data
.
getTotalBlockBytes
()),
new
BigDecimal
(
data
.
getGenBlockTotalNum
()));
data
.
setAverBlockBytes
(
averBlockBytes
.
intValue
());
this
.
blockDayCensusRepository
.
insert
(
data
);
this
.
saveCensusData
(
data
);
log
.
info
(
"date:{} 交易数据已统计完成"
,
date
);
}
else
{
log
.
info
(
"date:{} 暂无交易数据统计"
,
date
);
}
}
private
void
saveCensusData
(
BlockDayCensus
data
)
{
BlockDayCensusExample
example
=
new
BlockDayCensusExample
();
example
.
createCriteria
().
andCensusDateEqualTo
(
data
.
getCensusDate
());
List
<
BlockDayCensus
>
list
=
this
.
blockDayCensusRepository
.
selectByExample
(
example
);
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
Long
id
=
list
.
get
(
0
).
getId
();
this
.
blockDayCensusRepository
.
deleteById
(
id
);
}
this
.
blockDayCensusRepository
.
insert
(
data
);
}
}
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