refactor(系统设置): 认证接口联调,日志表添加索引

This commit is contained in:
WangXu10 2023-08-07 19:02:57 +08:00 committed by fit2-zhao
parent be15c3657d
commit e3171c2b12
5 changed files with 62 additions and 37 deletions

View File

@ -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
(

View File

@ -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 '主键' ,

View File

@ -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());
}
}

View File

@ -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;
}

View File

@ -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;
}
}