提交 bc74a0a9 编写于 作者: Q q4speed

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	frontend/src/business/components/common/components/search/MsTableAdvSearchBar.vue
......@@ -15,4 +15,6 @@ public interface ExtTestCaseMapper {
List<TestCaseDTO> listByMethod(@Param("request") QueryTestCaseRequest request);
List<TestCaseDTO> listBytestCaseIds(@Param("request") QueryTestCaseRequest request);
}
......@@ -2,13 +2,120 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestCaseMapper">
<sql id="condition">
<choose>
<when test='${object}.operator == "like"'>
like CONCAT('%', #{${object}.value},'%')
</when>
<when test='${object}.operator == "not like"'>
not like CONCAT('%', #{${object}.value},'%')
</when>
<when test='${object}.operator == "in"'>
in
<foreach collection="${object}.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<when test='${object}.operator == "not in"'>
not in
<foreach collection="${object}.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<when test='${object}.operator == "between"'>
between #{${object}.value[0]} and #{${object}.value[1]}
</when>
<when test='${object}.operator == "gt"'>
&gt; #{${object}.value}
</when>
<when test='${object}.operator == "lt"'>
&lt; #{${object}.value}
</when>
<when test='${object}.operator == "ge"'>
&gt;= #{${object}.value}
</when>
<when test='${object}.operator == "le"'>
&lt;= #{${object}.value}
</when>
<when test='${object}.operator == "current user"'>
= '${@io.metersphere.commons.utils.SessionUtils@getUserId()}'
</when>
<otherwise>
= #{${object}.value}
</otherwise>
</choose>
</sql>
<sql id="combine">
<if test="${condition}.name != null">
and test_case.name
<include refid="condition">
<property name="object" value="${condition}.name"/>
</include>
</if>
<if test="${condition}.module != null">
and test_case.node_path
<include refid="condition">
<property name="object" value="${condition}.module"/>
</include>
</if>
<if test="${condition}.priority != null">
and test_case.priority
<include refid="condition">
<property name="object" value="${condition}.priority"/>
</include>
</if>
<if test="${condition}.createTime != null">
and test_case.create_time
<include refid="condition">
<property name="object" value="${condition}.createTime"/>
</include>
</if>
<if test="${condition}.type != null">
and test_case.type
<include refid="condition">
<property name="object" value="${condition}.type"/>
</include>
</if>
<if test="${condition}.updateTime != null">
and test_case.update_time
<include refid="condition">
<property name="object" value="${condition}.updateTime"/>
</include>
</if>
<if test="${condition}.method != null">
and test_case.method
<include refid="condition">
<property name="object" value="${condition}.method"/>
</include>
</if>
<if test="${condition}.creator != null">
and test_case.maintainer
<include refid="condition">
<property name="object" value="${condition}.creator"/>
</include>
</if>
</sql>
<select id="getTestCaseNames" resultType="io.metersphere.base.domain.TestCase">
select test_case.id, test_case.name, test_case.priority, test_case.type
from test_case
<where>
<if test="request.name != null">
and test_case.name like CONCAT('%', #{request.name},'%')
</if>
<choose>
<!--高级-->
<when test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
</include>
</when>
<!--普通-->
<otherwise>
<if test="request.name != null">
and test_case.name like CONCAT('%', #{request.name},'%')
</if>
</otherwise>
</choose>
<if test="request.projectId != null">
AND test_case.project_id = #{request.projectId}
</if>
......@@ -80,4 +187,15 @@
</if>
</where>
</select>
<select id="listBytestCaseIds" resultType="io.metersphere.track.dto.TestCaseDTO">
select test_case.*,api_test.name as apiName,load_test.name AS performName from test_case left join api_test on test_case.test_id=api_test.id left join load_test on test_case.test_id=load_test.id
<where>
<if test="request.testCaseIds!=null and request.testCaseIds.size() > 0">
and test_case.id in
<foreach collection="request.testCaseIds" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</if>
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -57,17 +57,22 @@ public class PersonRepoImpl implements PersonRepo {
LdapTemplate ldapTemplate = getConnection();
String filter = getUserFilter();
String ou = getUserOu();
String[] arr = getUserOu();
List<Person> result = null;
try {
result = ldapTemplate.search(query().base(ou).filter(filter, username), getContextMapper());
} catch (NameNotFoundException e) {
MSException.throwException(Translator.get("login_fail_ou_error"));
} catch (InvalidNameException e) {
MSException.throwException(Translator.get("login_fail_ou_error"));
} catch (InvalidSearchFilterException e) {
MSException.throwException(Translator.get("login_fail_filter_error"));
for (String ou : arr) {
try {
result = ldapTemplate.search(query().base(ou.trim()).filter(filter, username), getContextMapper());
if (result.size() == 1) {
return result.get(0);
}
} catch (NameNotFoundException e) {
MSException.throwException(Translator.get("login_fail_ou_error"));
} catch (InvalidNameException e) {
MSException.throwException(Translator.get("login_fail_ou_error"));
} catch (InvalidSearchFilterException e) {
MSException.throwException(Translator.get("login_fail_filter_error"));
}
}
if (result.size() != 1) {
......@@ -87,14 +92,16 @@ public class PersonRepoImpl implements PersonRepo {
return filter;
}
private String getUserOu() {
private String[] getUserOu() {
String ou = service.getValue(ParamConstants.LDAP.OU.getValue());
if (StringUtils.isBlank(ou)) {
MSException.throwException(Translator.get("ldap_ou_is_null"));
}
return ou;
String[] arr = ou.split("\\|");
return arr;
}
protected ContextMapper getContextMapper() {
......
......@@ -109,6 +109,11 @@ public class TestCaseController {
public void testCaseTemplateExport(HttpServletResponse response){
testCaseService.testCaseTemplateExport(response);
}
@GetMapping("/export/testCase/{testCaseIds}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void testCaseExport(HttpServletResponse response,QueryTestCaseRequest request){
testCaseService.testCaseExport(response,request);
}
@PostMapping("/batch/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
......
......@@ -6,8 +6,10 @@ import lombok.Setter;
@Getter
@Setter
public class TestCaseDTO extends TestCaseWithBLOBs{
public class TestCaseDTO extends TestCaseWithBLOBs {
private String maintainerName;
private String apiName;
private String performName;
}
......@@ -16,6 +16,8 @@ public class QueryTestCaseRequest extends TestCase {
private List<String> nodeIds;
private List<String> testCaseIds;
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
......@@ -23,4 +25,6 @@ public class QueryTestCaseRequest extends TestCase {
private String planId;
private String workspaceId;
private Map<String, Object> combine;
}
......@@ -2,6 +2,8 @@ package io.metersphere.track.service;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
......@@ -101,7 +103,7 @@ public class TestCaseService {
return testCaseMapper.updateByPrimaryKeySelective(testCase);
}
private void checkTestCaseExist (TestCaseWithBLOBs testCase) {
private void checkTestCaseExist(TestCaseWithBLOBs testCase) {
if (testCase.getName() != null) {
TestCaseExample example = new TestCaseExample();
example.createCriteria()
......@@ -154,7 +156,7 @@ public class TestCaseService {
List<TestCase> testCaseNames = extTestCaseMapper.getTestCaseNames(request);
if ( StringUtils.isNotBlank(request.getPlanId()) ) {
if (StringUtils.isNotBlank(request.getPlanId())) {
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(request.getPlanId());
List<String> relevanceIds = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample).stream()
......@@ -284,9 +286,9 @@ public class TestCaseService {
data.setName(Translator.get("test_case") + i);
path.append("/" + Translator.get("module") + i);
data.setNodePath(path.toString());
data.setPriority("P" + i%4);
data.setType(types.get(i%3));
data.setMethod(methods.get(i%2));
data.setPriority("P" + i % 4);
data.setType(types.get(i % 3));
data.setMethod(methods.get(i % 2));
data.setPrerequisite(Translator.get("preconditions_optional"));
data.setStepDesc("1. " + Translator.get("step_tip_separate") +
"\n2. " + Translator.get("step_tip_order") + "\n3. " + Translator.get("step_tip_optional"));
......@@ -309,6 +311,73 @@ public class TestCaseService {
return list;
}
public void testCaseExport(HttpServletResponse response, QueryTestCaseRequest request) {
EasyExcelExporter easyExcelExporter = null;
try {
easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class);
easyExcelExporter.export(response, generateTestCaseExcel(request),
Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet"));
} catch (Exception e) {
MSException.throwException(e);
} finally {
easyExcelExporter.close();
}
}
private List<TestCaseExcelData> generateTestCaseExcel(QueryTestCaseRequest request) {
List<TestCaseDTO> TestCaseList = extTestCaseMapper.listBytestCaseIds(request);
List<TestCaseExcelData> list = new ArrayList<>();
SessionUser user = SessionUtils.getUser();
StringBuilder step = new StringBuilder("");
StringBuilder result = new StringBuilder("");
for (int i = 0; i < TestCaseList.size(); i++) {
TestCaseExcelData data = new TestCaseExcelData();
data.setName(TestCaseList.get(i).getName());
data.setNodePath(TestCaseList.get(i).getNodePath());
data.setPriority(TestCaseList.get(i).getPriority());
data.setType(TestCaseList.get(i).getType());
data.setMethod(TestCaseList.get(i).getMethod());
data.setPrerequisite(TestCaseList.get(i).getPrerequisite());
if (TestCaseList.get(i).getMethod().equals("manual")) {
String steps = TestCaseList.get(i).getSteps();
JSONArray jsonArray = JSON.parseArray(steps);
for (int j = 0; j <jsonArray.size(); j++) {
int num=j+1;
step.append(num + ":" + jsonArray.getJSONObject(j).getString("desc"));
step.append("\n");
data.setStepDesc(step.toString());
result.append(num + ":" + jsonArray.getJSONObject(j).getString("result"));
result.append("\n");
data.setStepResult(result.toString());
}
data.setRemark(TestCaseList.get(i).getRemark());
} else if(TestCaseList.get(i).getMethod().equals("auto")&&TestCaseList.get(i).getType().equals("api")){
data.setStepDesc("");
data.setStepResult("");
data.setRemark(TestCaseList.get(i).getApiName());
}else if(TestCaseList.get(i).getMethod().equals("auto")&&TestCaseList.get(i).getType().equals("performance")){
data.setStepDesc("");
data.setStepResult("");
data.setRemark(TestCaseList.get(i).getPerformName());
}
data.setMaintainer(user.getId());
list.add(data);
}
list.add(new TestCaseExcelData());
TestCaseExcelData explain = new TestCaseExcelData();
explain.setName(Translator.get("do_not_modify_header_order"));
explain.setNodePath(Translator.get("module_created_automatically"));
explain.setType(Translator.get("options") + "(functional、performance、api)");
explain.setMethod(Translator.get("options") + "(manual、auto)");
explain.setPriority(Translator.get("options") + "(P0、P1、P2、P3)");
explain.setMaintainer(Translator.get("please_input_workspace_member"));
list.add(explain);
return list;
}
public void editTestCaseBath(TestCaseBatchRequest request) {
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andIdIn(request.getIds());
......
<template>
<span class="adv-search-bar">
<el-link type="primary" @click="open">{{$t('commons.adv_search.title')}}</el-link>
<el-dialog :title="$t('commons.adv_search.combine')" :visible.sync="visible" custom-class="adv-dialog">
<el-dialog :title="$t('commons.adv_search.combine')" :visible.sync="visible" custom-class="adv-dialog" :append-to-body="true">
<div>
<!-- 如果有需求再加上-->
<!-- <div class="search-label">{{$t('commons.adv_search.combine')}}: </div>-->
......@@ -80,33 +80,6 @@
}
</script>
<style>
@media only screen and (min-width: 1800px) {
.el-dialog.adv-dialog {
width: 70%;
}
}
@media only screen and (min-width: 1560px) and (max-width: 1799px) {
.el-dialog.adv-dialog {
width: 80%;
}
}
@media only screen and (min-width: 1400px) and (max-width: 1559px) {
.el-dialog.adv-dialog {
width: 90%;
}
}
@media only screen and (max-width: 1399px) {
.el-dialog.adv-dialog {
width: 70%;
min-width: 655px;
}
}
</style>
<style scoped>
.adv-search-bar {
margin-left: 5px;
......@@ -131,20 +104,10 @@
width: 100%;
}
@media only screen and (max-width: 1399px) {
.search-item {
width: 100%;
}
}
@media only screen and (min-width: 1400px) {
.search-item {
width: 50%;
}
}
.search-item {
display: inline-block;
width: 50%;
max-width: 50%;
margin-top: 10px;
}
</style>
......@@ -160,6 +160,67 @@ export const TRIGGER_MODE = {
}
}
export const PRIORITY = {
key: "priority",
name: 'MsTableSearchSelect',
label: i18n.t("test_track.case.priority"),
operator: {
options: [OPERATORS.IN, OPERATORS.NOT_IN]
},
options: [
{label: "P0", value: "P0"},
{label: "P1", value: "P1"},
{label: "P2", value: "P2"},
{label: "P3", value: "P3"},
],
props: {
multiple: true
}
}
export const TYPE = {
key: "type",
name: 'MsTableSearchSelect',
label: i18n.t("test_track.case.type"),
operator: {
options: [OPERATORS.IN, OPERATORS.NOT_IN]
},
options: [
{label: i18n.t('commons.functional'), value: 'functional'},
{label: i18n.t('commons.performance'), value: 'performance'},
{label: i18n.t('commons.api'), value: 'api'}
],
props: {
multiple: true
}
}
export const METHOD = {
key: "method",
name: 'MsTableSearchSelect',
label: i18n.t("test_track.case.method"),
operator: {
options: [OPERATORS.IN, OPERATORS.NOT_IN]
},
options: [
{label: i18n.t('test_track.case.manual'), value: 'manual'},
{label: i18n.t('test_track.case.auto'), value: 'auto'}
],
props: {
multiple: true
}
}
export const MODULE = {
key: "module",
name: 'MsTableSearchInput',
label: i18n.t("test_track.case.module"),
operator: {
value: OPERATORS.LIKE.value, // 如果未设置value初始值,则value初始值为options[0]
options: [OPERATORS.LIKE, OPERATORS.NOT_LIKE] // 运算符候选项
},
}
export const getTestConfigs = () => {
return _.cloneDeep([NAME, UPDATE_TIME, PROJECT_NAME, CREATE_TIME, STATUS, CREATOR]);
}
......@@ -167,3 +228,7 @@ export const getTestConfigs = () => {
export const getReportConfigs = () => {
return _.cloneDeep([NAME, TEST_NAME, PROJECT_NAME, CREATE_TIME, STATUS, CREATOR, TRIGGER_MODE]);
}
export const getTestCaseConfigs = () => {
return _.cloneDeep([NAME, MODULE, PRIORITY, CREATE_TIME, TYPE, UPDATE_TIME, METHOD, CREATOR]);
}
<template>
<div>
<el-tooltip class="item" effect="dark" :content="$t('test_track.case.export.export')" placement="right">
<el-button type="info" icon="el-icon-download" size="mini" circle></el-button>
</el-tooltip>
<el-row>
<el-link type="primary" class="download-case"
@click="downloadCase"
>{{$t('test_track.case.import.download_case')}}
</el-link>
</el-row>
</div>
</template>
<script>
export default {
name: "TestCaseImport"
export default {
name: "TestCaseExport",
methods: {
downloadCase() {
}
}
}
</script>
<style scoped>
......
......@@ -11,6 +11,8 @@
</template>
<template v-slot:button>
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2" :content="$t('test_track.case.import.import')" @click="importTestCase"/>
<ms-table-button :is-tester-permission="true" icon="el-icon-download"
:content="$t('test_track.case.export.export')" @click="handleBatch('export')"/>
<ms-table-button :is-tester-permission="true" icon="el-icon-right" :content="$t('test_track.case.move')" @click="handleBatch('move')"/>
<ms-table-button :is-tester-permission="true" icon="el-icon-delete" :content="$t('test_track.case.delete')" @click="handleBatch('delete')"/>
<!--<test-case-export/>-->
......@@ -116,7 +118,7 @@
import MsTableOperator from "../../../common/components/MsTableOperator";
import MsTableOperatorButton from "../../../common/components/MsTableOperatorButton";
import MsTableButton from "../../../common/components/MsTableButton";
import {_filter, _sort, humpToLine} from "../../../../../common/js/utils";
import {_filter, _sort, downloadFile, humpToLine} from "../../../../../common/js/utils";
export default {
name: "TestCaseList",
......@@ -254,7 +256,7 @@
}
},
handleSelectionChange(selection, row) {
if(this.selectIds.has(row.id)){
if (this.selectIds.has(row.id)) {
this.selectIds.delete(row.id);
} else {
this.selectIds.add(row.id);
......@@ -263,15 +265,37 @@
importTestCase() {
this.$refs.testCaseImport.open();
},
handleBatch(type){
exportTestCase() {
let config = {
url: '/test/case/export/testCase/' + [...this.selectIds],
method: 'get',
responseType: 'blob'
};
this.result = this.$request(config).then(response => {
const filename = '测试用例.xlsx'
const blob = new Blob([response.data]);
if ("download" in document.createElement("a")) {
let aTag = document.createElement('a');
aTag.download = filename;
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(aTag.href)
} else {
navigator.msSaveBlob(blob, filename);
}
});
},
handleBatch(type) {
if (this.selectIds.size < 1) {
this.$warning(this.$t('test_track.plan_view.select_manipulate'));
return;
}
if (type === 'move'){
if (type === 'move') {
this.$emit('moveToNode', this.selectIds);
} else if (type === 'delete'){
} else if (type === 'delete') {
this.handleDeleteBatch();
} else {
this.exportTestCase();
}
},
filter(filters) {
......
......@@ -19,11 +19,7 @@
<el-container>
<el-main class="case-content" v-loading="result.loading">
<el-row>
<el-col :offset="16" :span="8">
<ms-table-search-bar :condition.sync="condition" @change="initData"/>
</el-col>
</el-row>
<ms-table-header :condition.sync="condition" @search="getCaseNames" title="" :show-create="false"/>
<el-table
:data="testCases"
@filter-change="filter"
......@@ -86,10 +82,21 @@
import TypeTableItem from "../../../common/tableItems/planview/TypeTableItem";
import {_filter} from "../../../../../../common/js/utils";
import MsTableSearchBar from "../../../../common/components/MsTableSearchBar";
import MsTableAdvSearchBar from "../../../../common/components/search/MsTableAdvSearchBar";
import MsTableHeader from "../../../../common/components/MsTableHeader";
import {getTestCaseConfigs} from "../../../../common/components/search/search-components";
export default {
name: "TestCaseRelevance",
components: {NodeTree, MsDialogFooter, PriorityTableItem, TypeTableItem, MsTableSearchBar},
components: {
NodeTree,
MsDialogFooter,
PriorityTableItem,
TypeTableItem,
MsTableSearchBar,
MsTableAdvSearchBar,
MsTableHeader
},
data() {
return {
result: {},
......@@ -100,7 +107,9 @@
treeNodes: [],
selectNodeIds: [],
selectNodeNames: [],
condition: {},
condition: {
components: getTestCaseConfigs()
},
priorityFilters: [
{text: 'P0', value: 'P0'},
{text: 'P1', value: 'P1'},
......@@ -143,17 +152,19 @@
this.$emit('refresh');
});
},
getCaseNames() {
getCaseNames(combine) {
let param = {};
// 只有在点击高级搜索的查询按钮时combine才有值
let condition = combine ? {combine: combine} : this.condition;
if (this.planId) {
// param.planId = this.planId;
this.condition.planId = this.planId;
condition.planId = this.planId;
}
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
// param.nodeIds = this.selectNodeIds;
this.condition.nodeIds = this.selectNodeIds;
condition.nodeIds = this.selectNodeIds;
}
this.result = this.$post('/test/case/name', this.condition, response => {
this.result = this.$post('/test/case/name', condition, response => {
this.testCases = response.data;
this.testCases.forEach(item => {
item.checked = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册