用例-增删改查
This commit is contained in:
@@ -17,8 +17,6 @@ import com.test.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 接口Controller
|
||||
*
|
||||
* @author xiaoe
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test/api")
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.test.test.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.test.common.utils.DateUtils;
|
||||
import com.test.test.domain.qo.IDQO;
|
||||
import com.test.test.domain.qo.TestCaseListQO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.test.common.annotation.Log;
|
||||
import com.test.common.core.controller.BaseController;
|
||||
import com.test.common.core.domain.AjaxResult;
|
||||
import com.test.common.enums.BusinessType;
|
||||
import com.test.test.domain.TestCase;
|
||||
import com.test.test.service.ITestCaseService;
|
||||
import com.test.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 用例Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test/case")
|
||||
public class TestCaseController extends BaseController {
|
||||
@Resource
|
||||
private ITestCaseService testCaseService;
|
||||
|
||||
/**
|
||||
* 查询用例列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(@Validated TestCaseListQO qo) {
|
||||
startPage();
|
||||
List<TestCase> list = testCaseService.selectTestCaseList(qo);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用例详细信息
|
||||
*/
|
||||
@PostMapping(value = "/detail")
|
||||
public AjaxResult getInfo(@RequestBody IDQO qo) {
|
||||
return success(testCaseService.selectTestCaseById(qo.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用例
|
||||
*/
|
||||
@Log(title = "用例", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/add")
|
||||
public AjaxResult add(@RequestBody TestCase testCase) {
|
||||
testCase.setCreateBy(getLoginUser().getUsername());
|
||||
testCase.setCreateTime(DateUtils.getNowDate());
|
||||
testCase.setStatus(1L);
|
||||
return toAjax(testCaseService.insertTestCase(testCase));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用例
|
||||
*/
|
||||
@Log(title = "用例", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
public AjaxResult edit(@RequestBody TestCase testCase) {
|
||||
return toAjax(testCaseService.updateTestCase(testCase));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用例
|
||||
*/
|
||||
@Log(title = "用例", businessType = BusinessType.DELETE)
|
||||
@PostMapping("/del")
|
||||
public AjaxResult remove(@RequestBody IDQO qo) {
|
||||
return toAjax(testCaseService.deleteTestCaseById(qo.getId()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.test.test.domain.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TestCaseListQO {
|
||||
@NotNull(message = "父节点id不能为空")
|
||||
private Long groupId;
|
||||
}
|
||||
@@ -1,62 +1,42 @@
|
||||
package com.test.test.mapper;
|
||||
|
||||
import com.test.test.domain.TestCase;
|
||||
import com.test.test.domain.qo.TestCaseListQO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用例Mapper接口
|
||||
*
|
||||
* @author test
|
||||
* @date 2025-02-18
|
||||
*/
|
||||
public interface TestCaseMapper
|
||||
{
|
||||
/**
|
||||
* 查询用例
|
||||
*
|
||||
* @param id 用例主键
|
||||
* @return 用例
|
||||
*/
|
||||
public TestCase selectTestCaseById(Long id);
|
||||
TestCase selectTestCaseById(Long id);
|
||||
|
||||
/**
|
||||
* 查询用例列表
|
||||
*
|
||||
* @param testCase 用例
|
||||
* @return 用例集合
|
||||
*/
|
||||
public List<TestCase> selectTestCaseList(TestCase testCase);
|
||||
List<TestCase> selectTestCaseList(TestCaseListQO qo);
|
||||
|
||||
/**
|
||||
* 新增用例
|
||||
*
|
||||
* @param testCase 用例
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertTestCase(TestCase testCase);
|
||||
int insertTestCase(TestCase testCase);
|
||||
|
||||
/**
|
||||
* 修改用例
|
||||
*
|
||||
* @param testCase 用例
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateTestCase(TestCase testCase);
|
||||
int updateTestCase(TestCase testCase);
|
||||
|
||||
/**
|
||||
* 删除用例
|
||||
*
|
||||
* @param id 用例主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteTestCaseById(Long id);
|
||||
int deleteTestCaseById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除用例
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteTestCaseByIds(Long[] ids);
|
||||
int deleteTestCaseByIds(Long[] ids);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.test.test.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.test.test.domain.TestCase;
|
||||
import com.test.test.domain.qo.TestCaseListQO;
|
||||
|
||||
/**
|
||||
* 用例Service接口
|
||||
*/
|
||||
public interface ITestCaseService {
|
||||
/**
|
||||
* 查询用例
|
||||
*/
|
||||
TestCase selectTestCaseById(Long id);
|
||||
|
||||
/**
|
||||
* 查询用例列表
|
||||
*/
|
||||
List<TestCase> selectTestCaseList(TestCaseListQO qo);
|
||||
|
||||
/**
|
||||
* 新增用例
|
||||
*/
|
||||
int insertTestCase(TestCase testCase);
|
||||
|
||||
/**
|
||||
* 修改用例
|
||||
*/
|
||||
int updateTestCase(TestCase testCase);
|
||||
|
||||
/**
|
||||
* 批量删除用例
|
||||
*/
|
||||
int deleteTestCaseByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除用例信息
|
||||
*/
|
||||
int deleteTestCaseById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.test.test.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.test.common.utils.DateUtils;
|
||||
import com.test.test.domain.qo.TestCaseListQO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.test.test.mapper.TestCaseMapper;
|
||||
import com.test.test.domain.TestCase;
|
||||
import com.test.test.service.ITestCaseService;
|
||||
|
||||
/**
|
||||
* 用例Service业务层处理
|
||||
*/
|
||||
@Service
|
||||
public class TestCaseServiceImpl implements ITestCaseService {
|
||||
@Resource
|
||||
private TestCaseMapper testCaseMapper;
|
||||
|
||||
/**
|
||||
* 查询用例
|
||||
*/
|
||||
@Override
|
||||
public TestCase selectTestCaseById(Long id) {
|
||||
return testCaseMapper.selectTestCaseById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用例列表
|
||||
*/
|
||||
@Override
|
||||
public List<TestCase> selectTestCaseList(TestCaseListQO qo) {
|
||||
return testCaseMapper.selectTestCaseList(qo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用例
|
||||
*/
|
||||
@Override
|
||||
public int insertTestCase(TestCase testCase) {
|
||||
return testCaseMapper.insertTestCase(testCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用例
|
||||
*/
|
||||
@Override
|
||||
public int updateTestCase(TestCase testCase) {
|
||||
testCase.setUpdateTime(DateUtils.getNowDate());
|
||||
return testCaseMapper.updateTestCase(testCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用例
|
||||
*/
|
||||
@Override
|
||||
public int deleteTestCaseByIds(Long[] ids) {
|
||||
return testCaseMapper.deleteTestCaseByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用例信息
|
||||
*/
|
||||
@Override
|
||||
public int deleteTestCaseById(Long id) {
|
||||
return testCaseMapper.deleteTestCaseById(id);
|
||||
}
|
||||
}
|
||||
@@ -33,15 +33,12 @@
|
||||
from test_case
|
||||
</sql>
|
||||
|
||||
<select id="selectTestCaseList" parameterType="TestCase" resultMap="TestCaseResult">
|
||||
<select id="selectTestCaseList" parameterType="TestCaseListQO" resultMap="TestCaseResult">
|
||||
<include refid="selectTestCaseVo"/>
|
||||
<where>
|
||||
<if test="groupId != null ">and group_id = #{groupId}</if>
|
||||
<if test="projectId != null ">and project_id = #{projectId}</if>
|
||||
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
|
||||
<if test="importance != null ">and importance = #{importance}</if>
|
||||
<if test="status != null ">and status = #{status}</if>
|
||||
group_id = #{groupId}
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectTestCaseById" parameterType="Long" resultMap="TestCaseResult">
|
||||
|
||||
46
test-ui/src/api/test/case.js
Normal file
46
test-ui/src/api/test/case.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询用例列表
|
||||
export function listCase(query) {
|
||||
return request({
|
||||
url: '/test/case/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询用例详细
|
||||
export function getCase(id) {
|
||||
return request({
|
||||
url: '/test/case/detail',
|
||||
method: 'post',
|
||||
data: {id}
|
||||
})
|
||||
}
|
||||
|
||||
// 新增用例
|
||||
export function addCase(data) {
|
||||
return request({
|
||||
url: '/test/case/add',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改用例
|
||||
export function updateCase(data) {
|
||||
return request({
|
||||
url: '/test/case/edit',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除用例
|
||||
export function delCase(id) {
|
||||
return request({
|
||||
url: '/test/case/del',
|
||||
method: 'post',
|
||||
data: {id}
|
||||
})
|
||||
}
|
||||
@@ -187,6 +187,7 @@ export default {
|
||||
}
|
||||
});
|
||||
this.getGroup(openList);
|
||||
this.$emit('click', res.data.id);
|
||||
});
|
||||
} else {
|
||||
updateGroup({
|
||||
|
||||
@@ -116,6 +116,20 @@ export const constantRoutes = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/case/detail',
|
||||
component: Layout,
|
||||
hidden: true,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: () => import('@/views/test/case/detail'),
|
||||
name: 'CaseDetail',
|
||||
noCache: true,
|
||||
meta: { title: '用例详情', activeMenu: '/case' }
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
// 动态路由,基于用户权限动态去加载
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<folder-page type="api" @click="folderHandleSelected" ref="folder">
|
||||
<div v-if="this.queryParams.groupId && this.queryParams.groupId !== 0">
|
||||
<div v-if="queryParams.groupId && queryParams.groupId !== 0">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="接口名称" prop="name">
|
||||
<el-input v-model="queryParams.name" placeholder="请输入接口名称" clearable @keyup.enter.native="handleQuery"/>
|
||||
@@ -120,7 +120,7 @@ export default {
|
||||
this.$tab.openPage("修改接口", "/api/edit", {id: row.id});
|
||||
},
|
||||
handleDelete(row) {
|
||||
this.$modal.confirm('是否确认删除接口编号为"' + row.id + '"的数据项?').then(function () {
|
||||
this.$modal.confirm('是否确认删除接口?').then(function () {
|
||||
return delApi(row.id);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
|
||||
16
test-ui/src/views/test/case/detail.vue
Normal file
16
test-ui/src/views/test/case/detail.vue
Normal file
@@ -0,0 +1,16 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "test",
|
||||
created() {
|
||||
console.log(this.$route.query.id);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
</style>
|
||||
@@ -1,30 +1,102 @@
|
||||
<template>
|
||||
<folder-page type="case" @click="folderHandleSelected">
|
||||
case
|
||||
<div v-if="queryParams.groupId && queryParams.groupId !== 0">
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新建用例</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
<el-table v-loading="loading" :data="dataList" @row-click="handleRowClick">
|
||||
<el-table-column label="用例名称" align="center" prop="name"/>
|
||||
<el-table-column label="创建人" align="center" prop="createBy"/>
|
||||
<el-table-column label="用例状态" align="center" prop="status" :formatter="row => ['','草稿', '通过', '不通过'][row.status]"/>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime"/>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row.id)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
|
||||
</div>
|
||||
<el-empty v-else/>
|
||||
</folder-page>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import FolderPage from "@/components/FolderPage/index.vue";
|
||||
import {addCase, delCase, listCase} from "@/api/test/case";
|
||||
|
||||
export default {
|
||||
name: "Case",
|
||||
components: {FolderPage},
|
||||
data() {
|
||||
return {
|
||||
|
||||
loading: false,
|
||||
showSearch: true,
|
||||
total: 0,
|
||||
dataList: [],
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
groupId: null,
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
folderHandleSelected(id) {
|
||||
console.log(id)
|
||||
if (id) {
|
||||
this.queryParams.groupId = id;
|
||||
this.getList();
|
||||
} else {
|
||||
this.dataList = [];
|
||||
}
|
||||
},
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listCase(this.queryParams).then(response => {
|
||||
this.dataList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
handleAdd() {
|
||||
this.$prompt('请输入名称', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPattern: /^(?!\s*$).+/,
|
||||
inputErrorMessage: '名称不能为空'
|
||||
}).then(({value}) => {
|
||||
if (value) {
|
||||
addCase({
|
||||
groupId: this.queryParams.groupId,
|
||||
name: value
|
||||
}).then(res => {
|
||||
this.$message.success("添加成功")
|
||||
this.getList()
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
handleRowClick(row) {
|
||||
this.$tab.openPage("用例 - " + row.name, "/case/detail", {id: row.id});
|
||||
},
|
||||
handleDelete(id) {
|
||||
this.$modal.confirm('是否确认删除用例?').then(function () {
|
||||
return delCase(id);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
::v-deep .el-table__row {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user