diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMock.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMock.java index 314d62288f..c74e5bbef3 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMock.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMock.java @@ -57,6 +57,9 @@ public class ApiDefinitionMock implements Serializable { @Schema(description = "更新人") private String updateUser; + @Schema(description = "版本id") + private String versionId; + private static final long serialVersionUID = 1L; public enum Column { @@ -71,7 +74,8 @@ public class ApiDefinitionMock implements Serializable { projectId("project_id", "projectId", "VARCHAR", false), apiDefinitionId("api_definition_id", "apiDefinitionId", "VARCHAR", false), statusCode("status_code", "statusCode", "INTEGER", false), - updateUser("update_user", "updateUser", "VARCHAR", false); + updateUser("update_user", "updateUser", "VARCHAR", false), + versionId("version_id", "versionId", "VARCHAR", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMockExample.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMockExample.java index aa47155e73..e4f48b0194 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMockExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionMockExample.java @@ -937,6 +937,76 @@ public class ApiDefinitionMockExample { addCriterion("update_user not between", value1, value2, "updateUser"); return (Criteria) this; } + + public Criteria andVersionIdIsNull() { + addCriterion("version_id is null"); + return (Criteria) this; + } + + public Criteria andVersionIdIsNotNull() { + addCriterion("version_id is not null"); + return (Criteria) this; + } + + public Criteria andVersionIdEqualTo(String value) { + addCriterion("version_id =", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdNotEqualTo(String value) { + addCriterion("version_id <>", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdGreaterThan(String value) { + addCriterion("version_id >", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdGreaterThanOrEqualTo(String value) { + addCriterion("version_id >=", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdLessThan(String value) { + addCriterion("version_id <", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdLessThanOrEqualTo(String value) { + addCriterion("version_id <=", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdLike(String value) { + addCriterion("version_id like", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdNotLike(String value) { + addCriterion("version_id not like", value, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdIn(List values) { + addCriterion("version_id in", values, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdNotIn(List values) { + addCriterion("version_id not in", values, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdBetween(String value1, String value2) { + addCriterion("version_id between", value1, value2, "versionId"); + return (Criteria) this; + } + + public Criteria andVersionIdNotBetween(String value1, String value2) { + addCriterion("version_id not between", value1, value2, "versionId"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionMockMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionMockMapper.xml index e265a093de..b5026d88bd 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionMockMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionMockMapper.xml @@ -14,6 +14,7 @@ + @@ -113,7 +114,7 @@ id, create_time, update_time, create_user, `name`, tags, `enable`, expect_num, project_id, - api_definition_id, status_code, update_user + api_definition_id, status_code, update_user, version_id @@ -281,6 +288,9 @@ update_user = #{record.updateUser,jdbcType=VARCHAR}, + + version_id = #{record.versionId,jdbcType=VARCHAR}, + @@ -299,7 +309,8 @@ project_id = #{record.projectId,jdbcType=VARCHAR}, api_definition_id = #{record.apiDefinitionId,jdbcType=VARCHAR}, status_code = #{record.statusCode,jdbcType=INTEGER}, - update_user = #{record.updateUser,jdbcType=VARCHAR} + update_user = #{record.updateUser,jdbcType=VARCHAR}, + version_id = #{record.versionId,jdbcType=VARCHAR} @@ -340,6 +351,9 @@ update_user = #{updateUser,jdbcType=VARCHAR}, + + version_id = #{versionId,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -355,20 +369,21 @@ project_id = #{projectId,jdbcType=VARCHAR}, api_definition_id = #{apiDefinitionId,jdbcType=VARCHAR}, status_code = #{statusCode,jdbcType=INTEGER}, - update_user = #{updateUser,jdbcType=VARCHAR} + update_user = #{updateUser,jdbcType=VARCHAR}, + version_id = #{versionId,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} insert into api_definition_mock (id, create_time, update_time, create_user, `name`, tags, `enable`, expect_num, project_id, - api_definition_id, status_code, update_user) + api_definition_id, status_code, update_user, version_id) values (#{item.id,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, #{item.enable,jdbcType=BIT}, #{item.expectNum,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.apiDefinitionId,jdbcType=VARCHAR}, #{item.statusCode,jdbcType=INTEGER}, - #{item.updateUser,jdbcType=VARCHAR}) + #{item.updateUser,jdbcType=VARCHAR}, #{item.versionId,jdbcType=VARCHAR}) @@ -417,6 +432,9 @@ #{item.updateUser,jdbcType=VARCHAR} + + #{item.versionId,jdbcType=VARCHAR} + ) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql index e97761d8e7..bd4e2ded9c 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql @@ -14,6 +14,7 @@ ALTER TABLE test_plan_config DROP COLUMN run_mode_config; ALTER TABLE test_plan_config ADD COLUMN test_planning BIT NOT NULL DEFAULT 0 COMMENT '是否开启测试规划'; ALTER TABLE api_definition_mock ADD COLUMN update_user VARCHAR(50) COMMENT '更新人'; +ALTER TABLE api_definition_mock ADD COLUMN version_id VARCHAR(50) COMMENT '版本id'; ALTER TABLE operation_history MODIFY COLUMN module VARCHAR(100); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionMockController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionMockController.java index 5203c936d5..551fd34605 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionMockController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionMockController.java @@ -1,6 +1,7 @@ package io.metersphere.api.controller.definition; import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import com.github.pagehelper.page.PageMethod; import io.metersphere.api.constants.ApiResource; import io.metersphere.api.constants.ApiResourceType; @@ -20,6 +21,8 @@ import io.metersphere.api.service.definition.ApiDefinitionMockNoticeService; import io.metersphere.api.service.definition.ApiDefinitionMockService; import io.metersphere.project.service.FileModuleService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.dto.OperationHistoryDTO; +import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; @@ -181,5 +184,15 @@ public class ApiDefinitionMockController { apiDefinitionMockService.batchEdit(request, SessionUtils.getUserId()); } + @PostMapping("/operation-history/page") + @Operation(summary = "接口测试-接口管理-mock-变更历史") + @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_MOCK_READ, PermissionConstants.PROJECT_API_DEFINITION_MOCK_UPDATE}) + @CheckOwner(resourceId = "#request.getSourceId()", resourceType = "api_definition_mock") + public Pager> operationHistoryList(@Validated @RequestBody OperationHistoryRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + return PageUtils.setPageInfo(page, apiDefinitionMockService.operationHistoryList(request)); + } + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java index 6678b38aca..c7b601b620 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java @@ -29,8 +29,11 @@ import io.metersphere.sdk.domain.EnvironmentExample; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.util.*; +import io.metersphere.system.dto.OperationHistoryDTO; +import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.notice.constants.NoticeConstants; +import io.metersphere.system.service.OperationHistoryService; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.utils.ServiceUtils; @@ -87,8 +90,11 @@ public class ApiDefinitionMockService { private ApiDefinitionMockLogService apiDefinitionMockLogService; @Resource private ApiDefinitionMockNoticeService apiDefinitionMockNoticeService; + @Resource + private OperationHistoryService operationHistoryService; public static final String STATUS = "Status"; public static final String TAGS = "Tags"; + private static final String MOCK_TABLE = "api_definition_mock"; public List getPage(ApiDefinitionMockPageRequest request) { return extApiDefinitionMockMapper.list(request); @@ -153,7 +159,7 @@ public class ApiDefinitionMockService { apiDefinitionMock.setEnable(true); ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionMock.getApiDefinitionId()); apiDefinitionMock.setExpectNum(String.valueOf(NumGenerator.nextNum(request.getProjectId() + "_" + apiDefinition.getNum(), ApplicationNumScope.API_MOCK))); - + apiDefinition.setVersionId(apiDefinition.getVersionId()); apiDefinitionMockMapper.insertSelective(apiDefinitionMock); ApiDefinitionMockConfig apiDefinitionMockConfig = new ApiDefinitionMockConfig(); apiDefinitionMockConfig.setId(apiDefinitionMock.getId()); @@ -426,4 +432,8 @@ public class ApiDefinitionMockService { return request.getSelectIds(); } } + + public List operationHistoryList(OperationHistoryRequest request) { + return operationHistoryService.listWidthTable(request, MOCK_TABLE); + } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java index e31f57df4d..c245e2c384 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java @@ -40,6 +40,7 @@ import io.metersphere.sdk.util.TempFileUtils; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.result.MsHttpResultCode; +import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; @@ -434,6 +435,14 @@ public class ApiDefinitionMockControllerTests extends BaseTest { checkLog(apiDefinitionMock.getId(), OperationLogType.UPDATE, ENABLE + apiDefinitionMock.getId()); assertErrorCode(this.requestGet(ENABLE + "111"), MsHttpResultCode.FAILED); + + OperationHistoryRequest request = new OperationHistoryRequest(); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setSourceId(apiDefinitionMock.getId()); + request.setPageSize(10); + request.setCurrent(1); + + requestPostWithOkAndReturn(BASE_PATH + "operation-history/page", request); // @@校验权限 requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_MOCK_UPDATE, ENABLE + apiDefinitionMock.getId()); } diff --git a/backend/services/api-test/src/test/resources/dml/init_api_definition.sql b/backend/services/api-test/src/test/resources/dml/init_api_definition.sql index 171eef0c31..e8e6a3f6a6 100644 --- a/backend/services/api-test/src/test/resources/dml/init_api_definition.sql +++ b/backend/services/api-test/src/test/resources/dml/init_api_definition.sql @@ -51,11 +51,11 @@ INSERT INTO template (id, name, remark, internal, update_time, create_time, crea DELETE FROM `api_definition_mock` WHERE `id` in ('mock_1', 'mock_2', 'mock_3', 'mock_4','mock_5'); INSERT INTO `api_definition_mock` VALUES - ('mock_1', 1641120000000, 1641120000000, 'user1', 'Mock 1', '[\"tag1\",\"tag2\"]', 1, 'EXPECT001', '100001100001', '1001', 200, null), - ('mock_2', 1641121000000, 1641121000000, 'user2', 'Mock 2', '[\"tag2\",\"tag3\"]', 1, 'EXPECT002', '100001100001', '1002', 200, null), - ('mock_3', 1641122000000, 1641122000000, 'user3', 'Mock 3', '[\"tag3\",\"tag4\"]', 1, 'EXPECT003', '100001100001', '1003', 200, null), - ('mock_4', 1641123000000, 1641123000000, 'user1', 'Mock 4', '[\"tag4\",\"tag5\"]', 1, 'EXPECT004', '100001100001', '1005', 400, null), - ('mock_5', 1641124000000, 1641124000000, 'user2', 'Mock 5', '[\"tag5\",\"tag1\"]', 1, 'EXPECT005', '100001100001', '1005', 400, null); + ('mock_1', 1641120000000, 1641120000000, 'user1', 'Mock 1', '[\"tag1\",\"tag2\"]', 1, 'EXPECT001', '100001100001', '1001', 200, null,'1'), + ('mock_2', 1641121000000, 1641121000000, 'user2', 'Mock 2', '[\"tag2\",\"tag3\"]', 1, 'EXPECT002', '100001100001', '1002', 200, null,'1'), + ('mock_3', 1641122000000, 1641122000000, 'user3', 'Mock 3', '[\"tag3\",\"tag4\"]', 1, 'EXPECT003', '100001100001', '1003', 200, null,'1'), + ('mock_4', 1641123000000, 1641123000000, 'user1', 'Mock 4', '[\"tag4\",\"tag5\"]', 1, 'EXPECT004', '100001100001', '1005', 400, null,'1'), + ('mock_5', 1641124000000, 1641124000000, 'user2', 'Mock 5', '[\"tag5\",\"tag1\"]', 1, 'EXPECT005', '100001100001', '1005', 400, null,'1'); DELETE FROM `api_definition_mock_config` WHERE `id` in ('mock_1', 'mock_2', 'mock_3', 'mock_4','mock_5'); INSERT INTO `api_definition_mock_config` VALUES diff --git a/backend/services/project-management/src/main/resources/message_task.json b/backend/services/project-management/src/main/resources/message_task.json index 96218aa6ae..62d8d9be46 100644 --- a/backend/services/project-management/src/main/resources/message_task.json +++ b/backend/services/project-management/src/main/resources/message_task.json @@ -585,8 +585,75 @@ "useDefaultSubject":true } ] + }, + { + "event":"MOCK_CREATE", + "eventName":"", + "receivers":[ + { + "id": "", + "name": "" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + }, + { + "event":"MOCK_UPDATE", + "eventName":"", + "receivers":[ + { + "id": "CREATE_USER", + "name": "" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + }, + { + "event":"MOCK_DELETE", + "eventName":"", + "receivers":[ + { + "id": "CREATE_USER", + "name": "" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] } ] + }, { "taskType":"API_SCENARIO_TASK",