From 620c7d02e831c6cf4658ff0d447b7320491c738d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E5=85=89=EF=BC=9A=E5=9F=8E=E4=B8=AD=E5=9F=8E?= <806783409@qq.com> Date: Wed, 30 Jan 2019 23:10:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=94=BE=E6=96=87=E6=A1=A3=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MgDocumentController.java | 27 ++++++++++++++----- .../controller/MgOpenDocController.java | 5 +++- .../swagger/controller/vo/LocationListVo.java | 9 +++++++ .../resources/webjars/open-doc/js/mg-ui.js | 27 ++++++++++++++----- .../webjars/zpages/docUrlDetailConfig.html | 10 +++++++ 5 files changed, 64 insertions(+), 14 deletions(-) diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java index 254568cd..a4ce859f 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java @@ -290,7 +290,7 @@ public class MgDocumentController { * @return 添加结果 */ @PostMapping(value = "/addSwaggerResources") - public ResponseJson addSwaggerResources(String resourcesUrl, String rewriteDomainUrl, String oldUrl) { + public ResponseJson addSwaggerResources(String resourcesUrl, String rewriteDomainUrl, String oldUrl, Integer openVisit) { String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST); // 转成set,防止重复 List resourcesList = new LinkedList<>(); @@ -306,13 +306,13 @@ public class MgDocumentController { oldUrl = this.encodeUrlParam(oldUrl); resourcesUrl = this.encodeUrlParam(resourcesUrl); String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body(); - boolean isLocation = this.addSwaggerLocationList(resourcesStr, rewriteDomainUrl, resourcesUrl, oldUrl); + boolean isLocation = this.addSwaggerLocationList(resourcesStr, rewriteDomainUrl, resourcesUrl, oldUrl, openVisit); if (!isLocation) { List resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); if (resourceList == null || resourceList.isEmpty()) { return DocResponseJson.warn("该地址未找到文档"); } - this.addSwaggerLocationList(resourceList, resourcesUrl); + this.addSwaggerLocationList(resourceList, resourcesUrl, rewriteDomainUrl, openVisit); SwaggerResourcesInfoVo resourcesInfoVo = new SwaggerResourcesInfoVo(resourcesUrl, resourceList); resourcesInfoVo.setRewriteDomainUrl(rewriteDomainUrl); resourcesList.add(resourcesInfoVo); @@ -398,14 +398,24 @@ public class MgDocumentController { /** * 直接添加地址 */ - private boolean addSwaggerLocationList(String resourcesStr, String rewriteDomainUrl, String locationUrl, String oldUrl) { + private boolean addSwaggerLocationList(String resourcesStr, String rewriteDomainUrl, String locationUrl, String oldUrl, Integer openVisit) { try { SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class); if (swaggerLocationVo != null && StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) { List locationList = this.getLocationSet(); - locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList()); + // 组装新的对象 LocationListVo locationListVo = new LocationListVo(locationUrl, ""); locationListVo.setRewriteDomainUrl(rewriteDomainUrl); + locationListVo.setOpenVisit(openVisit); + // 如果旧的不为空,使用旧的uuid + for (LocationListVo location : locationList) { + if (Objects.equals(location.getLocation(), oldUrl) && StringUtils.isNotBlank(location.getUuid())) { + locationListVo.setUuid(location.getUuid()); + break; + } + } + // 去除旧的,加入新的 + locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList()); locationList.add(locationListVo); this.storageSwaggerLocationList(locationList); return true; @@ -419,13 +429,16 @@ public class MgDocumentController { /** * 直接添加地址 */ - private void addSwaggerLocationList(List resourceList, String resourcesUrl) { + private void addSwaggerLocationList(List resourceList, String resourcesUrl, String rewriteDomainUrl, Integer openVisit) { List locationList = this.getLocationSet(); // 加入到location列表 String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1); for (SwaggerResource swaggerResource : resourceList) { String location = this.getLocationUrl(resourcesDomain, swaggerResource.getLocation(), swaggerResource.getName()); - locationList.add(new LocationListVo(location, resourcesUrl)); + LocationListVo locationListVo = new LocationListVo(location, resourcesUrl); + locationListVo.setRewriteDomainUrl(rewriteDomainUrl); + locationListVo.setOpenVisit(openVisit); + locationList.add(locationListVo); } this.storageSwaggerLocationList(locationList); } diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java index efccddd9..c6e86a19 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java @@ -68,12 +68,15 @@ public class MgOpenDocController { locationList = JSON.parseArray(swaggerLocationListStr, LocationListVo.class); } if (StringUtils.isNotBlank(choiceLocationList)) { - locationList = locationList.stream().filter(val -> Objects.equals(val.getUuid(), choiceLocationList)).collect(Collectors.toList()); + // uuid相同而且开启了文档 + locationList = locationList.stream().filter(val -> Objects.equals(val.getUuid(), choiceLocationList) && Objects.equals(val.getOpenVisit(), 1)).collect(Collectors.toList()); } else { DocResponseJson.ok().send(response); + return; } if (locationList.size() <= 0) { DocResponseJson.ok().send(response); + return; } List swaggerResourceStrList = new LinkedList<>(); for (LocationListVo location : locationList) { diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java index 661b89c5..7ba19247 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java @@ -11,6 +11,7 @@ public class LocationListVo { private String uuid; private String location; private String resources; + private Integer openVisit; private String rewriteDomainUrl; public LocationListVo(){ @@ -96,4 +97,12 @@ public class LocationListVo { public void setUuid(String uuid) { this.uuid = uuid; } + + public Integer getOpenVisit() { + return openVisit; + } + + public void setOpenVisit(Integer openVisit) { + this.openVisit = openVisit; + } } diff --git a/zyplayer-doc-swagger/src/main/resources/webjars/open-doc/js/mg-ui.js b/zyplayer-doc-swagger/src/main/resources/webjars/open-doc/js/mg-ui.js index 1f38dd1f..40325882 100644 --- a/zyplayer-doc-swagger/src/main/resources/webjars/open-doc/js/mg-ui.js +++ b/zyplayer-doc-swagger/src/main/resources/webjars/open-doc/js/mg-ui.js @@ -131,10 +131,14 @@ function addDocumentByLocationService(choiceDocList) { } documentJsonArr = []; initDashboard(); - - for (var i = 0; i < json.data.length; i++) { + var data = json.data || []; + if (data.length <= 0) { + documentLoadError('未找到相关文档,请确认地址是否正确'); + return; + } + for (var i = 0; i < data.length; i++) { showGlobalLoadingMessage('解析第' + (i + 1) + '份文档,请稍候...', true); - var tempDoc = deserialize(json.data[i]); + var tempDoc = deserialize(data[i]); console.log(tempDoc); documentJsonArr.push(tempDoc);// 加到所有文档 addHomePageDashboard(tempDoc, tempDoc.fullUrl); @@ -954,9 +958,7 @@ function updateTreeShowType() { } /** - * 初始化用户的设置 - * @param - * @returns + * 文档正常加载完成 */ function documentLoadFinish() { showGlobalLoadingMessage('文档解析完成!', false); @@ -969,6 +971,19 @@ function documentLoadFinish() { $('#homePageDashboard .dashboard').dashboard({draggable: false}); } +/** + * 文档加载完成-有错误 + */ +function documentLoadError(toastInfo) { + showGlobalLoadingMessage(toastInfo); + // 隐藏提示框 + setTimeout(function() { + globalLoadingMessager.hide(); + }, 3000); + regeneratePathTree(); + $('#homePageDashboard .dashboard').dashboard({draggable: false}); +} + /** * 存储用户设置 */ diff --git a/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html b/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html index 737f16a3..b9a66dc3 100644 --- a/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html +++ b/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html @@ -61,6 +61,12 @@ 重写域名地址: +
+
+ + +
+