解决循环或轮询编排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); public List<TestCaseStep> selectTestCaseStepListByCaseId(Long caseId);
/**
* 根据用例id查询所有用例步骤列表并按照步骤顺序排序
*
* @param caseId 用例id
* @return 用例步骤集合
*/
public List<Long> selectAllTestCaseStepIdListByCaseId(Long caseId);
int deleteTestCaseStepByCaseId(Long caseId); int deleteTestCaseStepByCaseId(Long caseId);
} }

View File

@@ -76,10 +76,20 @@ public class TestCaseStepServiceImpl implements ITestCaseStepService {
@Override @Override
@Transactional @Transactional
public int insertBatchTestCaseStep(TestCaseStepAddQO qo) { public int insertBatchTestCaseStep(TestCaseStepAddQO qo) {
testCaseStepMapper.deleteTestCaseStepByCaseId(qo.getCaseId()); List<Long> allTestCaseStepIdList =
testCaseStepMapper.selectAllTestCaseStepIdListByCaseId(qo.getCaseId());
int i = 0; int i = 0;
for (TestCaseStep testCaseStep1 : qo.getList()) { 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; return i;
} }

View File

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

View File

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

View File

@@ -179,6 +179,10 @@ export default {
type: Array type: Array
} }
}, },
created() {
// 在这里进行数据预处理
this.preProcessFormData();
},
data() { data() {
return { return {
activeName: "Headers", activeName: "Headers",
@@ -194,6 +198,32 @@ export default {
} }
}, },
methods: { 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) { folderHandleSelected(id) {
if (id) { if (id) {
this.queryParams.groupId = id; this.queryParams.groupId = id;
@@ -254,26 +284,22 @@ export default {
this.form.apiPort = p.port; this.form.apiPort = p.port;
this.form.apiProtocol = p.protocol; this.form.apiProtocol = p.protocol;
if (p.header) { 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([{ this.form.requestHeader.push([{
key: "", key: "",
value: "", value: "",
}]) }])
} else {
this.form.requestHeader = [{
key: "",
value: "",
}]
} }
} else { } else {
this.form.apiHttpId = undefined; this.form.apiHttpId = undefined;
this.form.apiHost = undefined; this.form.apiHost = undefined;
this.form.apiPort = undefined; this.form.apiPort = undefined;
this.form.apiProtocol = undefined; this.form.apiProtocol = undefined;
this.form.requestHeader = [{
key: "",
value: "",
}]
} }
}, },
handleTableEdit(e, flag, scope) { handleTableEdit(e, flag, scope) {

View File

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