Commit 12093c52 authored by jianhua.zhang's avatar jianhua.zhang

波场浏览器JAVA版

parent f968a6bd
...@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* @date 2020/11/04 * @date 2020/11/04
*/ */
@Slf4j @Slf4j
//@Component @Component
@RequiredArgsConstructor(onConstructor_ = @Autowired) @RequiredArgsConstructor(onConstructor_ = @Autowired)
public class Bootstrapper { public class Bootstrapper {
...@@ -74,12 +74,6 @@ public class Bootstrapper { ...@@ -74,12 +74,6 @@ public class Bootstrapper {
} }
private synchronized void startEngine() { private synchronized void startEngine() {
/*try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
Engine engine = new Engine("tron"); Engine engine = new Engine("tron");
engine.start(); engine.start();
} }
......
...@@ -14,4 +14,19 @@ public enum HomeSearchTypeEnum { ...@@ -14,4 +14,19 @@ public enum HomeSearchTypeEnum {
this.desc = desc; this.desc = desc;
} }
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
} }
...@@ -2,6 +2,7 @@ package com.wuban.tron.explore.controller; ...@@ -2,6 +2,7 @@ package com.wuban.tron.explore.controller;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.constant.Constant; import com.wuban.tron.explore.constant.Constant;
import com.wuban.tron.explore.constant.HomeSearchTypeEnum;
import com.wuban.tron.explore.entity.Address; import com.wuban.tron.explore.entity.Address;
import com.wuban.tron.explore.entity.BlockDayCensus; import com.wuban.tron.explore.entity.BlockDayCensus;
import com.wuban.tron.explore.entity.BlockHeader; import com.wuban.tron.explore.entity.BlockHeader;
...@@ -36,7 +37,7 @@ import java.util.List; ...@@ -36,7 +37,7 @@ import java.util.List;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/api/") @RequestMapping("/api/tron")
@RequiredArgsConstructor(onConstructor_ = @Autowired) @RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TransactionController { public class TransactionController {
...@@ -75,10 +76,11 @@ public class TransactionController { ...@@ -75,10 +76,11 @@ public class TransactionController {
example.createCriteria().andNumberEqualTo(Long.valueOf(condition)); example.createCriteria().andNumberEqualTo(Long.valueOf(condition));
PageInfo<Transaction> pageInfo = this.transactionService.getByPageWithCategory(reqParam.getStartIndex(), reqParam.getPageSize(), example); PageInfo<Transaction> pageInfo = this.transactionService.getByPageWithCategory(reqParam.getStartIndex(), reqParam.getPageSize(), example);
HomeSearchModel model = new HomeSearchModel(); HomeSearchModel<TransactionModel> model = new HomeSearchModel();
model.setBlock(blockHeader); model.setBlock(blockHeader);
List<TransactionModel> txList = this.transfer(pageInfo); List<TransactionModel> txList = this.transfer(pageInfo);
model.setTransList(txList); model.setTransList(txList);
model.setT(HomeSearchTypeEnum.BLOCK_INFO.getCode());
return ResponseKit.success(model); return ResponseKit.success(model);
} }
...@@ -94,6 +96,7 @@ public class TransactionController { ...@@ -94,6 +96,7 @@ public class TransactionController {
List<TransactionModel> txList = this.transfer(pageInfo); List<TransactionModel> txList = this.transfer(pageInfo);
model.setTransList(txList); model.setTransList(txList);
model.setAddress(address); model.setAddress(address);
model.setT(HomeSearchTypeEnum.ADDRESS_INFO.getCode());
return ResponseKit.success(model); return ResponseKit.success(model);
} }
...@@ -101,11 +104,12 @@ public class TransactionController { ...@@ -101,11 +104,12 @@ public class TransactionController {
交易hash 交易hash
*/ */
if (condition.length()== Constant.TX_ID_LEN) { if (condition.length()== Constant.TX_ID_LEN) {
HomeSearchModel<Transaction> model = new HomeSearchModel();
example.createCriteria().andTxIdEqualTo(condition); example.createCriteria().andTxIdEqualTo(condition);
List<Transaction> txList = this.transactionService.getByExample(example); List<Transaction> txList = this.transactionService.getByExample(example);
if (!CollectionUtils.isEmpty(txList)) { model.setT(HomeSearchTypeEnum.TRANSACTION_INFO.getCode());
return ResponseKit.success(txList.get(0)); model.setTransList(txList);
} return ResponseKit.success(model);
} }
return ResponseKit.success(); return ResponseKit.success();
...@@ -166,6 +170,36 @@ public class TransactionController { ...@@ -166,6 +170,36 @@ public class TransactionController {
return ResponseKit.success(selfPageInfo); return ResponseKit.success(selfPageInfo);
} }
/**
* 首页 - 根据区块高度获取交易列表
*
* @param reqParam
* @return
*/
@RequestMapping(value="index/block/trans", method = RequestMethod.POST)
public ApiResponse transByBlock(@RequestBody SearchRequest reqParam) {
if (StringUtils.isEmpty(reqParam.getCondition())) {
return ResponseKit.success();
}
String condition = StringUtils.trimAllWhitespace(reqParam.getCondition());
BlockHeaderExample headerExample = new BlockHeaderExample();
headerExample.createCriteria().andNumberEqualTo(Long.valueOf(condition));
BlockHeader blockHeader = this.blockHeaderService.getOneByExample(headerExample);
TransactionExample example = new TransactionExample();
example.createCriteria().andNumberEqualTo(Long.valueOf(condition));
PageInfo<Transaction> pageInfo = this.transactionService.getByPageWithCategory(reqParam.getStartIndex(), reqParam.getPageSize(), example);
HomeSearchModel<TransactionModel> model = new HomeSearchModel();
model.setBlock(blockHeader);
List<TransactionModel> txList = this.transfer(pageInfo);
model.setTransList(txList);
model.setT(HomeSearchTypeEnum.BLOCK_INFO.getCode());
return ResponseKit.success(model);
}
/** /**
* 首页 - TRANSACTION HISTORY IN 14 DAYS * 首页 - TRANSACTION HISTORY IN 14 DAYS
* *
...@@ -207,19 +241,37 @@ public class TransactionController { ...@@ -207,19 +241,37 @@ public class TransactionController {
return ResponseKit.success(model); return ResponseKit.success(model);
} }
/**
* 用户余额排行榜
*
* @return
*/
@RequestMapping(value="/user/balance/top", method = RequestMethod.POST)
public ApiResponse userBalanceTop(@RequestBody PageRequest reqParam) {
AddressExample example = new AddressExample();
example.setOrderByClause("balance desc");
PageInfo<Address> pageInfo = this.addressService.selectByPager(reqParam.getStartIndex(), reqParam.getPageSize(), example);
SelfPageInfo<Address> selfPageInfo = new SelfPageInfo<>();
selfPageInfo.setList(pageInfo.getList());
selfPageInfo.setTotalItems(pageInfo.getTotal());
selfPageInfo.setTotalPages(pageInfo.getPages());
return ResponseKit.success(selfPageInfo);
}
/** /**
* 交易详情 * 交易详情
* *
* @return * @return
*/ */
@RequestMapping(value="/trans/info", method = RequestMethod.GET) @RequestMapping(value="/trans/info", method = RequestMethod.GET)
public ApiResponse userTrans(String txId) { public ApiResponse userTrans(String hash) {
if (StringUtils.isEmpty(txId)) { if (StringUtils.isEmpty(hash)) {
return ResponseKit.success(); return ResponseKit.success();
} }
TransactionExample example = new TransactionExample(); TransactionExample example = new TransactionExample();
example.createCriteria().andTxIdEqualTo(txId); example.createCriteria().andTxIdEqualTo(hash);
List<Transaction> txList = this.transactionService.getByExample(example); List<Transaction> txList = this.transactionService.getByExample(example);
if (!CollectionUtils.isEmpty(txList)) { if (!CollectionUtils.isEmpty(txList)) {
return ResponseKit.success(txList.get(0)); return ResponseKit.success(txList.get(0));
...@@ -263,8 +315,9 @@ public class TransactionController { ...@@ -263,8 +315,9 @@ public class TransactionController {
} }
@Data @Data
class HomeSearchModel { class HomeSearchModel<T> {
private BlockHeader block; private BlockHeader block;
private List<TransactionModel> transList; private List<T> transList;
private Address address; private Address address;
private int t;
} }
...@@ -33,4 +33,12 @@ public interface AddressRepository { ...@@ -33,4 +33,12 @@ public interface AddressRepository {
*/ */
void updateById(@Param("record") Address record); void updateById(@Param("record") Address record);
/**
* 分页查询
*
* @param example 查询条件参数
* @return 分页记录列表
*/
List<Address> selectByPager(@Param("example") AddressExample example);
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ public class AccountBalanceTask extends Job { ...@@ -27,7 +27,7 @@ public class AccountBalanceTask extends Job {
private AddressService addressService = SpringContextUtil.getBean(AddressService.class); private AddressService addressService = SpringContextUtil.getBean(AddressService.class);
private static final int SIZE = 5; private static final int SIZE = 50;
private String name = "AccountBalanceThreadPool"; private String name = "AccountBalanceThreadPool";
...@@ -69,7 +69,7 @@ public class AccountBalanceTask extends Job { ...@@ -69,7 +69,7 @@ public class AccountBalanceTask extends Job {
public synchronized void initPool() { public synchronized void initPool() {
if (threadPool == null) { if (threadPool == null) {
threadPool = new ThreadPoolExecutor(SIZE, SIZE * 2, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), threadPool = new ThreadPoolExecutor(SIZE, SIZE * 2, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
new ExecutorThreadFactory()); new ExecutorThreadFactory());
log.info("初始化线程池 name:{} coreSize:{} maxSize:{}", name, SIZE, SIZE * 2); log.info("初始化线程池 name:{} coreSize:{} maxSize:{}", name, SIZE, SIZE * 2);
} }
......
package com.wuban.tron.explore.service; package com.wuban.tron.explore.service;
import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.entity.Address; import com.wuban.tron.explore.entity.Address;
import com.wuban.tron.explore.entity.example.AddressExample; import com.wuban.tron.explore.entity.example.AddressExample;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -30,4 +31,12 @@ public interface AddressService { ...@@ -30,4 +31,12 @@ public interface AddressService {
*/ */
Address selectOneByExample(@Param("example") AddressExample example); Address selectOneByExample(@Param("example") AddressExample example);
/**
* 分页查询
*
* @param example 查询条件参数
* @return 分页记录列表
*/
PageInfo<Address> selectByPager(Integer startIndex, Integer pageSize, AddressExample example);
} }
package com.wuban.tron.explore.service.impl; package com.wuban.tron.explore.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.dao.AddressRepository; import com.wuban.tron.explore.dao.AddressRepository;
import com.wuban.tron.explore.entity.Address; import com.wuban.tron.explore.entity.Address;
import com.wuban.tron.explore.entity.example.AddressExample; import com.wuban.tron.explore.entity.example.AddressExample;
...@@ -37,4 +39,18 @@ public class AddressServiceImpl implements AddressService { ...@@ -37,4 +39,18 @@ public class AddressServiceImpl implements AddressService {
return this.addressRepository.selectOneByExample(example); return this.addressRepository.selectOneByExample(example);
} }
/**
* 分页查询
*
* @param example 查询条件参数
* @return 分页记录列表
*/
@Override
public PageInfo<Address> selectByPager(Integer startIndex,Integer pageSize, AddressExample example) {
PageHelper.startPage(startIndex, pageSize);
List<Address> list = this.addressRepository.selectByPager(example);
PageInfo<Address> pageInfo = new PageInfo<>(list);
return pageInfo;
}
} }
...@@ -5,9 +5,9 @@ spring: ...@@ -5,9 +5,9 @@ spring:
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://123.56.5.114:13306/test_tron?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://coupon-d.mysql.db.wuban.net.cn:30101/tron-explore?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root username: root
password: root123456 password: ^osyBXr7}duMefFb
# 初始化大小,最小,最大 # 初始化大小,最小,最大
initialSize: 5 initialSize: 5
minIdle: 5 minIdle: 5
...@@ -26,8 +26,8 @@ spring: ...@@ -26,8 +26,8 @@ spring:
maxPoolPreparedStatementPerConnectionSize: 20 maxPoolPreparedStatementPerConnectionSize: 20
redis: redis:
host: 123.56.5.114 host: coupon.redis.db.wuban.net.cn
port: 6379 port: 30104
jedis: jedis:
pool: pool:
max-active: 1024 max-active: 1024
...@@ -35,8 +35,8 @@ spring: ...@@ -35,8 +35,8 @@ spring:
max-wait: 10000 max-wait: 10000
min-idle: 100 min-idle: 100
timeout: 10000 timeout: 10000
password: 123456 password: lk_2AF|;29l3qvZJ
database: 2 database: 8
mybatis: mybatis:
mapper-locations: classpath:*.xml mapper-locations: classpath:*.xml
......
...@@ -82,9 +82,10 @@ ...@@ -82,9 +82,10 @@
</trim> </trim>
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertOnDuplicateKey" parameterType="java.util.Map"> <insert id="batchInsertOnDuplicateKey" parameterType="java.util.Map">
insert into <include refid="Table_Name"/> insert into <include refid="Table_Name"/>
<trim prefix="(" suffix=")" suffixOverrides=",">selectByPagerEx <trim prefix="(" suffix=")" suffixOverrides=",">
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
</trim> </trim>
values values
...@@ -94,7 +95,7 @@ ...@@ -94,7 +95,7 @@
</trim> </trim>
</foreach> </foreach>
ON DUPLICATE KEY UPDATE address = VALUES(address) ON DUPLICATE KEY UPDATE address = VALUES(address)
</insert> </insert>
<!-- end insert --> <!-- end insert -->
<!-- delete --> <!-- delete -->
<delete id="deleteById" parameterType="java.util.Map"> <delete id="deleteById" parameterType="java.util.Map">
...@@ -191,6 +192,18 @@ ...@@ -191,6 +192,18 @@
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause"/>
</if> </if>
</select> </select>
<!-- end select --> <!-- end select -->
<!-- My Custom Interfaces --> <!-- My Custom Interfaces -->
<select id="selectByPager" resultMap="AddressMap" parameterType="java.util.Map">
select
address,balance
from <include refid="Table_Name"/>
<if test="example != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment