feat(接口定义):完成回收站功能

This commit is contained in:
fit2-zhao 2020-11-27 11:30:47 +08:00
parent 4871c9864a
commit e081448183
10 changed files with 120 additions and 47 deletions

View File

@ -57,6 +57,12 @@ public class ApiDefinitionController {
apiDefinitionService.deleteBatch(ids);
}
@PostMapping("/removeToGc")
public void removeToGc(@RequestBody List<String> ids) {
apiDefinitionService.removeToGc(ids);
}
@GetMapping("/get/{id}")
public ApiDefinition get(@PathVariable String id) {
return apiDefinitionService.get(id);

View File

@ -22,7 +22,7 @@ public class ApiDefinitionRequest {
private String userId;
private boolean recent = false;
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
private List<String> filters;
private Map<String, Object> combine;
private List<String> ids;
}

View File

@ -52,6 +52,7 @@ public class ApiDefinitionService {
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
@Resource
private JMeterService jMeterService;
private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24);
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
@ -118,7 +119,7 @@ public class ApiDefinitionService {
}
public void delete(String apiId) {
apiTestCaseService.checkIsRelateTest(apiId);
apiTestCaseService.deleteTestCase(apiId);
deleteFileByTestId(apiId);
apiDefinitionExecResultMapper.deleteByResourceId(apiId);
apiDefinitionMapper.deleteByPrimaryKey(apiId);
@ -132,6 +133,9 @@ public class ApiDefinitionService {
});
}
public void removeToGc(List<String> apiIds) {
apiDefinitionMapper.removeToGc(apiIds);
}
public void deleteBodyFiles(String apiId) {
File file = new File(BODY_FILE_DIR + "/" + apiId);

View File

@ -104,6 +104,17 @@ public class ApiTestCaseService {
deleteBodyFiles(testId);
}
public void deleteTestCase(String apiId) {
ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
testCaseExample.createCriteria().andApiDefinitionIdEqualTo(apiId);
List<ApiTestCase> testCases = apiTestCaseMapper.selectByExample(testCaseExample);
if (testCases.size() > 0) {
for (ApiTestCase testCase : testCases) {
this.delete(testCase.getId());
}
}
}
/**
* 是否已经创建了测试用例
*/

View File

@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ApiDefinitionMapper {
List<ApiDefinitionResult> list(@Param("request") ApiDefinitionRequest request);
List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids);
@ -36,4 +36,7 @@ public interface ApiDefinitionMapper {
int updateByPrimaryKeyWithBLOBs(ApiDefinition record);
int updateByPrimaryKey(ApiDefinition record);
int removeToGc(@Param("ids") List<String> ids);
}

View File

@ -219,7 +219,6 @@
<property name="name" value="request.name"/>
</include>
</if>
<if test="request.name != null">
and api_definition.name like CONCAT('%', #{request.name},'%')
</if>
@ -251,15 +250,9 @@
</foreach>
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
and api_definition.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
and api_definition.status in
<foreach collection="request.filters" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
</where>
@ -411,4 +404,14 @@
update_time = #{updateTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="removeToGc">
update api_definition
set
status = 'Trash'
where id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</update>
</mapper>

View File

@ -252,6 +252,7 @@
/deep/ .el-tabs__header {
margin: 0 0 5px;
width: calc(100% - 90px);
}
/deep/ .el-main {

View File

@ -24,12 +24,10 @@
:label="$t('api_test.definition.api_status')"
show-overflow-tooltip>
<template v-slot:default="scope">
<ms-tag v-if="scope.row.status == 'Prepare'" type="info"
:content="$t('test_track.plan.plan_status_prepare')"/>
<ms-tag v-if="scope.row.status == 'Underway'" type="primary"
:content="$t('test_track.plan.plan_status_running')"/>
<ms-tag v-if="scope.row.status == 'Completed'" type="success"
:content="$t('test_track.plan.plan_status_completed')"/>
<ms-tag v-if="scope.row.status == 'Prepare'" type="info" :content="$t('test_track.plan.plan_status_prepare')"/>
<ms-tag v-if="scope.row.status == 'Underway'" type="primary" :content="$t('test_track.plan.plan_status_running')"/>
<ms-tag v-if="scope.row.status == 'Completed'" type="success" :content="$t('test_track.plan.plan_status_completed')"/>
<ms-tag v-if="scope.row.status == 'Trash'" type="danger" content="废弃"/>
</template>
</el-table-column>
@ -38,9 +36,8 @@
:label="$t('api_test.definition.api_type')"
show-overflow-tooltip>
<template v-slot:default="scope" class="request-method">
<el-tag size="mini"
:style="{'background-color': getColor(true, scope.row.method)}" class="api-el-tag"> {{ scope.row.method
}}
<el-tag size="mini" :style="{'background-color': getColor(true, scope.row.method)}" class="api-el-tag">
{{ scope.row.method}}
</el-tag>
</template>
</el-table-column>
@ -112,7 +109,7 @@
import MsContainer from "../../../common/components/MsContainer";
import MsBottomContainer from "./BottomContainer";
import ShowMoreBtn from "../../../../components/track/case/components/ShowMoreBtn";
import {API_METHOD_COLOUR} from "../model/JsonData";
import {API_METHOD_COLOUR, FILTER_MAP_1, FILTER_MAP_2} from "../model/JsonData";
export default {
name: "ApiList",
@ -172,10 +169,15 @@
},
methods: {
initApiTable() {
this.condition.filters = ["Prepare", "Underway", "Completed"];
if (this.currentModule != null) {
if (this.currentModule.id == "root") {
this.condition.moduleIds = [];
} else {
} else if (this.currentModule.id == "gc") {
this.condition.moduleIds = [];
this.condition.filters = ["Trash"];
}
else {
this.condition.moduleIds = this.currentModule.ids;
}
}
@ -238,19 +240,35 @@
this.$emit('editApi', row);
},
handleDeleteBatch() {
this.$alert(this.$t('api_test.definition.request.delete_confirm') + "", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
let ids = Array.from(this.selectRows).map(row => row.id);
this.$post('/api/definition/deleteBatch/', ids, () => {
this.selectRows.clear();
this.initApiTable();
this.$success(this.$t('commons.delete_success'));
});
if (this.currentModule != undefined && this.currentModule.id == "gc") {
this.$alert(this.$t('api_test.definition.request.delete_confirm') + "", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
let ids = Array.from(this.selectRows).map(row => row.id);
this.$post('/api/definition/deleteBatch/', ids, () => {
this.selectRows.clear();
this.initApiTable();
this.$success(this.$t('commons.delete_success'));
});
}
}
}
});
});
} else {
this.$alert(this.$t('api_test.definition.request.delete_confirm') + "", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
let ids = Array.from(this.selectRows).map(row => row.id);
this.$post('/api/definition/removeToGc/', ids, () => {
this.selectRows.clear();
this.initApiTable();
this.$success(this.$t('commons.delete_success'));
});
}
}
});
}
},
handleTestCase(testCase) {
let h = window.screen.height;
@ -266,10 +284,25 @@
this.selectApi.url = request.path;
this.isHide = false;
},
handleDelete(testCase) {
this.$get('/api/definition/delete/' + testCase.id, () => {
this.$success(this.$t('commons.delete_success'));
this.initApiTable();
handleDelete(api) {
if (this.currentModule != undefined && this.currentModule.id == "gc") {
this.$get('/api/definition/delete/' + api.id, () => {
this.$success(this.$t('commons.delete_success'));
this.initApiTable();
});
return;
}
this.$alert(this.$t('api_test.definition.request.delete_confirm') + ' ' + api.name + " ", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
let ids = [api.id];
this.$post('/api/definition/removeToGc/', ids, () => {
this.$success(this.$t('commons.delete_success'));
this.initApiTable();
});
}
}
});
},
apiCaseClose() {

View File

@ -54,11 +54,15 @@
class="ms-el-input" size="mini"></el-input>
</template>
<!-- 如果不是编辑状态 -->
<span class="node-title" v-else v-text="data.name"></span>
<div v-else>
<i class="el-icon-delete" v-if="data.id==='gc'"/>
<i class="el-icon-folder" v-else/>
<span class="node-title" v-text="data.name"></span>
</div>
<span class="node-operate child">
<el-tooltip
v-if="data.id!='root'"
v-if="data.id!='root' && data.id!='gc'"
class="item"
effect="dark"
:open-delay="200"
@ -68,6 +72,7 @@
</el-tooltip>
<el-tooltip
v-if="data.id!='gc'"
class="item"
effect="dark"
:open-delay="200"
@ -77,7 +82,7 @@
</el-tooltip>
<el-tooltip
v-if="data.id!='root'"
v-if="data.id!='root' && data.id!='gc'"
class="item"
effect="dark"
:open-delay="200"
@ -114,7 +119,7 @@
options: OPTIONS,
protocol: OPTIONS[0].value,
httpVisible: false,
expandedNode: ["root"],
expandedNode: [],
filterText: "",
nextFlag: true,
currentProject: {},
@ -139,17 +144,19 @@
methods: {
getApiModuleTree() {
if (this.currentProject) {
if (this.expandedNode.length === 0) {
this.expandedNode.push("root");
}
this.$get("/api/module/list/" + this.currentProject.id + "/" + this.protocol, response => {
if (response.data != undefined && response.data != null) {
this.data[0].children = response.data;
this.data[1].children = response.data;
let moduleOptions = [];
this.data[0].children.forEach(node => {
this.data[1].children.forEach(node => {
this.buildNodePath(node, {path: ''}, moduleOptions);
});
this.$emit('getApiModuleTree', moduleOptions);
}
});
}
},
handleCommand(e) {

View File

@ -14,6 +14,11 @@ export const OPTIONS = [
]
export const DEFAULT_DATA = [{
"id": "gc",
"name": "回收站",
"level": 1,
"children": [],
},{
"id": "root",
"name": "默认模块",
"level": 0,