From e3171c2b12c98425e7cc16eb163f31e029f1f5b0 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 7 Aug 2023 19:02:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3=E8=81=94=E8=B0=83?= =?UTF-8?q?=EF=BC=8C=E6=97=A5=E5=BF=97=E8=A1=A8=E6=B7=BB=E5=8A=A0=E7=B4=A2?= =?UTF-8?q?=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3.0.0/ddl/V3.0.0_11__system_setting.sql | 23 -------------- .../migration/3.0.0/ddl/V3.0.0_2__sdk_ddl.sql | 10 +++++++ .../controller/AuthSourceController.java | 7 +++-- .../metersphere/system/dto/AuthSourceDTO.java | 30 +++++++++++++++++++ .../system/service/AuthSourceService.java | 29 +++++++++++------- 5 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/AuthSourceDTO.java diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql index 8a696a56f3..cc7767c013 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql @@ -114,29 +114,6 @@ CREATE TABLE IF NOT EXISTS novice_statistics DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '新手村'; -CREATE TABLE IF NOT EXISTS operation_log -( - `id` VARCHAR(50) NOT NULL COMMENT '主键', - `project_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '项目id', - `create_time` BIGINT NOT NULL COMMENT '操作时间', - `create_user` VARCHAR(50) COMMENT '操作人', - `source_id` VARCHAR(50) COMMENT '资源id', - `method` VARCHAR(255) NOT NULL COMMENT '操作方法', - `type` VARCHAR(20) NOT NULL COMMENT '操作类型/add/update/delete', - `module` VARCHAR(50) COMMENT '操作模块/api/case/scenario/ui', - `details` VARCHAR(500) COMMENT '操作详情', - `path` VARCHAR(255) COMMENT '操作路径', - PRIMARY KEY (id) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_general_ci COMMENT = '操作日志'; - -CREATE INDEX idx_create_time ON operation_log(`create_time`); -CREATE INDEX idx_create_user ON operation_log(`create_user`); -CREATE INDEX idx_method ON operation_log(`method`); -CREATE INDEX idx_module ON operation_log(`module`); -CREATE INDEX idx_project_id ON operation_log(`project_id`); -CREATE INDEX idx_type ON operation_log(`type`); CREATE TABLE IF NOT EXISTS plugin ( diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_2__sdk_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_2__sdk_ddl.sql index 73cff6028e..cebbed6332 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_2__sdk_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_2__sdk_ddl.sql @@ -19,6 +19,16 @@ CREATE TABLE IF NOT EXISTS operation_log DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '操作日志'; +CREATE INDEX idx_create_time ON operation_log(create_time); +CREATE INDEX idx_create_user ON operation_log(create_user); +CREATE INDEX idx_method ON operation_log(method); +CREATE INDEX idx_module ON operation_log(module); +CREATE INDEX idx_project_id ON operation_log(project_id); +CREATE INDEX idx_type ON operation_log(type); +CREATE INDEX idx_organization_id ON operation_log(organization_id); +CREATE INDEX idx_source_id ON operation_log(source_id); + + DROP TABLE IF EXISTS operation_log_blob; CREATE TABLE operation_log_blob( `id` VARCHAR(50) NOT NULL COMMENT '主键' , diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java index e8f7da9a6d..2525c51122 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java @@ -9,6 +9,7 @@ import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; import io.metersphere.system.domain.AuthSource; +import io.metersphere.system.dto.AuthSourceDTO; import io.metersphere.system.request.AuthSourceRequest; import io.metersphere.system.request.AuthSourceStatusRequest; import io.metersphere.system.service.AuthSourceLogService; @@ -58,7 +59,7 @@ public class AuthSourceController { @GetMapping("/get/{id}") @Operation(summary = "获取认证设置详细信息") @RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ) - public AuthSource get(@PathVariable(value = "id") String id) { + public AuthSourceDTO get(@PathVariable(value = "id") String id) { return authSourceService.getAuthSource(id); } @@ -75,7 +76,7 @@ public class AuthSourceController { @Operation(summary = "更新状态") @RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request.getId())", msClass = AuthSourceLogService.class) - public void updateStatus(@Validated @RequestBody AuthSourceStatusRequest request ) { - authSourceService.updateStatus(request.getId(), request.getEnable()); + public AuthSource updateStatus(@Validated @RequestBody AuthSourceStatusRequest request ) { + return authSourceService.updateStatus(request.getId(), request.getEnable()); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/AuthSourceDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/AuthSourceDTO.java new file mode 100644 index 0000000000..073cd42de4 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/AuthSourceDTO.java @@ -0,0 +1,30 @@ +package io.metersphere.system.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +@Data +@EqualsAndHashCode(callSuper = false) +public class AuthSourceDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(title = "认证源ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String id; + + + @Schema(title = "描述") + private String description; + + @Schema(title = "名称", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; + + @Schema(title = "类型") + private String type; + + @Schema(title = "认证源配置", requiredMode = Schema.RequiredMode.REQUIRED) + private String configuration; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java index 0acdf43106..4be5024005 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java @@ -2,16 +2,20 @@ package io.metersphere.system.service; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.AuthSource; import io.metersphere.system.domain.AuthSourceExample; +import io.metersphere.system.dto.AuthSourceDTO; import io.metersphere.system.mapper.AuthSourceMapper; import io.metersphere.system.request.AuthSourceRequest; import jakarta.annotation.Resource; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.UUID; @@ -37,7 +41,7 @@ public class AuthSourceService { long createTime = System.currentTimeMillis(); AuthSource source = new AuthSource(); source.setName(authSource.getName()); - source.setConfiguration(authSource.getConfiguration().getBytes()); + source.setConfiguration(authSource.getConfiguration().getBytes(StandardCharsets.UTF_8)); source.setDescription(authSource.getDescription()); source.setType(authSource.getType()); source.setCreateTime(createTime); @@ -68,8 +72,12 @@ public class AuthSourceService { authSourceMapper.deleteByPrimaryKey(id); } - public AuthSource getAuthSource(String id) { - return authSourceMapper.selectByPrimaryKey(id); + public AuthSourceDTO getAuthSource(String id) { + AuthSource source = authSourceMapper.selectByPrimaryKey(id); + AuthSourceDTO authSourceDTO = new AuthSourceDTO(); + BeanUtils.copyBean(authSourceDTO, source); + authSourceDTO.setConfiguration(new String(source.getConfiguration(), StandardCharsets.UTF_8)); + return authSourceDTO; } public AuthSourceRequest updateAuthSource(AuthSourceRequest authSource) { @@ -85,13 +93,12 @@ public class AuthSourceService { return authSource; } - public void updateStatus(String id, Boolean status) { - if (status != null) { - AuthSource record = new AuthSource(); - record.setId(id); - record.setEnable(status); - record.setUpdateTime(System.currentTimeMillis()); - authSourceMapper.updateByPrimaryKeySelective(record); - } + public AuthSource updateStatus(String id, Boolean status) { + AuthSource record = new AuthSource(); + record.setId(id); + record.setEnable(BooleanUtils.toBooleanDefaultIfNull(status,false)); + record.setUpdateTime(System.currentTimeMillis()); + authSourceMapper.updateByPrimaryKeySelective(record); + return record; } }