From 084df76f7a2bf3013f127fd84306ac4f1782c534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E8=BE=89?= Date: Thu, 8 Apr 2021 18:14:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=20push.doc=20=E4=BC=9A=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=88=B6=E7=B1=BBdocInfo=EF=BC=8C=E5=AF=BC=E8=87=B4=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E6=97=A0=E6=B3=95=E6=9F=A5=E7=9C=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server-api/src/main/java/cn/torna/api/open/DocApi.java | 7 ++++++- .../src/main/java/cn/torna/service/DocInfoService.java | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/server-api/src/main/java/cn/torna/api/open/DocApi.java b/server/server-api/src/main/java/cn/torna/api/open/DocApi.java index 7dd3cf98..5e7b7733 100644 --- a/server/server-api/src/main/java/cn/torna/api/open/DocApi.java +++ b/server/server-api/src/main/java/cn/torna/api/open/DocApi.java @@ -33,6 +33,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * @author tanghc @@ -67,6 +70,8 @@ public class DocApi { String token = context.getToken(); log.info("收到文档推送,appKey:{}, token:{}", appKey, token); long moduleId = context.getModuleId(); + Set parentIds = param.getApis().parallelStream().map(DocPushItemParam::getParentId) + .filter(Objects::nonNull).collect(Collectors.toSet()); tornaTransactionManager.execute(() -> { // 设置调试环境 for (DebugEnvParam debugEnv : param.getDebugEnvs()) { @@ -74,7 +79,7 @@ public class DocApi { } // 先删除之前的文档 User user = context.getApiUser(); - docInfoService.deleteModuleDocs(moduleId, user.getUserId()); + docInfoService.deleteModuleDocs(moduleId, user.getUserId(), parentIds); for (DocPushItemParam detailPushParam : param.getApis()) { this.pushDocItem(detailPushParam, context); } diff --git a/server/server-service/src/main/java/cn/torna/service/DocInfoService.java b/server/server-service/src/main/java/cn/torna/service/DocInfoService.java index e9f3867e..d1f0251c 100755 --- a/server/server-service/src/main/java/cn/torna/service/DocInfoService.java +++ b/server/server-service/src/main/java/cn/torna/service/DocInfoService.java @@ -29,6 +29,7 @@ import org.springframework.util.CollectionUtils; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -296,12 +297,16 @@ public class DocInfoService extends BaseService { * 删除模块下所有文档 * @param moduleId 模块id * @param userId 用户id,只能删除自己创建的 + * @param parentIds 父级id */ - public void deleteModuleDocs(long moduleId, long userId) { + public void deleteModuleDocs(long moduleId, long userId, Set parentIds) { Query query = new Query() .eq("module_id", moduleId) .eq("create_mode", OperationMode.OPEN.getType()) .eq("creator_id", userId); + if (parentIds != null && parentIds.size() > 0) { + query.notIn("id", parentIds); + } this.getMapper().deleteByQuery(query); } } \ No newline at end of file -- Gitee