feat(系统设置): log表新增批次id字段
This commit is contained in:
parent
b066e459c6
commit
92047fd3d7
|
@ -6,6 +6,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
@ -34,6 +36,10 @@ public class OperationLog implements Serializable {
|
|||
@Schema(description = "资源id")
|
||||
private String sourceId;
|
||||
|
||||
@Schema(description = "批次id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{operation_log.batch_id.not_blank}", groups = {Created.class})
|
||||
private String batchId;
|
||||
|
||||
@Schema(description = "操作方法", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{operation_log.method.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 255, message = "{operation_log.method.length_range}", groups = {Created.class, Updated.class})
|
||||
|
@ -54,4 +60,86 @@ public class OperationLog implements Serializable {
|
|||
private String path;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public enum Column {
|
||||
id("id", "id", "VARCHAR", false),
|
||||
projectId("project_id", "projectId", "VARCHAR", false),
|
||||
organizationId("organization_id", "organizationId", "VARCHAR", false),
|
||||
createTime("create_time", "createTime", "BIGINT", false),
|
||||
createUser("create_user", "createUser", "VARCHAR", false),
|
||||
sourceId("source_id", "sourceId", "VARCHAR", false),
|
||||
batchId("batch_id", "batchId", "VARCHAR", false),
|
||||
method("method", "method", "VARCHAR", true),
|
||||
type("type", "type", "VARCHAR", true),
|
||||
module("module", "module", "VARCHAR", true),
|
||||
content("content", "content", "VARCHAR", false),
|
||||
path("path", "path", "VARCHAR", true);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -514,6 +514,76 @@ public class OperationLogExample {
|
|||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdIsNull() {
|
||||
addCriterion("batch_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdIsNotNull() {
|
||||
addCriterion("batch_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdEqualTo(String value) {
|
||||
addCriterion("batch_id =", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdNotEqualTo(String value) {
|
||||
addCriterion("batch_id <>", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdGreaterThan(String value) {
|
||||
addCriterion("batch_id >", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("batch_id >=", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdLessThan(String value) {
|
||||
addCriterion("batch_id <", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdLessThanOrEqualTo(String value) {
|
||||
addCriterion("batch_id <=", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdLike(String value) {
|
||||
addCriterion("batch_id like", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdNotLike(String value) {
|
||||
addCriterion("batch_id not like", value, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdIn(List<String> values) {
|
||||
addCriterion("batch_id in", values, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdNotIn(List<String> values) {
|
||||
addCriterion("batch_id not in", values, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdBetween(String value1, String value2) {
|
||||
addCriterion("batch_id between", value1, value2, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andBatchIdNotBetween(String value1, String value2) {
|
||||
addCriterion("batch_id not between", value1, value2, "batchId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMethodIsNull() {
|
||||
addCriterion("`method` is null");
|
||||
return (Criteria) this;
|
||||
|
|
|
@ -27,4 +27,8 @@ public interface OperationLogMapper {
|
|||
int updateByPrimaryKeySelective(OperationLog record);
|
||||
|
||||
int updateByPrimaryKey(OperationLog record);
|
||||
|
||||
int batchInsert(@Param("list") List<OperationLog> list);
|
||||
|
||||
int batchInsertSelective(@Param("list") List<OperationLog> list, @Param("selective") OperationLog.Column ... selective);
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
<result column="create_time" jdbcType="BIGINT" property="createTime" />
|
||||
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
|
||||
<result column="source_id" jdbcType="VARCHAR" property="sourceId" />
|
||||
<result column="batch_id" jdbcType="VARCHAR" property="batchId" />
|
||||
<result column="method" jdbcType="VARCHAR" property="method" />
|
||||
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||
<result column="module" jdbcType="VARCHAR" property="module" />
|
||||
|
@ -73,8 +74,8 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, project_id, organization_id, create_time, create_user, source_id, `method`, `type`,
|
||||
`module`, content, `path`
|
||||
id, project_id, organization_id, create_time, create_user, source_id, batch_id, `method`,
|
||||
`type`, `module`, content, `path`
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.metersphere.sdk.domain.OperationLogExample" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -109,12 +110,14 @@
|
|||
<insert id="insert" parameterType="io.metersphere.sdk.domain.OperationLog">
|
||||
insert into operation_log (id, project_id, organization_id,
|
||||
create_time, create_user, source_id,
|
||||
`method`, `type`, `module`,
|
||||
content, `path`)
|
||||
batch_id, `method`, `type`,
|
||||
`module`, content, `path`
|
||||
)
|
||||
values (#{id,jdbcType=VARCHAR}, #{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})
|
||||
#{batchId,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 into operation_log
|
||||
|
@ -137,6 +140,9 @@
|
|||
<if test="sourceId != null">
|
||||
source_id,
|
||||
</if>
|
||||
<if test="batchId != null">
|
||||
batch_id,
|
||||
</if>
|
||||
<if test="method != null">
|
||||
`method`,
|
||||
</if>
|
||||
|
@ -172,6 +178,9 @@
|
|||
<if test="sourceId != null">
|
||||
#{sourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="batchId != null">
|
||||
#{batchId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="method != null">
|
||||
#{method,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -216,6 +225,9 @@
|
|||
<if test="record.sourceId != null">
|
||||
source_id = #{record.sourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.batchId != null">
|
||||
batch_id = #{record.batchId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.method != null">
|
||||
`method` = #{record.method,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -244,6 +256,7 @@
|
|||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
create_user = #{record.createUser,jdbcType=VARCHAR},
|
||||
source_id = #{record.sourceId,jdbcType=VARCHAR},
|
||||
batch_id = #{record.batchId,jdbcType=VARCHAR},
|
||||
`method` = #{record.method,jdbcType=VARCHAR},
|
||||
`type` = #{record.type,jdbcType=VARCHAR},
|
||||
`module` = #{record.module,jdbcType=VARCHAR},
|
||||
|
@ -271,6 +284,9 @@
|
|||
<if test="sourceId != null">
|
||||
source_id = #{sourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="batchId != null">
|
||||
batch_id = #{batchId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="method != null">
|
||||
`method` = #{method,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -296,6 +312,7 @@
|
|||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
create_user = #{createUser,jdbcType=VARCHAR},
|
||||
source_id = #{sourceId,jdbcType=VARCHAR},
|
||||
batch_id = #{batchId,jdbcType=VARCHAR},
|
||||
`method` = #{method,jdbcType=VARCHAR},
|
||||
`type` = #{type,jdbcType=VARCHAR},
|
||||
`module` = #{module,jdbcType=VARCHAR},
|
||||
|
@ -303,4 +320,67 @@
|
|||
`path` = #{path,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<insert id="batchInsert" parameterType="map">
|
||||
insert into operation_log
|
||||
(id, project_id, organization_id, create_time, create_user, source_id, batch_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.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.sourceId,jdbcType=VARCHAR},
|
||||
#{item.batchId,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 into operation_log (
|
||||
<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=VARCHAR}
|
||||
</if>
|
||||
<if test="'project_id'.toString() == column.value">
|
||||
#{item.projectId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'organization_id'.toString() == column.value">
|
||||
#{item.organizationId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'create_time'.toString() == column.value">
|
||||
#{item.createTime,jdbcType=BIGINT}
|
||||
</if>
|
||||
<if test="'create_user'.toString() == column.value">
|
||||
#{item.createUser,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'source_id'.toString() == column.value">
|
||||
#{item.sourceId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'batch_id'.toString() == column.value">
|
||||
#{item.batchId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'method'.toString() == column.value">
|
||||
#{item.method,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'type'.toString() == column.value">
|
||||
#{item.type,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'module'.toString() == column.value">
|
||||
#{item.module,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'content'.toString() == column.value">
|
||||
#{item.content,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'path'.toString() == column.value">
|
||||
#{item.path,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
|
@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS operation_log
|
|||
`create_time` BIGINT NOT NULL COMMENT '操作时间',
|
||||
`create_user` VARCHAR(50) COMMENT '操作人',
|
||||
`source_id` VARCHAR(50) COMMENT '资源id',
|
||||
`batch_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',
|
||||
|
|
|
@ -55,6 +55,7 @@ public class OperationLogService {
|
|||
log.setCreateUser("admin");
|
||||
}
|
||||
// 限制长度
|
||||
log.setBatchId(UUID.randomUUID().toString());
|
||||
saveBlob(operationLogMapper, operationLogBlobMapper, log);
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,9 @@ public class OperationLogService {
|
|||
OperationLogBlobMapper logBlobMapper = sqlSession.getMapper(OperationLogBlobMapper.class);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(logs)) {
|
||||
String batchId = UUID.randomUUID().toString();
|
||||
logs.forEach(item -> {
|
||||
item.setBatchId(batchId);
|
||||
if (StringUtils.isBlank(item.getId())) {
|
||||
item.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ operation_log.project_id.length_range=Operating log project id must be between {
|
|||
operation_log.organization_id.not_blank=Operation log organization id must not be blank
|
||||
operation_log_resource.id.not_blank=Operating log resource id must not be blank
|
||||
operation_log.organization_id.length_range=Operation log organization id must be between {min} and {max} characters long
|
||||
operation_log.batch_id.not_blank=Operating log batch id must not be blank
|
||||
operation_log_resource.operating_log_id.not_blank=Operating log resource operating log id must not be blank
|
||||
operation_log_resource.operating_log_id.length_range=Operating log resource operating log id must be between {min} and {max} characters long
|
||||
operation_log_resource.source_id.not_blank=Operating log resource source id must not be blank
|
||||
|
|
|
@ -49,6 +49,7 @@ operation_log.project_id.not_blank=操作日志项目ID不能为空
|
|||
operation_log.project_id.length_range=操作日志项目ID长度必须在{min}和{max}之间
|
||||
operation_log.organization_id.not_blank=操作日志组织ID不能为空
|
||||
operation_log.organization_id.length_range=操作日志组织ID长度必须在{min}和{max}之间
|
||||
operation_log.batch_id.not_blank=操作日志批次ID不能为空
|
||||
operation_log_resource.id.not_blank=操作日志资源ID不能为空
|
||||
operation_log_resource.operating_log_id.not_blank=操作日志资源操作日志ID不能为空
|
||||
operation_log_resource.operating_log_id.length_range=操作日志资源操作日志ID长度必须在{min}和{max}之间
|
||||
|
|
|
@ -49,6 +49,7 @@ operation_log.project_id.not_blank=操作日誌項目ID不能為空
|
|||
operation_log.project_id.length_range=操作日誌項目ID長度必須在{min}和{max}之間
|
||||
operation_log.organization_id.not_blank=操作日誌組織ID不能為空
|
||||
operation_log.organization_id.length_range=操作日誌組織ID長度必須在{min}和{max}之間
|
||||
operation_log.batch_id.not_blank=操作日誌批次ID不能為空
|
||||
operation_log_resource.id.not_blank=操作日誌資源ID不能為空
|
||||
operation_log_resource.operating_log_id.not_blank=操作日誌資源操作日誌ID不能為空
|
||||
operation_log_resource.operating_log_id.length_range=操作日誌資源操作日誌ID長度必須在{min}和{max}之間
|
||||
|
|
Loading…
Reference in New Issue