Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
HCJ0001 committed Feb 24, 2020
1 parent bf52b63 commit d2af6d5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ams/src/main/java/press/whcj/ams/common/ColumnName.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface ColumnName {
String STRUCTURE_ID = "structureId";
String GROUP = "group";
String GROUP_ID = "groupId";
String GROUP_$ID = "group.id";
String GROUP_$ID = "group.$id";
String API_ID = "apiId";
String API_SUCCESS_MOCK = "apiSuccessMock";
String API_FAILURE_MOCK = "apiFailureMock";
Expand Down
1 change: 1 addition & 0 deletions ams/src/main/java/press/whcj/ams/entity/dto/ApiDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class ApiDto extends ApiVo {
private List<String> ids = new ArrayList<>();
private String structureId;
private String nameOrUri;
private List<String> groupIds = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package press.whcj.ams.service.impl;

import org.bson.types.ObjectId;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
Expand Down Expand Up @@ -76,9 +77,9 @@ public void delete(ApiGroup apiGroupDto) {
return;
}
// concat sub & parent
mongoTemplate.findAndModify(new Query(Criteria.where(ColumnName.PARENT_ID).is(apiGroupId)),
mongoTemplate.updateMulti(new Query(Criteria.where(ColumnName.PARENT_ID).is(apiGroupId)),
Update.update(ColumnName.PARENT_ID, apiGroupDto.getParentId()), ApiGroup.class);
mongoTemplate.findAndModify(new Query(Criteria.where(ColumnName.GROUP_$ID).is(apiGroupId)),
mongoTemplate.updateMulti(new Query(Criteria.where(ColumnName.GROUP_$ID).is(new ObjectId(apiGroupId))),
Update.update(ColumnName.GROUP, new ApiGroup(apiGroupDto.getParentId())), Api.class);
mongoTemplate.remove(apiGroupDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public MongoPage<ApiVo> findPage(ApiDto apiDto) {
Criteria criteria = Criteria.where(ColumnName.PROJECT_ID).is(apiDto.getProjectId())
.and(ColumnName.IS_DEL).ne(Constant.Is.YES);
// concat query condition
if (!StringUtils.isEmpty(apiDto.getGroupId())) {
criteria = criteria.and(ColumnName.GROUP_$ID).is(apiDto.getGroupId());
if (!apiDto.getGroupIds().isEmpty()) {
List<ObjectId> ids = apiDto.getGroupIds().stream().map(ObjectId::new).collect(Collectors.toList());
criteria = criteria.and(ColumnName.GROUP_$ID).in(ids);
}
if (!StringUtils.isEmpty(apiDto.getNameOrUri())) {
BsonRegularExpression expression = new BsonRegularExpression("^.*" + apiDto.getNameOrUri() + ".*$", "i");
Expand All @@ -122,7 +123,11 @@ public MongoPage<ApiVo> findPage(ApiDto apiDto) {
}
Query query = new Query(criteria);
query.with(page.buildPageRequest()).with(QSort.by(Sort.Direction.DESC, ColumnName.UPDATE_TIME));
page.setTotal(mongoTemplate.count(query, Api.class));
long total = mongoTemplate.count(query, Api.class);
page.setTotal(total);
if (total == 0L) {
return page;
}
return page.setRecords(mongoTemplate.find(query, ApiVo.class, Constant.CollectionName.API));
}

Expand Down
6 changes: 5 additions & 1 deletion front/src/common/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ export const UTILS = {
$this.$axios.post(url, dataObj.query).then(resp => {
if (this.checkResp(resp)) {
const data = resp.data.data;
dataObj.dataList = data.records;
if (!data.records) {
dataObj.dataList = [];
} else {
dataObj.dataList = data.records;
}
dataObj.query.page.total = data.total;
if (data.total !== 0 && (dataObj.query.page.current - 1) * dataObj.query.page.size > data.total) {
dataObj.query.page.current = 1;
Expand Down
3 changes: 0 additions & 3 deletions front/src/components/selectApiGroup/selectApiGroupDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@
});
}
},
created() {
this.findApiGroups();
}
};
</script>

Expand Down
36 changes: 29 additions & 7 deletions front/src/views/apiDoc/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
group
</el-button>
</div>
<div class="select-all" @click="selectGroup({id:''})">all</div>
<el-tree :data="groups" :props="{label:'name',children:'childList'}"
<div class="select-all" @click="selectGroup">all</div>
<el-tree :data="groups" :props="{label:'name',children:'childList'}" :expand-on-click-node="false"
node-key="id" default-expand-all @node-click="selectGroup"
draggable @node-drop="moveNode" highlight-current>
<span class="api-group-node" slot-scope="{node,data}">
Expand All @@ -28,7 +28,7 @@
</template>
</span>
<el-dropdown @command="command" style="float:right;padding-right: 5px">
<span class="el-dropdown-link">
<span class="el-dropdown-link" @click.stop="()=>{}">
<i class="el-icon-arrow-down el-icon-more"/>
</span>
<el-dropdown-menu slot="dropdown">
Expand Down Expand Up @@ -179,7 +179,7 @@
<edit-api-group-dialog :dialog="editApiGroupDialog" :form="editApiGroupForm" @flush="findApiGroups"/>
<confirm-dialog :dialog="delConfirmDialog" :form="delForm" @flush="delConfirmDialog.flush"/>
<select-api-status-dialog :dialog="selectApiStatusDialog" @flush="findApiPage"/>
<select-api-group-dialog :dialog="selectApiGroupDialog" @flush="findApiPage"/>
<select-api-group-dialog :dialog="selectApiGroupDialog" @flush="findApiPage" ref="select-api-group-dialog"/>
</div>
</template>

Expand Down Expand Up @@ -209,6 +209,7 @@
editApiGroupForm: {},
dataList: [],
query: {
groupIds: [],
apiStatus: undefined,
nameOrUri: '',
page: {
Expand All @@ -218,6 +219,7 @@
}
},
selectedGroupId: '',
selectedGroup: undefined,
delConfirmDialog: {
show: false,
title: 'Delete Confirm',
Expand Down Expand Up @@ -251,13 +253,18 @@
return UTILS.formatDate(new Date(time), CONSTANT.CONFIG.DATE_FORMAT);
},
selectGroup(apiGroup) {
if (apiGroup.id === '') {
if (!apiGroup) {
// click all
let selectElement = document.getElementsByClassName('el-tree-node is-current is-focusable');
if (selectElement.length > 0) {
selectElement[0].classList.remove('is-current');
}
this.selectedGroupId = '';
this.selectedGroup = undefined;
} else {
this.selectedGroupId = apiGroup.id;
this.selectedGroup = apiGroup;
}
this.selectedGroupId = apiGroup.id;
this.findApiPage();
},
command(func) {
Expand Down Expand Up @@ -315,7 +322,18 @@
this.showSelect = false;
this.selectApiStatusDialog.apiStatus = '';
this.query.projectId = this.projectId;
this.query.groupId = this.selectedGroupId;
this.query.groupIds = [];
if (this.selectedGroup && this.selectedGroup.id) {
// get all child group id
let stack = Array(this.selectedGroup);
while (stack.length > 0) {
let pop = stack.pop();
this.query.groupIds.push(pop.id);
if (pop.childList && pop.childList.length > 0) {
pop.childList.forEach(child => stack.push(child));
}
}
}
UTILS.findPage(this, this, CONSTANT.REQUEST_URL.API_FIND_PAGE);
},
addApi() {
Expand Down Expand Up @@ -434,6 +452,7 @@
this.selectApiGroupDialog.ids = [];
selection.forEach(row => this.selectApiGroupDialog.ids.push(row.id));
this.selectApiGroupDialog.show = true;
this.$refs['select-api-group-dialog'].findApiGroups();
},
selectQueryStatus(apiStatus) {
this.query.apiStatus = apiStatus;
Expand Down Expand Up @@ -461,6 +480,9 @@
#api-doc-container
border 1px solid #d9d9d9
.el-tree-node__content
height 30px
.el-table__header-wrapper
height 40px
Expand Down

0 comments on commit d2af6d5

Please sign in to comment.