diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/OperationLogHistory.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/OperationLogHistory.java new file mode 100644 index 0000000000..0a1055f0f3 --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/OperationLogHistory.java @@ -0,0 +1,117 @@ +package io.metersphere.system.domain; + +import io.metersphere.validation.groups.*; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import lombok.Data; + +@Data +public class OperationLogHistory implements Serializable { + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{operation_log_history.id.not_blank}", groups = {Updated.class}) + private Long id; + + @Schema(description = "项目id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{operation_log_history.project_id.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 50, message = "{operation_log_history.project_id.length_range}", groups = {Created.class, Updated.class}) + private String projectId; + + @Schema(description = "操作时间") + private Long createTime; + + @Schema(description = "操作人") + private String createUser; + + @Schema(description = "资源id") + private String sourceId; + + @Schema(description = "操作类型/add/update/delete", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{operation_log_history.type.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 20, message = "{operation_log_history.type.length_range}", groups = {Created.class, Updated.class}) + private String type; + + @Schema(description = "操作模块/api/case/scenario/ui") + private String module; + + private static final long serialVersionUID = 1L; + + public enum Column { + id("id", "id", "BIGINT", false), + projectId("project_id", "projectId", "VARCHAR", false), + createTime("create_time", "createTime", "BIGINT", false), + createUser("create_user", "createUser", "VARCHAR", false), + sourceId("source_id", "sourceId", "VARCHAR", false), + type("type", "type", "VARCHAR", true), + module("module", "module", "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 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/system/domain/OperationLogHistoryExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/OperationLogHistoryExample.java new file mode 100644 index 0000000000..0bb600f3dc --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/OperationLogHistoryExample.java @@ -0,0 +1,670 @@ +package io.metersphere.system.domain; + +import java.util.ArrayList; +import java.util.List; + +public class OperationLogHistoryExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public OperationLogHistoryExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andProjectIdIsNull() { + addCriterion("project_id is null"); + return (Criteria) this; + } + + public Criteria andProjectIdIsNotNull() { + addCriterion("project_id is not null"); + return (Criteria) this; + } + + public Criteria andProjectIdEqualTo(String value) { + addCriterion("project_id =", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotEqualTo(String value) { + addCriterion("project_id <>", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdGreaterThan(String value) { + addCriterion("project_id >", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdGreaterThanOrEqualTo(String value) { + addCriterion("project_id >=", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLessThan(String value) { + addCriterion("project_id <", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLessThanOrEqualTo(String value) { + addCriterion("project_id <=", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLike(String value) { + addCriterion("project_id like", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotLike(String value) { + addCriterion("project_id not like", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdIn(List values) { + addCriterion("project_id in", values, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotIn(List values) { + addCriterion("project_id not in", values, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdBetween(String value1, String value2) { + addCriterion("project_id between", value1, value2, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotBetween(String value1, String value2) { + addCriterion("project_id not between", value1, value2, "projectId"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Long value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Long value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Long value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Long value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Long value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Long value1, Long value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Long value1, Long value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateUserIsNull() { + addCriterion("create_user is null"); + return (Criteria) this; + } + + public Criteria andCreateUserIsNotNull() { + addCriterion("create_user is not null"); + return (Criteria) this; + } + + public Criteria andCreateUserEqualTo(String value) { + addCriterion("create_user =", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotEqualTo(String value) { + addCriterion("create_user <>", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThan(String value) { + addCriterion("create_user >", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThanOrEqualTo(String value) { + addCriterion("create_user >=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThan(String value) { + addCriterion("create_user <", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThanOrEqualTo(String value) { + addCriterion("create_user <=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLike(String value) { + addCriterion("create_user like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotLike(String value) { + addCriterion("create_user not like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserIn(List values) { + addCriterion("create_user in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotIn(List values) { + addCriterion("create_user not in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserBetween(String value1, String value2) { + addCriterion("create_user between", value1, value2, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotBetween(String value1, String value2) { + addCriterion("create_user not between", value1, value2, "createUser"); + return (Criteria) this; + } + + public Criteria andSourceIdIsNull() { + addCriterion("source_id is null"); + return (Criteria) this; + } + + public Criteria andSourceIdIsNotNull() { + addCriterion("source_id is not null"); + return (Criteria) this; + } + + public Criteria andSourceIdEqualTo(String value) { + addCriterion("source_id =", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdNotEqualTo(String value) { + addCriterion("source_id <>", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdGreaterThan(String value) { + addCriterion("source_id >", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdGreaterThanOrEqualTo(String value) { + addCriterion("source_id >=", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdLessThan(String value) { + addCriterion("source_id <", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdLessThanOrEqualTo(String value) { + addCriterion("source_id <=", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdLike(String value) { + addCriterion("source_id like", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdNotLike(String value) { + addCriterion("source_id not like", value, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdIn(List values) { + addCriterion("source_id in", values, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdNotIn(List values) { + addCriterion("source_id not in", values, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdBetween(String value1, String value2) { + addCriterion("source_id between", value1, value2, "sourceId"); + return (Criteria) this; + } + + public Criteria andSourceIdNotBetween(String value1, String value2) { + addCriterion("source_id not between", value1, value2, "sourceId"); + return (Criteria) this; + } + + public Criteria andTypeIsNull() { + addCriterion("`type` is null"); + return (Criteria) this; + } + + public Criteria andTypeIsNotNull() { + addCriterion("`type` is not null"); + return (Criteria) this; + } + + public Criteria andTypeEqualTo(String value) { + addCriterion("`type` =", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotEqualTo(String value) { + addCriterion("`type` <>", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThan(String value) { + addCriterion("`type` >", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThanOrEqualTo(String value) { + addCriterion("`type` >=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThan(String value) { + addCriterion("`type` <", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThanOrEqualTo(String value) { + addCriterion("`type` <=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLike(String value) { + addCriterion("`type` like", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotLike(String value) { + addCriterion("`type` not like", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeIn(List values) { + addCriterion("`type` in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotIn(List values) { + addCriterion("`type` not in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeBetween(String value1, String value2) { + addCriterion("`type` between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotBetween(String value1, String value2) { + addCriterion("`type` not between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andModuleIsNull() { + addCriterion("`module` is null"); + return (Criteria) this; + } + + public Criteria andModuleIsNotNull() { + addCriterion("`module` is not null"); + return (Criteria) this; + } + + public Criteria andModuleEqualTo(String value) { + addCriterion("`module` =", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleNotEqualTo(String value) { + addCriterion("`module` <>", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleGreaterThan(String value) { + addCriterion("`module` >", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleGreaterThanOrEqualTo(String value) { + addCriterion("`module` >=", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleLessThan(String value) { + addCriterion("`module` <", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleLessThanOrEqualTo(String value) { + addCriterion("`module` <=", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleLike(String value) { + addCriterion("`module` like", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleNotLike(String value) { + addCriterion("`module` not like", value, "module"); + return (Criteria) this; + } + + public Criteria andModuleIn(List values) { + addCriterion("`module` in", values, "module"); + return (Criteria) this; + } + + public Criteria andModuleNotIn(List values) { + addCriterion("`module` not in", values, "module"); + return (Criteria) this; + } + + public Criteria andModuleBetween(String value1, String value2) { + addCriterion("`module` between", value1, value2, "module"); + return (Criteria) this; + } + + public Criteria andModuleNotBetween(String value1, String value2) { + addCriterion("`module` not between", value1, value2, "module"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/OperationLogHistoryMapper.java b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/OperationLogHistoryMapper.java new file mode 100644 index 0000000000..3c79f1c077 --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/OperationLogHistoryMapper.java @@ -0,0 +1,34 @@ +package io.metersphere.system.mapper; + +import io.metersphere.system.domain.OperationLogHistory; +import io.metersphere.system.domain.OperationLogHistoryExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface OperationLogHistoryMapper { + long countByExample(OperationLogHistoryExample example); + + int deleteByExample(OperationLogHistoryExample example); + + int deleteByPrimaryKey(Long id); + + int insert(OperationLogHistory record); + + int insertSelective(OperationLogHistory record); + + List selectByExample(OperationLogHistoryExample example); + + OperationLogHistory selectByPrimaryKey(Long id); + + int updateByExampleSelective(@Param("record") OperationLogHistory record, @Param("example") OperationLogHistoryExample example); + + int updateByExample(@Param("record") OperationLogHistory record, @Param("example") OperationLogHistoryExample example); + + int updateByPrimaryKeySelective(OperationLogHistory record); + + int updateByPrimaryKey(OperationLogHistory record); + + int batchInsert(@Param("list") List list); + + int batchInsertSelective(@Param("list") List list, @Param("selective") OperationLogHistory.Column ... selective); +} \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/OperationLogHistoryMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/OperationLogHistoryMapper.xml new file mode 100644 index 0000000000..63dd456bd4 --- /dev/null +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/OperationLogHistoryMapper.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, project_id, create_time, create_user, source_id, `type`, `module` + + + + + delete from operation_log_history + where id = #{id,jdbcType=BIGINT} + + + delete from operation_log_history + + + + + + insert into operation_log_history (id, project_id, create_time, + create_user, source_id, `type`, + `module`) + values (#{id,jdbcType=BIGINT}, #{projectId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, + #{createUser,jdbcType=VARCHAR}, #{sourceId,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, + #{module,jdbcType=VARCHAR}) + + + insert into operation_log_history + + + id, + + + project_id, + + + create_time, + + + create_user, + + + source_id, + + + `type`, + + + `module`, + + + + + #{id,jdbcType=BIGINT}, + + + #{projectId,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=BIGINT}, + + + #{createUser,jdbcType=VARCHAR}, + + + #{sourceId,jdbcType=VARCHAR}, + + + #{type,jdbcType=VARCHAR}, + + + #{module,jdbcType=VARCHAR}, + + + + + + update operation_log_history + + + id = #{record.id,jdbcType=BIGINT}, + + + project_id = #{record.projectId,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=BIGINT}, + + + create_user = #{record.createUser,jdbcType=VARCHAR}, + + + source_id = #{record.sourceId,jdbcType=VARCHAR}, + + + `type` = #{record.type,jdbcType=VARCHAR}, + + + `module` = #{record.module,jdbcType=VARCHAR}, + + + + + + + + update operation_log_history + set id = #{record.id,jdbcType=BIGINT}, + project_id = #{record.projectId,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + create_user = #{record.createUser,jdbcType=VARCHAR}, + source_id = #{record.sourceId,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, + `module` = #{record.module,jdbcType=VARCHAR} + + + + + + update operation_log_history + + + project_id = #{projectId,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=BIGINT}, + + + create_user = #{createUser,jdbcType=VARCHAR}, + + + source_id = #{sourceId,jdbcType=VARCHAR}, + + + `type` = #{type,jdbcType=VARCHAR}, + + + `module` = #{module,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update operation_log_history + set project_id = #{projectId,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + create_user = #{createUser,jdbcType=VARCHAR}, + source_id = #{sourceId,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=VARCHAR}, + `module` = #{module,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + + insert into operation_log_history + (id, project_id, create_time, create_user, source_id, `type`, `module`) + values + + (#{item.id,jdbcType=BIGINT}, #{item.projectId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, + #{item.createUser,jdbcType=VARCHAR}, #{item.sourceId,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, + #{item.module,jdbcType=VARCHAR}) + + + + insert into operation_log_history ( + + ${column.escapedColumnName} + + ) + values + + ( + + + #{item.id,jdbcType=BIGINT} + + + #{item.projectId,jdbcType=VARCHAR} + + + #{item.createTime,jdbcType=BIGINT} + + + #{item.createUser,jdbcType=VARCHAR} + + + #{item.sourceId,jdbcType=VARCHAR} + + + #{item.type,jdbcType=VARCHAR} + + + #{item.module,jdbcType=VARCHAR} + + + ) + + + \ No newline at end of file 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 fb15da290e..6798a52ec3 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 @@ -129,5 +129,25 @@ CREATE TABLE IF NOT EXISTS worker_node DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'DB WorkerID Assigner for UID Generator'; +CREATE TABLE operation_log_history +( + `id` BIGINT NOT NULL AUTO_INCREMENT 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', + `type` VARCHAR(20) NOT NULL COMMENT '操作类型/add/update/delete', + `module` VARCHAR(50) COMMENT '操作模块/api/case/scenario/ui', + PRIMARY KEY (id) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT = '变更记录'; + +CREATE INDEX idx_create_time ON operation_log_history (`create_time`); +CREATE INDEX idx_create_user ON operation_log_history (`create_user`); +CREATE INDEX idx_module ON operation_log_history (`module`); +CREATE INDEX idx_project_id ON operation_log_history (`project_id`); +CREATE INDEX idx_type ON operation_log_history (`type`); + -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/log/service/OperationLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/log/service/OperationLogService.java index b095ec8593..9e73e9174e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/log/service/OperationLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/log/service/OperationLogService.java @@ -2,18 +2,18 @@ package io.metersphere.system.log.service; import io.metersphere.project.domain.Project; import io.metersphere.sdk.domain.OperationLogBlob; -import io.metersphere.system.log.dto.LogDTO; -import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.mapper.OperationLogBlobMapper; +import io.metersphere.sdk.mapper.OperationLogMapper; +import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.Translator; +import io.metersphere.system.domain.OperationLogHistory; +import io.metersphere.system.domain.Organization; +import io.metersphere.system.dto.sdk.OptionDTO; +import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.vo.OperationLogRequest; import io.metersphere.system.log.vo.OperationLogResponse; -import io.metersphere.sdk.mapper.*; -import io.metersphere.sdk.util.Translator; -import io.metersphere.system.domain.Organization; -import io.metersphere.system.mapper.BaseOperationLogMapper; -import io.metersphere.system.mapper.BaseOrganizationMapper; -import io.metersphere.system.mapper.BaseProjectMapper; -import io.metersphere.system.mapper.BaseUserMapper; +import io.metersphere.system.mapper.*; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -35,6 +35,8 @@ public class OperationLogService { @Resource private OperationLogMapper operationLogMapper; @Resource + private OperationLogHistoryMapper operationLogHistoryMapper; + @Resource private OperationLogBlobMapper operationLogBlobMapper; @Resource private SqlSessionFactory sqlSessionFactory; @@ -51,18 +53,11 @@ public class OperationLogService { @Resource private BaseOrganizationMapper baseOrganizationMapper; - public void add(LogDTO log) { - if (StringUtils.isBlank(log.getProjectId())) { - log.setProjectId("none"); - } - if (StringUtils.isBlank(log.getCreateUser())) { - log.setCreateUser("admin"); - } - log.setContent(subStrContent(log.getContent())); - operationLogMapper.insert(log); - operationLogBlobMapper.insert(getBlob(log)); + private static OperationLogHistory getHistory(LogDTO log) { + OperationLogHistory history = new OperationLogHistory(); + BeanUtils.copyBean(history, log); + return history; } - private OperationLogBlob getBlob(LogDTO log) { OperationLogBlob blob = new OperationLogBlob(); blob.setId(log.getId()); @@ -78,28 +73,17 @@ public class OperationLogService { return content; } - @Async - public void batchAdd(List logs) { - if (CollectionUtils.isEmpty(logs)) { - return; + public void add(LogDTO log) { + if (StringUtils.isBlank(log.getProjectId())) { + log.setProjectId("none"); } - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - 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); - // 限制长度 - operationLogMapper.insert(item); - logBlobMapper.insert(getBlob(item)); - }); - } - sqlSession.flushStatements(); - if (sqlSessionFactory != null) { - SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + if (StringUtils.isBlank(log.getCreateUser())) { + log.setCreateUser("admin"); } + log.setContent(subStrContent(log.getContent())); + operationLogMapper.insert(log); + operationLogHistoryMapper.insert(getHistory(log)); + operationLogBlobMapper.insert(getBlob(log)); } public List list(OperationLogRequest request) { @@ -127,4 +111,29 @@ public class OperationLogService { } return list; } + + @Async + public void batchAdd(List logs) { + if (CollectionUtils.isEmpty(logs)) { + return; + } + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + 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); + // 限制长度 + operationLogMapper.insert(item); + operationLogHistoryMapper.insert(getHistory(item)); + logBlobMapper.insert(getBlob(item)); + }); + } + sqlSession.flushStatements(); + if (sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } + } }