feat(功能用例): 关联需求

This commit is contained in:
guoyuqi 2023-12-04 11:20:29 +08:00 committed by f2c-ci-robot[bot]
parent 6be74d1ab0
commit 3c094677ee
15 changed files with 307 additions and 99 deletions

View File

@ -20,6 +20,11 @@ public class FunctionalCaseDemand implements Serializable {
@Size(min = 1, max = 50, message = "{functional_case_demand.case_id.length_range}", groups = {Created.class, Updated.class}) @Size(min = 1, max = 50, message = "{functional_case_demand.case_id.length_range}", groups = {Created.class, Updated.class})
private String caseId; private String caseId;
@Schema(description = "父需求id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case_demand.parent.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{functional_case_demand.parent.length_range}", groups = {Created.class, Updated.class})
private String parent;
@Schema(description = "需求ID") @Schema(description = "需求ID")
private String demandId; private String demandId;
@ -53,6 +58,7 @@ public class FunctionalCaseDemand implements Serializable {
public enum Column { public enum Column {
id("id", "id", "VARCHAR", false), id("id", "id", "VARCHAR", false),
caseId("case_id", "caseId", "VARCHAR", false), caseId("case_id", "caseId", "VARCHAR", false),
parent("parent", "parent", "VARCHAR", false),
demandId("demand_id", "demandId", "VARCHAR", false), demandId("demand_id", "demandId", "VARCHAR", false),
demandName("demand_name", "demandName", "VARCHAR", false), demandName("demand_name", "demandName", "VARCHAR", false),
demandUrl("demand_url", "demandUrl", "VARCHAR", false), demandUrl("demand_url", "demandUrl", "VARCHAR", false),

View File

@ -244,6 +244,76 @@ public class FunctionalCaseDemandExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andParentIsNull() {
addCriterion("parent is null");
return (Criteria) this;
}
public Criteria andParentIsNotNull() {
addCriterion("parent is not null");
return (Criteria) this;
}
public Criteria andParentEqualTo(String value) {
addCriterion("parent =", value, "parent");
return (Criteria) this;
}
public Criteria andParentNotEqualTo(String value) {
addCriterion("parent <>", value, "parent");
return (Criteria) this;
}
public Criteria andParentGreaterThan(String value) {
addCriterion("parent >", value, "parent");
return (Criteria) this;
}
public Criteria andParentGreaterThanOrEqualTo(String value) {
addCriterion("parent >=", value, "parent");
return (Criteria) this;
}
public Criteria andParentLessThan(String value) {
addCriterion("parent <", value, "parent");
return (Criteria) this;
}
public Criteria andParentLessThanOrEqualTo(String value) {
addCriterion("parent <=", value, "parent");
return (Criteria) this;
}
public Criteria andParentLike(String value) {
addCriterion("parent like", value, "parent");
return (Criteria) this;
}
public Criteria andParentNotLike(String value) {
addCriterion("parent not like", value, "parent");
return (Criteria) this;
}
public Criteria andParentIn(List<String> values) {
addCriterion("parent in", values, "parent");
return (Criteria) this;
}
public Criteria andParentNotIn(List<String> values) {
addCriterion("parent not in", values, "parent");
return (Criteria) this;
}
public Criteria andParentBetween(String value1, String value2) {
addCriterion("parent between", value1, value2, "parent");
return (Criteria) this;
}
public Criteria andParentNotBetween(String value1, String value2) {
addCriterion("parent not between", value1, value2, "parent");
return (Criteria) this;
}
public Criteria andDemandIdIsNull() { public Criteria andDemandIdIsNull() {
addCriterion("demand_id is null"); addCriterion("demand_id is null");
return (Criteria) this; return (Criteria) this;

View File

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="io.metersphere.functional.domain.FunctionalCaseDemand"> <resultMap id="BaseResultMap" type="io.metersphere.functional.domain.FunctionalCaseDemand">
<id column="id" jdbcType="VARCHAR" property="id" /> <id column="id" jdbcType="VARCHAR" property="id" />
<result column="case_id" jdbcType="VARCHAR" property="caseId" /> <result column="case_id" jdbcType="VARCHAR" property="caseId" />
<result column="parent" jdbcType="VARCHAR" property="parent" />
<result column="demand_id" jdbcType="VARCHAR" property="demandId" /> <result column="demand_id" jdbcType="VARCHAR" property="demandId" />
<result column="demand_name" jdbcType="VARCHAR" property="demandName" /> <result column="demand_name" jdbcType="VARCHAR" property="demandName" />
<result column="demand_url" jdbcType="VARCHAR" property="demandUrl" /> <result column="demand_url" jdbcType="VARCHAR" property="demandUrl" />
@ -72,8 +73,8 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, case_id, demand_id, demand_name, demand_url, demand_platform, create_time, update_time, id, case_id, parent, demand_id, demand_name, demand_url, demand_platform, create_time,
create_user, update_user update_time, create_user, update_user
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.functional.domain.FunctionalCaseDemandExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.functional.domain.FunctionalCaseDemandExample" resultMap="BaseResultMap">
select select
@ -106,14 +107,14 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand"> <insert id="insert" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand">
insert into functional_case_demand (id, case_id, demand_id, insert into functional_case_demand (id, case_id, parent,
demand_name, demand_url, demand_platform, demand_id, demand_name, demand_url,
create_time, update_time, create_user, demand_platform, create_time, update_time,
update_user) create_user, update_user)
values (#{id,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR}, #{demandId,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR}, #{parent,jdbcType=VARCHAR},
#{demandName,jdbcType=VARCHAR}, #{demandUrl,jdbcType=VARCHAR}, #{demandPlatform,jdbcType=VARCHAR}, #{demandId,jdbcType=VARCHAR}, #{demandName,jdbcType=VARCHAR}, #{demandUrl,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{demandPlatform,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{updateUser,jdbcType=VARCHAR}) #{createUser,jdbcType=VARCHAR}, #{updateUser,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand"> <insert id="insertSelective" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand">
insert into functional_case_demand insert into functional_case_demand
@ -124,6 +125,9 @@
<if test="caseId != null"> <if test="caseId != null">
case_id, case_id,
</if> </if>
<if test="parent != null">
parent,
</if>
<if test="demandId != null"> <if test="demandId != null">
demand_id, demand_id,
</if> </if>
@ -156,6 +160,9 @@
<if test="caseId != null"> <if test="caseId != null">
#{caseId,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR},
</if> </if>
<if test="parent != null">
#{parent,jdbcType=VARCHAR},
</if>
<if test="demandId != null"> <if test="demandId != null">
#{demandId,jdbcType=VARCHAR}, #{demandId,jdbcType=VARCHAR},
</if> </if>
@ -197,6 +204,9 @@
<if test="record.caseId != null"> <if test="record.caseId != null">
case_id = #{record.caseId,jdbcType=VARCHAR}, case_id = #{record.caseId,jdbcType=VARCHAR},
</if> </if>
<if test="record.parent != null">
parent = #{record.parent,jdbcType=VARCHAR},
</if>
<if test="record.demandId != null"> <if test="record.demandId != null">
demand_id = #{record.demandId,jdbcType=VARCHAR}, demand_id = #{record.demandId,jdbcType=VARCHAR},
</if> </if>
@ -230,6 +240,7 @@
update functional_case_demand update functional_case_demand
set id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
case_id = #{record.caseId,jdbcType=VARCHAR}, case_id = #{record.caseId,jdbcType=VARCHAR},
parent = #{record.parent,jdbcType=VARCHAR},
demand_id = #{record.demandId,jdbcType=VARCHAR}, demand_id = #{record.demandId,jdbcType=VARCHAR},
demand_name = #{record.demandName,jdbcType=VARCHAR}, demand_name = #{record.demandName,jdbcType=VARCHAR},
demand_url = #{record.demandUrl,jdbcType=VARCHAR}, demand_url = #{record.demandUrl,jdbcType=VARCHAR},
@ -248,6 +259,9 @@
<if test="caseId != null"> <if test="caseId != null">
case_id = #{caseId,jdbcType=VARCHAR}, case_id = #{caseId,jdbcType=VARCHAR},
</if> </if>
<if test="parent != null">
parent = #{parent,jdbcType=VARCHAR},
</if>
<if test="demandId != null"> <if test="demandId != null">
demand_id = #{demandId,jdbcType=VARCHAR}, demand_id = #{demandId,jdbcType=VARCHAR},
</if> </if>
@ -278,6 +292,7 @@
<update id="updateByPrimaryKey" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand"> <update id="updateByPrimaryKey" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand">
update functional_case_demand update functional_case_demand
set case_id = #{caseId,jdbcType=VARCHAR}, set case_id = #{caseId,jdbcType=VARCHAR},
parent = #{parent,jdbcType=VARCHAR},
demand_id = #{demandId,jdbcType=VARCHAR}, demand_id = #{demandId,jdbcType=VARCHAR},
demand_name = #{demandName,jdbcType=VARCHAR}, demand_name = #{demandName,jdbcType=VARCHAR},
demand_url = #{demandUrl,jdbcType=VARCHAR}, demand_url = #{demandUrl,jdbcType=VARCHAR},
@ -290,14 +305,14 @@
</update> </update>
<insert id="batchInsert" parameterType="map"> <insert id="batchInsert" parameterType="map">
insert into functional_case_demand insert into functional_case_demand
(id, case_id, demand_id, demand_name, demand_url, demand_platform, create_time, update_time, (id, case_id, parent, demand_id, demand_name, demand_url, demand_platform, create_time,
create_user, update_user) update_time, create_user, update_user)
values values
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.caseId,jdbcType=VARCHAR}, #{item.demandId,jdbcType=VARCHAR}, (#{item.id,jdbcType=VARCHAR}, #{item.caseId,jdbcType=VARCHAR}, #{item.parent,jdbcType=VARCHAR},
#{item.demandName,jdbcType=VARCHAR}, #{item.demandUrl,jdbcType=VARCHAR}, #{item.demandPlatform,jdbcType=VARCHAR}, #{item.demandId,jdbcType=VARCHAR}, #{item.demandName,jdbcType=VARCHAR}, #{item.demandUrl,jdbcType=VARCHAR},
#{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.demandPlatform,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT},
#{item.updateUser,jdbcType=VARCHAR}) #{item.createUser,jdbcType=VARCHAR}, #{item.updateUser,jdbcType=VARCHAR})
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertSelective" parameterType="map"> <insert id="batchInsertSelective" parameterType="map">
@ -316,6 +331,9 @@
<if test="'case_id'.toString() == column.value"> <if test="'case_id'.toString() == column.value">
#{item.caseId,jdbcType=VARCHAR} #{item.caseId,jdbcType=VARCHAR}
</if> </if>
<if test="'parent'.toString() == column.value">
#{item.parent,jdbcType=VARCHAR}
</if>
<if test="'demand_id'.toString() == column.value"> <if test="'demand_id'.toString() == column.value">
#{item.demandId,jdbcType=VARCHAR} #{item.demandId,jdbcType=VARCHAR}
</if> </if>

View File

@ -182,25 +182,25 @@ CREATE INDEX idx_source_id ON functional_case_test (source_id);
CREATE TABLE IF NOT EXISTS functional_case_demand CREATE TABLE IF NOT EXISTS functional_case_demand
( (
`id` VARCHAR(50) NOT NULL COMMENT 'ID', `id` VARCHAR(50) NOT NULL COMMENT 'ID' ,
`case_id` VARCHAR(50) NOT NULL COMMENT '功能用例ID', `case_id` VARCHAR(50) NOT NULL COMMENT '功能用例ID' ,
`demand_id` VARCHAR(50) COMMENT '需求ID', `parent` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父需求id' ,
`demand_name` VARCHAR(64) NOT NULL COMMENT '需求标题', `demand_id` VARCHAR(50) COMMENT '需求ID' ,
`demand_url` VARCHAR(255) COMMENT '需求地址', `demand_name` VARCHAR(64) NOT NULL DEFAULT 'NONE' COMMENT '需求标题' ,
`demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台', `demand_url` VARCHAR(255) COMMENT '需求地址' ,
`create_time` BIGINT NOT NULL COMMENT '创建时间', `demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台' ,
`update_time` BIGINT NOT NULL COMMENT '更新时间', `create_time` BIGINT NOT NULL COMMENT '创建时间' ,
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人', `update_time` BIGINT NOT NULL COMMENT '更新时间' ,
`update_user` VARCHAR(50) NOT NULL COMMENT '更新人', `create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
PRIMARY KEY (id) `update_user` VARCHAR(50) NOT NULL COMMENT '更新人' ,
PRIMARY KEY (id)
) ENGINE = InnoDB ) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '功能用例和需求的中间表'; COLLATE = utf8mb4_general_ci COMMENT = '功能用例和需求的中间表';
CREATE INDEX idx_case_id ON functional_case_demand (case_id); CREATE INDEX idx_case_id ON functional_case_demand(case_id);
CREATE INDEX idx_demand_name ON functional_case_demand (demand_name); CREATE INDEX idx_demand_platform ON functional_case_demand(demand_platform);
CREATE INDEX idx_demand_platform ON functional_case_demand (demand_platform);
CREATE TABLE IF NOT EXISTS functional_minder_extra_node CREATE TABLE IF NOT EXISTS functional_minder_extra_node
( (

View File

@ -137,6 +137,7 @@ case_module.not.exist=用例模块不存在
#case #case
case.demand.not.exist=需求不存在 case.demand.not.exist=需求不存在
case.demand.name.not.exist=需求名称不能为空 case.demand.name.not.exist=需求名称不能为空
case.demand.id.not.exist=需求id不能为空
case_review.prepared=未开始 case_review.prepared=未开始
case_review.underway=进行中 case_review.underway=进行中
case_review.completed=已完成 case_review.completed=已完成

View File

@ -154,6 +154,7 @@ file.transfer.failed=File transfer FAILED
#case #case
case.demand.not.exist=Demand does not exist case.demand.not.exist=Demand does not exist
case.demand.name.not.exist=Demand name cannot be empty case.demand.name.not.exist=Demand name cannot be empty
case.demand.id.not.exist=Demand id cannot be empty
case_review.prepared=Prepared case_review.prepared=Prepared
case_review.underway=Underway case_review.underway=Underway
case_review.completed=Completed case_review.completed=Completed

View File

@ -153,6 +153,7 @@ file.transfer.failed=文件转存失败
#case #case
case.demand.not.exist=需求不存在 case.demand.not.exist=需求不存在
case.demand.name.not.exist=需求名称不能为空 case.demand.name.not.exist=需求名称不能为空
case.demand.id.not.exist=需求id不能为空
case_review.prepared=未开始 case_review.prepared=未开始
case_review.underway=进行中 case_review.underway=进行中
case_review.completed=已完成 case_review.completed=已完成

View File

@ -154,6 +154,7 @@ file.transfer.failed=文件轉存失敗
#case #case
case.demand.not.exist=需求不存在 case.demand.not.exist=需求不存在
case.demand.name.not.exist=需求名稱不能為空 case.demand.name.not.exist=需求名稱不能為空
case.demand.id.not.exist=需求id不能為空]
case_review.prepared=未開始 case_review.prepared=未開始
case_review.underway=進行中 case_review.underway=進行中
case_review.completed=已完成 case_review.completed=已完成

View File

@ -15,6 +15,9 @@ public class DemandDTO implements Serializable {
@Schema(description = "需求ID") @Schema(description = "需求ID")
private String demandId; private String demandId;
@Schema(description = "需求ID")
private String parent;
@Schema(description = "需求标题", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "需求标题", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case_demand.demand_name.not_blank}") @NotBlank(message = "{functional_case_demand.demand_name.not_blank}")
private String demandName; private String demandName;

View File

@ -3,11 +3,18 @@ package io.metersphere.functional.dto;
import io.metersphere.functional.domain.FunctionalCaseDemand; import io.metersphere.functional.domain.FunctionalCaseDemand;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Data @Data
@NoArgsConstructor
public class FunctionalDemandDTO extends FunctionalCaseDemand { public class FunctionalDemandDTO extends FunctionalCaseDemand {
@Schema(description = "同平台需求展开项") @Schema(description = "同平台需求展开项")
private List<FunctionalCaseDemand> children; private List<FunctionalDemandDTO> children = new ArrayList<>();;
public void addChild(FunctionalDemandDTO demandDTO) {
children.add(demandDTO);
}
} }

View File

@ -1,6 +1,7 @@
package io.metersphere.functional.mapper; package io.metersphere.functional.mapper;
import io.metersphere.functional.domain.FunctionalCaseDemand; import io.metersphere.functional.domain.FunctionalCaseDemand;
import io.metersphere.functional.dto.FunctionalDemandDTO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -10,7 +11,7 @@ import java.util.List;
*/ */
public interface ExtFunctionalCaseDemandMapper { public interface ExtFunctionalCaseDemandMapper {
List<FunctionalCaseDemand> selectGroupByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId); List<FunctionalDemandDTO> selectGroupByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId);
List<FunctionalCaseDemand> selectByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId, @Param("platforms") List<String> platforms, @Param("ids") List<String> ids); List<FunctionalCaseDemand> selectByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId, @Param("platforms") List<String> platforms, @Param("ids") List<String> ids);
} }

View File

@ -2,17 +2,17 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper"> <mapper namespace="io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper">
<select id="selectGroupByKeyword" resultType="io.metersphere.functional.domain.FunctionalCaseDemand"> <select id="selectGroupByKeyword" resultType="io.metersphere.functional.dto.FunctionalDemandDTO">
SELECT SELECT
* *
FROM functional_case_demand FROM functional_case_demand
WHERE functional_case_demand.case_id = #{caseId} WHERE functional_case_demand.case_id = #{caseId}
AND functional_case_demand.parent = 'NONE'
<if test="keyword != null and keyword != ''"> <if test="keyword != null and keyword != ''">
AND ( AND (
functional_case_demand.demand_id = #{keyword} OR functional_case_demand.demand_id = #{keyword} OR
(functional_case_demand.demand_name LIKE CONCAT('%', #{keyword}, '%')) (functional_case_demand.demand_name LIKE CONCAT('%', #{keyword}, '%'))
) )
</if> </if>
GROUP BY functional_case_demand.demand_platform GROUP BY functional_case_demand.demand_platform
</select> </select>

View File

@ -22,7 +22,7 @@ public class FunctionalCaseDemandRequest {
@NotBlank(message = "{functional_case_demand.case_id.not_blank}") @NotBlank(message = "{functional_case_demand.case_id.not_blank}")
private String caseId; private String caseId;
@Schema(description = "需求所属平台(默认是LOCAL)") @Schema(description = "需求所属平台(本地创建为系统平台名称)")
@NotBlank(message = "{functional_case_demand.demand_platform.not_blank}") @NotBlank(message = "{functional_case_demand.demand_platform.not_blank}")
private String demandPlatform; private String demandPlatform;

View File

@ -1,6 +1,7 @@
package io.metersphere.functional.service; package io.metersphere.functional.service;
import io.metersphere.functional.domain.FunctionalCaseDemand; import io.metersphere.functional.domain.FunctionalCaseDemand;
import io.metersphere.functional.domain.FunctionalCaseDemandExample;
import io.metersphere.functional.dto.DemandDTO; import io.metersphere.functional.dto.DemandDTO;
import io.metersphere.functional.dto.FunctionalDemandDTO; import io.metersphere.functional.dto.FunctionalDemandDTO;
import io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper; import io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper;
@ -10,6 +11,8 @@ import io.metersphere.functional.request.QueryDemandListRequest;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.SystemParameter;
import io.metersphere.system.mapper.SystemParameterMapper;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -39,45 +42,59 @@ public class FunctionalCaseDemandService {
private ExtFunctionalCaseDemandMapper extFunctionalCaseDemandMapper; private ExtFunctionalCaseDemandMapper extFunctionalCaseDemandMapper;
@Resource @Resource
private SqlSessionFactory sqlSessionFactory; private SqlSessionFactory sqlSessionFactory;
@Resource
private SystemParameterMapper systemParameterMapper;
/** /**
* 获取需求列表 * 获取需求列表
*
* @param request QueryDemandListRequest * @param request QueryDemandListRequest
* @return List<FunctionalCaseDemand> * @return List<FunctionalCaseDemand>
*/ */
public List<FunctionalDemandDTO> listFunctionalCaseDemands(QueryDemandListRequest request) { public List<FunctionalDemandDTO> listFunctionalCaseDemands(QueryDemandListRequest request) {
List<FunctionalCaseDemand> functionalCaseDemands = extFunctionalCaseDemandMapper.selectGroupByKeyword(request.getKeyword(), request.getCaseId()); List<FunctionalDemandDTO> parentDemands = extFunctionalCaseDemandMapper.selectGroupByKeyword(request.getKeyword(), request.getCaseId());
List<String> platforms = functionalCaseDemands.stream().map(FunctionalCaseDemand::getDemandPlatform).distinct().toList(); if (CollectionUtils.isEmpty(parentDemands)) {
List<String> ids = functionalCaseDemands.stream().map(FunctionalCaseDemand::getId).distinct().toList(); return new ArrayList<>();
List<FunctionalCaseDemand> functionalCaseDemandChildList = extFunctionalCaseDemandMapper.selectByKeyword(request.getKeyword(), request.getCaseId(), platforms, ids);
Map<String, List<FunctionalCaseDemand>> platformDemandMap = functionalCaseDemandChildList.stream().collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandPlatform));
List<FunctionalDemandDTO> list = new ArrayList<>();
for (FunctionalCaseDemand functionalCaseDemand : functionalCaseDemands) {
FunctionalDemandDTO functionalDemandDTO = new FunctionalDemandDTO();
BeanUtils.copyBean(functionalDemandDTO,functionalCaseDemand);
List<FunctionalCaseDemand> childrenDemands= platformDemandMap.get(functionalCaseDemand.getDemandPlatform());
if (CollectionUtils.isNotEmpty(childrenDemands)) {
functionalDemandDTO.setChildren(childrenDemands);
} else {
functionalDemandDTO.setChildren(new ArrayList<>());
}
list.add(functionalDemandDTO);
} }
return list; List<String> ids = parentDemands.stream().map(FunctionalCaseDemand::getId).toList();
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andIdNotIn(ids);
Map<String, FunctionalDemandDTO> functionalCaseDemandMap = parentDemands.stream().filter(t -> StringUtils.isNotBlank(t.getDemandId())).collect(Collectors.toMap(FunctionalCaseDemand::getDemandId, t -> t));
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
int lastSize = 0;
while (CollectionUtils.isNotEmpty(functionalCaseDemands) && functionalCaseDemands.size() != lastSize) {
lastSize = functionalCaseDemands.size();
List<FunctionalCaseDemand> notMatchedList = new ArrayList<>();
for (FunctionalCaseDemand demand : functionalCaseDemands) {
if (functionalCaseDemandMap.containsKey(demand.getParent())) {
FunctionalDemandDTO functionalDemandDTO = new FunctionalDemandDTO();
BeanUtils.copyBean(functionalDemandDTO, demand);
functionalCaseDemandMap.get(demand.getParent()).addChild(functionalDemandDTO);
functionalCaseDemandMap.put(demand.getDemandId(), functionalDemandDTO);
} else {
notMatchedList.add(demand);
}
}
functionalCaseDemands = notMatchedList;
}
return parentDemands;
} }
/** /**
* 新增本地需求 * 新增本地需求
*
* @param request 页面参数 * @param request 页面参数
* @param userId 当前操作人 * @param userId 当前操作人
*/ */
public void addDemand(FunctionalCaseDemandRequest request, String userId) { public void addDemand(FunctionalCaseDemandRequest request, String userId) {
if (checkDemandList(request)) return; if (checkDemandList(request)) return;
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, request.getDemandList().get(0)); FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, request.getDemandList().get(0), new ArrayList<>());
functionalCaseDemandMapper.insert(functionalCaseDemand); if (functionalCaseDemand != null) {
functionalCaseDemandMapper.insertSelective(functionalCaseDemand);
}
} }
private static FunctionalCaseDemand buildFunctionalCaseDemand(FunctionalCaseDemandRequest request, String userId, DemandDTO demandDTO) { private FunctionalCaseDemand buildFunctionalCaseDemand(FunctionalCaseDemandRequest request, String userId, DemandDTO demandDTO, List<String> existDemandIds) {
FunctionalCaseDemand functionalCaseDemand = new FunctionalCaseDemand(); FunctionalCaseDemand functionalCaseDemand = new FunctionalCaseDemand();
functionalCaseDemand.setId(IDGenerator.nextStr()); functionalCaseDemand.setId(IDGenerator.nextStr());
functionalCaseDemand.setCaseId(request.getCaseId()); functionalCaseDemand.setCaseId(request.getCaseId());
@ -86,6 +103,9 @@ public class FunctionalCaseDemandService {
functionalCaseDemand.setCreateUser(userId); functionalCaseDemand.setCreateUser(userId);
functionalCaseDemand.setUpdateTime(System.currentTimeMillis()); functionalCaseDemand.setUpdateTime(System.currentTimeMillis());
functionalCaseDemand.setUpdateUser(userId); functionalCaseDemand.setUpdateUser(userId);
if (existDemandIds.contains(demandDTO.getDemandId())) {
return null;
}
dealWithDemand(demandDTO, functionalCaseDemand); dealWithDemand(demandDTO, functionalCaseDemand);
return functionalCaseDemand; return functionalCaseDemand;
} }
@ -96,12 +116,33 @@ public class FunctionalCaseDemandService {
/** /**
* 处理单个需求 * 处理单个需求
* @param demandDTO 需求参数 *
* @param demandDTO 需求参数
* @param functionalCaseDemand functionalCaseDemand * @param functionalCaseDemand functionalCaseDemand
*/ */
private static void dealWithDemand(DemandDTO demandDTO, FunctionalCaseDemand functionalCaseDemand) { private void dealWithDemand(DemandDTO demandDTO, FunctionalCaseDemand functionalCaseDemand) {
if (StringUtils.isNotBlank(demandDTO.getDemandId())) { SystemParameter systemParameter = systemParameterMapper.selectByPrimaryKey("ui.platformName");
String paramValue;
if (systemParameter == null || StringUtils.isBlank(systemParameter.getParamValue())) {
paramValue = "MeterSphere";
} else {
paramValue = systemParameter.getParamValue();
}
if (StringUtils.equalsIgnoreCase(functionalCaseDemand.getDemandPlatform(), paramValue)) {
if (StringUtils.isNotBlank(demandDTO.getDemandId())) {
functionalCaseDemand.setDemandId(demandDTO.getDemandId());
}
functionalCaseDemand.setParent("NONE");
} else {
if (StringUtils.isBlank(demandDTO.getDemandId())) {
throw new MSException(Translator.get("case.demand.id.not.exist"));
}
functionalCaseDemand.setDemandId(demandDTO.getDemandId()); functionalCaseDemand.setDemandId(demandDTO.getDemandId());
if (StringUtils.isBlank(demandDTO.getParent())) {
functionalCaseDemand.setParent("NONE");
} else {
functionalCaseDemand.setParent(demandDTO.getParent());
}
} }
if (StringUtils.isBlank(demandDTO.getDemandName())) { if (StringUtils.isBlank(demandDTO.getDemandName())) {
throw new MSException(Translator.get("case.demand.name.not.exist")); throw new MSException(Translator.get("case.demand.name.not.exist"));
@ -114,8 +155,9 @@ public class FunctionalCaseDemandService {
/** /**
* 更新本地需求 * 更新本地需求
*
* @param request 页面参数 * @param request 页面参数
* @param userId 当前操作人 * @param userId 当前操作人
*/ */
public void updateDemand(FunctionalCaseDemandRequest request, String userId) { public void updateDemand(FunctionalCaseDemandRequest request, String userId) {
if (checkDemandList(request)) return; if (checkDemandList(request)) return;
@ -133,6 +175,7 @@ public class FunctionalCaseDemandService {
/** /**
* 取消关联需求 就是将该需求关系删除 * 取消关联需求 就是将该需求关系删除
*
* @param id 需求关系ID * @param id 需求关系ID
*/ */
public void deleteDemand(String id) { public void deleteDemand(String id) {
@ -141,16 +184,24 @@ public class FunctionalCaseDemandService {
/** /**
* 批量关联第三方需求 需要带有所属平台 * 批量关联第三方需求 需要带有所属平台
*
* @param request 页面参数 * @param request 页面参数
* @param userId 当前操作人 * @param userId 当前操作人
*/ */
public void batchRelevance(FunctionalCaseDemandRequest request, String userId) { public void batchRelevance(FunctionalCaseDemandRequest request, String userId) {
if (checkDemandList(request)) return; if (checkDemandList(request)) return;
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
FunctionalCaseDemandMapper functionalCaseDemandMapper = sqlSession.getMapper(FunctionalCaseDemandMapper.class); FunctionalCaseDemandMapper functionalCaseDemandMapper = sqlSession.getMapper(FunctionalCaseDemandMapper.class);
List<String> demandIds = request.getDemandList().stream().map(DemandDTO::getDemandId).toList();
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andDemandPlatformEqualTo(request.getDemandPlatform()).andDemandIdIn(demandIds);
List<FunctionalCaseDemand> existDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
List<String> existDemandIds = existDemands.stream().map(FunctionalCaseDemand::getDemandId).toList();
for (DemandDTO demandDTO : request.getDemandList()) { for (DemandDTO demandDTO : request.getDemandList()) {
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, demandDTO); FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, demandDTO, existDemandIds);
functionalCaseDemandMapper.insert(functionalCaseDemand); if (functionalCaseDemand != null) {
functionalCaseDemandMapper.insert(functionalCaseDemand);
}
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);

View File

@ -14,10 +14,13 @@ import io.metersphere.sdk.mapper.OperationLogMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.SystemParameter;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.SystemParameterMapper;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -43,6 +46,8 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
private FunctionalCaseDemandMapper functionalCaseDemandMapper; private FunctionalCaseDemandMapper functionalCaseDemandMapper;
@Resource @Resource
private OperationLogMapper operationLogMapper; private OperationLogMapper operationLogMapper;
@Resource
private SystemParameterMapper systemParameterMapper;
private static final String URL_DEMAND_PAGE = "/functional/case/demand/page"; private static final String URL_DEMAND_PAGE = "/functional/case/demand/page";
private static final String URL_DEMAND_ADD = "/functional/case/demand/add"; private static final String URL_DEMAND_ADD = "/functional/case/demand/add";
@ -57,7 +62,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
public void addDemandSuccess() throws Exception { public void addDemandSuccess() throws Exception {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入1"); demandDTO.setDemandName("手动加入1");
@ -71,7 +76,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>(); demandList = new ArrayList<>();
demandDTO = new DemandDTO(); demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入孩子"); demandDTO.setDemandName("手动加入孩子");
@ -89,7 +94,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
public void addDemandEmpty() throws Exception { public void addDemandEmpty() throws Exception {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
functionalCaseDemandRequest.setDemandList(demandList); functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest); this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest);
@ -100,7 +105,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>(); demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入3"); demandDTO.setDemandName("手动加入3");
@ -118,7 +123,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
public void addDemandFalse() throws Exception { public void addDemandFalse() throws Exception {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandId("111"); demandDTO.setDemandId("111");
@ -131,7 +136,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
Assertions.assertTrue(functionalCaseDemands.isEmpty()); Assertions.assertTrue(functionalCaseDemands.isEmpty());
functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>(); demandList = new ArrayList<>();
demandDTO = new DemandDTO(); demandDTO = new DemandDTO();
demandDTO.setDemandId("111"); demandDTO.setDemandId("111");
@ -143,13 +148,18 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
@Test @Test
@Order(4) @Order(4)
public void updateDemandSuccess() throws Exception { public void updateDemandSuccess() throws Exception {
SystemParameter systemParameter = new SystemParameter();
systemParameter.setParamKey("ui.platformName");
systemParameter.setParamValue("Metersphere");
systemParameter.setType("text");
systemParameterMapper.insertSelective(systemParameter);
String id = getId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); String id = getId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
FunctionalCaseDemandExample functionalCaseDemandExample; FunctionalCaseDemandExample functionalCaseDemandExample;
List<FunctionalCaseDemand> functionalCaseDemands; List<FunctionalCaseDemand> functionalCaseDemands;
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId(id); functionalCaseDemandRequest.setId(id);
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入2"); demandDTO.setDemandName("手动加入2");
@ -171,7 +181,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId(id); functionalCaseDemandRequest.setId(id);
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
functionalCaseDemandRequest.setDemandList(demandList); functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_UPDATE, functionalCaseDemandRequest); this.requestPostWithOkAndReturn(URL_DEMAND_UPDATE, functionalCaseDemandRequest);
@ -190,7 +200,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId(id); functionalCaseDemandRequest.setId(id);
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandId("111"); demandDTO.setDemandId("111");
@ -205,7 +215,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId("hehe"); functionalCaseDemandRequest.setId("hehe");
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>(); demandList = new ArrayList<>();
demandDTO = new DemandDTO(); demandDTO = new DemandDTO();
demandDTO.setDemandId("111"); demandDTO.setDemandId("111");
@ -216,7 +226,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>(); demandList = new ArrayList<>();
demandDTO = new DemandDTO(); demandDTO = new DemandDTO();
demandDTO.setDemandId("111"); demandDTO.setDemandId("111");
@ -236,26 +246,17 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
@Test @Test
@Order(7) @Order(7)
public void getDemandList() throws Exception { public void getDemandList() throws Exception {
QueryDemandListRequest queryDemandListRequest = new QueryDemandListRequest(); QueryDemandListRequest queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID");
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest); MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
Pager<List<FunctionalDemandDTO>> tableData = JSON.parseObject(JSON.toJSONString( Pager<List<FunctionalDemandDTO>> tableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
Pager.class); Pager.class);
//返回值的页码和当前页码相同 //返回值的页码和当前页码相同
Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent()); Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent());
List<FunctionalDemandDTO> list = JSON.parseArray(JSON.toJSONString(tableData.getList()), FunctionalDemandDTO.class);
for (FunctionalDemandDTO functionalDemandDTO : list) {
Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalDemandDTO.getChildren()));
}
//返回的数据量不超过规定要返回的数据量相同 //返回的数据量不超过规定要返回的数据量相同
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= queryDemandListRequest.getPageSize()); Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= queryDemandListRequest.getPageSize());
queryDemandListRequest = new QueryDemandListRequest(); queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest); mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
tableData = JSON.parseObject(JSON.toJSONString( tableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
@ -265,10 +266,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
//返回的数据量为空 //返回的数据量为空
Assertions.assertTrue(CollectionUtils.isEmpty(tableData.getList())); Assertions.assertTrue(CollectionUtils.isEmpty(tableData.getList()));
queryDemandListRequest = new QueryDemandListRequest(); queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest); mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
tableData = JSON.parseObject(JSON.toJSONString( tableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
@ -277,10 +275,15 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent()); Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent());
//返回的数据量不超过规定要返回的数据量相同 //返回的数据量不超过规定要返回的数据量相同
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= queryDemandListRequest.getPageSize()); Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= queryDemandListRequest.getPageSize());
List<FunctionalDemandDTO> list1 = JSON.parseArray(JSON.toJSONString(tableData.getList()), FunctionalDemandDTO.class); }
for (FunctionalDemandDTO functionalDemandDTO : list1) {
Assertions.assertTrue(CollectionUtils.isEmpty(functionalDemandDTO.getChildren())); @NotNull
} private static QueryDemandListRequest getQueryDemandListRequest(String caseId) {
QueryDemandListRequest queryDemandListRequest = new QueryDemandListRequest();
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
queryDemandListRequest.setCaseId(caseId);
return queryDemandListRequest;
} }
@Test @Test
@ -314,11 +317,13 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
demandList.add(demandDTO); demandList.add(demandDTO);
DemandDTO demandDTO2 = new DemandDTO(); DemandDTO demandDTO2 = new DemandDTO();
demandDTO2.setDemandId("100002"); demandDTO2.setDemandId("100002");
demandDTO2.setParent("100001");
demandDTO2.setDemandName("手动加入Tapd1"); demandDTO2.setDemandName("手动加入Tapd1");
demandDTO2.setDemandUrl("https://www.tapd.cn/55049933/prong/stories/view/1155049933001012783"); demandDTO2.setDemandUrl("https://www.tapd.cn/55049933/prong/stories/view/1155049933001012783");
demandList.add(demandDTO2); demandList.add(demandDTO2);
DemandDTO demandDTO3 = new DemandDTO(); DemandDTO demandDTO3 = new DemandDTO();
demandDTO3.setDemandId("100003"); demandDTO3.setDemandId("100003");
demandDTO3.setParent("100002");
demandDTO3.setDemandName("手动加入Tapd2"); demandDTO3.setDemandName("手动加入Tapd2");
demandList.add(demandDTO3); demandList.add(demandDTO3);
functionalCaseDemandRequest.setDemandList(demandList); functionalCaseDemandRequest.setDemandList(demandList);
@ -327,6 +332,16 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2"); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertEquals(functionalCaseDemands.size(), demandList.size()); Assertions.assertEquals(functionalCaseDemands.size(), demandList.size());
QueryDemandListRequest queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
Pager<List<FunctionalDemandDTO>> tableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
Pager.class);
List<FunctionalDemandDTO> list1 = JSON.parseArray(JSON.toJSONString(tableData.getList()), FunctionalDemandDTO.class);
for (FunctionalDemandDTO functionalDemandDTO : list1) {
Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalDemandDTO.getChildren()));
}
} }
@Test @Test
@ -342,6 +357,29 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("ZanDao"); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("ZanDao");
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertTrue(CollectionUtils.isEmpty(functionalCaseDemands)); Assertions.assertTrue(CollectionUtils.isEmpty(functionalCaseDemands));
functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("TAPD");
List<FunctionalCaseDemand> functionalCaseDemandOld = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("TAPD");
demandList = new ArrayList<>();
DemandDTO demandDTO3 = new DemandDTO();
demandDTO3.setDemandId("100003");
demandDTO3.setParent("100002");
demandDTO3.setDemandName("手动加入Tapd2");
demandList.add(demandDTO3);
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_BATCH_RELEVANCE, functionalCaseDemandRequest);
functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("TAPD");
List<FunctionalCaseDemand> functionalCaseDemandNew = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertEquals(functionalCaseDemandOld.size(), functionalCaseDemandNew.size());
} }
@Test @Test
@ -358,16 +396,26 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
DemandDTO demandDTO2 = new DemandDTO(); DemandDTO demandDTO2 = new DemandDTO();
demandDTO2.setDemandId("100006"); demandDTO2.setDemandId("100006");
demandList.add(demandDTO2); demandList.add(demandDTO2);
DemandDTO demandDTO3 = new DemandDTO();
demandDTO3.setDemandId("100007");
demandDTO3.setDemandName("手动加入jira2");
demandList.add(demandDTO3);
functionalCaseDemandRequest.setDemandList(demandList); functionalCaseDemandRequest.setDemandList(demandList);
this.requestPost(URL_DEMAND_BATCH_RELEVANCE, functionalCaseDemandRequest).andExpect(status().is5xxServerError()); this.requestPost(URL_DEMAND_BATCH_RELEVANCE, functionalCaseDemandRequest).andExpect(status().is5xxServerError());
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample(); FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("jira"); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("jira");
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertTrue(CollectionUtils.isEmpty(functionalCaseDemands)); Assertions.assertTrue(CollectionUtils.isEmpty(functionalCaseDemands));
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("jira");
demandList = new ArrayList<>();
demandDTO = new DemandDTO();
demandDTO.setDemandId("100007");
demandDTO.setDemandName("手动加入jira");
demandList.add(demandDTO);
demandDTO2 = new DemandDTO();
demandDTO2.setDemandName("手动加入jira2");
demandList.add(demandDTO2);
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPost(URL_DEMAND_BATCH_RELEVANCE, functionalCaseDemandRequest).andExpect(status().is5xxServerError());
} }
@Test @Test