From 49f78a215a0841ec93ad4904569ae99e65151956 Mon Sep 17 00:00:00 2001 From: CodingCattwo <847701726@qq.com> Date: Fri, 4 Dec 2020 11:36:15 +0800 Subject: [PATCH 1/3] fix ignore path repeat --- .../webank/webase/node/mgr/contract/ContractService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java b/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java index d8b546160..89900b6e0 100644 --- a/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java +++ b/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java @@ -128,7 +128,11 @@ private TbContract newContract(Contract contract) { // save contract path log.debug("newContract save contract path"); // if exist, auto not save - contractPathService.save(contract.getGroupId(), contract.getContractPath()); + try { + contractPathService.save(contract.getGroupId(), contract.getContractPath()); + } catch (NodeMgrException e) { + log.warn("newContract and contract path exist, not save path"); + } return tbContract; } From e47f784cce2a1cfb2339c463b017535f87ee5ec7 Mon Sep 17 00:00:00 2001 From: CodingCattwo <847701726@qq.com> Date: Fri, 4 Dec 2020 11:45:10 +0800 Subject: [PATCH 2/3] fix ignore path repeat optimzie --- .../webank/webase/node/mgr/contract/ContractService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java b/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java index 89900b6e0..176d0fa94 100644 --- a/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java +++ b/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java @@ -127,12 +127,8 @@ private TbContract newContract(Contract contract) { contractMapper.add(tbContract); // save contract path log.debug("newContract save contract path"); - // if exist, auto not save - try { - contractPathService.save(contract.getGroupId(), contract.getContractPath()); - } catch (NodeMgrException e) { - log.warn("newContract and contract path exist, not save path"); - } + // if exist, auto not save (ignor) + contractPathService.save(contract.getGroupId(), contract.getContractPath(), true); return tbContract; } From 0c92838f64086bb76a16788c8d81f8250189a0ed Mon Sep 17 00:00:00 2001 From: CodingCattwo <847701726@qq.com> Date: Fri, 4 Dec 2020 11:49:11 +0800 Subject: [PATCH 3/3] optimize path save --- .../webase/node/mgr/contract/ContractController.java | 2 +- .../webase/node/mgr/contract/ContractPathService.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java b/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java index 63b6ae09e..025532f11 100644 --- a/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java +++ b/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java @@ -279,7 +279,7 @@ public BaseResponse addContractPath(@Valid @RequestBody ContractPathParam param) if ("".equals(contractPath)) { contractPath = "/"; } - int result = contractPathService.save(param.getGroupId(), contractPath); + int result = contractPathService.save(param.getGroupId(), contractPath, false); response.setData(result); log.info("end addContractPath. useTime:{} add result:{}", diff --git a/src/main/java/com/webank/webase/node/mgr/contract/ContractPathService.java b/src/main/java/com/webank/webase/node/mgr/contract/ContractPathService.java index 1131116d3..fd2b45670 100644 --- a/src/main/java/com/webank/webase/node/mgr/contract/ContractPathService.java +++ b/src/main/java/com/webank/webase/node/mgr/contract/ContractPathService.java @@ -42,11 +42,15 @@ public List listContractPath(Integer groupId) { * @param pathName * @return */ - public int save(Integer groupId, String pathName) { + public int save(Integer groupId, String pathName, boolean ignoreRepeat) { TbContractPath check = contractPathMapper.findOne(new ContractPathParam(groupId, pathName)); if (check != null) { - log.error("save path, path exists check:{}", check); - throw new NodeMgrException(ConstantCode.CONTRACT_PATH_IS_EXISTS); + if (ignoreRepeat) { + return 0; + } else { + log.error("save path, path exists check:{}", check); + throw new NodeMgrException(ConstantCode.CONTRACT_PATH_IS_EXISTS); + } } TbContractPath contractPath = new TbContractPath(); contractPath.setContractPath(pathName);