refactor: 日志表重构

This commit is contained in:
fit2-zhao 2023-08-31 13:35:51 +08:00 committed by fit2-zhao
parent 733b15478c
commit 7f30c221fd
14 changed files with 231 additions and 147 deletions

View File

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

View File

@ -1,20 +1,18 @@
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)
@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 = "变更前内容")
private byte[] originalValue;
@ -23,4 +21,77 @@ public class OperationLogBlob implements Serializable {
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<Column> 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();
}
}
}

View File

@ -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<String> values) {
public Criteria andIdIn(List<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
public Criteria andIdNotIn(List<Long> 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;
}

View File

@ -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<String> values) {
public Criteria andIdIn(List<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
public Criteria andIdNotIn(List<Long> 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;
}

View File

@ -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<OperationLogBlob> 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<OperationLogBlob> list);
int batchInsertSelective(@Param("list") List<OperationLogBlob> list, @Param("selective") OperationLogBlob.Column ... selective);
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.sdk.mapper.OperationLogBlobMapper">
<resultMap id="BaseResultMap" type="io.metersphere.sdk.domain.OperationLogBlob">
<id column="id" jdbcType="VARCHAR" property="id" />
<id column="id" jdbcType="BIGINT" property="id" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.sdk.domain.OperationLogBlob">
<result column="original_value" jdbcType="LONGVARBINARY" property="originalValue" />
@ -102,17 +102,17 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from operation_log_blob
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from operation_log_blob
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.sdk.domain.OperationLogBlobExample">
delete from operation_log_blob
@ -123,7 +123,7 @@
<insert id="insert" parameterType="io.metersphere.sdk.domain.OperationLogBlob">
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}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.sdk.domain.OperationLogBlob">
@ -141,7 +141,7 @@
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
#{id,jdbcType=BIGINT},
</if>
<if test="originalValue != null">
#{originalValue,jdbcType=LONGVARBINARY},
@ -161,7 +161,7 @@
update operation_log_blob
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.originalValue != null">
original_value = #{record.originalValue,jdbcType=LONGVARBINARY},
@ -176,7 +176,7 @@
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
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}
<if test="_parameter != null">
@ -185,7 +185,7 @@
</update>
<update id="updateByExample" parameterType="map">
update operation_log_blob
set id = #{record.id,jdbcType=VARCHAR}
set id = #{record.id,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -200,12 +200,44 @@
modified_value = #{modifiedValue,jdbcType=LONGVARBINARY},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.sdk.domain.OperationLogBlob">
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}
</update>
<insert id="batchInsert" parameterType="map">
insert into operation_log_blob
(id, original_value, modified_value)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=BIGINT}, #{item.originalValue,jdbcType=LONGVARBINARY}, #{item.modifiedValue,jdbcType=LONGVARBINARY}
)
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
insert into operation_log_blob (
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
)
values
<foreach collection="list" item="item" separator=",">
(
<foreach collection="selective" item="column" separator=",">
<if test="'id'.toString() == column.value">
#{item.id,jdbcType=BIGINT}
</if>
<if test="'original_value'.toString() == column.value">
#{item.originalValue,jdbcType=LONGVARBINARY}
</if>
<if test="'modified_value'.toString() == column.value">
#{item.modifiedValue,jdbcType=LONGVARBINARY}
</if>
</foreach>
)
</foreach>
</insert>
</mapper>

View File

@ -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<OperationLog> selectByExample(OperationLogExample example);
OperationLog selectByPrimaryKey(String id);
OperationLog selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") OperationLog record, @Param("example") OperationLogExample example);

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.sdk.mapper.OperationLogMapper">
<resultMap id="BaseResultMap" type="io.metersphere.sdk.domain.OperationLog">
<id column="id" jdbcType="VARCHAR" property="id" />
<id column="id" jdbcType="BIGINT" property="id" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="organization_id" jdbcType="VARCHAR" property="organizationId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
@ -90,15 +90,15 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from operation_log
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from operation_log
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.sdk.domain.OperationLogExample">
delete from operation_log
@ -106,17 +106,17 @@
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.sdk.domain.OperationLog">
insert into operation_log (id, project_id, organization_id,
<insert id="insert" parameterType="io.metersphere.sdk.domain.OperationLog" useGeneratedKeys="true" keyProperty="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>
<insert id="insertSelective" parameterType="io.metersphere.sdk.domain.OperationLog">
<insert id="insertSelective" parameterType="io.metersphere.sdk.domain.OperationLog" useGeneratedKeys="true" keyProperty="id">
insert into operation_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -155,7 +155,7 @@
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
#{id,jdbcType=BIGINT},
</if>
<if test="projectId != null">
#{projectId,jdbcType=VARCHAR},
@ -199,7 +199,7 @@
update operation_log
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.projectId != null">
project_id = #{record.projectId,jdbcType=VARCHAR},
@ -238,7 +238,7 @@
</update>
<update id="updateByExample" parameterType="map">
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},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.sdk.domain.OperationLog">
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}
</update>
<insert id="batchInsert" parameterType="map">
<insert id="batchInsert" parameterType="map" useGeneratedKeys="true" keyProperty="id">
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
<foreach collection="list" item="item" separator=",">
(#{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})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
<insert id="batchInsertSelective" parameterType="map" useGeneratedKeys="true" keyProperty="id">
insert into operation_log (
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
@ -326,7 +326,7 @@
(
<foreach collection="selective" item="column" separator=",">
<if test="'id'.toString() == column.value">
#{item.id,jdbcType=VARCHAR}
#{item.id,jdbcType=BIGINT}
</if>
<if test="'project_id'.toString() == column.value">
#{item.projectId,jdbcType=VARCHAR}

View File

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

View File

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

View File

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

View File

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

View File

@ -58,7 +58,6 @@ public class UserRoleRelationService {
List<UserRole> 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);

View File

@ -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');