build(功能用例): MyBatis自定义TypeHandler解决字段映射问题

Signed-off-by: guoyuqi <xiaomeinvG@126.com>
This commit is contained in:
guoyuqi 2024-01-08 21:01:30 +08:00 committed by 刘瑞斌
parent 0df503b683
commit 276ac224f2
15 changed files with 425 additions and 121 deletions

View File

@ -30,7 +30,14 @@
<version>${mybatis-starter.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -7,6 +7,7 @@ import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Data;
@Data
@ -63,7 +64,7 @@ public class CaseReview implements Serializable {
private BigDecimal passRate;
@Schema(description = "标签")
private String tags;
private java.util.List<String> tags;
@Schema(description = "描述")
private String description;

View File

@ -65,19 +65,50 @@ public class CaseReviewExample {
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> tagsCriteria;
protected List<Criterion> allCriteria;
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
tagsCriteria = new ArrayList<Criterion>();
}
public List<Criterion> getTagsCriteria() {
return tagsCriteria;
}
protected void addTagsCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
tagsCriteria.add(new Criterion(condition, value, "io.metersphere.handler.ListTypeHandler"));
allCriteria = null;
}
protected void addTagsCriterion(String condition, List<String> value1, List<String> value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
tagsCriteria.add(new Criterion(condition, value1, value2, "io.metersphere.handler.ListTypeHandler"));
allCriteria = null;
}
public boolean isValid() {
return criteria.size() > 0;
return criteria.size() > 0
|| tagsCriteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
if (allCriteria == null) {
allCriteria = new ArrayList<Criterion>();
allCriteria.addAll(criteria);
allCriteria.addAll(tagsCriteria);
}
return allCriteria;
}
public List<Criterion> getCriteria() {
@ -89,6 +120,7 @@ public class CaseReviewExample {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
allCriteria = null;
}
protected void addCriterion(String condition, Object value, String property) {
@ -96,6 +128,7 @@ public class CaseReviewExample {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
allCriteria = null;
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
@ -103,6 +136,7 @@ public class CaseReviewExample {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
allCriteria = null;
}
public Criteria andIdIsNull() {
@ -895,63 +929,63 @@ public class CaseReviewExample {
return (Criteria) this;
}
public Criteria andTagsEqualTo(String value) {
addCriterion("tags =", value, "tags");
public Criteria andTagsEqualTo(List<String> value) {
addTagsCriterion("tags =", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotEqualTo(String value) {
addCriterion("tags <>", value, "tags");
public Criteria andTagsNotEqualTo(List<String> value) {
addTagsCriterion("tags <>", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThan(String value) {
addCriterion("tags >", value, "tags");
public Criteria andTagsGreaterThan(List<String> value) {
addTagsCriterion("tags >", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThanOrEqualTo(String value) {
addCriterion("tags >=", value, "tags");
public Criteria andTagsGreaterThanOrEqualTo(List<String> value) {
addTagsCriterion("tags >=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThan(String value) {
addCriterion("tags <", value, "tags");
public Criteria andTagsLessThan(List<String> value) {
addTagsCriterion("tags <", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThanOrEqualTo(String value) {
addCriterion("tags <=", value, "tags");
public Criteria andTagsLessThanOrEqualTo(List<String> value) {
addTagsCriterion("tags <=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLike(String value) {
addCriterion("tags like", value, "tags");
public Criteria andTagsLike(List<String> value) {
addTagsCriterion("tags like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotLike(String value) {
addCriterion("tags not like", value, "tags");
public Criteria andTagsNotLike(List<String> value) {
addTagsCriterion("tags not like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsIn(List<String> values) {
addCriterion("tags in", values, "tags");
public Criteria andTagsIn(List<List<String>> values) {
addTagsCriterion("tags in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsNotIn(List<String> values) {
addCriterion("tags not in", values, "tags");
public Criteria andTagsNotIn(List<List<String>> values) {
addTagsCriterion("tags not in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsBetween(String value1, String value2) {
addCriterion("tags between", value1, value2, "tags");
public Criteria andTagsBetween(List<String> value1, List<String> value2) {
addTagsCriterion("tags between", value1, value2, "tags");
return (Criteria) this;
}
public Criteria andTagsNotBetween(String value1, String value2) {
addCriterion("tags not between", value1, value2, "tags");
public Criteria andTagsNotBetween(List<String> value1, List<String> value2) {
addTagsCriterion("tags not between", value1, value2, "tags");
return (Criteria) this;
}

View File

@ -6,6 +6,7 @@ import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Data;
@Data
@ -44,7 +45,7 @@ public class FunctionalCase implements Serializable {
private String reviewStatus;
@Schema(description = "标签JSON)")
private String tags;
private java.util.List<String> tags;
@Schema(description = "编辑模式:步骤模式/文本模式", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.case_edit_type.not_blank}", groups = {Created.class})

View File

@ -64,19 +64,50 @@ public class FunctionalCaseExample {
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> tagsCriteria;
protected List<Criterion> allCriteria;
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
tagsCriteria = new ArrayList<Criterion>();
}
public List<Criterion> getTagsCriteria() {
return tagsCriteria;
}
protected void addTagsCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
tagsCriteria.add(new Criterion(condition, value, "io.metersphere.handler.ListTypeHandler"));
allCriteria = null;
}
protected void addTagsCriterion(String condition, List<String> value1, List<String> value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
tagsCriteria.add(new Criterion(condition, value1, value2, "io.metersphere.handler.ListTypeHandler"));
allCriteria = null;
}
public boolean isValid() {
return criteria.size() > 0;
return criteria.size() > 0
|| tagsCriteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
if (allCriteria == null) {
allCriteria = new ArrayList<Criterion>();
allCriteria.addAll(criteria);
allCriteria.addAll(tagsCriteria);
}
return allCriteria;
}
public List<Criterion> getCriteria() {
@ -88,6 +119,7 @@ public class FunctionalCaseExample {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
allCriteria = null;
}
protected void addCriterion(String condition, Object value, String property) {
@ -95,6 +127,7 @@ public class FunctionalCaseExample {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
allCriteria = null;
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
@ -102,6 +135,7 @@ public class FunctionalCaseExample {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
allCriteria = null;
}
public Criteria andIdIsNull() {
@ -594,63 +628,63 @@ public class FunctionalCaseExample {
return (Criteria) this;
}
public Criteria andTagsEqualTo(String value) {
addCriterion("tags =", value, "tags");
public Criteria andTagsEqualTo(List<String> value) {
addTagsCriterion("tags =", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotEqualTo(String value) {
addCriterion("tags <>", value, "tags");
public Criteria andTagsNotEqualTo(List<String> value) {
addTagsCriterion("tags <>", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThan(String value) {
addCriterion("tags >", value, "tags");
public Criteria andTagsGreaterThan(List<String> value) {
addTagsCriterion("tags >", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThanOrEqualTo(String value) {
addCriterion("tags >=", value, "tags");
public Criteria andTagsGreaterThanOrEqualTo(List<String> value) {
addTagsCriterion("tags >=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThan(String value) {
addCriterion("tags <", value, "tags");
public Criteria andTagsLessThan(List<String> value) {
addTagsCriterion("tags <", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThanOrEqualTo(String value) {
addCriterion("tags <=", value, "tags");
public Criteria andTagsLessThanOrEqualTo(List<String> value) {
addTagsCriterion("tags <=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLike(String value) {
addCriterion("tags like", value, "tags");
public Criteria andTagsLike(List<String> value) {
addTagsCriterion("tags like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotLike(String value) {
addCriterion("tags not like", value, "tags");
public Criteria andTagsNotLike(List<String> value) {
addTagsCriterion("tags not like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsIn(List<String> values) {
addCriterion("tags in", values, "tags");
public Criteria andTagsIn(List<List<String>> values) {
addTagsCriterion("tags in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsNotIn(List<String> values) {
addCriterion("tags not in", values, "tags");
public Criteria andTagsNotIn(List<List<String>> values) {
addTagsCriterion("tags not in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsBetween(String value1, String value2) {
addCriterion("tags between", value1, value2, "tags");
public Criteria andTagsBetween(List<String> value1, List<String> value2) {
addTagsCriterion("tags between", value1, value2, "tags");
return (Criteria) this;
}
public Criteria andTagsNotBetween(String value1, String value2) {
addCriterion("tags not between", value1, value2, "tags");
public Criteria andTagsNotBetween(List<String> value1, List<String> value2) {
addTagsCriterion("tags not between", value1, value2, "tags");
return (Criteria) this;
}

View File

@ -14,7 +14,7 @@
<result column="end_time" jdbcType="BIGINT" property="endTime" />
<result column="case_count" jdbcType="INTEGER" property="caseCount" />
<result column="pass_rate" jdbcType="DECIMAL" property="passRate" />
<result column="tags" jdbcType="VARCHAR" property="tags" />
<result column="tags" jdbcType="VARCHAR" property="tags" typeHandler="io.metersphere.handler.ListTypeHandler" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
@ -45,6 +45,25 @@
</when>
</choose>
</foreach>
<foreach collection="criteria.tagsCriteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} and #{criterion.secondValue,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem,typeHandler=io.metersphere.handler.ListTypeHandler}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
@ -74,6 +93,25 @@
</when>
</choose>
</foreach>
<foreach collection="criteria.tagsCriteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} and #{criterion.secondValue,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem,typeHandler=io.metersphere.handler.ListTypeHandler}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
@ -119,16 +157,16 @@
module_id, project_id, `status`,
review_pass_rule, pos, start_time,
end_time, case_count, pass_rate,
tags, description, create_time,
create_user, update_time, update_user
)
tags, description,
create_time, create_user, update_time,
update_user)
values (#{id,jdbcType=VARCHAR}, #{num,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{moduleId,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{reviewPassRule,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{startTime,jdbcType=BIGINT},
#{endTime,jdbcType=BIGINT}, #{caseCount,jdbcType=INTEGER}, #{passRate,jdbcType=DECIMAL},
#{tags,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{createUser,jdbcType=VARCHAR}, #{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR}
)
#{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}, #{description,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{updateTime,jdbcType=BIGINT},
#{updateUser,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.functional.domain.CaseReview">
insert into case_review
@ -226,7 +264,7 @@
#{passRate,jdbcType=DECIMAL},
</if>
<if test="tags != null">
#{tags,jdbcType=VARCHAR},
#{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
@ -291,7 +329,7 @@
pass_rate = #{record.passRate,jdbcType=DECIMAL},
</if>
<if test="record.tags != null">
tags = #{record.tags,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=VARCHAR},
@ -327,7 +365,7 @@
end_time = #{record.endTime,jdbcType=BIGINT},
case_count = #{record.caseCount,jdbcType=INTEGER},
pass_rate = #{record.passRate,jdbcType=DECIMAL},
tags = #{record.tags,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
description = #{record.description,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
create_user = #{record.createUser,jdbcType=VARCHAR},
@ -374,7 +412,7 @@
pass_rate = #{passRate,jdbcType=DECIMAL},
</if>
<if test="tags != null">
tags = #{tags,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
@ -407,7 +445,7 @@
end_time = #{endTime,jdbcType=BIGINT},
case_count = #{caseCount,jdbcType=INTEGER},
pass_rate = #{passRate,jdbcType=DECIMAL},
tags = #{tags,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
description = #{description,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
create_user = #{createUser,jdbcType=VARCHAR},
@ -426,9 +464,9 @@
#{item.moduleId,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR},
#{item.reviewPassRule,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.startTime,jdbcType=BIGINT},
#{item.endTime,jdbcType=BIGINT}, #{item.caseCount,jdbcType=INTEGER}, #{item.passRate,jdbcType=DECIMAL},
#{item.tags,jdbcType=VARCHAR}, #{item.description,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT},
#{item.createUser,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR}
)
#{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{item.description,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR},
#{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -478,7 +516,7 @@
#{item.passRate,jdbcType=DECIMAL}
</if>
<if test="'tags'.toString() == column.value">
#{item.tags,jdbcType=VARCHAR}
#{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}
</if>
<if test="'description'.toString() == column.value">
#{item.description,jdbcType=VARCHAR}

View File

@ -9,7 +9,7 @@
<result column="template_id" jdbcType="VARCHAR" property="templateId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="review_status" jdbcType="VARCHAR" property="reviewStatus" />
<result column="tags" jdbcType="VARCHAR" property="tags" />
<result column="tags" jdbcType="VARCHAR" property="tags" typeHandler="io.metersphere.handler.ListTypeHandler" />
<result column="case_edit_type" jdbcType="VARCHAR" property="caseEditType" />
<result column="pos" jdbcType="BIGINT" property="pos" />
<result column="version_id" jdbcType="VARCHAR" property="versionId" />
@ -49,6 +49,25 @@
</when>
</choose>
</foreach>
<foreach collection="criteria.tagsCriteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} and #{criterion.secondValue,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem,typeHandler=io.metersphere.handler.ListTypeHandler}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
@ -78,6 +97,25 @@
</when>
</choose>
</foreach>
<foreach collection="criteria.tagsCriteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value,typeHandler=io.metersphere.handler.ListTypeHandler} and #{criterion.secondValue,typeHandler=io.metersphere.handler.ListTypeHandler}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem,typeHandler=io.metersphere.handler.ListTypeHandler}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
@ -121,20 +159,20 @@
<insert id="insert" parameterType="io.metersphere.functional.domain.FunctionalCase">
insert into functional_case (id, num, module_id,
project_id, template_id, `name`,
review_status, tags, case_edit_type,
pos, version_id, ref_id,
last_execute_result, deleted, public_case,
latest, create_user, update_user,
delete_user, create_time, update_time,
delete_time)
review_status, tags,
case_edit_type, pos, version_id,
ref_id, last_execute_result, deleted,
public_case, latest, create_user,
update_user, delete_user, create_time,
update_time, delete_time)
values (#{id,jdbcType=VARCHAR}, #{num,jdbcType=BIGINT}, #{moduleId,jdbcType=VARCHAR},
#{projectId,jdbcType=VARCHAR}, #{templateId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{reviewStatus,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, #{caseEditType,jdbcType=VARCHAR},
#{pos,jdbcType=BIGINT}, #{versionId,jdbcType=VARCHAR}, #{refId,jdbcType=VARCHAR},
#{lastExecuteResult,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT}, #{publicCase,jdbcType=BIT},
#{latest,jdbcType=BIT}, #{createUser,jdbcType=VARCHAR}, #{updateUser,jdbcType=VARCHAR},
#{deleteUser,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{deleteTime,jdbcType=BIGINT})
#{reviewStatus,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{caseEditType,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{versionId,jdbcType=VARCHAR},
#{refId,jdbcType=VARCHAR}, #{lastExecuteResult,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT},
#{publicCase,jdbcType=BIT}, #{latest,jdbcType=BIT}, #{createUser,jdbcType=VARCHAR},
#{updateUser,jdbcType=VARCHAR}, #{deleteUser,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{deleteTime,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.functional.domain.FunctionalCase">
insert into functional_case
@ -229,7 +267,7 @@
#{reviewStatus,jdbcType=VARCHAR},
</if>
<if test="tags != null">
#{tags,jdbcType=VARCHAR},
#{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="caseEditType != null">
#{caseEditType,jdbcType=VARCHAR},
@ -306,7 +344,7 @@
review_status = #{record.reviewStatus,jdbcType=VARCHAR},
</if>
<if test="record.tags != null">
tags = #{record.tags,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="record.caseEditType != null">
case_edit_type = #{record.caseEditType,jdbcType=VARCHAR},
@ -364,7 +402,7 @@
template_id = #{record.templateId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
review_status = #{record.reviewStatus,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
case_edit_type = #{record.caseEditType,jdbcType=VARCHAR},
pos = #{record.pos,jdbcType=BIGINT},
version_id = #{record.versionId,jdbcType=VARCHAR},
@ -405,7 +443,7 @@
review_status = #{reviewStatus,jdbcType=VARCHAR},
</if>
<if test="tags != null">
tags = #{tags,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="caseEditType != null">
case_edit_type = #{caseEditType,jdbcType=VARCHAR},
@ -460,7 +498,7 @@
template_id = #{templateId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
review_status = #{reviewStatus,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
case_edit_type = #{caseEditType,jdbcType=VARCHAR},
pos = #{pos,jdbcType=BIGINT},
version_id = #{versionId,jdbcType=VARCHAR},
@ -486,12 +524,12 @@
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.num,jdbcType=BIGINT}, #{item.moduleId,jdbcType=VARCHAR},
#{item.projectId,jdbcType=VARCHAR}, #{item.templateId,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
#{item.reviewStatus,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR}, #{item.caseEditType,jdbcType=VARCHAR},
#{item.pos,jdbcType=BIGINT}, #{item.versionId,jdbcType=VARCHAR}, #{item.refId,jdbcType=VARCHAR},
#{item.lastExecuteResult,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}, #{item.publicCase,jdbcType=BIT},
#{item.latest,jdbcType=BIT}, #{item.createUser,jdbcType=VARCHAR}, #{item.updateUser,jdbcType=VARCHAR},
#{item.deleteUser,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT},
#{item.deleteTime,jdbcType=BIGINT})
#{item.reviewStatus,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{item.caseEditType,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.versionId,jdbcType=VARCHAR},
#{item.refId,jdbcType=VARCHAR}, #{item.lastExecuteResult,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT},
#{item.publicCase,jdbcType=BIT}, #{item.latest,jdbcType=BIT}, #{item.createUser,jdbcType=VARCHAR},
#{item.updateUser,jdbcType=VARCHAR}, #{item.deleteUser,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT},
#{item.updateTime,jdbcType=BIGINT}, #{item.deleteTime,jdbcType=BIGINT})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -526,7 +564,7 @@
#{item.reviewStatus,jdbcType=VARCHAR}
</if>
<if test="'tags'.toString() == column.value">
#{item.tags,jdbcType=VARCHAR}
#{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler}
</if>
<if test="'case_edit_type'.toString() == column.value">
#{item.caseEditType,jdbcType=VARCHAR}

View File

@ -0,0 +1,45 @@
package io.metersphere.handler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeReference;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class BaseTypeHandler<T> extends TypeReference<T> implements TypeHandler<T> {
@Override
public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException {
if (parameter == null) {
ps.setNull(i, jdbcType.TYPE_CODE);
} else {
setNonNullParameter(ps, i, parameter, jdbcType);
}
}
@Override
public T getResult(ResultSet rs, String columnName) throws SQLException {
return getNullableResult(rs, columnName);
}
@Override
public T getResult(ResultSet rs, int columnIndex) throws SQLException {
return getNullableResult(rs, columnIndex);
}
@Override
public T getResult(CallableStatement cs, int columnIndex) throws SQLException {
return getNullableResult(cs, columnIndex);
}
public abstract void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException;
public abstract T getNullableResult(ResultSet rs, String columnName) throws SQLException;
public abstract T getNullableResult(ResultSet rs, int columnIndex) throws SQLException;
public abstract T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException;
}

View File

@ -0,0 +1,99 @@
package io.metersphere.handler;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.micrometer.common.util.StringUtils;
import org.apache.ibatis.type.JdbcType;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class ListTypeHandler extends BaseTypeHandler<List<String>>{
@Override
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
String d = toJSONString(parameter);
ps.setString(i, d);
}
@Override
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
String values = rs.getString(columnName);
return getResults(values);
}
@Override
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String values = rs.getString(columnIndex);
return getResults(values);
}
@Override
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String values = cs.getString(columnIndex);
return getResults(values);
}
private List<String> getResults(String values) {
if (StringUtils.isNotBlank(values)) {
return parseArray(values, String.class);
}
return new ArrayList<>();
}
private static final ObjectMapper objectMapper = JsonMapper.builder()
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
.build();
private static final TypeFactory typeFactory = objectMapper.getTypeFactory();
public static final int DEFAULT_MAX_STRING_LEN = 20_000_000_0;
static {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// 支持json字符中带注释符
objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
// 自动检测所有类的全部属性
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
// 如果一个对象中没有任何的属性那么在序列化的时候就会报错
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
// 设置JSON处理字符长度限制
objectMapper.getFactory()
.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build());
// 处理时间格式
objectMapper.registerModule(new JavaTimeModule());
}
public static String toJSONString(Object value) {
try {
return objectMapper.writeValueAsString(value);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> List<T> parseArray(String content, Class<T> valueType) {
CollectionType javaType = typeFactory.constructCollectionType(List.class, valueType);
try {
return objectMapper.readValue(content, javaType);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -530,7 +530,7 @@
update functional_case
<set>
<if test="functionalCase.tags != null and functionalCase.tags != ''">
tags = #{functionalCase.tags},
tags = #{functionalCase.tags,typeHandler=io.metersphere.handler.ListTypeHandler},
</if>
<if test="functionalCase.updateUser != null and functionalCase.updateUser != ''">
update_user = #{functionalCase.updateUser},

View File

@ -5,7 +5,6 @@ import io.metersphere.functional.domain.CaseReview;
import io.metersphere.functional.mapper.CaseReviewMapper;
import io.metersphere.functional.mapper.ExtCaseReviewMapper;
import io.metersphere.functional.request.CaseReviewRequest;
import io.metersphere.sdk.util.JSON;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -39,7 +38,7 @@ public class CaseReviewNoticeService {
caseReview.setCreateUser(null);
}
if (CollectionUtils.isNotEmpty(request.getTags())) {
caseReview.setTags(JSON.toJSONString(request.getTags()));
caseReview.setTags(request.getTags());
}
caseReview.setStartTime(request.getStartTime());
caseReview.setEndTime(request.getEndTime());

View File

@ -17,7 +17,6 @@ import io.metersphere.sdk.constants.ApplicationNumScope;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.mapper.ExtUserMapper;
@ -261,7 +260,7 @@ public class CaseReviewService {
caseReview.setName(request.getName());
caseReview.setModuleId(request.getModuleId());
if (CollectionUtils.isNotEmpty(request.getTags())) {
caseReview.setTags(JSON.toJSONString(request.getTags()));
caseReview.setTags(request.getTags());
}
caseReview.setStartTime(request.getStartTime());
caseReview.setEndTime(request.getEndTime());
@ -333,7 +332,7 @@ public class CaseReviewService {
caseReview.setReviewPassRule(request.getReviewPassRule());
caseReview.setPos(getNextPos(request.getProjectId()));
if (CollectionUtils.isNotEmpty(request.getTags())) {
caseReview.setTags(JSON.toJSONString(request.getTags()));
caseReview.setTags(request.getTags());
}
caseReview.setPassRate(BigDecimal.valueOf(0.00));
if (CollectionUtils.isEmpty(caseIds)) {

View File

@ -152,7 +152,7 @@ public class FunctionalCaseService {
functionalCase.setCreateTime(System.currentTimeMillis());
functionalCase.setUpdateTime(System.currentTimeMillis());
functionalCase.setVersionId(StringUtils.defaultIfBlank(request.getVersionId(), extBaseProjectVersionMapper.getDefaultVersion(request.getProjectId())));
functionalCase.setTags(JSON.toJSONString(request.getTags()));
functionalCase.setTags(request.getTags());
functionalCaseMapper.insertSelective(functionalCase);
//附属表
FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob();
@ -643,13 +643,13 @@ public class FunctionalCaseService {
FunctionalCaseMapper caseMapper = sqlSession.getMapper(FunctionalCaseMapper.class);
ids.forEach(id -> {
FunctionalCase functionalCase = new FunctionalCase();
if (StringUtils.isNotBlank(collect.get(id).getTags())) {
List<String> tags = JSON.parseArray(collect.get(id).getTags(), String.class);
if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) {
List<String> tags = collect.get(id).getTags();
tags.addAll(request.getTags());
List<String> newTags = tags.stream().distinct().collect(Collectors.toList());
functionalCase.setTags(JSON.toJSONString(newTags));
functionalCase.setTags(newTags);
} else {
functionalCase.setTags(JSON.toJSONString(request.getTags()));
functionalCase.setTags(request.getTags());
}
functionalCase.setId(id);
functionalCase.setUpdateTime(System.currentTimeMillis());
@ -661,7 +661,7 @@ public class FunctionalCaseService {
} else {
//替换标签
FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setTags(JSON.toJSONString(request.getTags()));
functionalCase.setTags(request.getTags());
functionalCase.setProjectId(request.getProjectId());
functionalCase.setUpdateTime(System.currentTimeMillis());
functionalCase.setUpdateUser(userId);

View File

@ -70,22 +70,26 @@
</javaClientGenerator>
<!--要生成的数据库表 -->
<table tableName="functional_case" />
<table tableName="functional_case_blob" />
<table tableName="functional_case">
<columnOverride column="tags" javaType="java.util.List&lt;String&gt;" jdbcType="VARCHAR" typeHandler="io.metersphere.handler.ListTypeHandler" />
</table>
<!-- <table tableName="functional_case_blob" />
<table tableName="functional_case_comment" />
<table tableName="functional_case_module" />
<table tableName="functional_case_attachment" />
<table tableName="functional_case_follower" />
<table tableName="functional_case_relationship_edge" />
<table tableName="functional_case_test" />
<table tableName="functional_minder_extra_node" />
<table tableName="functional_case_custom_field" />
<table tableName="case_review" />
<table tableName="functional_case_test" />-->
<!--<table tableName="functional_minder_extra_node" />
<table tableName="functional_case_custom_field" />-->
<table tableName="case_review" >
<columnOverride column="tags" javaType="java.util.List&lt;String&gt;" jdbcType="VARCHAR" typeHandler="io.metersphere.handler.ListTypeHandler" />
</table>
<!--
<table tableName="case_review_user" />
<table tableName="case_review_functional_case" />
<table tableName="case_review_functional_case_user" />
<table tableName="case_review_follower" />
<table tableName="case_review_follower" />-->
<!-- 要忽略的字段-->

View File

@ -252,6 +252,7 @@ public class FunctionalTestCaseControllerTests extends BaseTest {
Assertions.assertNotNull(functionalCaseTestDTOS);
}
private List<BaseTreeNode> getModuleTreeNode() throws Exception {
MvcResult result = this.requestPostWithOkAndReturn(URL_CASE_MODULE_TREE, new AssociateCaseModuleRequest() {{
this.setProtocol("HTTP");
@ -299,6 +300,10 @@ public class FunctionalTestCaseControllerTests extends BaseTest {
functionalCase.setCreateTime(System.currentTimeMillis());
functionalCase.setUpdateUser("gyq");
functionalCase.setUpdateTime(System.currentTimeMillis());
List<String>tags = new ArrayList<>();
tags.add("111");
tags.add("222");
functionalCase.setTags(tags);
functionalCaseMapper.insertSelective(functionalCase);
}