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})
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")
private String demandId;
@ -53,6 +58,7 @@ public class FunctionalCaseDemand implements Serializable {
public enum Column {
id("id", "id", "VARCHAR", false),
caseId("case_id", "caseId", "VARCHAR", false),
parent("parent", "parent", "VARCHAR", false),
demandId("demand_id", "demandId", "VARCHAR", false),
demandName("demand_name", "demandName", "VARCHAR", false),
demandUrl("demand_url", "demandUrl", "VARCHAR", false),

View File

@ -244,6 +244,76 @@ public class FunctionalCaseDemandExample {
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() {
addCriterion("demand_id is null");
return (Criteria) this;

View File

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="io.metersphere.functional.domain.FunctionalCaseDemand">
<id column="id" jdbcType="VARCHAR" property="id" />
<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_name" jdbcType="VARCHAR" property="demandName" />
<result column="demand_url" jdbcType="VARCHAR" property="demandUrl" />
@ -72,8 +73,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, case_id, demand_id, demand_name, demand_url, demand_platform, create_time, update_time,
create_user, update_user
id, case_id, parent, demand_id, demand_name, demand_url, demand_platform, create_time,
update_time, create_user, update_user
</sql>
<select id="selectByExample" parameterType="io.metersphere.functional.domain.FunctionalCaseDemandExample" resultMap="BaseResultMap">
select
@ -106,14 +107,14 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand">
insert into functional_case_demand (id, case_id, demand_id,
demand_name, demand_url, demand_platform,
create_time, update_time, create_user,
update_user)
values (#{id,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR}, #{demandId,jdbcType=VARCHAR},
#{demandName,jdbcType=VARCHAR}, #{demandUrl,jdbcType=VARCHAR}, #{demandPlatform,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR},
#{updateUser,jdbcType=VARCHAR})
insert into functional_case_demand (id, case_id, parent,
demand_id, demand_name, demand_url,
demand_platform, create_time, update_time,
create_user, update_user)
values (#{id,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR}, #{parent,jdbcType=VARCHAR},
#{demandId,jdbcType=VARCHAR}, #{demandName,jdbcType=VARCHAR}, #{demandUrl,jdbcType=VARCHAR},
#{demandPlatform,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{createUser,jdbcType=VARCHAR}, #{updateUser,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand">
insert into functional_case_demand
@ -124,6 +125,9 @@
<if test="caseId != null">
case_id,
</if>
<if test="parent != null">
parent,
</if>
<if test="demandId != null">
demand_id,
</if>
@ -156,6 +160,9 @@
<if test="caseId != null">
#{caseId,jdbcType=VARCHAR},
</if>
<if test="parent != null">
#{parent,jdbcType=VARCHAR},
</if>
<if test="demandId != null">
#{demandId,jdbcType=VARCHAR},
</if>
@ -197,6 +204,9 @@
<if test="record.caseId != null">
case_id = #{record.caseId,jdbcType=VARCHAR},
</if>
<if test="record.parent != null">
parent = #{record.parent,jdbcType=VARCHAR},
</if>
<if test="record.demandId != null">
demand_id = #{record.demandId,jdbcType=VARCHAR},
</if>
@ -230,6 +240,7 @@
update functional_case_demand
set id = #{record.id,jdbcType=VARCHAR},
case_id = #{record.caseId,jdbcType=VARCHAR},
parent = #{record.parent,jdbcType=VARCHAR},
demand_id = #{record.demandId,jdbcType=VARCHAR},
demand_name = #{record.demandName,jdbcType=VARCHAR},
demand_url = #{record.demandUrl,jdbcType=VARCHAR},
@ -248,6 +259,9 @@
<if test="caseId != null">
case_id = #{caseId,jdbcType=VARCHAR},
</if>
<if test="parent != null">
parent = #{parent,jdbcType=VARCHAR},
</if>
<if test="demandId != null">
demand_id = #{demandId,jdbcType=VARCHAR},
</if>
@ -278,6 +292,7 @@
<update id="updateByPrimaryKey" parameterType="io.metersphere.functional.domain.FunctionalCaseDemand">
update functional_case_demand
set case_id = #{caseId,jdbcType=VARCHAR},
parent = #{parent,jdbcType=VARCHAR},
demand_id = #{demandId,jdbcType=VARCHAR},
demand_name = #{demandName,jdbcType=VARCHAR},
demand_url = #{demandUrl,jdbcType=VARCHAR},
@ -290,14 +305,14 @@
</update>
<insert id="batchInsert" parameterType="map">
insert into functional_case_demand
(id, case_id, demand_id, demand_name, demand_url, demand_platform, create_time, update_time,
create_user, update_user)
(id, case_id, parent, demand_id, demand_name, demand_url, demand_platform, create_time,
update_time, create_user, update_user)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.caseId,jdbcType=VARCHAR}, #{item.demandId,jdbcType=VARCHAR},
#{item.demandName,jdbcType=VARCHAR}, #{item.demandUrl,jdbcType=VARCHAR}, #{item.demandPlatform,jdbcType=VARCHAR},
#{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR},
#{item.updateUser,jdbcType=VARCHAR})
(#{item.id,jdbcType=VARCHAR}, #{item.caseId,jdbcType=VARCHAR}, #{item.parent,jdbcType=VARCHAR},
#{item.demandId,jdbcType=VARCHAR}, #{item.demandName,jdbcType=VARCHAR}, #{item.demandUrl,jdbcType=VARCHAR},
#{item.demandPlatform,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT},
#{item.createUser,jdbcType=VARCHAR}, #{item.updateUser,jdbcType=VARCHAR})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -316,6 +331,9 @@
<if test="'case_id'.toString() == column.value">
#{item.caseId,jdbcType=VARCHAR}
</if>
<if test="'parent'.toString() == column.value">
#{item.parent,jdbcType=VARCHAR}
</if>
<if test="'demand_id'.toString() == column.value">
#{item.demandId,jdbcType=VARCHAR}
</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
(
`id` VARCHAR(50) NOT NULL COMMENT 'ID',
`case_id` VARCHAR(50) NOT NULL COMMENT '功能用例ID',
`demand_id` VARCHAR(50) COMMENT '需求ID',
`demand_name` VARCHAR(64) NOT NULL COMMENT '需求标题',
`demand_url` VARCHAR(255) COMMENT '需求地址',
`demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台',
`create_time` BIGINT NOT NULL COMMENT '创建时间',
`update_time` BIGINT NOT NULL COMMENT '更新时间',
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人',
`update_user` VARCHAR(50) NOT NULL COMMENT '更新人',
PRIMARY KEY (id)
`id` VARCHAR(50) NOT NULL COMMENT 'ID' ,
`case_id` VARCHAR(50) NOT NULL COMMENT '功能用例ID' ,
`parent` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父需求id' ,
`demand_id` VARCHAR(50) COMMENT '需求ID' ,
`demand_name` VARCHAR(64) NOT NULL DEFAULT 'NONE' COMMENT '需求标题' ,
`demand_url` VARCHAR(255) COMMENT '需求地址' ,
`demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台' ,
`create_time` BIGINT NOT NULL COMMENT '创建时间' ,
`update_time` BIGINT NOT NULL COMMENT '更新时间' ,
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
`update_user` VARCHAR(50) NOT NULL COMMENT '更新人' ,
PRIMARY KEY (id)
) ENGINE = InnoDB
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_demand_name ON functional_case_demand (demand_name);
CREATE INDEX idx_demand_platform ON functional_case_demand (demand_platform);
CREATE INDEX idx_case_id ON functional_case_demand(case_id);
CREATE INDEX idx_demand_platform ON functional_case_demand(demand_platform);
CREATE TABLE IF NOT EXISTS functional_minder_extra_node
(

View File

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

View File

@ -154,6 +154,7 @@ file.transfer.failed=File transfer FAILED
#case
case.demand.not.exist=Demand does not exist
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.underway=Underway
case_review.completed=Completed

View File

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

View File

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

View File

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

View File

@ -3,11 +3,18 @@ package io.metersphere.functional.dto;
import io.metersphere.functional.domain.FunctionalCaseDemand;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Data
@NoArgsConstructor
public class FunctionalDemandDTO extends FunctionalCaseDemand {
@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;
import io.metersphere.functional.domain.FunctionalCaseDemand;
import io.metersphere.functional.dto.FunctionalDemandDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -10,7 +11,7 @@ import java.util.List;
*/
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);
}

View File

@ -2,17 +2,17 @@
<!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">
<select id="selectGroupByKeyword" resultType="io.metersphere.functional.domain.FunctionalCaseDemand">
<select id="selectGroupByKeyword" resultType="io.metersphere.functional.dto.FunctionalDemandDTO">
SELECT
*
FROM functional_case_demand
WHERE functional_case_demand.case_id = #{caseId}
AND functional_case_demand.parent = 'NONE'
<if test="keyword != null and keyword != ''">
AND (
functional_case_demand.demand_id = #{keyword} OR
(functional_case_demand.demand_name LIKE CONCAT('%', #{keyword}, '%'))
)
</if>
GROUP BY functional_case_demand.demand_platform
</select>

View File

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

View File

@ -1,6 +1,7 @@
package io.metersphere.functional.service;
import io.metersphere.functional.domain.FunctionalCaseDemand;
import io.metersphere.functional.domain.FunctionalCaseDemandExample;
import io.metersphere.functional.dto.DemandDTO;
import io.metersphere.functional.dto.FunctionalDemandDTO;
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.util.BeanUtils;
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 jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
@ -39,45 +42,59 @@ public class FunctionalCaseDemandService {
private ExtFunctionalCaseDemandMapper extFunctionalCaseDemandMapper;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Resource
private SystemParameterMapper systemParameterMapper;
/**
* 获取需求列表
*
* @param request QueryDemandListRequest
* @return List<FunctionalCaseDemand>
*/
public List<FunctionalDemandDTO> listFunctionalCaseDemands(QueryDemandListRequest request) {
List<FunctionalCaseDemand> functionalCaseDemands = extFunctionalCaseDemandMapper.selectGroupByKeyword(request.getKeyword(), request.getCaseId());
List<String> platforms = functionalCaseDemands.stream().map(FunctionalCaseDemand::getDemandPlatform).distinct().toList();
List<String> ids = functionalCaseDemands.stream().map(FunctionalCaseDemand::getId).distinct().toList();
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);
List<FunctionalDemandDTO> parentDemands = extFunctionalCaseDemandMapper.selectGroupByKeyword(request.getKeyword(), request.getCaseId());
if (CollectionUtils.isEmpty(parentDemands)) {
return new ArrayList<>();
}
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 userId 当前操作人
* @param userId 当前操作人
*/
public void addDemand(FunctionalCaseDemandRequest request, String userId) {
if (checkDemandList(request)) return;
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, request.getDemandList().get(0));
functionalCaseDemandMapper.insert(functionalCaseDemand);
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, request.getDemandList().get(0), new ArrayList<>());
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.setId(IDGenerator.nextStr());
functionalCaseDemand.setCaseId(request.getCaseId());
@ -86,6 +103,9 @@ public class FunctionalCaseDemandService {
functionalCaseDemand.setCreateUser(userId);
functionalCaseDemand.setUpdateTime(System.currentTimeMillis());
functionalCaseDemand.setUpdateUser(userId);
if (existDemandIds.contains(demandDTO.getDemandId())) {
return null;
}
dealWithDemand(demandDTO, functionalCaseDemand);
return functionalCaseDemand;
}
@ -96,12 +116,33 @@ public class FunctionalCaseDemandService {
/**
* 处理单个需求
* @param demandDTO 需求参数
*
* @param demandDTO 需求参数
* @param functionalCaseDemand functionalCaseDemand
*/
private static void dealWithDemand(DemandDTO demandDTO, FunctionalCaseDemand functionalCaseDemand) {
if (StringUtils.isNotBlank(demandDTO.getDemandId())) {
private void dealWithDemand(DemandDTO demandDTO, FunctionalCaseDemand functionalCaseDemand) {
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());
if (StringUtils.isBlank(demandDTO.getParent())) {
functionalCaseDemand.setParent("NONE");
} else {
functionalCaseDemand.setParent(demandDTO.getParent());
}
}
if (StringUtils.isBlank(demandDTO.getDemandName())) {
throw new MSException(Translator.get("case.demand.name.not.exist"));
@ -114,8 +155,9 @@ public class FunctionalCaseDemandService {
/**
* 更新本地需求
*
* @param request 页面参数
* @param userId 当前操作人
* @param userId 当前操作人
*/
public void updateDemand(FunctionalCaseDemandRequest request, String userId) {
if (checkDemandList(request)) return;
@ -133,6 +175,7 @@ public class FunctionalCaseDemandService {
/**
* 取消关联需求 就是将该需求关系删除
*
* @param id 需求关系ID
*/
public void deleteDemand(String id) {
@ -141,16 +184,24 @@ public class FunctionalCaseDemandService {
/**
* 批量关联第三方需求 需要带有所属平台
*
* @param request 页面参数
* @param userId 当前操作人
* @param userId 当前操作人
*/
public void batchRelevance(FunctionalCaseDemandRequest request, String userId) {
if (checkDemandList(request)) return;
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
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()) {
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, demandDTO);
functionalCaseDemandMapper.insert(functionalCaseDemand);
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request, userId, demandDTO, existDemandIds);
if (functionalCaseDemand != null) {
functionalCaseDemandMapper.insert(functionalCaseDemand);
}
}
sqlSession.flushStatements();
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.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.SystemParameter;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.SystemParameterMapper;
import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -43,6 +46,8 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
private FunctionalCaseDemandMapper functionalCaseDemandMapper;
@Resource
private OperationLogMapper operationLogMapper;
@Resource
private SystemParameterMapper systemParameterMapper;
private static final String URL_DEMAND_PAGE = "/functional/case/demand/page";
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 {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入1");
@ -71,7 +76,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>();
demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入孩子");
@ -89,7 +94,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
public void addDemandEmpty() throws Exception {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>();
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest);
@ -100,7 +105,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入3");
@ -118,7 +123,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
public void addDemandFalse() throws Exception {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandId("111");
@ -131,7 +136,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
Assertions.assertTrue(functionalCaseDemands.isEmpty());
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>();
demandDTO = new DemandDTO();
demandDTO.setDemandId("111");
@ -143,13 +148,18 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
@Test
@Order(4)
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");
FunctionalCaseDemandExample functionalCaseDemandExample;
List<FunctionalCaseDemand> functionalCaseDemands;
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId(id);
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入2");
@ -171,7 +181,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId(id);
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>();
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_UPDATE, functionalCaseDemandRequest);
@ -190,7 +200,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
FunctionalCaseDemandRequest functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId(id);
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandId("111");
@ -205,7 +215,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId("hehe");
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>();
demandDTO = new DemandDTO();
demandDTO.setDemandId("111");
@ -216,7 +226,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>();
demandDTO = new DemandDTO();
demandDTO.setDemandId("111");
@ -236,26 +246,17 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
@Test
@Order(7)
public void getDemandList() throws Exception {
QueryDemandListRequest queryDemandListRequest = new QueryDemandListRequest();
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
QueryDemandListRequest queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID");
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);
//返回值的页码和当前页码相同
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());
queryDemandListRequest = new QueryDemandListRequest();
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
tableData = JSON.parseObject(JSON.toJSONString(
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()));
queryDemandListRequest = new QueryDemandListRequest();
queryDemandListRequest.setCurrent(1);
queryDemandListRequest.setPageSize(5);
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
queryDemandListRequest = getQueryDemandListRequest("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
tableData = JSON.parseObject(JSON.toJSONString(
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.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
@ -314,11 +317,13 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
demandList.add(demandDTO);
DemandDTO demandDTO2 = new DemandDTO();
demandDTO2.setDemandId("100002");
demandDTO2.setParent("100001");
demandDTO2.setDemandName("手动加入Tapd1");
demandDTO2.setDemandUrl("https://www.tapd.cn/55049933/prong/stories/view/1155049933001012783");
demandList.add(demandDTO2);
DemandDTO demandDTO3 = new DemandDTO();
demandDTO3.setDemandId("100003");
demandDTO3.setParent("100002");
demandDTO3.setDemandName("手动加入Tapd2");
demandList.add(demandDTO3);
functionalCaseDemandRequest.setDemandList(demandList);
@ -327,6 +332,16 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
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
@ -342,6 +357,29 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("ZanDao");
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
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
@ -358,16 +396,26 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
DemandDTO demandDTO2 = new DemandDTO();
demandDTO2.setDemandId("100006");
demandList.add(demandDTO2);
DemandDTO demandDTO3 = new DemandDTO();
demandDTO3.setDemandId("100007");
demandDTO3.setDemandName("手动加入jira2");
demandList.add(demandDTO3);
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPost(URL_DEMAND_BATCH_RELEVANCE, functionalCaseDemandRequest).andExpect(status().is5xxServerError());
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("jira");
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
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