解决循环或轮询编排bug

This commit is contained in:
liangdaliang
2025-03-12 18:22:24 +08:00
parent 2cdc43cd0f
commit 96e1237c20
6 changed files with 88 additions and 12 deletions

View File

@@ -68,5 +68,13 @@ public interface TestCaseStepMapper
*/
public List<TestCaseStep> selectTestCaseStepListByCaseId(Long caseId);
/**
* 根据用例id查询所有用例步骤列表并按照步骤顺序排序
*
* @param caseId 用例id
* @return 用例步骤集合
*/
public List<Long> selectAllTestCaseStepIdListByCaseId(Long caseId);
int deleteTestCaseStepByCaseId(Long caseId);
}

View File

@@ -76,10 +76,20 @@ public class TestCaseStepServiceImpl implements ITestCaseStepService {
@Override
@Transactional
public int insertBatchTestCaseStep(TestCaseStepAddQO qo) {
testCaseStepMapper.deleteTestCaseStepByCaseId(qo.getCaseId());
List<Long> allTestCaseStepIdList =
testCaseStepMapper.selectAllTestCaseStepIdListByCaseId(qo.getCaseId());
int i = 0;
for (TestCaseStep testCaseStep1 : qo.getList()) {
i += insertTestCaseStep(testCaseStep1);
if (testCaseStep1.getId() != null) {
allTestCaseStepIdList.remove(testCaseStep1.getId());
updateTestCaseStep(testCaseStep1);
} else {
insertTestCaseStep(testCaseStep1);
}
i ++;
}
for (Long testCaseStepId : allTestCaseStepIdList) {
deleteTestCaseStepById(testCaseStepId);
}
return i;
}

View File

@@ -235,4 +235,9 @@
where case_id = #{caseId} and del_flag = '0' and parent_id is null
ORDER BY step_num
</select>
<select id="selectAllTestCaseStepIdListByCaseId" parameterType="Long" resultType="Long">
select id from test_case_step
where case_id = #{caseId} and del_flag = '0'
</select>
</mapper>

View File

@@ -49,11 +49,33 @@ export default {
},
saveStep(list) {
let p = []
let index = 1;
list.forEach((item) => {
item.assertion.pop();
item.assignment.pop();
item.requestHeader.pop();
item.requestParams.pop();
if (item.stepNum) {
item.stepNum = index;
}
index ++;
let childrenList = item.childrenList;
if (childrenList) {
item.childrenList = null;
let cindex = 1;
childrenList.forEach((children) => {
p.push({
...children,
caseId: this.$route.query.id,
stepNum: cindex,
assertion: JSON.stringify(children.assertion),
assignment: JSON.stringify(children.assignment),
requestHeader: JSON.stringify(children.requestHeader),
requestParams: JSON.stringify(children.requestParams)
});
cindex ++;
});
}
p.push({
...item,
caseId: this.$route.query.id,
@@ -63,6 +85,7 @@ export default {
requestParams: JSON.stringify(item.requestParams)
});
})
console.log(p)
addCaseStep({
caseId: this.$route.query.id,
list: p

View File

@@ -179,6 +179,10 @@ export default {
type: Array
}
},
created() {
// 在这里进行数据预处理
this.preProcessFormData();
},
data() {
return {
activeName: "Headers",
@@ -194,6 +198,32 @@ export default {
}
},
methods: {
preProcessFormData() {
if (typeof this.form.requestHeader === 'string') {
try {
this.form.requestHeader = JSON.parse(this.form.requestHeader);
} catch (e) {
}
}
if (typeof this.form.requestParams === 'string') {
try {
this.form.requestParams = JSON.parse(this.form.requestParams);
} catch (e) {
}
}
if (typeof this.form.assignment === 'string') {
try {
this.form.assignment = JSON.parse(this.form.assignment);
} catch (e) {
}
}
if (typeof this.form.assertion === 'string') {
try {
this.form.assertion = JSON.parse(this.form.assertion);
} catch (e) {
}
}
},
folderHandleSelected(id) {
if (id) {
this.queryParams.groupId = id;
@@ -254,26 +284,22 @@ export default {
this.form.apiPort = p.port;
this.form.apiProtocol = p.protocol;
if (p.header) {
this.form.requestHeader = JSON.parse(p.header);
let newHeader = JSON.parse(p.header);
if (newHeader && newHeader.length > 0) {
this.form.requestHeader = newHeader;
} else {
return;
}
this.form.requestHeader.push([{
key: "",
value: "",
}])
} else {
this.form.requestHeader = [{
key: "",
value: "",
}]
}
} else {
this.form.apiHttpId = undefined;
this.form.apiHost = undefined;
this.form.apiPort = undefined;
this.form.apiProtocol = undefined;
this.form.requestHeader = [{
key: "",
value: "",
}]
}
},
handleTableEdit(e, flag, scope) {

View File

@@ -65,6 +65,10 @@ export default {
},
methods: {
handleAdd(type) {
if (!this.form.id) {
this.$modal.msgError("请先保存循环或轮询主步骤再新增子步骤!");
return;
}
this.list.push({
name: "",
parentId: this.form.id,