From 1f64a7e300c08c15cd5ca4460b53379c5186136b Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Sat, 15 Jun 2024 17:37:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E6=94=AF=E6=8C=81=E6=89=A7=E8=A1=8C=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/TestPlanReportFunctionCase.java | 6 +- .../TestPlanReportFunctionCaseExample.java | 70 +++++++++++++++++++ .../TestPlanReportFunctionCaseMapper.xml | 34 +++++++-- .../migration/3.0.1/ddl/V3.0.1_2__ga_ddl.sql | 1 + .../plan/service/TestPlanReportService.java | 22 ++++-- 5 files changed, 121 insertions(+), 12 deletions(-) diff --git a/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCase.java b/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCase.java index e997283972..8fba3f98ce 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCase.java +++ b/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCase.java @@ -69,6 +69,9 @@ public class TestPlanReportFunctionCase implements Serializable { @NotNull(message = "{test_plan_report_function_case.pos.not_blank}", groups = {Created.class}) private Long pos; + @Schema(description = "执行报告ID") + private String functionCaseExecuteReportId; + private static final long serialVersionUID = 1L; public enum Column { @@ -84,7 +87,8 @@ public class TestPlanReportFunctionCase implements Serializable { functionCaseBugCount("function_case_bug_count", "functionCaseBugCount", "BIGINT", false), functionCaseExecuteResult("function_case_execute_result", "functionCaseExecuteResult", "VARCHAR", false), testPlanCollectionId("test_plan_collection_id", "testPlanCollectionId", "VARCHAR", false), - pos("pos", "pos", "BIGINT", false); + pos("pos", "pos", "BIGINT", false), + functionCaseExecuteReportId("function_case_execute_report_id", "functionCaseExecuteReportId", "VARCHAR", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCaseExample.java b/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCaseExample.java index 04d6e97c89..c7f0b817c2 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCaseExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/plan/domain/TestPlanReportFunctionCaseExample.java @@ -983,6 +983,76 @@ public class TestPlanReportFunctionCaseExample { addCriterion("pos not between", value1, value2, "pos"); return (Criteria) this; } + + public Criteria andFunctionCaseExecuteReportIdIsNull() { + addCriterion("function_case_execute_report_id is null"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdIsNotNull() { + addCriterion("function_case_execute_report_id is not null"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdEqualTo(String value) { + addCriterion("function_case_execute_report_id =", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdNotEqualTo(String value) { + addCriterion("function_case_execute_report_id <>", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdGreaterThan(String value) { + addCriterion("function_case_execute_report_id >", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdGreaterThanOrEqualTo(String value) { + addCriterion("function_case_execute_report_id >=", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdLessThan(String value) { + addCriterion("function_case_execute_report_id <", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdLessThanOrEqualTo(String value) { + addCriterion("function_case_execute_report_id <=", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdLike(String value) { + addCriterion("function_case_execute_report_id like", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdNotLike(String value) { + addCriterion("function_case_execute_report_id not like", value, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdIn(List values) { + addCriterion("function_case_execute_report_id in", values, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdNotIn(List values) { + addCriterion("function_case_execute_report_id not in", values, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdBetween(String value1, String value2) { + addCriterion("function_case_execute_report_id between", value1, value2, "functionCaseExecuteReportId"); + return (Criteria) this; + } + + public Criteria andFunctionCaseExecuteReportIdNotBetween(String value1, String value2) { + addCriterion("function_case_execute_report_id not between", value1, value2, "functionCaseExecuteReportId"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/plan/mapper/TestPlanReportFunctionCaseMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/plan/mapper/TestPlanReportFunctionCaseMapper.xml index 6bdaaaa15e..a78ef47c65 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/plan/mapper/TestPlanReportFunctionCaseMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/plan/mapper/TestPlanReportFunctionCaseMapper.xml @@ -15,6 +15,7 @@ + @@ -77,7 +78,8 @@ id, test_plan_report_id, test_plan_function_case_id, function_case_id, function_case_num, function_case_name, function_case_module, function_case_priority, function_case_execute_user, - function_case_bug_count, function_case_execute_result, test_plan_collection_id, pos + function_case_bug_count, function_case_execute_result, test_plan_collection_id, pos, + function_case_execute_report_id @@ -256,6 +264,9 @@ pos = #{record.pos,jdbcType=BIGINT}, + + function_case_execute_report_id = #{record.functionCaseExecuteReportId,jdbcType=VARCHAR}, + @@ -275,7 +286,8 @@ function_case_bug_count = #{record.functionCaseBugCount,jdbcType=BIGINT}, function_case_execute_result = #{record.functionCaseExecuteResult,jdbcType=VARCHAR}, test_plan_collection_id = #{record.testPlanCollectionId,jdbcType=VARCHAR}, - pos = #{record.pos,jdbcType=BIGINT} + pos = #{record.pos,jdbcType=BIGINT}, + function_case_execute_report_id = #{record.functionCaseExecuteReportId,jdbcType=VARCHAR} @@ -319,6 +331,9 @@ pos = #{pos,jdbcType=BIGINT}, + + function_case_execute_report_id = #{functionCaseExecuteReportId,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -335,7 +350,8 @@ function_case_bug_count = #{functionCaseBugCount,jdbcType=BIGINT}, function_case_execute_result = #{functionCaseExecuteResult,jdbcType=VARCHAR}, test_plan_collection_id = #{testPlanCollectionId,jdbcType=VARCHAR}, - pos = #{pos,jdbcType=BIGINT} + pos = #{pos,jdbcType=BIGINT}, + function_case_execute_report_id = #{functionCaseExecuteReportId,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -343,7 +359,7 @@ (id, test_plan_report_id, test_plan_function_case_id, function_case_id, function_case_num, function_case_name, function_case_module, function_case_priority, function_case_execute_user, function_case_bug_count, function_case_execute_result, test_plan_collection_id, - pos) + pos, function_case_execute_report_id) values (#{item.id,jdbcType=VARCHAR}, #{item.testPlanReportId,jdbcType=VARCHAR}, #{item.testPlanFunctionCaseId,jdbcType=VARCHAR}, @@ -351,7 +367,8 @@ #{item.functionCaseName,jdbcType=VARCHAR}, #{item.functionCaseModule,jdbcType=VARCHAR}, #{item.functionCasePriority,jdbcType=VARCHAR}, #{item.functionCaseExecuteUser,jdbcType=VARCHAR}, #{item.functionCaseBugCount,jdbcType=BIGINT}, #{item.functionCaseExecuteResult,jdbcType=VARCHAR}, - #{item.testPlanCollectionId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}) + #{item.testPlanCollectionId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.functionCaseExecuteReportId,jdbcType=VARCHAR} + ) @@ -403,6 +420,9 @@ #{item.pos,jdbcType=BIGINT} + + #{item.functionCaseExecuteReportId,jdbcType=VARCHAR} + ) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.1/ddl/V3.0.1_2__ga_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.0.1/ddl/V3.0.1_2__ga_ddl.sql index 2f0c3f6fd5..0367f62e50 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.1/ddl/V3.0.1_2__ga_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.1/ddl/V3.0.1_2__ga_ddl.sql @@ -227,6 +227,7 @@ ALTER TABLE test_plan_report DROP `execute_time`; -- 计划报告功能用例明细表 ALTER TABLE test_plan_report_function_case ADD `test_plan_collection_id` VARCHAR(50) NOT NULL COMMENT '测试集ID'; ALTER TABLE test_plan_report_function_case ADD `pos` BIGINT NOT NULL COMMENT '自定义排序'; +ALTER TABLE test_plan_report_function_case ADD `function_case_execute_report_id` VARCHAR(50) COMMENT '执行报告ID'; CREATE INDEX idx_test_plan_collection_id ON test_plan_report_function_case(test_plan_collection_id); CREATE INDEX idx_pos ON test_plan_report_function_case(pos); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index d7a438901a..5484581eb6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -40,10 +40,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -69,6 +66,8 @@ public class TestPlanReportService { private ExtTestPlanReportBugMapper extTestPlanReportBugMapper; @Resource private ExtTestPlanReportFunctionalCaseMapper extTestPlanReportFunctionalCaseMapper; + @Resource + private TestPlanCaseExecuteHistoryMapper testPlanCaseExecuteHistoryMapper; @Resource private ExtTestPlanReportApiCaseMapper extTestPlanReportApiCaseMapper; @Resource @@ -339,12 +338,27 @@ public class TestPlanReportService { List ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList(); List options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids); Map casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); + // 关联的功能用例最新一次执行历史 + List relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList(); + TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample(); + example.createCriteria().andTestPlanCaseIdIn(relateIds); + List functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example); + Map> functionalExecMap = functionalExecHisList.stream().collect(Collectors.groupingBy(TestPlanCaseExecuteHistory::getTestPlanCaseId)); + + reportFunctionCases.forEach(reportFunctionalCase -> { reportFunctionalCase.setId(IDGenerator.nextStr()); reportFunctionalCase.setTestPlanReportId(report.getId()); reportFunctionalCase.setFunctionCaseModule(moduleParam.getFunctionalModuleMap().getOrDefault(reportFunctionalCase.getFunctionCaseModule(), ModuleTreeUtils.MODULE_PATH_PREFIX + reportFunctionalCase.getFunctionCaseModule())); reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId())); + List hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId()); + if (CollectionUtils.isNotEmpty(hisList)) { + Optional lastExecuteHisOpt = hisList.stream().sorted(Comparator.comparing(TestPlanCaseExecuteHistory::getCreateTime).reversed()).map(TestPlanCaseExecuteHistory::getId).findFirst(); + reportFunctionalCase.setFunctionCaseExecuteReportId(lastExecuteHisOpt.get()); + } else { + reportFunctionalCase.setFunctionCaseExecuteReportId(null); + } }); // 插入计划功能用例关联数据 -> 报告内容 TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);