diff --git a/backend/framework/domain/src/main/java/io/metersphere/project/domain/CustomFunction.java b/backend/framework/domain/src/main/java/io/metersphere/project/domain/CustomFunction.java index d9983f6dbf..c66a07eebb 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/project/domain/CustomFunction.java +++ b/backend/framework/domain/src/main/java/io/metersphere/project/domain/CustomFunction.java @@ -36,7 +36,7 @@ public class CustomFunction implements Serializable { @Schema(description = "脚本语言类型") private String type; - @Schema(description = "脚本状态(进行中/已完成)") + @Schema(description = "脚本状态(草稿/测试通过)") private String status; @Schema(description = "创建时间") diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql index 292bf5991d..50bc57b601 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS custom_function `tags` VARCHAR(1000) COMMENT '标签', `description` VARCHAR(500) COMMENT '函数描述', `type` VARCHAR(50) DEFAULT NULL COMMENT '脚本语言类型', - `status` VARCHAR(50) COMMENT '脚本状态(进行中/已完成)' , + `status` VARCHAR(50) COMMENT '脚本状态(草稿/测试通过)' , `create_time` BIGINT COMMENT '创建时间' , `update_time` BIGINT COMMENT '更新时间' , `create_user` VARCHAR(50) COMMENT '创建人' , 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 909ad463e7..12b3793d77 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 @@ -102,7 +102,7 @@ public class ApiDefinitionMockController { } @PostMapping("/upload/temp/file") - @Operation(summary = "上传接口定义所需的文件资源,并返回文件ID") + @Operation(summary = "上传接口 Mock 所需的文件资源,并返回文件ID") @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_MOCK_ADD, PermissionConstants.PROJECT_API_DEFINITION_MOCK_UPDATE}) public String uploadTempFile(@RequestParam("file") MultipartFile file) { return apiDefinitionMockService.uploadTempFile(file); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionPageRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionPageRequest.java index d5aeee65ec..da2c784029 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionPageRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionPageRequest.java @@ -27,6 +27,6 @@ public class CustomFunctionPageRequest extends BasePageRequest implements Serial @Schema(description = "脚本语言类型") private String type; - @Schema(description = "脚本状态(进行中/已完成)") + @Schema(description = "脚本状态(草稿/测试通过)") private String status; } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java index 1e894045be..16b6cb8165 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java @@ -35,7 +35,7 @@ public class CustomFunctionRequest implements Serializable { @Schema(description = "脚本语言类型") private String type; - @Schema(description = "脚本状态(进行中/已完成)") + @Schema(description = "脚本状态(草稿/测试通过)") private String status; @Schema(description = "标签") diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/enums/CustomFunctionStatus.java b/backend/services/project-management/src/main/java/io/metersphere/project/enums/CustomFunctionStatus.java new file mode 100644 index 0000000000..d9ff18e174 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/enums/CustomFunctionStatus.java @@ -0,0 +1,11 @@ +package io.metersphere.project.enums; + +/** + * @author: LAN + * @date: 2024/1/12 11:03 + * @version: 1.0 + */ +public enum CustomFunctionStatus { + DRAFT, + PASSED +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtCustomFunctionMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtCustomFunctionMapper.xml index f03f81e3b4..c124766b89 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtCustomFunctionMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtCustomFunctionMapper.xml @@ -15,17 +15,6 @@ - - - and ( diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CustomFunctionService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CustomFunctionService.java index 24cb99692e..3670c31d30 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CustomFunctionService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CustomFunctionService.java @@ -7,6 +7,7 @@ import io.metersphere.project.dto.customfunction.CustomFunctionDTO; import io.metersphere.project.dto.customfunction.request.CustomFunctionPageRequest; import io.metersphere.project.dto.customfunction.request.CustomFunctionRequest; import io.metersphere.project.dto.customfunction.request.CustomFunctionUpdateRequest; +import io.metersphere.project.enums.CustomFunctionStatus; import io.metersphere.project.enums.result.ProjectResultCode; import io.metersphere.project.mapper.CustomFunctionBlobMapper; import io.metersphere.project.mapper.CustomFunctionMapper; @@ -43,7 +44,15 @@ public class CustomFunctionService { ExtCustomFunctionMapper extCustomFunctionMapper; public List getPage(CustomFunctionPageRequest request) { - return extCustomFunctionMapper.list(request); + List list = extCustomFunctionMapper.list(request); + if (!CollectionUtils.isEmpty(list)) { + processCustomFunction(list); + } + return list; + } + + private void processCustomFunction(List list) { + list.forEach(item -> handleCustomFunctionBlob(item.getId(), item)); } public CustomFunctionDTO get(String id) { @@ -57,12 +66,16 @@ public class CustomFunctionService { public void handleCustomFunctionBlob(String id, CustomFunctionDTO customFunctionDTO) { Optional customFunctionBlobOptional = Optional.ofNullable(customFunctionBlobMapper.selectByPrimaryKey(id)); customFunctionBlobOptional.ifPresent(blob -> { - customFunctionDTO.setParams(new String(blob.getParams(), StandardCharsets.UTF_8)); - customFunctionDTO.setScript(new String(blob.getScript(), StandardCharsets.UTF_8)); - customFunctionDTO.setResult(new String(blob.getResult(), StandardCharsets.UTF_8)); + customFunctionDTO.setParams(toStringOrDefault(blob.getParams())); + customFunctionDTO.setScript(toStringOrDefault(blob.getScript())); + customFunctionDTO.setResult(toStringOrDefault(blob.getResult())); }); } + private String toStringOrDefault(byte[] bytes) { + return (bytes != null) ? new String(bytes, StandardCharsets.UTF_8) : null; + } + public CustomFunction add(CustomFunctionRequest request, String userId) { ProjectService.checkResourceExist(request.getProjectId()); @@ -70,6 +83,7 @@ public class CustomFunctionService { BeanUtils.copyBean(customFunction, request); checkAddExist(customFunction); customFunction.setId(IDGenerator.nextStr()); + customFunction.setStatus(request.getStatus() != null ? request.getStatus() : CustomFunctionStatus.DRAFT.toString()); customFunction.setCreateTime(System.currentTimeMillis()); customFunction.setUpdateTime(System.currentTimeMillis()); customFunction.setCreateUser(userId); @@ -78,17 +92,7 @@ public class CustomFunctionService { customFunction.setTags(request.getTags()); } customFunctionMapper.insertSelective(customFunction); - CustomFunctionBlob customFunctionBlob = new CustomFunctionBlob(); - customFunctionBlob.setId(customFunction.getId()); - if(request.getParams() != null) { - customFunctionBlob.setParams(request.getParams().getBytes()); - } - if(request.getScript() != null) { - customFunctionBlob.setScript(request.getScript().getBytes()); - } - if(request.getResult() != null) { - customFunctionBlob.setResult(request.getResult().getBytes()); - } + CustomFunctionBlob customFunctionBlob = createCustomFunctionBlob(customFunction, request.getParams(), request.getScript(), request.getResult()); customFunctionBlobMapper.insertSelective(customFunctionBlob); return customFunction; @@ -106,18 +110,17 @@ public class CustomFunctionService { customFunction.setTags(request.getTags()); } customFunctionMapper.updateByPrimaryKeySelective(customFunction); + CustomFunctionBlob customFunctionBlob = createCustomFunctionBlob(customFunction, request.getParams(), request.getScript(), request.getResult()); + customFunctionBlobMapper.updateByPrimaryKeySelective(customFunctionBlob); + } + + private CustomFunctionBlob createCustomFunctionBlob(CustomFunction customFunction, String params, String script, String result) { CustomFunctionBlob customFunctionBlob = new CustomFunctionBlob(); customFunctionBlob.setId(customFunction.getId()); - if(request.getParams() != null) { - customFunctionBlob.setParams(request.getParams().getBytes()); - } - if(request.getScript() != null) { - customFunctionBlob.setScript(request.getScript().getBytes()); - } - if(request.getResult() != null) { - customFunctionBlob.setResult(request.getResult().getBytes()); - } - customFunctionBlobMapper.updateByPrimaryKeySelective(customFunctionBlob); + customFunctionBlob.setParams(params != null ? params.getBytes() : null); + customFunctionBlob.setScript(script != null ? script.getBytes() : null); + customFunctionBlob.setResult(result != null ? result.getBytes() : null); + return customFunctionBlob; } public void updateStatus(CustomFunctionUpdateRequest request, String userId) { diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/CustomFunctionControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/CustomFunctionControllerTests.java index bee98de0c3..461535bfad 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/CustomFunctionControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/CustomFunctionControllerTests.java @@ -316,7 +316,7 @@ public class CustomFunctionControllerTests extends BaseTest { private void configureKeywordSearch(CustomFunctionPageRequest request) { - request.setKeyword("100"); + request.setKeyword("test"); request.setSort(Map.of("status", "asc")); }