From 5dbdc5229cb31e5e7814771e62b82df1c0255808 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Mon, 14 Aug 2023 15:40:22 +0800 Subject: [PATCH] Update node overview --- .../ontio/controller/NodesController.java | 10 ++++----- .../ontio/mapper/NodeOverviewMapper.java | 4 ---- .../github/ontio/model/dao/NodeOverview.java | 22 +++++++++++++++++++ .../ontio/service/impl/NodesServiceImpl.java | 15 +++---------- .../db/migration/V1.79__tbl_node_overview.sql | 1 + .../resources/mapper/NodeOverviewMapper.xml | 15 ------------- 6 files changed, 31 insertions(+), 36 deletions(-) create mode 100644 back-end-projects/Explorer/src/main/resources/db/migration/V1.79__tbl_node_overview.sql diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java index a6ad33c2..c4d99c9f 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java @@ -51,16 +51,16 @@ public NodesController(NodesServiceImpl nodesService, @ApiOperation(value = "Get block count to next round") @GetMapping(value = "/block-count-to-next-round") public ResponseBean getBlkCountToNxtRnd() { - long blkCountToNxtRnd = nodesService.getBlkCountToNxtRnd(); - long leftTime2NextRound = nodesService.getLeftTimeToNextRound(); + NodeOverview nodeOverview = nodesService.getNodeOverviewInfo(); long maxStakingChangeCount = configService.getMaxStakingChangeCount(); - if (blkCountToNxtRnd < 0 || leftTime2NextRound < 0 || maxStakingChangeCount <= 0) { + if (nodeOverview == null || maxStakingChangeCount <= 0) { return new ResponseBean(ErrorInfo.INNER_ERROR.code(), ErrorInfo.INNER_ERROR.desc(), ""); } JSONObject result = new JSONObject(); - result.put("count_to_next_round", blkCountToNxtRnd); + result.put("count_to_next_round", nodeOverview.getBlkCntToNxtRnd()); result.put("max_staking_change_count", maxStakingChangeCount); - result.put("left_time_to_next_round", leftTime2NextRound); + result.put("left_time_to_next_round", nodeOverview.getLeftTimeToNextRnd()); + result.put("round_start_time", nodeOverview.getRndStartTime()); return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), result); } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeOverviewMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeOverviewMapper.java index 308351cc..73f8d7ce 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeOverviewMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeOverviewMapper.java @@ -7,8 +7,4 @@ @Repository public interface NodeOverviewMapper extends Mapper { - Long selectBlkCountToNxtRnd(); - - Long selectLeftTimeToNxtRnd(); - } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/NodeOverview.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/NodeOverview.java index ec06b613..c72713fb 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/NodeOverview.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/NodeOverview.java @@ -11,6 +11,12 @@ public class NodeOverview { @Column(name = "blk_cnt_to_nxt_rnd") private Long blkCntToNxtRnd; + @Column(name = "left_time_to_next_rnd") + private Integer leftTimeToNextRnd; + + @Column(name = "rnd_start_time") + private Integer rndStartTime; + /** * @return id */ @@ -38,4 +44,20 @@ public Long getBlkCntToNxtRnd() { public void setBlkCntToNxtRnd(Long blkCntToNxtRnd) { this.blkCntToNxtRnd = blkCntToNxtRnd; } + + public Integer getLeftTimeToNextRnd() { + return leftTimeToNextRnd; + } + + public void setLeftTimeToNextRnd(Integer leftTimeToNextRnd) { + this.leftTimeToNextRnd = leftTimeToNextRnd; + } + + public Integer getRndStartTime() { + return rndStartTime; + } + + public void setRndStartTime(Integer rndStartTime) { + this.rndStartTime = rndStartTime; + } } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java index a11902a9..3273b095 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java @@ -133,21 +133,12 @@ private synchronized void initSDK() { } } - public long getBlkCountToNxtRnd() { + public NodeOverview getNodeOverviewInfo() { try { - return nodeOverviewMapper.selectBlkCountToNxtRnd(); + return nodeOverviewMapper.selectByPrimaryKey(1); } catch (Exception e) { log.warn("Getting block count to next round failed: {}", e.getMessage()); - return -1; - } - } - - public long getLeftTimeToNextRound() { - try { - return nodeOverviewMapper.selectLeftTimeToNxtRnd(); - } catch (Exception e) { - log.warn("Getting left time to next round failed: {}", e.getMessage()); - return -1; + return null; } } diff --git a/back-end-projects/Explorer/src/main/resources/db/migration/V1.79__tbl_node_overview.sql b/back-end-projects/Explorer/src/main/resources/db/migration/V1.79__tbl_node_overview.sql new file mode 100644 index 00000000..3fe068b0 --- /dev/null +++ b/back-end-projects/Explorer/src/main/resources/db/migration/V1.79__tbl_node_overview.sql @@ -0,0 +1 @@ +ALTER TABLE tbl_node_overview ADD COLUMN `rnd_start_time` int(11) DEFAULT NULL COMMENT '当前周期开始时间'; \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/resources/mapper/NodeOverviewMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/NodeOverviewMapper.xml index c9bf030f..6b69d3b7 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/NodeOverviewMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/NodeOverviewMapper.xml @@ -2,9 +2,6 @@ - @@ -15,16 +12,4 @@ - - - - \ No newline at end of file