refactor: 项目表增加系统ID字段

项目表增加系统ID字段,用于优化Mock环境展示用
This commit is contained in:
song-tianyang 2021-05-27 16:20:46 +08:00 committed by 刘瑞斌
parent c76cc9a432
commit dffc1b6c2a
6 changed files with 139 additions and 13 deletions

View File

@ -35,5 +35,7 @@ public class Project implements Serializable {
private String createUser;
private String systemId;
private static final long serialVersionUID = 1L;
}

View File

@ -1103,6 +1103,76 @@ public class ProjectExample {
addCriterion("create_user not between", value1, value2, "createUser");
return (Criteria) this;
}
public Criteria andSystemIdIsNull() {
addCriterion("system_id is null");
return (Criteria) this;
}
public Criteria andSystemIdIsNotNull() {
addCriterion("system_id is not null");
return (Criteria) this;
}
public Criteria andSystemIdEqualTo(String value) {
addCriterion("system_id =", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdNotEqualTo(String value) {
addCriterion("system_id <>", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdGreaterThan(String value) {
addCriterion("system_id >", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdGreaterThanOrEqualTo(String value) {
addCriterion("system_id >=", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdLessThan(String value) {
addCriterion("system_id <", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdLessThanOrEqualTo(String value) {
addCriterion("system_id <=", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdLike(String value) {
addCriterion("system_id like", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdNotLike(String value) {
addCriterion("system_id not like", value, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdIn(List<String> values) {
addCriterion("system_id in", values, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdNotIn(List<String> values) {
addCriterion("system_id not in", values, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdBetween(String value1, String value2) {
addCriterion("system_id between", value1, value2, "systemId");
return (Criteria) this;
}
public Criteria andSystemIdNotBetween(String value1, String value2) {
addCriterion("system_id not between", value1, value2, "systemId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -17,6 +17,7 @@
<result column="custom_num" jdbcType="BIT" property="customNum" />
<result column="scenario_custom_num" jdbcType="BIT" property="scenarioCustomNum" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
<result column="system_id" jdbcType="VARCHAR" property="systemId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -79,7 +80,7 @@
<sql id="Base_Column_List">
id, workspace_id, `name`, description, create_time, update_time, tapd_id, jira_key,
zentao_id, `repeatable`, case_template_id, issue_template_id, custom_num, scenario_custom_num,
create_user
create_user, system_id
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.ProjectExample" resultMap="BaseResultMap">
select
@ -116,14 +117,14 @@
description, create_time, update_time,
tapd_id, jira_key, zentao_id,
`repeatable`, case_template_id, issue_template_id,
custom_num, scenario_custom_num, create_user
)
custom_num, scenario_custom_num, create_user,
system_id)
values (#{id,jdbcType=VARCHAR}, #{workspaceId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{tapdId,jdbcType=VARCHAR}, #{jiraKey,jdbcType=VARCHAR}, #{zentaoId,jdbcType=VARCHAR},
#{repeatable,jdbcType=BIT}, #{caseTemplateId,jdbcType=VARCHAR}, #{issueTemplateId,jdbcType=VARCHAR},
#{customNum,jdbcType=BIT}, #{scenarioCustomNum,jdbcType=BIT}, #{createUser,jdbcType=VARCHAR}
)
#{customNum,jdbcType=BIT}, #{scenarioCustomNum,jdbcType=BIT}, #{createUser,jdbcType=VARCHAR},
#{systemId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.Project">
insert into project
@ -173,6 +174,9 @@
<if test="createUser != null">
create_user,
</if>
<if test="systemId != null">
system_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -220,6 +224,9 @@
<if test="createUser != null">
#{createUser,jdbcType=VARCHAR},
</if>
<if test="systemId != null">
#{systemId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.ProjectExample" resultType="java.lang.Long">
@ -276,6 +283,9 @@
<if test="record.createUser != null">
create_user = #{record.createUser,jdbcType=VARCHAR},
</if>
<if test="record.systemId != null">
system_id = #{record.systemId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -297,7 +307,8 @@
issue_template_id = #{record.issueTemplateId,jdbcType=VARCHAR},
custom_num = #{record.customNum,jdbcType=BIT},
scenario_custom_num = #{record.scenarioCustomNum,jdbcType=BIT},
create_user = #{record.createUser,jdbcType=VARCHAR}
create_user = #{record.createUser,jdbcType=VARCHAR},
system_id = #{record.systemId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -347,6 +358,9 @@
<if test="createUser != null">
create_user = #{createUser,jdbcType=VARCHAR},
</if>
<if test="systemId != null">
system_id = #{systemId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -365,7 +379,8 @@
issue_template_id = #{issueTemplateId,jdbcType=VARCHAR},
custom_num = #{customNum,jdbcType=BIT},
scenario_custom_num = #{scenarioCustomNum,jdbcType=BIT},
create_user = #{createUser,jdbcType=VARCHAR}
create_user = #{createUser,jdbcType=VARCHAR},
system_id = #{systemId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -37,10 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -93,12 +90,18 @@ public class ProjectService {
MSException.throwException(Translator.get("project_name_already_exists"));
}
project.setId(UUID.randomUUID().toString());
long allCount = projectMapper.countByExample(null);
String systemId = String.valueOf(100001+allCount);
long createTime = System.currentTimeMillis();
project.setCreateTime(createTime);
project.setUpdateTime(createTime);
// set workspace id
project.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
project.setCreateUser(SessionUtils.getUserId());
project.setSystemId(systemId);
projectMapper.insertSelective(project);
return project;
}

View File

@ -0,0 +1,36 @@
-- project add column
ALTER table project add system_id varchar(50) null;
-- reduse old data
DROP PROCEDURE IF EXISTS project_systemid;
DELIMITER //
CREATE PROCEDURE project_systemid()
BEGIN
DECLARE projectId VARCHAR(64);
DECLARE num INT;
DECLARE done INT DEFAULT 0;
DECLARE cursor1 CURSOR FOR (SELECT DISTINCT id
FROM project
WHERE system_id IS NULL);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET num = 100001;
OPEN cursor1;
outer_loop:
LOOP
FETCH cursor1 INTO projectId;
IF done
THEN
LEAVE outer_loop;
END IF;
UPDATE project
SET system_id = num
WHERE id = projectId;
SET num = num + 1;
SET done = 0;
END LOOP;
CLOSE cursor1;
END //
DELIMITER ;
CALL project_systemid();
DROP PROCEDURE IF EXISTS project_systemid;

View File

@ -77,8 +77,8 @@
<table tableName="test_case_review_scenario"/>
<table tableName="test_plan"/>
<table tableName="test_case_test"/>-->
<table tableName="api_test_environment"></table>
<table tableName="custom_field_template"></table>
<!-- <table tableName="api_test_environment"></table>-->
<table tableName="project"></table>
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->