fix: 修复改了资源池之后资源池ID变了的问题

This commit is contained in:
Captain.B 2020-10-28 12:19:19 +08:00
parent d26c05a306
commit 9a34a5f27f
2 changed files with 206 additions and 203 deletions

View File

@ -210,7 +210,6 @@ public class TestResourcePoolService {
private void updateTestResource(TestResource testResource) { private void updateTestResource(TestResource testResource) {
testResource.setUpdateTime(System.currentTimeMillis()); testResource.setUpdateTime(System.currentTimeMillis());
testResource.setCreateTime(System.currentTimeMillis()); testResource.setCreateTime(System.currentTimeMillis());
testResource.setId(UUID.randomUUID().toString());
testResourceMapper.insertSelective(testResource); testResourceMapper.insertSelective(testResource);
} }

View File

@ -3,9 +3,10 @@
<el-card class="table-card" v-loading="result.loading"> <el-card class="table-card" v-loading="result.loading">
<template v-slot:header> <template v-slot:header>
<ms-table-header :condition.sync="condition" @search="search" @create="create" <ms-table-header :condition.sync="condition" @search="search" @create="create"
:create-tip="$t('test_resource_pool.create_resource_pool')" :title="$t('commons.test_resource_pool')"/> :create-tip="$t('test_resource_pool.create_resource_pool')"
:title="$t('commons.test_resource_pool')"/>
</template> </template>
<el-table border class="adjust-table" :data="items" style="width: 100%"> <el-table border class="adjust-table" :data="items" style="width: 100%">
<el-table-column prop="name" :label="$t('commons.name')"/> <el-table-column prop="name" :label="$t('commons.name')"/>
<el-table-column prop="description" :label="$t('commons.description')"/> <el-table-column prop="description" :label="$t('commons.description')"/>
<el-table-column prop="type" :label="$t('test_resource_pool.type')"> <el-table-column prop="type" :label="$t('test_resource_pool.type')">
@ -174,225 +175,228 @@
</template> </template>
<script> <script>
import MsCreateBox from "../CreateBox"; import MsCreateBox from "../CreateBox";
import MsTablePagination from "../../common/pagination/TablePagination"; import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableHeader from "../../common/components/MsTableHeader"; import MsTableHeader from "../../common/components/MsTableHeader";
import MsTableOperator from "../../common/components/MsTableOperator"; import MsTableOperator from "../../common/components/MsTableOperator";
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import {listenGoBack, removeGoBackListener} from "../../../../common/js/utils"; import {listenGoBack, removeGoBackListener} from "../../../../common/js/utils";
export default { export default {
name: "MsTestResourcePool", name: "MsTestResourcePool",
components: {MsCreateBox, MsTablePagination, MsTableHeader, MsTableOperator, MsDialogFooter}, components: {MsCreateBox, MsTablePagination, MsTableHeader, MsTableOperator, MsDialogFooter},
data() { data() {
return { return {
result: {}, result: {},
createVisible: false, createVisible: false,
infoList: [], infoList: [],
updateVisible: false, updateVisible: false,
queryPath: "testresourcepool/list", queryPath: "testresourcepool/list",
condition: {}, condition: {},
items: [], items: [],
currentPage: 1, currentPage: 1,
pageSize: 5, pageSize: 5,
total: 0, total: 0,
form: {}, form: {},
rule: { rule: {
name: [ name: [
{required: true, message: this.$t('test_resource_pool.input_pool_name'), trigger: 'blur'}, {required: true, message: this.$t('test_resource_pool.input_pool_name'), trigger: 'blur'},
{min: 2, max: 20, message: this.$t('commons.input_limit', [2, 20]), trigger: 'blur'}, {min: 2, max: 20, message: this.$t('commons.input_limit', [2, 20]), trigger: 'blur'},
{ {
required: true, required: true,
pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/, pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,
message: this.$t('test_resource_pool.pool_name_valid'), message: this.$t('test_resource_pool.pool_name_valid'),
trigger: 'blur' trigger: 'blur'
} }
], ],
description: [ description: [
{max: 60, message: this.$t('commons.input_limit', [0, 60]), trigger: 'blur'} {max: 60, message: this.$t('commons.input_limit', [0, 60]), trigger: 'blur'}
], ],
type: [ type: [
{required: true, message: this.$t('test_resource_pool.select_pool_type'), trigger: 'blur'} {required: true, message: this.$t('test_resource_pool.select_pool_type'), trigger: 'blur'}
] ]
} }
}
},
activated() {
this.initTableData();
},
methods: {
initTableData() {
this.result = this.$post(this.buildPagePath(this.queryPath), this.condition, response => {
let data = response.data;
this.items = data.listObject;
this.total = data.itemCount;
})
},
changeResourceType() {
this.infoList = [];
this.infoList.push({})
},
addResourceInfo() {
this.infoList.push({})
},
removeResourceInfo(index) {
if (this.infoList.length > 1) {
this.infoList.splice(index, 1)
} else {
this.$warning(this.$t('test_resource_pool.cannot_remove_all_node'))
} }
}, },
activated() { validateResourceInfo() {
this.initTableData(); if (this.infoList.length <= 0) {
}, return {validate: false, msg: this.$t('test_resource_pool.cannot_empty')}
methods: { }
initTableData() {
this.result = this.$post(this.buildPagePath(this.queryPath), this.condition, response => { let resultValidate = {validate: true, msg: this.$t('test_resource_pool.fill_the_data')};
let data = response.data; this.infoList.forEach(function (info) {
this.items = data.listObject; for (let key in info) {
this.total = data.itemCount; if (info[key] != '0' && !info[key]) {
})
},
changeResourceType() {
this.infoList = [];
this.infoList.push({})
},
addResourceInfo() {
this.infoList.push({})
},
removeResourceInfo(index) {
if (this.infoList.length > 1) {
this.infoList.splice(index, 1)
} else {
this.$warning(this.$t('test_resource_pool.cannot_remove_all_node'))
}
},
validateResourceInfo() {
if (this.infoList.length <= 0) {
return {validate: false, msg: this.$t('test_resource_pool.cannot_empty')}
}
let resultValidate = {validate: true, msg: this.$t('test_resource_pool.fill_the_data')};
this.infoList.forEach(function (info) {
for (let key in info) {
if (info[key] != '0' && !info[key]) {
resultValidate.validate = false
return false;
}
}
if (!info.maxConcurrency) {
resultValidate.validate = false resultValidate.validate = false
return false; return false;
} }
});
return resultValidate;
},
buildPagePath(path) {
return path + "/" + this.currentPage + "/" + this.pageSize;
},
search() {
this.initTableData();
},
create() {
this.createVisible = true;
listenGoBack(this.closeFunc);
},
edit(row) {
this.updateVisible = true;
this.form = JSON.parse(JSON.stringify(row));
this.convertResources();
listenGoBack(this.closeFunc);
},
convertResources() {
let resources = [];
if (this.form.resources) {
this.form.resources.forEach(function (resource) {
resources.push(JSON.parse(resource.configuration));
})
} }
this.infoList = resources;
},
del(row) {
window.console.log(row);
this.$confirm(this.$t('test_resource_pool.delete_prompt'), this.$t('commons.prompt'), {
confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get(`/testresourcepool/delete/${row.id}`,() => {
this.initTableData();
this.$success(this.$t('commons.delete_success'));
});
}).catch(() => {
this.$info(this.$t('commons.delete_cancel'));
});
},
createTestResourcePool(createTestResourcePoolForm) {
this.$refs[createTestResourcePoolForm].validate(valid => {
if (valid) {
let vri = this.validateResourceInfo();
if (vri.validate) {
this.convertSubmitResources();
this.result = this.$post("/testresourcepool/add", this.form, () => {
this.$message({
type: 'success',
message: this.$t('commons.save_success')
},
this.createVisible = false,
this.initTableData());
});
} else {
this.$warning(vri.msg);
return false;
}
} else { if (!info.maxConcurrency) {
return false; resultValidate.validate = false
} return false;
}
});
return resultValidate;
},
buildPagePath(path) {
return path + "/" + this.currentPage + "/" + this.pageSize;
},
search() {
this.initTableData();
},
create() {
this.createVisible = true;
listenGoBack(this.closeFunc);
},
edit(row) {
this.updateVisible = true;
this.form = JSON.parse(JSON.stringify(row));
this.convertResources();
listenGoBack(this.closeFunc);
},
convertResources() {
let resources = [];
if (this.form.resources) {
this.form.resources.forEach(function (resource) {
let configuration = JSON.parse(resource.configuration);
configuration.id = resource.id
resources.push(configuration);
}) })
}, }
convertSubmitResources() { this.infoList = resources;
let resources = []; },
let poolId = this.form.id; del(row) {
this.infoList.forEach(function (info) { window.console.log(row);
let resource = {"configuration": JSON.stringify(info)}; this.$confirm(this.$t('test_resource_pool.delete_prompt'), this.$t('commons.prompt'), {
if (poolId) { confirmButtonText: this.$t('commons.confirm'),
resource.testResourcePoolId = poolId; cancelButtonText: this.$t('commons.cancel'),
} type: 'warning'
resources.push(resource); }).then(() => {
this.result = this.$get(`/testresourcepool/delete/${row.id}`, () => {
this.initTableData();
this.$success(this.$t('commons.delete_success'));
}); });
this.form.resources = resources; }).catch(() => {
}, this.$info(this.$t('commons.delete_cancel'));
updateTestResourcePool(updateTestResourcePoolForm) { });
this.$refs[updateTestResourcePoolForm].validate(valid => { },
if (valid) { createTestResourcePool(createTestResourcePoolForm) {
let vri = this.validateResourceInfo(); this.$refs[createTestResourcePoolForm].validate(valid => {
if (vri.validate) { if (valid) {
this.convertSubmitResources(); let vri = this.validateResourceInfo();
this.result = this.$post("/testresourcepool/update", this.form, () => { if (vri.validate) {
this.$message({ this.convertSubmitResources();
type: 'success', this.result = this.$post("/testresourcepool/add", this.form, () => {
message: this.$t('commons.modify_success') this.$message({
}, type: 'success',
this.updateVisible = false, message: this.$t('commons.save_success')
this.initTableData(), },
self.loading = false); this.createVisible = false,
}); this.initTableData());
} else { });
this.$warning(vri.msg);
return false;
}
} else { } else {
this.$warning(vri.msg);
return false; return false;
} }
});
}, } else {
closeFunc() { return false;
this.form = {}; }
this.updateVisible = false; })
this.createVisible = false; },
removeGoBackListener(this.closeFunc); convertSubmitResources() {
}, let resources = [];
changeSwitch(row) { let poolId = this.form.id;
this.result.loading = true; this.infoList.forEach(function (info) {
this.$info(this.$t('test_resource_pool.check_in'), 1000); let configuration = JSON.stringify(info);
this.$get('/testresourcepool/update/' + row.id + '/' + row.status) let resource = {"configuration": configuration, id: info.id};
.then(() => { if (poolId) {
this.$success(this.$t('test_resource_pool.status_change_success')); resource.testResourcePoolId = poolId;
this.result.loading = false; }
}).catch(() => { resources.push(resource);
this.$error(this.$t('test_resource_pool.status_change_failed')); });
row.status = 'INVALID'; this.form.resources = resources;
this.result.loading = false; },
}) updateTestResourcePool(updateTestResourcePoolForm) {
} this.$refs[updateTestResourcePoolForm].validate(valid => {
if (valid) {
let vri = this.validateResourceInfo();
if (vri.validate) {
this.convertSubmitResources();
this.result = this.$post("/testresourcepool/update", this.form, () => {
this.$message({
type: 'success',
message: this.$t('commons.modify_success')
},
this.updateVisible = false,
this.initTableData(),
self.loading = false);
});
} else {
this.$warning(vri.msg);
return false;
}
} else {
return false;
}
});
},
closeFunc() {
this.form = {};
this.updateVisible = false;
this.createVisible = false;
removeGoBackListener(this.closeFunc);
},
changeSwitch(row) {
this.result.loading = true;
this.$info(this.$t('test_resource_pool.check_in'), 1000);
this.$get('/testresourcepool/update/' + row.id + '/' + row.status)
.then(() => {
this.$success(this.$t('test_resource_pool.status_change_success'));
this.result.loading = false;
}).catch(() => {
this.$error(this.$t('test_resource_pool.status_change_failed'));
row.status = 'INVALID';
this.result.loading = false;
})
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.box { .box {
padding-left: 5px; padding-left: 5px;
} }
</style> </style>