diff --git a/sql/update20230407.sql b/sql/update20230407.sql deleted file mode 100644 index 31fe9a3..0000000 --- a/sql/update20230407.sql +++ /dev/null @@ -1,6 +0,0 @@ -alter table tbl_node_info_off_chain - add bad_actor tinyint(1) default 0 null comment 'bad actor节点标签,前十个周期内任一周期fee ratio下调超过50% -'; - -alter table tbl_node_info_off_chain - add risky tinyint(1) default 0 null comment '风险提示标签单次fee sharing向上调整超过50%'; \ No newline at end of file diff --git a/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java b/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java index 6680b43..160f31a 100644 --- a/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java +++ b/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java @@ -71,18 +71,20 @@ public Response insertOffChainInfo(InsertOffChainNodeInfoDto insertOffChainNodeI String address = insertOffChainNodeInfoDto.getAddress(); String name = insertOffChainNodeInfoDto.getName(); String publicKey = insertOffChainNodeInfoDto.getPublicKey(); - if (StringUtils.isEmpty(publicKey)) { + if (!StringUtils.hasLength(publicKey)) { return new Response(61001, "Public key is blank", ""); } String peerInfo = ontSdkService.getPeerInfo(publicKey); - if (!StringUtils.isEmpty(peerInfo)) { + if (StringUtils.hasLength(peerInfo)) { + JSONObject jsonObject = JSONObject.parseObject(peerInfo); + int status = jsonObject.getIntValue("status"); NodeInfoOffChain nodeInfoOffChain = new NodeInfoOffChain(); nodeInfoOffChain.setPublicKey(publicKey); nodeInfoOffChain.setAddress(address); nodeInfoOffChain.setName(name); nodeInfoOffChain.setVerification(0); nodeInfoOffChain.setOntId(""); - nodeInfoOffChain.setNodeType(1); + nodeInfoOffChain.setNodeType(status); nodeInfoOffChain.setOpenFlag(true); nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain); return new Response(0, "SUCCESS", "SUCCESS"); @@ -109,14 +111,22 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf if (ontId == null) { nodeInfoOffChain.setOntId(""); } - nodeInfoOffChain.setNodeType(1); String nodePublicKey = nodeInfoOffChain.getPublicKey(); String name = nodeInfoOffChainMapper.selectNameByPublicKey(nodePublicKey); - if (StringUtils.isEmpty(name)) { + if (!StringUtils.hasLength(name)) { // insert + String peerInfo = ontSdkService.getPeerInfo(nodePublicKey); + if (StringUtils.hasLength(peerInfo)) { + JSONObject jsonObject = JSONObject.parseObject(peerInfo); + int status = jsonObject.getIntValue("status"); + nodeInfoOffChain.setNodeType(status); + } else { + nodeInfoOffChain.setNodeType(1); + } nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain); } else { // update + nodeInfoOffChain.setNodeType(null); nodeInfoOffChainMapper.updateByPrimaryKeySelective(nodeInfoOffChain); } return new Response(0, "SUCCESS", "SUCCESS"); @@ -147,14 +157,22 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh if (ontId == null) { nodeInfoOffChain.setOntId(""); } - nodeInfoOffChain.setNodeType(1); String nodePublicKey = nodeInfoOffChain.getPublicKey(); String name = nodeInfoOffChainMapper.selectNameByPublicKey(nodePublicKey); - if (StringUtils.isEmpty(name)) { + if (!StringUtils.hasLength(name)) { // insert + String peerInfo = ontSdkService.getPeerInfo(nodePublicKey); + if (StringUtils.hasLength(peerInfo)) { + JSONObject jsonObject = JSONObject.parseObject(peerInfo); + int status = jsonObject.getIntValue("status"); + nodeInfoOffChain.setNodeType(status); + } else { + nodeInfoOffChain.setNodeType(1); + } nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain); } else { // update + nodeInfoOffChain.setNodeType(null); nodeInfoOffChainMapper.updateByPrimaryKeySelective(nodeInfoOffChain); } return new Response(0, "SUCCESS", "SUCCESS"); diff --git a/src/main/resources/mapper/NodeInfoOffChainMapper.xml b/src/main/resources/mapper/NodeInfoOffChainMapper.xml index c23e6ab..8856efd 100644 --- a/src/main/resources/mapper/NodeInfoOffChainMapper.xml +++ b/src/main/resources/mapper/NodeInfoOffChainMapper.xml @@ -31,20 +31,19 @@ INSERT INTO tbl_node_info_off_chain ( name, public_key, address, node_type, ont_id, open_flag ) SELECT CASE - onchain.name + name WHEN '' THEN - CONCAT('Node','_',SUBSTRING(onchain.public_key,1,6)) ELSE onchain.name + CONCAT('Node','_',SUBSTRING(public_key,1,6)) ELSE name END, - onchain.public_key, - onchain.address, - onchain.STATUS, + public_key, + address, + status, '', 1 FROM tbl_node_info_on_chain onchain - LEFT JOIN tbl_node_info_off_chain offchain ON onchain.public_key = offchain.public_key -WHERE - offchain.public_key IS NULL; + ON DUPLICATE KEY UPDATE + node_type = VALUES(node_type)