refactor: 优化接口定义查询

This commit is contained in:
CaptainB 2022-01-23 15:43:54 +08:00 committed by 刘瑞斌
parent d07a58d06a
commit b675991298
7 changed files with 473 additions and 243 deletions

View File

@ -617,7 +617,18 @@ public class ApiDefinitionService {
ids.add(request.getId());
apiTestCaseService.updateByApiDefinitionId(ids, test.getPath(), test.getMethod(), test.getProtocol());
}
return test;
//
ApiDefinitionWithBLOBs result = apiDefinitionMapper.selectByPrimaryKey(test.getId());
checkAndSetLatestVersion(result.getRefId());
return result;
}
/**
* 检查设置最新版本
*/
private void checkAndSetLatestVersion(String refId) {
extApiDefinitionMapper.clearLatestVersion(refId);
extApiDefinitionMapper.addLatestVersion(refId);
}
public void saveFollows(String definitionId, List<String> follows) {
@ -659,6 +670,7 @@ public class ApiDefinitionService {
test.setOrder(ServiceUtils.getNextOrder(request.getProjectId(), extApiDefinitionMapper::getLastOrder));
test.setRefId(request.getId());
test.setVersionId(request.getVersionId());
test.setLatest(true); // 新建一定是最新的
if (StringUtils.isEmpty(request.getModuleId()) || "default-module".equals(request.getModuleId())) {
ApiModuleExample example = new ApiModuleExample();
example.createCriteria().andProjectIdEqualTo(test.getProjectId()).andProtocolEqualTo(test.getProtocol()).andNameEqualTo("未规划接口");
@ -1893,6 +1905,8 @@ public class ApiDefinitionService {
apiTestCaseMapper.deleteByExample(apiTestCaseExample);
//
apiDefinitionMapper.deleteByExample(example);
checkAndSetLatestVersion(refId);
}
public List<ApiDefinitionWithBLOBs> getByIds(List<String> ids) {

View File

@ -1,8 +1,9 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApiDefinition implements Serializable {
private String id;
@ -13,10 +14,6 @@ public class ApiDefinition implements Serializable {
private String method;
private String protocol;
private String path;
private String modulePath;
private String environmentId;
@ -33,6 +30,10 @@ public class ApiDefinition implements Serializable {
private Long updateTime;
private String protocol;
private String path;
private Integer num;
private String tags;
@ -53,9 +54,13 @@ public class ApiDefinition implements Serializable {
private Long order;
private String versionId;
private String version;
private String refId;
private String versionId;
private Boolean latest;
private static final long serialVersionUID = 1L;
}

View File

@ -384,146 +384,6 @@ public class ApiDefinitionExample {
return (Criteria) this;
}
public Criteria andProtocolIsNull() {
addCriterion("protocol is null");
return (Criteria) this;
}
public Criteria andProtocolIsNotNull() {
addCriterion("protocol is not null");
return (Criteria) this;
}
public Criteria andProtocolEqualTo(String value) {
addCriterion("protocol =", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotEqualTo(String value) {
addCriterion("protocol <>", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThan(String value) {
addCriterion("protocol >", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThanOrEqualTo(String value) {
addCriterion("protocol >=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThan(String value) {
addCriterion("protocol <", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThanOrEqualTo(String value) {
addCriterion("protocol <=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLike(String value) {
addCriterion("protocol like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotLike(String value) {
addCriterion("protocol not like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolIn(List<String> values) {
addCriterion("protocol in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotIn(List<String> values) {
addCriterion("protocol not in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolBetween(String value1, String value2) {
addCriterion("protocol between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotBetween(String value1, String value2) {
addCriterion("protocol not between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andPathIsNull() {
addCriterion("`path` is null");
return (Criteria) this;
}
public Criteria andPathIsNotNull() {
addCriterion("`path` is not null");
return (Criteria) this;
}
public Criteria andPathEqualTo(String value) {
addCriterion("`path` =", value, "path");
return (Criteria) this;
}
public Criteria andPathNotEqualTo(String value) {
addCriterion("`path` <>", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThan(String value) {
addCriterion("`path` >", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThanOrEqualTo(String value) {
addCriterion("`path` >=", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThan(String value) {
addCriterion("`path` <", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThanOrEqualTo(String value) {
addCriterion("`path` <=", value, "path");
return (Criteria) this;
}
public Criteria andPathLike(String value) {
addCriterion("`path` like", value, "path");
return (Criteria) this;
}
public Criteria andPathNotLike(String value) {
addCriterion("`path` not like", value, "path");
return (Criteria) this;
}
public Criteria andPathIn(List<String> values) {
addCriterion("`path` in", values, "path");
return (Criteria) this;
}
public Criteria andPathNotIn(List<String> values) {
addCriterion("`path` not in", values, "path");
return (Criteria) this;
}
public Criteria andPathBetween(String value1, String value2) {
addCriterion("`path` between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andPathNotBetween(String value1, String value2) {
addCriterion("`path` not between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andModulePathIsNull() {
addCriterion("module_path is null");
return (Criteria) this;
@ -1064,6 +924,146 @@ public class ApiDefinitionExample {
return (Criteria) this;
}
public Criteria andProtocolIsNull() {
addCriterion("protocol is null");
return (Criteria) this;
}
public Criteria andProtocolIsNotNull() {
addCriterion("protocol is not null");
return (Criteria) this;
}
public Criteria andProtocolEqualTo(String value) {
addCriterion("protocol =", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotEqualTo(String value) {
addCriterion("protocol <>", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThan(String value) {
addCriterion("protocol >", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThanOrEqualTo(String value) {
addCriterion("protocol >=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThan(String value) {
addCriterion("protocol <", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThanOrEqualTo(String value) {
addCriterion("protocol <=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLike(String value) {
addCriterion("protocol like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotLike(String value) {
addCriterion("protocol not like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolIn(List<String> values) {
addCriterion("protocol in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotIn(List<String> values) {
addCriterion("protocol not in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolBetween(String value1, String value2) {
addCriterion("protocol between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotBetween(String value1, String value2) {
addCriterion("protocol not between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andPathIsNull() {
addCriterion("`path` is null");
return (Criteria) this;
}
public Criteria andPathIsNotNull() {
addCriterion("`path` is not null");
return (Criteria) this;
}
public Criteria andPathEqualTo(String value) {
addCriterion("`path` =", value, "path");
return (Criteria) this;
}
public Criteria andPathNotEqualTo(String value) {
addCriterion("`path` <>", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThan(String value) {
addCriterion("`path` >", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThanOrEqualTo(String value) {
addCriterion("`path` >=", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThan(String value) {
addCriterion("`path` <", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThanOrEqualTo(String value) {
addCriterion("`path` <=", value, "path");
return (Criteria) this;
}
public Criteria andPathLike(String value) {
addCriterion("`path` like", value, "path");
return (Criteria) this;
}
public Criteria andPathNotLike(String value) {
addCriterion("`path` not like", value, "path");
return (Criteria) this;
}
public Criteria andPathIn(List<String> values) {
addCriterion("`path` in", values, "path");
return (Criteria) this;
}
public Criteria andPathNotIn(List<String> values) {
addCriterion("`path` not in", values, "path");
return (Criteria) this;
}
public Criteria andPathBetween(String value1, String value2) {
addCriterion("`path` between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andPathNotBetween(String value1, String value2) {
addCriterion("`path` not between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andNumIsNull() {
addCriterion("num is null");
return (Criteria) this;
@ -1734,73 +1734,73 @@ public class ApiDefinitionExample {
return (Criteria) this;
}
public Criteria andVersionIdIsNull() {
addCriterion("version_id is null");
public Criteria andVersionIsNull() {
addCriterion("version is null");
return (Criteria) this;
}
public Criteria andVersionIdIsNotNull() {
addCriterion("version_id is not null");
public Criteria andVersionIsNotNull() {
addCriterion("version is not null");
return (Criteria) this;
}
public Criteria andVersionIdEqualTo(String value) {
addCriterion("version_id =", value, "versionId");
public Criteria andVersionEqualTo(String value) {
addCriterion("version =", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdNotEqualTo(String value) {
addCriterion("version_id <>", value, "versionId");
public Criteria andVersionNotEqualTo(String value) {
addCriterion("version <>", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdGreaterThan(String value) {
addCriterion("version_id >", value, "versionId");
public Criteria andVersionGreaterThan(String value) {
addCriterion("version >", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdGreaterThanOrEqualTo(String value) {
addCriterion("version_id >=", value, "versionId");
public Criteria andVersionGreaterThanOrEqualTo(String value) {
addCriterion("version >=", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdLessThan(String value) {
addCriterion("version_id <", value, "versionId");
public Criteria andVersionLessThan(String value) {
addCriterion("version <", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdLessThanOrEqualTo(String value) {
addCriterion("version_id <=", value, "versionId");
public Criteria andVersionLessThanOrEqualTo(String value) {
addCriterion("version <=", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdLike(String value) {
addCriterion("version_id like", value, "versionId");
public Criteria andVersionLike(String value) {
addCriterion("version like", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdNotLike(String value) {
addCriterion("version_id not like", value, "versionId");
public Criteria andVersionNotLike(String value) {
addCriterion("version not like", value, "version");
return (Criteria) this;
}
public Criteria andVersionIdIn(List<String> values) {
addCriterion("version_id in", values, "versionId");
public Criteria andVersionIn(List<String> values) {
addCriterion("version in", values, "version");
return (Criteria) this;
}
public Criteria andVersionIdNotIn(List<String> values) {
addCriterion("version_id not in", values, "versionId");
public Criteria andVersionNotIn(List<String> values) {
addCriterion("version not in", values, "version");
return (Criteria) this;
}
public Criteria andVersionIdBetween(String value1, String value2) {
addCriterion("version_id between", value1, value2, "versionId");
public Criteria andVersionBetween(String value1, String value2) {
addCriterion("version between", value1, value2, "version");
return (Criteria) this;
}
public Criteria andVersionIdNotBetween(String value1, String value2) {
addCriterion("version_id not between", value1, value2, "versionId");
public Criteria andVersionNotBetween(String value1, String value2) {
addCriterion("version not between", value1, value2, "version");
return (Criteria) this;
}
@ -1873,6 +1873,136 @@ public class ApiDefinitionExample {
addCriterion("ref_id not between", value1, value2, "refId");
return (Criteria) this;
}
public Criteria andVersionIdIsNull() {
addCriterion("version_id is null");
return (Criteria) this;
}
public Criteria andVersionIdIsNotNull() {
addCriterion("version_id is not null");
return (Criteria) this;
}
public Criteria andVersionIdEqualTo(String value) {
addCriterion("version_id =", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotEqualTo(String value) {
addCriterion("version_id <>", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdGreaterThan(String value) {
addCriterion("version_id >", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdGreaterThanOrEqualTo(String value) {
addCriterion("version_id >=", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdLessThan(String value) {
addCriterion("version_id <", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdLessThanOrEqualTo(String value) {
addCriterion("version_id <=", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdLike(String value) {
addCriterion("version_id like", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotLike(String value) {
addCriterion("version_id not like", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdIn(List<String> values) {
addCriterion("version_id in", values, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotIn(List<String> values) {
addCriterion("version_id not in", values, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdBetween(String value1, String value2) {
addCriterion("version_id between", value1, value2, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotBetween(String value1, String value2) {
addCriterion("version_id not between", value1, value2, "versionId");
return (Criteria) this;
}
public Criteria andLatestIsNull() {
addCriterion("latest is null");
return (Criteria) this;
}
public Criteria andLatestIsNotNull() {
addCriterion("latest is not null");
return (Criteria) this;
}
public Criteria andLatestEqualTo(Boolean value) {
addCriterion("latest =", value, "latest");
return (Criteria) this;
}
public Criteria andLatestNotEqualTo(Boolean value) {
addCriterion("latest <>", value, "latest");
return (Criteria) this;
}
public Criteria andLatestGreaterThan(Boolean value) {
addCriterion("latest >", value, "latest");
return (Criteria) this;
}
public Criteria andLatestGreaterThanOrEqualTo(Boolean value) {
addCriterion("latest >=", value, "latest");
return (Criteria) this;
}
public Criteria andLatestLessThan(Boolean value) {
addCriterion("latest <", value, "latest");
return (Criteria) this;
}
public Criteria andLatestLessThanOrEqualTo(Boolean value) {
addCriterion("latest <=", value, "latest");
return (Criteria) this;
}
public Criteria andLatestIn(List<Boolean> values) {
addCriterion("latest in", values, "latest");
return (Criteria) this;
}
public Criteria andLatestNotIn(List<Boolean> values) {
addCriterion("latest not in", values, "latest");
return (Criteria) this;
}
public Criteria andLatestBetween(Boolean value1, Boolean value2) {
addCriterion("latest between", value1, value2, "latest");
return (Criteria) this;
}
public Criteria andLatestNotBetween(Boolean value1, Boolean value2) {
addCriterion("latest not between", value1, value2, "latest");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -6,8 +6,6 @@
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="method" jdbcType="VARCHAR" property="method" />
<result column="protocol" jdbcType="VARCHAR" property="protocol" />
<result column="path" jdbcType="VARCHAR" property="path" />
<result column="module_path" jdbcType="VARCHAR" property="modulePath" />
<result column="environment_id" jdbcType="VARCHAR" property="environmentId" />
<result column="schedule" jdbcType="VARCHAR" property="schedule" />
@ -16,6 +14,8 @@
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="protocol" jdbcType="VARCHAR" property="protocol" />
<result column="path" jdbcType="VARCHAR" property="path" />
<result column="num" jdbcType="INTEGER" property="num" />
<result column="tags" jdbcType="VARCHAR" property="tags" />
<result column="original_state" jdbcType="VARCHAR" property="originalState" />
@ -26,8 +26,10 @@
<result column="delete_time" jdbcType="BIGINT" property="deleteTime" />
<result column="delete_user_id" jdbcType="VARCHAR" property="deleteUserId" />
<result column="order" jdbcType="BIGINT" property="order" />
<result column="version_id" jdbcType="VARCHAR" property="versionId" />
<result column="version" jdbcType="VARCHAR" property="version" />
<result column="ref_id" jdbcType="VARCHAR" property="refId" />
<result column="version_id" jdbcType="VARCHAR" property="versionId" />
<result column="latest" jdbcType="BIT" property="latest" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
<result column="description" jdbcType="LONGVARCHAR" property="description" />
@ -94,10 +96,10 @@
</where>
</sql>
<sql id="Base_Column_List">
id, project_id, `name`, `method`, protocol, `path`, module_path, environment_id,
schedule, `status`, module_id, user_id, create_time, update_time, num, tags, original_state,
id, project_id, `name`, `method`, module_path, environment_id, schedule, `status`,
module_id, user_id, create_time, update_time, protocol, `path`, num, tags, original_state,
create_user, case_total, case_status, case_passing_rate, delete_time, delete_user_id,
`order`, version_id, ref_id
`order`, version, ref_id, version_id, latest
</sql>
<sql id="Blob_Column_List">
description, request, response, remark
@ -151,28 +153,28 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
insert into api_definition (id, project_id, `name`,
`method`, protocol, `path`,
module_path, environment_id, schedule,
`status`, module_id, user_id,
create_time, update_time, num,
INSERT INTO api_definition (id, project_id, `name`,
`method`, module_path, environment_id,
schedule, `status`, module_id,
user_id, create_time, update_time,
protocol, `path`, num,
tags, original_state, create_user,
case_total, case_status, case_passing_rate,
delete_time, delete_user_id, `order`,
version_id, ref_id, description,
request, response, remark
)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{method,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR},
#{modulePath,jdbcType=VARCHAR}, #{environmentId,jdbcType=VARCHAR}, #{schedule,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{num,jdbcType=INTEGER},
version, ref_id, version_id,
latest, description, request,
response, remark)
VALUES (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{method,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR}, #{environmentId,jdbcType=VARCHAR},
#{schedule,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR},
#{userId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{protocol,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER},
#{tags,jdbcType=VARCHAR}, #{originalState,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
#{caseTotal,jdbcType=VARCHAR}, #{caseStatus,jdbcType=VARCHAR}, #{casePassingRate,jdbcType=VARCHAR},
#{deleteTime,jdbcType=BIGINT}, #{deleteUserId,jdbcType=VARCHAR}, #{order,jdbcType=BIGINT},
#{versionId,jdbcType=VARCHAR}, #{refId,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR},
#{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR}, #{remark,jdbcType=LONGVARCHAR}
)
#{version,jdbcType=VARCHAR}, #{refId,jdbcType=VARCHAR}, #{versionId,jdbcType=VARCHAR},
#{latest,jdbcType=BIT}, #{description,jdbcType=LONGVARCHAR}, #{request,jdbcType=LONGVARCHAR},
#{response,jdbcType=LONGVARCHAR}, #{remark,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
insert into api_definition
@ -189,12 +191,6 @@
<if test="method != null">
`method`,
</if>
<if test="protocol != null">
protocol,
</if>
<if test="path != null">
`path`,
</if>
<if test="modulePath != null">
module_path,
</if>
@ -219,6 +215,12 @@
<if test="updateTime != null">
update_time,
</if>
<if test="protocol != null">
protocol,
</if>
<if test="path != null">
`path`,
</if>
<if test="num != null">
num,
</if>
@ -249,12 +251,18 @@
<if test="order != null">
`order`,
</if>
<if test="versionId != null">
version_id,
<if test="version != null">
version,
</if>
<if test="refId != null">
ref_id,
</if>
<if test="versionId != null">
version_id,
</if>
<if test="latest != null">
latest,
</if>
<if test="description != null">
description,
</if>
@ -281,12 +289,6 @@
<if test="method != null">
#{method,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
#{protocol,jdbcType=VARCHAR},
</if>
<if test="path != null">
#{path,jdbcType=VARCHAR},
</if>
<if test="modulePath != null">
#{modulePath,jdbcType=VARCHAR},
</if>
@ -311,6 +313,12 @@
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="protocol != null">
#{protocol,jdbcType=VARCHAR},
</if>
<if test="path != null">
#{path,jdbcType=VARCHAR},
</if>
<if test="num != null">
#{num,jdbcType=INTEGER},
</if>
@ -341,12 +349,18 @@
<if test="order != null">
#{order,jdbcType=BIGINT},
</if>
<if test="versionId != null">
#{versionId,jdbcType=VARCHAR},
<if test="version != null">
#{version,jdbcType=VARCHAR},
</if>
<if test="refId != null">
#{refId,jdbcType=VARCHAR},
</if>
<if test="versionId != null">
#{versionId,jdbcType=VARCHAR},
</if>
<if test="latest != null">
#{latest,jdbcType=BIT},
</if>
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
@ -382,12 +396,6 @@
<if test="record.method != null">
`method` = #{record.method,jdbcType=VARCHAR},
</if>
<if test="record.protocol != null">
protocol = #{record.protocol,jdbcType=VARCHAR},
</if>
<if test="record.path != null">
`path` = #{record.path,jdbcType=VARCHAR},
</if>
<if test="record.modulePath != null">
module_path = #{record.modulePath,jdbcType=VARCHAR},
</if>
@ -412,6 +420,12 @@
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.protocol != null">
protocol = #{record.protocol,jdbcType=VARCHAR},
</if>
<if test="record.path != null">
`path` = #{record.path,jdbcType=VARCHAR},
</if>
<if test="record.num != null">
num = #{record.num,jdbcType=INTEGER},
</if>
@ -442,12 +456,18 @@
<if test="record.order != null">
`order` = #{record.order,jdbcType=BIGINT},
</if>
<if test="record.versionId != null">
version_id = #{record.versionId,jdbcType=VARCHAR},
<if test="record.version != null">
version = #{record.version,jdbcType=VARCHAR},
</if>
<if test="record.refId != null">
ref_id = #{record.refId,jdbcType=VARCHAR},
</if>
<if test="record.versionId != null">
version_id = #{record.versionId,jdbcType=VARCHAR},
</if>
<if test="record.latest != null">
latest = #{record.latest,jdbcType=BIT},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=LONGVARCHAR},
</if>
@ -471,8 +491,6 @@
project_id = #{record.projectId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
`method` = #{record.method,jdbcType=VARCHAR},
protocol = #{record.protocol,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
module_path = #{record.modulePath,jdbcType=VARCHAR},
environment_id = #{record.environmentId,jdbcType=VARCHAR},
schedule = #{record.schedule,jdbcType=VARCHAR},
@ -481,6 +499,8 @@
user_id = #{record.userId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
protocol = #{record.protocol,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER},
tags = #{record.tags,jdbcType=VARCHAR},
original_state = #{record.originalState,jdbcType=VARCHAR},
@ -491,8 +511,10 @@
delete_time = #{record.deleteTime,jdbcType=BIGINT},
delete_user_id = #{record.deleteUserId,jdbcType=VARCHAR},
`order` = #{record.order,jdbcType=BIGINT},
version_id = #{record.versionId,jdbcType=VARCHAR},
version = #{record.version,jdbcType=VARCHAR},
ref_id = #{record.refId,jdbcType=VARCHAR},
version_id = #{record.versionId,jdbcType=VARCHAR},
latest = #{record.latest,jdbcType=BIT},
description = #{record.description,jdbcType=LONGVARCHAR},
request = #{record.request,jdbcType=LONGVARCHAR},
response = #{record.response,jdbcType=LONGVARCHAR},
@ -507,8 +529,6 @@
project_id = #{record.projectId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
`method` = #{record.method,jdbcType=VARCHAR},
protocol = #{record.protocol,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
module_path = #{record.modulePath,jdbcType=VARCHAR},
environment_id = #{record.environmentId,jdbcType=VARCHAR},
schedule = #{record.schedule,jdbcType=VARCHAR},
@ -517,6 +537,8 @@
user_id = #{record.userId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
protocol = #{record.protocol,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER},
tags = #{record.tags,jdbcType=VARCHAR},
original_state = #{record.originalState,jdbcType=VARCHAR},
@ -527,8 +549,10 @@
delete_time = #{record.deleteTime,jdbcType=BIGINT},
delete_user_id = #{record.deleteUserId,jdbcType=VARCHAR},
`order` = #{record.order,jdbcType=BIGINT},
version = #{record.version,jdbcType=VARCHAR},
ref_id = #{record.refId,jdbcType=VARCHAR},
version_id = #{record.versionId,jdbcType=VARCHAR},
ref_id = #{record.refId,jdbcType=VARCHAR}
latest = #{record.latest,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -545,12 +569,6 @@
<if test="method != null">
`method` = #{method,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
protocol = #{protocol,jdbcType=VARCHAR},
</if>
<if test="path != null">
`path` = #{path,jdbcType=VARCHAR},
</if>
<if test="modulePath != null">
module_path = #{modulePath,jdbcType=VARCHAR},
</if>
@ -575,6 +593,12 @@
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="protocol != null">
protocol = #{protocol,jdbcType=VARCHAR},
</if>
<if test="path != null">
`path` = #{path,jdbcType=VARCHAR},
</if>
<if test="num != null">
num = #{num,jdbcType=INTEGER},
</if>
@ -605,12 +629,18 @@
<if test="order != null">
`order` = #{order,jdbcType=BIGINT},
</if>
<if test="versionId != null">
version_id = #{versionId,jdbcType=VARCHAR},
<if test="version != null">
version = #{version,jdbcType=VARCHAR},
</if>
<if test="refId != null">
ref_id = #{refId,jdbcType=VARCHAR},
</if>
<if test="versionId != null">
version_id = #{versionId,jdbcType=VARCHAR},
</if>
<if test="latest != null">
latest = #{latest,jdbcType=BIT},
</if>
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
@ -631,8 +661,6 @@
set project_id = #{projectId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
`method` = #{method,jdbcType=VARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
module_path = #{modulePath,jdbcType=VARCHAR},
environment_id = #{environmentId,jdbcType=VARCHAR},
schedule = #{schedule,jdbcType=VARCHAR},
@ -641,6 +669,8 @@
user_id = #{userId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
protocol = #{protocol,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER},
tags = #{tags,jdbcType=VARCHAR},
original_state = #{originalState,jdbcType=VARCHAR},
@ -651,8 +681,10 @@
delete_time = #{deleteTime,jdbcType=BIGINT},
delete_user_id = #{deleteUserId,jdbcType=VARCHAR},
`order` = #{order,jdbcType=BIGINT},
version_id = #{versionId,jdbcType=VARCHAR},
version = #{version,jdbcType=VARCHAR},
ref_id = #{refId,jdbcType=VARCHAR},
version_id = #{versionId,jdbcType=VARCHAR},
latest = #{latest,jdbcType=BIT},
description = #{description,jdbcType=LONGVARCHAR},
request = #{request,jdbcType=LONGVARCHAR},
response = #{response,jdbcType=LONGVARCHAR},
@ -664,8 +696,6 @@
set project_id = #{projectId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
`method` = #{method,jdbcType=VARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
module_path = #{modulePath,jdbcType=VARCHAR},
environment_id = #{environmentId,jdbcType=VARCHAR},
schedule = #{schedule,jdbcType=VARCHAR},
@ -674,6 +704,8 @@
user_id = #{userId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
protocol = #{protocol,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER},
tags = #{tags,jdbcType=VARCHAR},
original_state = #{originalState,jdbcType=VARCHAR},
@ -684,8 +716,10 @@
delete_time = #{deleteTime,jdbcType=BIGINT},
delete_user_id = #{deleteUserId,jdbcType=VARCHAR},
`order` = #{order,jdbcType=BIGINT},
version = #{version,jdbcType=VARCHAR},
ref_id = #{refId,jdbcType=VARCHAR},
version_id = #{versionId,jdbcType=VARCHAR},
ref_id = #{refId,jdbcType=VARCHAR}
latest = #{latest,jdbcType=BIT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -72,7 +72,7 @@ public interface ExtApiDefinitionMapper {
Long getPreOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder);
Long getLastOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder);
Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
long countQuotedApiByProjectId(String projectId);
@ -81,4 +81,8 @@ public interface ExtApiDefinitionMapper {
int countByIds(@Param("ids") List<String> ids);
long countByExample(ApiDefinitionExample example);
void clearLatestVersion(String refId);
void addLatestVersion(String refId);
}

View File

@ -872,4 +872,47 @@
AND ${versionTable}.latest = 1
</if>
</sql>
<update id="clearLatestVersion">
UPDATE api_definition
SET latest = 0
<where>
<if test="refId != null">
and ref_id = #{refId}
</if>
</where>
</update>
<update id="addLatestVersion">
UPDATE api_definition
INNER JOIN ((
SELECT tmp.id
FROM api_definition tmp
JOIN project_version
ON tmp.project_id = project_version.project_id AND
tmp.version_id = project_version.id AND project_version.latest = TRUE
WHERE ref_id = #{refId,jdbcType=VARCHAR}
LIMIT 1
)
UNION
(
SELECT tmp.id
FROM api_definition tmp
JOIN project_version
ON tmp.project_id = project_version.project_id AND
tmp.version_id = project_version.id
AND NOT EXISTS(SELECT ref_id
FROM api_definition tmp2
JOIN project_version
ON tmp2.project_id =
project_version.project_id AND
version_id =
project_version.id AND
project_version.latest = TRUE
WHERE tmp.ref_id = tmp2.ref_id)
WHERE tmp.ref_id = #{refId,jdbcType=VARCHAR}
ORDER BY tmp.update_time DESC
LIMIT 1)) AS t ON api_definition.id = t.id
SET api_definition.latest = TRUE
</update>
</mapper>

View File

@ -71,7 +71,7 @@
<!--<table tableName="test_plan"/>-->
<!--<table tableName="api_scenario_report"/>-->
<!--<table tableName="test_case_review"/>-->
<table tableName="api_scenario_report"/>
<table tableName="api_definition"/>
<!--<table tableName="enterprise_test_report_send_record"/>-->
<!--<table tableName="test_case_review_api_case"/>
<table tableName="test_case_review_load"/>