开放文档逻辑修改,增加开关

This commit is contained in:
暮光:城中城
2019-01-30 23:10:28 +08:00
parent 496bb0d106
commit 620c7d02e8
5 changed files with 64 additions and 14 deletions

View File

@@ -290,7 +290,7 @@ public class MgDocumentController {
* @return 添加结果 * @return 添加结果
*/ */
@PostMapping(value = "/addSwaggerResources") @PostMapping(value = "/addSwaggerResources")
public ResponseJson<Object> addSwaggerResources(String resourcesUrl, String rewriteDomainUrl, String oldUrl) { public ResponseJson<Object> addSwaggerResources(String resourcesUrl, String rewriteDomainUrl, String oldUrl, Integer openVisit) {
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST); String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
// 转成set防止重复 // 转成set防止重复
List<SwaggerResourcesInfoVo> resourcesList = new LinkedList<>(); List<SwaggerResourcesInfoVo> resourcesList = new LinkedList<>();
@@ -306,13 +306,13 @@ public class MgDocumentController {
oldUrl = this.encodeUrlParam(oldUrl); oldUrl = this.encodeUrlParam(oldUrl);
resourcesUrl = this.encodeUrlParam(resourcesUrl); resourcesUrl = this.encodeUrlParam(resourcesUrl);
String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body(); 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) { if (!isLocation) {
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
if (resourceList == null || resourceList.isEmpty()) { if (resourceList == null || resourceList.isEmpty()) {
return DocResponseJson.warn("该地址未找到文档"); return DocResponseJson.warn("该地址未找到文档");
} }
this.addSwaggerLocationList(resourceList, resourcesUrl); this.addSwaggerLocationList(resourceList, resourcesUrl, rewriteDomainUrl, openVisit);
SwaggerResourcesInfoVo resourcesInfoVo = new SwaggerResourcesInfoVo(resourcesUrl, resourceList); SwaggerResourcesInfoVo resourcesInfoVo = new SwaggerResourcesInfoVo(resourcesUrl, resourceList);
resourcesInfoVo.setRewriteDomainUrl(rewriteDomainUrl); resourcesInfoVo.setRewriteDomainUrl(rewriteDomainUrl);
resourcesList.add(resourcesInfoVo); 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 { try {
SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class); SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class);
if (swaggerLocationVo != null && StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) { if (swaggerLocationVo != null && StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) {
List<LocationListVo> locationList = this.getLocationSet(); List<LocationListVo> locationList = this.getLocationSet();
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList()); // 组装新的对象
LocationListVo locationListVo = new LocationListVo(locationUrl, ""); LocationListVo locationListVo = new LocationListVo(locationUrl, "");
locationListVo.setRewriteDomainUrl(rewriteDomainUrl); 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); locationList.add(locationListVo);
this.storageSwaggerLocationList(locationList); this.storageSwaggerLocationList(locationList);
return true; return true;
@@ -419,13 +429,16 @@ public class MgDocumentController {
/** /**
* 直接添加地址 * 直接添加地址
*/ */
private void addSwaggerLocationList(List<SwaggerResource> resourceList, String resourcesUrl) { private void addSwaggerLocationList(List<SwaggerResource> resourceList, String resourcesUrl, String rewriteDomainUrl, Integer openVisit) {
List<LocationListVo> locationList = this.getLocationSet(); List<LocationListVo> locationList = this.getLocationSet();
// 加入到location列表 // 加入到location列表
String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1); String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
for (SwaggerResource swaggerResource : resourceList) { for (SwaggerResource swaggerResource : resourceList) {
String location = this.getLocationUrl(resourcesDomain, swaggerResource.getLocation(), swaggerResource.getName()); 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); this.storageSwaggerLocationList(locationList);
} }

View File

@@ -68,12 +68,15 @@ public class MgOpenDocController {
locationList = JSON.parseArray(swaggerLocationListStr, LocationListVo.class); locationList = JSON.parseArray(swaggerLocationListStr, LocationListVo.class);
} }
if (StringUtils.isNotBlank(choiceLocationList)) { 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 { } else {
DocResponseJson.ok().send(response); DocResponseJson.ok().send(response);
return;
} }
if (locationList.size() <= 0) { if (locationList.size() <= 0) {
DocResponseJson.ok().send(response); DocResponseJson.ok().send(response);
return;
} }
List<String> swaggerResourceStrList = new LinkedList<>(); List<String> swaggerResourceStrList = new LinkedList<>();
for (LocationListVo location : locationList) { for (LocationListVo location : locationList) {

View File

@@ -11,6 +11,7 @@ public class LocationListVo {
private String uuid; private String uuid;
private String location; private String location;
private String resources; private String resources;
private Integer openVisit;
private String rewriteDomainUrl; private String rewriteDomainUrl;
public LocationListVo(){ public LocationListVo(){
@@ -96,4 +97,12 @@ public class LocationListVo {
public void setUuid(String uuid) { public void setUuid(String uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
public Integer getOpenVisit() {
return openVisit;
}
public void setOpenVisit(Integer openVisit) {
this.openVisit = openVisit;
}
} }

View File

@@ -131,10 +131,14 @@ function addDocumentByLocationService(choiceDocList) {
} }
documentJsonArr = []; documentJsonArr = [];
initDashboard(); initDashboard();
var data = json.data || [];
for (var i = 0; i < json.data.length; i++) { if (data.length <= 0) {
documentLoadError('未找到相关文档,请确认地址是否正确');
return;
}
for (var i = 0; i < data.length; i++) {
showGlobalLoadingMessage('解析第' + (i + 1) + '份文档,请稍候...', true); showGlobalLoadingMessage('解析第' + (i + 1) + '份文档,请稍候...', true);
var tempDoc = deserialize(json.data[i]); var tempDoc = deserialize(data[i]);
console.log(tempDoc); console.log(tempDoc);
documentJsonArr.push(tempDoc);// 加到所有文档 documentJsonArr.push(tempDoc);// 加到所有文档
addHomePageDashboard(tempDoc, tempDoc.fullUrl); addHomePageDashboard(tempDoc, tempDoc.fullUrl);
@@ -954,9 +958,7 @@ function updateTreeShowType() {
} }
/** /**
* 初始化用户的设置 * 文档正常加载完成
* @param
* @returns
*/ */
function documentLoadFinish() { function documentLoadFinish() {
showGlobalLoadingMessage('文档解析完成!', false); showGlobalLoadingMessage('文档解析完成!', false);
@@ -969,6 +971,19 @@ function documentLoadFinish() {
$('#homePageDashboard .dashboard').dashboard({draggable: false}); $('#homePageDashboard .dashboard').dashboard({draggable: false});
} }
/**
* 文档加载完成-有错误
*/
function documentLoadError(toastInfo) {
showGlobalLoadingMessage(toastInfo);
// 隐藏提示框
setTimeout(function() {
globalLoadingMessager.hide();
}, 3000);
regeneratePathTree();
$('#homePageDashboard .dashboard').dashboard({draggable: false});
}
/** /**
* 存储用户设置 * 存储用户设置
*/ */

View File

@@ -61,6 +61,12 @@
重写域名地址: 重写域名地址:
<input v-model="rewriteDomainUrl" type="text" name="rewriteDomainUrl" class="form-control" placeholder="文档展示配置页 勾选“重写域名”重写的地址"> <input v-model="rewriteDomainUrl" type="text" name="rewriteDomainUrl" class="form-control" placeholder="文档展示配置页 勾选“重写域名”重写的地址">
</div> </div>
<div class="input-line">
<div class="switch switch-inline">
<input type="checkbox" v-model="openVisit">
<label>是否开启开放文档</label>
</div>
</div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-primary" v-on:click="addNewDocumentBtn">保存</button> <button type="button" class="btn btn-primary" v-on:click="addNewDocumentBtn">保存</button>
@@ -85,6 +91,7 @@
swaggerLocationList: [], swaggerLocationList: [],
addNewDocumentInput: '', addNewDocumentInput: '',
rewriteDomainUrl: '', rewriteDomainUrl: '',
openVisit: '',
oldLocation: '' oldLocation: ''
}, },
methods: { methods: {
@@ -109,9 +116,11 @@
app.oldLocation = item.location; app.oldLocation = item.location;
app.addNewDocumentInput = item.location; app.addNewDocumentInput = item.location;
app.rewriteDomainUrl = item.rewriteDomainUrl; app.rewriteDomainUrl = item.rewriteDomainUrl;
app.openVisit = (item.openVisit == 1);
$('#addNewDocumentModal').modal({moveable: true}); $('#addNewDocumentModal').modal({moveable: true});
}, },
addNewDocument: function(){ addNewDocument: function(){
app.openVisit = false;
app.oldLocation = ''; app.oldLocation = '';
app.addNewDocumentInput = ''; app.addNewDocumentInput = '';
$('#addNewDocumentModal').modal({moveable:true}); $('#addNewDocumentModal').modal({moveable:true});
@@ -122,6 +131,7 @@
Toast.error("地址不可以为空");return; Toast.error("地址不可以为空");return;
} }
var param = { var param = {
openVisit: app.openVisit ? 1 : 0,
resourcesUrl: addNewDocumentInput, resourcesUrl: addNewDocumentInput,
rewriteDomainUrl: app.rewriteDomainUrl, rewriteDomainUrl: app.rewriteDomainUrl,
oldUrl: app.oldLocation oldUrl: app.oldLocation