From 7f30c221fdd9ec3a821255b94b0d8be0a723489c Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 31 Aug 2023 13:35:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=97=A5=E5=BF=97=E8=A1=A8?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/sdk/domain/OperationLog.java | 9 +- .../sdk/domain/OperationLogBlob.java | 93 ++++++++++++++++--- .../sdk/domain/OperationLogBlobExample.java | 30 ++---- .../sdk/domain/OperationLogExample.java | 30 ++---- .../sdk/mapper/OperationLogBlobMapper.java | 11 ++- .../sdk/mapper/OperationLogBlobMapper.xml | 58 +++++++++--- .../sdk/mapper/OperationLogMapper.java | 4 +- .../sdk/mapper/OperationLogMapper.xml | 38 ++++---- .../migration/3.0.0/ddl/V3.0.0_2__sdk_ddl.sql | 4 +- .../sdk/config/ModuleOpenApiConfig.java | 24 ++--- .../java/io/metersphere/sdk/dto/LogDTO.java | 3 - .../sdk/log/service/OperationLogService.java | 49 +++++----- .../service/UserRoleRelationService.java | 1 - .../resources/dml/init_operation_log_test.sql | 24 ++--- 14 files changed, 231 insertions(+), 147 deletions(-) diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLog.java b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLog.java index bd10212c88..063f920ffd 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLog.java +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLog.java @@ -5,17 +5,17 @@ import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import lombok.Data; + import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; -import lombok.Data; @Data public class OperationLog implements Serializable { - @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{operation_log.id.not_blank}", groups = {Updated.class}) - @Size(min = 1, max = 50, message = "{operation_log.id.length_range}", groups = {Created.class, Updated.class}) - private String id; + private Long id; @Schema(description = "项目id", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{operation_log.project_id.not_blank}", groups = {Created.class}) @@ -137,4 +137,5 @@ public class OperationLog implements Serializable { return this.getEscapedColumnName(); } } + } \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlob.java b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlob.java index c8f60e8db7..7c6632e551 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlob.java +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlob.java @@ -1,26 +1,97 @@ package io.metersphere.sdk.domain; -import io.metersphere.validation.groups.Created; -import io.metersphere.validation.groups.Updated; +import io.metersphere.validation.groups.*; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; -import lombok.Data; - +import jakarta.validation.constraints.*; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import lombok.Data; @Data public class OperationLogBlob implements Serializable { - @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{operation_log_blob.id.not_blank}", groups = {Updated.class}) - @Size(min = 1, max = 50, message = "{operation_log_blob.id.length_range}", groups = {Created.class, Updated.class}) - private String id; + private Long id; - @Schema(description = "变更前内容") + @Schema(description = "变更前内容") private byte[] originalValue; - @Schema(description = "变更后内容") + @Schema(description = "变更后内容") private byte[] modifiedValue; private static final long serialVersionUID = 1L; + + public enum Column { + id("id", "id", "BIGINT", false), + originalValue("original_value", "originalValue", "LONGVARBINARY", false), + modifiedValue("modified_value", "modifiedValue", "LONGVARBINARY", false); + + private static final String BEGINNING_DELIMITER = "`"; + + private static final String ENDING_DELIMITER = "`"; + + private final String column; + + private final boolean isColumnNameDelimited; + + private final String javaProperty; + + private final String jdbcType; + + public String value() { + return this.column; + } + + public String getValue() { + return this.column; + } + + public String getJavaProperty() { + return this.javaProperty; + } + + public String getJdbcType() { + return this.jdbcType; + } + + Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) { + this.column = column; + this.javaProperty = javaProperty; + this.jdbcType = jdbcType; + this.isColumnNameDelimited = isColumnNameDelimited; + } + + public String desc() { + return this.getEscapedColumnName() + " DESC"; + } + + public String asc() { + return this.getEscapedColumnName() + " ASC"; + } + + public static Column[] excludes(Column ... excludes) { + ArrayList columns = new ArrayList<>(Arrays.asList(Column.values())); + if (excludes != null && excludes.length > 0) { + columns.removeAll(new ArrayList<>(Arrays.asList(excludes))); + } + return columns.toArray(new Column[]{}); + } + + public static Column[] all() { + return Column.values(); + } + + public String getEscapedColumnName() { + if (this.isColumnNameDelimited) { + return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString(); + } else { + return this.column; + } + } + + public String getAliasedEscapedColumnName() { + return this.getEscapedColumnName(); + } + } } \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlobExample.java b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlobExample.java index 3cb2284d6e..4017e7a080 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlobExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogBlobExample.java @@ -114,62 +114,52 @@ public class OperationLogBlobExample { return (Criteria) this; } - public Criteria andIdEqualTo(String value) { + public Criteria andIdEqualTo(Long value) { addCriterion("id =", value, "id"); return (Criteria) this; } - public Criteria andIdNotEqualTo(String value) { + public Criteria andIdNotEqualTo(Long value) { addCriterion("id <>", value, "id"); return (Criteria) this; } - public Criteria andIdGreaterThan(String value) { + public Criteria andIdGreaterThan(Long value) { addCriterion("id >", value, "id"); return (Criteria) this; } - public Criteria andIdGreaterThanOrEqualTo(String value) { + public Criteria andIdGreaterThanOrEqualTo(Long value) { addCriterion("id >=", value, "id"); return (Criteria) this; } - public Criteria andIdLessThan(String value) { + public Criteria andIdLessThan(Long value) { addCriterion("id <", value, "id"); return (Criteria) this; } - public Criteria andIdLessThanOrEqualTo(String value) { + public Criteria andIdLessThanOrEqualTo(Long value) { addCriterion("id <=", value, "id"); return (Criteria) this; } - public Criteria andIdLike(String value) { - addCriterion("id like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotLike(String value) { - addCriterion("id not like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdIn(List values) { + public Criteria andIdIn(List values) { addCriterion("id in", values, "id"); return (Criteria) this; } - public Criteria andIdNotIn(List values) { + public Criteria andIdNotIn(List values) { addCriterion("id not in", values, "id"); return (Criteria) this; } - public Criteria andIdBetween(String value1, String value2) { + public Criteria andIdBetween(Long value1, Long value2) { addCriterion("id between", value1, value2, "id"); return (Criteria) this; } - public Criteria andIdNotBetween(String value1, String value2) { + public Criteria andIdNotBetween(Long value1, Long value2) { addCriterion("id not between", value1, value2, "id"); return (Criteria) this; } diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogExample.java b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogExample.java index 4bea901000..8023ed5c13 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/domain/OperationLogExample.java @@ -114,62 +114,52 @@ public class OperationLogExample { return (Criteria) this; } - public Criteria andIdEqualTo(String value) { + public Criteria andIdEqualTo(Long value) { addCriterion("id =", value, "id"); return (Criteria) this; } - public Criteria andIdNotEqualTo(String value) { + public Criteria andIdNotEqualTo(Long value) { addCriterion("id <>", value, "id"); return (Criteria) this; } - public Criteria andIdGreaterThan(String value) { + public Criteria andIdGreaterThan(Long value) { addCriterion("id >", value, "id"); return (Criteria) this; } - public Criteria andIdGreaterThanOrEqualTo(String value) { + public Criteria andIdGreaterThanOrEqualTo(Long value) { addCriterion("id >=", value, "id"); return (Criteria) this; } - public Criteria andIdLessThan(String value) { + public Criteria andIdLessThan(Long value) { addCriterion("id <", value, "id"); return (Criteria) this; } - public Criteria andIdLessThanOrEqualTo(String value) { + public Criteria andIdLessThanOrEqualTo(Long value) { addCriterion("id <=", value, "id"); return (Criteria) this; } - public Criteria andIdLike(String value) { - addCriterion("id like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotLike(String value) { - addCriterion("id not like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdIn(List values) { + public Criteria andIdIn(List values) { addCriterion("id in", values, "id"); return (Criteria) this; } - public Criteria andIdNotIn(List values) { + public Criteria andIdNotIn(List values) { addCriterion("id not in", values, "id"); return (Criteria) this; } - public Criteria andIdBetween(String value1, String value2) { + public Criteria andIdBetween(Long value1, Long value2) { addCriterion("id between", value1, value2, "id"); return (Criteria) this; } - public Criteria andIdNotBetween(String value1, String value2) { + public Criteria andIdNotBetween(Long value1, Long value2) { addCriterion("id not between", value1, value2, "id"); return (Criteria) this; } diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.java b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.java index c25e10d684..58e3729202 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.java +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.java @@ -2,16 +2,15 @@ package io.metersphere.sdk.mapper; import io.metersphere.sdk.domain.OperationLogBlob; import io.metersphere.sdk.domain.OperationLogBlobExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface OperationLogBlobMapper { long countByExample(OperationLogBlobExample example); int deleteByExample(OperationLogBlobExample example); - int deleteByPrimaryKey(String id); + int deleteByPrimaryKey(Long id); int insert(OperationLogBlob record); @@ -21,7 +20,7 @@ public interface OperationLogBlobMapper { List selectByExample(OperationLogBlobExample example); - OperationLogBlob selectByPrimaryKey(String id); + OperationLogBlob selectByPrimaryKey(Long id); int updateByExampleSelective(@Param("record") OperationLogBlob record, @Param("example") OperationLogBlobExample example); @@ -32,4 +31,8 @@ public interface OperationLogBlobMapper { int updateByPrimaryKeySelective(OperationLogBlob record); int updateByPrimaryKeyWithBLOBs(OperationLogBlob record); + + int batchInsert(@Param("list") List list); + + int batchInsertSelective(@Param("list") List list, @Param("selective") OperationLogBlob.Column ... selective); } \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.xml index 7b077a2373..e4311cc876 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogBlobMapper.xml @@ -1,8 +1,8 @@ - + - + @@ -102,17 +102,17 @@ order by ${orderByClause} - select , from operation_log_blob - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} - + delete from operation_log_blob - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} delete from operation_log_blob @@ -123,7 +123,7 @@ insert into operation_log_blob (id, original_value, modified_value ) - values (#{id,jdbcType=VARCHAR}, #{originalValue,jdbcType=LONGVARBINARY}, #{modifiedValue,jdbcType=LONGVARBINARY} + values (#{id,jdbcType=BIGINT}, #{originalValue,jdbcType=LONGVARBINARY}, #{modifiedValue,jdbcType=LONGVARBINARY} ) @@ -141,7 +141,7 @@ - #{id,jdbcType=VARCHAR}, + #{id,jdbcType=BIGINT}, #{originalValue,jdbcType=LONGVARBINARY}, @@ -161,7 +161,7 @@ update operation_log_blob - id = #{record.id,jdbcType=VARCHAR}, + id = #{record.id,jdbcType=BIGINT}, original_value = #{record.originalValue,jdbcType=LONGVARBINARY}, @@ -176,7 +176,7 @@ update operation_log_blob - set id = #{record.id,jdbcType=VARCHAR}, + set id = #{record.id,jdbcType=BIGINT}, original_value = #{record.originalValue,jdbcType=LONGVARBINARY}, modified_value = #{record.modifiedValue,jdbcType=LONGVARBINARY} @@ -185,7 +185,7 @@ update operation_log_blob - set id = #{record.id,jdbcType=VARCHAR} + set id = #{record.id,jdbcType=BIGINT} @@ -200,12 +200,44 @@ modified_value = #{modifiedValue,jdbcType=LONGVARBINARY}, - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} update operation_log_blob set original_value = #{originalValue,jdbcType=LONGVARBINARY}, modified_value = #{modifiedValue,jdbcType=LONGVARBINARY} - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + insert into operation_log_blob + (id, original_value, modified_value) + values + + (#{item.id,jdbcType=BIGINT}, #{item.originalValue,jdbcType=LONGVARBINARY}, #{item.modifiedValue,jdbcType=LONGVARBINARY} + ) + + + + insert into operation_log_blob ( + + ${column.escapedColumnName} + + ) + values + + ( + + + #{item.id,jdbcType=BIGINT} + + + #{item.originalValue,jdbcType=LONGVARBINARY} + + + #{item.modifiedValue,jdbcType=LONGVARBINARY} + + + ) + + \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.java b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.java index 8318e88a1b..eeb12bbc4c 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.java +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.java @@ -10,7 +10,7 @@ public interface OperationLogMapper { int deleteByExample(OperationLogExample example); - int deleteByPrimaryKey(String id); + int deleteByPrimaryKey(Long id); int insert(OperationLog record); @@ -18,7 +18,7 @@ public interface OperationLogMapper { List selectByExample(OperationLogExample example); - OperationLog selectByPrimaryKey(String id); + OperationLog selectByPrimaryKey(Long id); int updateByExampleSelective(@Param("record") OperationLog record, @Param("example") OperationLogExample example); diff --git a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.xml index 15b5ff3288..30f5916a5c 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/sdk/mapper/OperationLogMapper.xml @@ -2,7 +2,7 @@ - + @@ -90,15 +90,15 @@ order by ${orderByClause} - select from operation_log - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} - + delete from operation_log - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} delete from operation_log @@ -106,17 +106,17 @@ - - insert into operation_log (id, project_id, organization_id, + + insert into operation_log (project_id, organization_id, create_time, create_user, source_id, `method`, `type`, `module`, content, `path`) - values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR}, + values (#{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{sourceId,jdbcType=VARCHAR}, #{method,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{module,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}) - + insert into operation_log @@ -155,7 +155,7 @@ - #{id,jdbcType=VARCHAR}, + #{id,jdbcType=BIGINT}, #{projectId,jdbcType=VARCHAR}, @@ -199,7 +199,7 @@ update operation_log - id = #{record.id,jdbcType=VARCHAR}, + id = #{record.id,jdbcType=BIGINT}, project_id = #{record.projectId,jdbcType=VARCHAR}, @@ -238,7 +238,7 @@ update operation_log - set id = #{record.id,jdbcType=VARCHAR}, + set id = #{record.id,jdbcType=BIGINT}, project_id = #{record.projectId,jdbcType=VARCHAR}, organization_id = #{record.organizationId,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, @@ -287,7 +287,7 @@ `path` = #{path,jdbcType=VARCHAR}, - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} update operation_log @@ -301,21 +301,21 @@ `module` = #{module,jdbcType=VARCHAR}, content = #{content,jdbcType=VARCHAR}, `path` = #{path,jdbcType=VARCHAR} - where id = #{id,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} - + insert into operation_log - (id, project_id, organization_id, create_time, create_user, source_id, `method`, + (project_id, organization_id, create_time, create_user, source_id, `method`, `type`, `module`, content, `path`) values - (#{item.id,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, + ( #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.sourceId,jdbcType=VARCHAR}, #{item.method,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, #{item.module,jdbcType=VARCHAR}, #{item.content,jdbcType=VARCHAR}, #{item.path,jdbcType=VARCHAR}) - + insert into operation_log ( ${column.escapedColumnName} @@ -326,7 +326,7 @@ ( - #{item.id,jdbcType=VARCHAR} + #{item.id,jdbcType=BIGINT} #{item.projectId,jdbcType=VARCHAR} 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 8a40b873a4..49ee4e6cb7 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 @@ -3,7 +3,7 @@ SET SESSION innodb_lock_wait_timeout = 7200; CREATE TABLE IF NOT EXISTS operation_log ( - `id` VARCHAR(50) NOT NULL COMMENT '主键', + `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键' , `project_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '项目id', `organization_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '组织id', `create_time` BIGINT NOT NULL COMMENT '操作时间', @@ -31,7 +31,7 @@ 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 '主键' , + `id` BIGINT NOT NULL COMMENT '主键,与operation_log表id一致' , `original_value` LONGBLOB COMMENT '变更前内容' , `modified_value` LONGBLOB COMMENT '变更后内容' , PRIMARY KEY (id) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/ModuleOpenApiConfig.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/ModuleOpenApiConfig.java index 14e36ec78f..7266f26d36 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/ModuleOpenApiConfig.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/ModuleOpenApiConfig.java @@ -6,11 +6,13 @@ import org.springframework.context.annotation.Configuration; @Configuration public class ModuleOpenApiConfig { + private static final String prePackages = "io.metersphere."; + @Bean public GroupedOpenApi systemApi() { return GroupedOpenApi.builder() .group("system-setting") - .packagesToScan("io.metersphere.system") + .packagesToScan(prePackages + "system") .build(); } @@ -18,7 +20,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi projectApi() { return GroupedOpenApi.builder() .group("project-management") - .packagesToScan("io.metersphere.project") + .packagesToScan(prePackages + "project") .build(); } @@ -26,7 +28,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi apiTestApi() { return GroupedOpenApi.builder() .group("api-test") - .packagesToScan("io.metersphere.api") + .packagesToScan(prePackages + "api") .build(); } @@ -34,7 +36,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi bugApi() { return GroupedOpenApi.builder() .group("bug-management") - .packagesToScan("io.metersphere.bug") + .packagesToScan(prePackages + "bug") .build(); } @@ -42,7 +44,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi caseApi() { return GroupedOpenApi.builder() .group("case-management") - .packagesToScan("io.metersphere.functional") + .packagesToScan(prePackages + "functional") .build(); } @@ -50,7 +52,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi loadApi() { return GroupedOpenApi.builder() .group("load-test") - .packagesToScan("io.metersphere.load") + .packagesToScan(prePackages + "load") .build(); } @@ -59,7 +61,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi planApi() { return GroupedOpenApi.builder() .group("test-plan") - .packagesToScan("io.metersphere.plan") + .packagesToScan(prePackages + "plan") .build(); } @@ -67,7 +69,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi uiApi() { return GroupedOpenApi.builder() .group("ui-test") - .packagesToScan("io.metersphere.ui") + .packagesToScan(prePackages + "ui") .build(); } @@ -75,7 +77,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi workstationApi() { return GroupedOpenApi.builder() .group("workstation") - .packagesToScan("io.metersphere.workstation") + .packagesToScan(prePackages + "workstation") .build(); } @@ -83,7 +85,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi xpackApi() { return GroupedOpenApi.builder() .group("xpack") - .packagesToScan("io.metersphere.xpack") + .packagesToScan(prePackages + "xpack") .build(); } @@ -91,7 +93,7 @@ public class ModuleOpenApiConfig { public GroupedOpenApi sdkApi() { return GroupedOpenApi.builder() .group("sdk") - .packagesToScan("io.metersphere.sdk") + .packagesToScan(prePackages + "sdk") .build(); } } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/LogDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/LogDTO.java index 760e1c161f..54be3f5dc8 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/LogDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/LogDTO.java @@ -5,8 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.UUID; - @Data @EqualsAndHashCode(callSuper = false) public class LogDTO extends OperationLog { @@ -26,7 +24,6 @@ public class LogDTO extends OperationLog { this.setType(type); this.setModule(module); this.setContent(content); - this.setId(UUID.randomUUID().toString()); this.setCreateTime(System.currentTimeMillis()); } } \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java index 11076b40af..bd969c1db2 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/service/OperationLogService.java @@ -17,12 +17,12 @@ import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.stream.Collectors; @Service @@ -54,48 +54,50 @@ public class OperationLogService { if (StringUtils.isBlank(log.getCreateUser())) { log.setCreateUser("admin"); } - // 限制长度 - saveBlob(operationLogMapper, operationLogBlobMapper, log); + log.setContent(subStrContent(log.getContent())); + operationLogMapper.insert(log); + operationLogBlobMapper.insert(getBlob(log)); } + private OperationLogBlob getBlob(LogDTO log) { + OperationLogBlob blob = new OperationLogBlob(); + blob.setId(log.getId()); + blob.setOriginalValue(log.getOriginalValue()); + blob.setModifiedValue(log.getModifiedValue()); + return blob; + } + + private String subStrContent(String content) { + if (StringUtils.isNotBlank(content) && content.length() > 500) { + return content.substring(0, 499); + } + return content; + } + + @Async public void batchAdd(List logs) { if (CollectionUtils.isEmpty(logs)) { return; } SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - OperationLogMapper logMapper = sqlSession.getMapper(OperationLogMapper.class); OperationLogBlobMapper logBlobMapper = sqlSession.getMapper(OperationLogBlobMapper.class); if (CollectionUtils.isNotEmpty(logs)) { long currentTimeMillis = System.currentTimeMillis(); logs.forEach(item -> { + item.setContent(subStrContent(item.getContent())); item.setCreateTime(currentTimeMillis); - if (StringUtils.isBlank(item.getId())) { - item.setId(UUID.randomUUID().toString()); - } // 限制长度 - saveBlob(logMapper, logBlobMapper, item); + operationLogMapper.insert(item); + logBlobMapper.insert(getBlob(item)); }); } sqlSession.flushStatements(); - if (sqlSession != null && sqlSessionFactory != null) { + if (sqlSessionFactory != null) { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } } - private void saveBlob(OperationLogMapper logMapper, OperationLogBlobMapper logBlobMapper, LogDTO item) { - if (StringUtils.isNotBlank(item.getContent()) && item.getContent().length() > 500) { - item.setContent(item.getContent().substring(0, 499)); - } - logMapper.insert(item); - OperationLogBlob blob = new OperationLogBlob(); - blob.setId(item.getId()); - blob.setOriginalValue(item.getOriginalValue()); - blob.setModifiedValue(item.getModifiedValue()); - logBlobMapper.insert(blob); - } - - public List list(OperationLogRequest request) { int compare = Long.compare(request.getStartTime(), request.getEndTime()); if (compare > 0) { @@ -118,10 +120,7 @@ public class OperationLogService { item.setProjectName(projectMap.getOrDefault(item.getProjectId(), StringUtils.EMPTY)); item.setOrganizationName(organizationMap.getOrDefault(item.getOrganizationId(), StringUtils.EMPTY)); }); - - } - return list; } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java index b2bbcafd59..7ab2b9a4d0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java @@ -58,7 +58,6 @@ public class UserRoleRelationService { List userRoleList = userRoleMapper.selectByExample(example); userRoleList.forEach(userRole -> { LogDTO log = new LogDTO(); - log.setId(UUID.randomUUID().toString()); log.setProjectId(OperationLogConstants.SYSTEM); log.setOrganizationId(OperationLogConstants.SYSTEM); log.setType(operationType); diff --git a/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql b/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql index 72495b6801..71ebf98345 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_operation_log_test.sql @@ -7,16 +7,16 @@ INSERT INTO project (id, num, organization_id, name, description, create_user, u -- 初始化日志记录 -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'SYSTEM', 'SYSTEM', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'SYSTEM', 'SYSTEM', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'ORGANIZATION', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'ORGANIZATION', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); -INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'SYSTEM', 'SYSTEM', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'SYSTEM', 'SYSTEM', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'ORGANIZATION', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'ORGANIZATION', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_001', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_001', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add'); +INSERT INTO operation_log( `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES ( 'project_id_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');