refactor(项目管理): 优化环境查询接口模块树和选中的模块

This commit is contained in:
wxg0103 2024-01-12 19:58:18 +08:00 committed by Craftsman
parent 7919e356e2
commit 2f0ff19744
21 changed files with 326 additions and 161 deletions

View File

@ -9,15 +9,15 @@ import java.util.Arrays;
import lombok.Data; import lombok.Data;
@Data @Data
public class ProjectParameters implements Serializable { public class ProjectParameter implements Serializable {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{project_parameters.id.not_blank}", groups = {Updated.class}) @NotBlank(message = "{project_parameter.id.not_blank}", groups = {Updated.class})
@Size(min = 1, max = 50, message = "{project_parameters.id.length_range}", groups = {Created.class, Updated.class}) @Size(min = 1, max = 50, message = "{project_parameter.id.length_range}", groups = {Created.class, Updated.class})
private String id; private String id;
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{project_parameters.project_id.not_blank}", groups = {Created.class}) @NotBlank(message = "{project_parameter.project_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{project_parameters.project_id.length_range}", groups = {Created.class, Updated.class}) @Size(min = 1, max = 50, message = "{project_parameter.project_id.length_range}", groups = {Created.class, Updated.class})
private String projectId; private String projectId;
@Schema(description = "创建人") @Schema(description = "创建人")

View File

@ -3,14 +3,14 @@ package io.metersphere.sdk.domain;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ProjectParametersExample { public class ProjectParameterExample {
protected String orderByClause; protected String orderByClause;
protected boolean distinct; protected boolean distinct;
protected List<Criteria> oredCriteria; protected List<Criteria> oredCriteria;
public ProjectParametersExample() { public ProjectParameterExample() {
oredCriteria = new ArrayList<Criteria>(); oredCriteria = new ArrayList<Criteria>();
} }

View File

@ -0,0 +1,41 @@
package io.metersphere.sdk.mapper;
import io.metersphere.sdk.domain.ProjectParameter;
import io.metersphere.sdk.domain.ProjectParameterExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ProjectParameterMapper {
long countByExample(ProjectParameterExample example);
int deleteByExample(ProjectParameterExample example);
int deleteByPrimaryKey(String id);
int insert(ProjectParameter record);
int insertSelective(ProjectParameter record);
List<ProjectParameter> selectByExampleWithBLOBs(ProjectParameterExample example);
List<ProjectParameter> selectByExample(ProjectParameterExample example);
ProjectParameter selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") ProjectParameter record, @Param("example") ProjectParameterExample example);
int updateByExampleWithBLOBs(@Param("record") ProjectParameter record, @Param("example") ProjectParameterExample example);
int updateByExample(@Param("record") ProjectParameter record, @Param("example") ProjectParameterExample example);
int updateByPrimaryKeySelective(ProjectParameter record);
int updateByPrimaryKeyWithBLOBs(ProjectParameter record);
int updateByPrimaryKey(ProjectParameter record);
int batchInsert(@Param("list") List<ProjectParameter> list);
int batchInsertSelective(@Param("list") List<ProjectParameter> list, @Param("selective") ProjectParameter.Column... selective);
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!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.sdk.mapper.ProjectParametersMapper"> <mapper namespace="io.metersphere.sdk.mapper.ProjectParameterMapper">
<resultMap id="BaseResultMap" type="io.metersphere.sdk.domain.ProjectParameters"> <resultMap id="BaseResultMap" type="io.metersphere.sdk.domain.ProjectParameter">
<id column="id" jdbcType="VARCHAR" property="id" /> <id column="id" jdbcType="VARCHAR" property="id" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" /> <result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" /> <result column="create_user" jdbcType="VARCHAR" property="createUser" />
@ -9,7 +9,7 @@
<result column="create_time" jdbcType="BIGINT" property="createTime" /> <result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" /> <result column="update_time" jdbcType="BIGINT" property="updateTime" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.sdk.domain.ProjectParameters"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.sdk.domain.ProjectParameter">
<result column="parameters" jdbcType="LONGVARBINARY" property="parameters" /> <result column="parameters" jdbcType="LONGVARBINARY" property="parameters" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
@ -76,7 +76,7 @@
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
`parameters` `parameters`
</sql> </sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.sdk.domain.ProjectParametersExample" resultMap="ResultMapWithBLOBs"> <select id="selectByExampleWithBLOBs" parameterType="io.metersphere.sdk.domain.ProjectParameterExample" resultMap="ResultMapWithBLOBs">
select select
<if test="distinct"> <if test="distinct">
distinct distinct
@ -84,7 +84,7 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
, ,
<include refid="Blob_Column_List" /> <include refid="Blob_Column_List" />
from project_parameters from project_parameter
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
@ -92,13 +92,13 @@
order by ${orderByClause} order by ${orderByClause}
</if> </if>
</select> </select>
<select id="selectByExample" parameterType="io.metersphere.sdk.domain.ProjectParametersExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.sdk.domain.ProjectParameterExample" resultMap="BaseResultMap">
select select
<if test="distinct"> <if test="distinct">
distinct distinct
</if> </if>
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from project_parameters from project_parameter
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
@ -111,29 +111,29 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
, ,
<include refid="Blob_Column_List" /> <include refid="Blob_Column_List" />
from project_parameters from project_parameter
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from project_parameters delete from project_parameter
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</delete> </delete>
<delete id="deleteByExample" parameterType="io.metersphere.sdk.domain.ProjectParametersExample"> <delete id="deleteByExample" parameterType="io.metersphere.sdk.domain.ProjectParameterExample">
delete from project_parameters delete from project_parameter
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.sdk.domain.ProjectParameters"> <insert id="insert" parameterType="io.metersphere.sdk.domain.ProjectParameter">
insert into project_parameters (id, project_id, create_user, insert into project_parameter (id, project_id, create_user,
update_user, create_time, update_time, update_user, create_time, update_time,
`parameters`) `parameters`)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
#{updateUser,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{parameters,jdbcType=LONGVARBINARY}) #{parameters,jdbcType=LONGVARBINARY})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.sdk.domain.ProjectParameters"> <insert id="insertSelective" parameterType="io.metersphere.sdk.domain.ProjectParameter">
insert into project_parameters insert into project_parameter
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
id, id,
@ -181,14 +181,14 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.sdk.domain.ProjectParametersExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.metersphere.sdk.domain.ProjectParameterExample" resultType="java.lang.Long">
select count(*) from project_parameters select count(*) from project_parameter
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
</select> </select>
<update id="updateByExampleSelective" parameterType="map"> <update id="updateByExampleSelective" parameterType="map">
update project_parameters update project_parameter
<set> <set>
<if test="record.id != null"> <if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR}, id = #{record.id,jdbcType=VARCHAR},
@ -217,7 +217,7 @@
</if> </if>
</update> </update>
<update id="updateByExampleWithBLOBs" parameterType="map"> <update id="updateByExampleWithBLOBs" parameterType="map">
update project_parameters update project_parameter
set id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR},
create_user = #{record.createUser,jdbcType=VARCHAR}, create_user = #{record.createUser,jdbcType=VARCHAR},
@ -230,7 +230,7 @@
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
update project_parameters update project_parameter
set id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR},
create_user = #{record.createUser,jdbcType=VARCHAR}, create_user = #{record.createUser,jdbcType=VARCHAR},
@ -241,8 +241,8 @@
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.sdk.domain.ProjectParameters"> <update id="updateByPrimaryKeySelective" parameterType="io.metersphere.sdk.domain.ProjectParameter">
update project_parameters update project_parameter
<set> <set>
<if test="projectId != null"> <if test="projectId != null">
project_id = #{projectId,jdbcType=VARCHAR}, project_id = #{projectId,jdbcType=VARCHAR},
@ -265,8 +265,8 @@
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.sdk.domain.ProjectParameters"> <update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.sdk.domain.ProjectParameter">
update project_parameters update project_parameter
set project_id = #{projectId,jdbcType=VARCHAR}, set project_id = #{projectId,jdbcType=VARCHAR},
create_user = #{createUser,jdbcType=VARCHAR}, create_user = #{createUser,jdbcType=VARCHAR},
update_user = #{updateUser,jdbcType=VARCHAR}, update_user = #{updateUser,jdbcType=VARCHAR},
@ -275,8 +275,8 @@
`parameters` = #{parameters,jdbcType=LONGVARBINARY} `parameters` = #{parameters,jdbcType=LONGVARBINARY}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.sdk.domain.ProjectParameters"> <update id="updateByPrimaryKey" parameterType="io.metersphere.sdk.domain.ProjectParameter">
update project_parameters update project_parameter
set project_id = #{projectId,jdbcType=VARCHAR}, set project_id = #{projectId,jdbcType=VARCHAR},
create_user = #{createUser,jdbcType=VARCHAR}, create_user = #{createUser,jdbcType=VARCHAR},
update_user = #{updateUser,jdbcType=VARCHAR}, update_user = #{updateUser,jdbcType=VARCHAR},
@ -285,7 +285,7 @@
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<insert id="batchInsert" parameterType="map"> <insert id="batchInsert" parameterType="map">
insert into project_parameters insert into project_parameter
(id, project_id, create_user, update_user, create_time, update_time, `parameters` (id, project_id, create_user, update_user, create_time, update_time, `parameters`
) )
values values
@ -296,7 +296,7 @@
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertSelective" parameterType="map"> <insert id="batchInsertSelective" parameterType="map">
insert into project_parameters ( insert into project_parameter (
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
${column.escapedColumnName} ${column.escapedColumnName}
</foreach> </foreach>

View File

@ -1,40 +0,0 @@
package io.metersphere.sdk.mapper;
import io.metersphere.sdk.domain.ProjectParameters;
import io.metersphere.sdk.domain.ProjectParametersExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface ProjectParametersMapper {
long countByExample(ProjectParametersExample example);
int deleteByExample(ProjectParametersExample example);
int deleteByPrimaryKey(String id);
int insert(ProjectParameters record);
int insertSelective(ProjectParameters record);
List<ProjectParameters> selectByExampleWithBLOBs(ProjectParametersExample example);
List<ProjectParameters> selectByExample(ProjectParametersExample example);
ProjectParameters selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") ProjectParameters record, @Param("example") ProjectParametersExample example);
int updateByExampleWithBLOBs(@Param("record") ProjectParameters record, @Param("example") ProjectParametersExample example);
int updateByExample(@Param("record") ProjectParameters record, @Param("example") ProjectParametersExample example);
int updateByPrimaryKeySelective(ProjectParameters record);
int updateByPrimaryKeyWithBLOBs(ProjectParameters record);
int updateByPrimaryKey(ProjectParameters record);
int batchInsert(@Param("list") List<ProjectParameters> list);
int batchInsertSelective(@Param("list") List<ProjectParameters> list, @Param("selective") ProjectParameters.Column ... selective);
}

View File

@ -103,7 +103,7 @@ CREATE INDEX idx_environment_group_id ON environment_group_relation(environment_
CREATE INDEX idx_environment_id ON environment_group_relation(environment_id); CREATE INDEX idx_environment_id ON environment_group_relation(environment_id);
CREATE INDEX idx_project_id ON environment_group_relation(project_id); CREATE INDEX idx_project_id ON environment_group_relation(project_id);
CREATE TABLE IF NOT EXISTS project_parameters( CREATE TABLE IF NOT EXISTS project_parameter(
`id` VARCHAR(50) NOT NULL COMMENT 'ID' , `id` VARCHAR(50) NOT NULL COMMENT 'ID' ,
`project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' , `project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' ,
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人' , `create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS project_parameters(
DEFAULT CHARSET = utf8mb4 DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '项目级参数'; COLLATE = utf8mb4_general_ci COMMENT = '项目级参数';
CREATE INDEX idx_project_id ON project_parameters(project_id); CREATE INDEX idx_project_id ON project_parameter(project_id);
CREATE TABLE IF NOT EXISTS worker_node CREATE TABLE IF NOT EXISTS worker_node

View File

@ -0,0 +1,5 @@
package io.metersphere.api.constants;
public enum ModuleStatus {
All, None, Current
}

View File

@ -3,6 +3,8 @@ package io.metersphere.api.controller.definition;
import io.metersphere.api.dto.debug.ModuleCreateRequest; import io.metersphere.api.dto.debug.ModuleCreateRequest;
import io.metersphere.api.dto.debug.ModuleUpdateRequest; import io.metersphere.api.dto.debug.ModuleUpdateRequest;
import io.metersphere.api.dto.definition.ApiModuleRequest; import io.metersphere.api.dto.definition.ApiModuleRequest;
import io.metersphere.api.dto.definition.EnvApiModuleRequest;
import io.metersphere.api.dto.definition.EnvApiTreeDTO;
import io.metersphere.api.service.definition.ApiDefinitionModuleService; import io.metersphere.api.service.definition.ApiDefinitionModuleService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.BaseTreeNode;
@ -89,4 +91,10 @@ public class ApiDefinitionModuleController {
public List<BaseTreeNode> getTrashTree(@RequestBody @Validated ApiModuleRequest request) { public List<BaseTreeNode> getTrashTree(@RequestBody @Validated ApiModuleRequest request) {
return apiDefinitionModuleService.getTrashTree(request, true); return apiDefinitionModuleService.getTrashTree(request, true);
} }
@PostMapping("/env/tree")
@Operation(summary = "获取环境中的接口树和选中的模块")
public EnvApiTreeDTO envTree(@RequestBody @Validated EnvApiModuleRequest request) {
return apiDefinitionModuleService.envTree(request);
}
} }

View File

@ -0,0 +1,14 @@
package io.metersphere.api.dto.definition;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class ApiModuleDTO {
@Schema(description = "模块ID")
private String id;
@Schema(description = "id的状态 None:手动选 Current:选中当前 All:全选中")
private String status;
@Schema(description = "是否禁用")
private Boolean disabled = false;
}

View File

@ -0,0 +1,18 @@
package io.metersphere.api.dto.definition;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.util.List;
@Data
public class EnvApiModuleRequest {
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_definition_module.project_id.not_blank}")
private String projectId;
@Schema(description = "关键字")
private List<ApiModuleDTO> selectedModules;
}

View File

@ -0,0 +1,16 @@
package io.metersphere.api.dto.definition;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
public class EnvApiTreeDTO {
@Schema(description = "模块树")
private List<BaseTreeNode> moduleTree;
@Schema(description = "选中的id")
private List<ApiModuleDTO> selectedModules;
}

View File

@ -39,4 +39,5 @@ public interface ExtApiDefinitionModuleMapper {
List<ModuleCountDTO> countModuleIdByProviderRequest(@Param("table") String resourceType, @Param("sourceName") String sourceName, @Param("apiCaseColumnName") String apiCaseColumnName, @Param("request") AssociateCaseModuleProviderRequest request, @Param("deleted") boolean deleted); List<ModuleCountDTO> countModuleIdByProviderRequest(@Param("table") String resourceType, @Param("sourceName") String sourceName, @Param("apiCaseColumnName") String apiCaseColumnName, @Param("request") AssociateCaseModuleProviderRequest request, @Param("deleted") boolean deleted);
List<BaseTreeNode> selectIdAndParentIdByProviderRequest(@Param("request") AssociateCaseModuleProviderRequest request); List<BaseTreeNode> selectIdAndParentIdByProviderRequest(@Param("request") AssociateCaseModuleProviderRequest request);
} }

View File

@ -1,11 +1,15 @@
package io.metersphere.api.service.definition; package io.metersphere.api.service.definition;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.api.constants.ModuleStatus;
import io.metersphere.api.domain.*; import io.metersphere.api.domain.*;
import io.metersphere.api.dto.debug.ApiTreeNode; import io.metersphere.api.dto.debug.ApiTreeNode;
import io.metersphere.api.dto.debug.ModuleCreateRequest; import io.metersphere.api.dto.debug.ModuleCreateRequest;
import io.metersphere.api.dto.debug.ModuleUpdateRequest; import io.metersphere.api.dto.debug.ModuleUpdateRequest;
import io.metersphere.api.dto.definition.ApiModuleDTO;
import io.metersphere.api.dto.definition.ApiModuleRequest; import io.metersphere.api.dto.definition.ApiModuleRequest;
import io.metersphere.api.dto.definition.EnvApiModuleRequest;
import io.metersphere.api.dto.definition.EnvApiTreeDTO;
import io.metersphere.api.mapper.*; import io.metersphere.api.mapper.*;
import io.metersphere.api.service.debug.ApiDebugModuleService; import io.metersphere.api.service.debug.ApiDebugModuleService;
import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.dto.ModuleCountDTO;
@ -30,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -283,4 +288,58 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted); List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted);
return apiDebugModuleService.getBaseTreeNodes(apiTreeNodeList, baseTreeNodes); return apiDebugModuleService.getBaseTreeNodes(apiTreeNodeList, baseTreeNodes);
} }
public EnvApiTreeDTO envTree(EnvApiModuleRequest request) {
EnvApiTreeDTO envApiTreeDTO = new EnvApiTreeDTO();
ApiModuleRequest apiModuleRequest = new ApiModuleRequest();
apiModuleRequest.setProjectId(request.getProjectId());
apiModuleRequest.setProtocol(ModuleConstants.NODE_PROTOCOL_HTTP);
List<BaseTreeNode> fileModuleList = extApiDefinitionModuleMapper.selectBaseByRequest(apiModuleRequest);
List<BaseTreeNode> baseTreeNodes = super.buildTreeAndCountResource(fileModuleList, true, Translator.get(UNPLANNED_API));
envApiTreeDTO.setModuleTree(baseTreeNodes);
//根据选择的模块id 来补充选中的id
List<ApiModuleDTO> selectedModules = request.getSelectedModules();
List<ApiModuleDTO> currentModules = new ArrayList<>();
if (CollectionUtils.isNotEmpty(selectedModules)) {
//将选中的模块id转换为Map 方便后面的查询 key为id
Map<String, ApiModuleDTO> selectedModuleMap = selectedModules.stream().collect(Collectors.toMap(ApiModuleDTO::getId, apiModuleDTO -> apiModuleDTO));
getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap);
}
envApiTreeDTO.setSelectedModules(currentModules);
return envApiTreeDTO;
}
public void getAllModuleIds(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules, Map<String, ApiModuleDTO> selectedModuleMap) {
baseTreeNodes.forEach(baseTreeNode -> {
if (selectedModuleMap.containsKey(baseTreeNode.getId())) {
ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId());
if (StringUtils.equals(apiModuleDTO.getStatus(), ModuleStatus.All.name())) {
currentModules.add(apiModuleDTO);
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
setChildren(baseTreeNode.getChildren(), currentModules);
}
} else {
currentModules.add(apiModuleDTO);
}
}
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
getAllModuleIds(baseTreeNode.getChildren(), currentModules, selectedModuleMap);
}
});
}
public void setChildren(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules) {
baseTreeNodes.forEach(baseTreeNode -> {
ApiModuleDTO children = new ApiModuleDTO();
children.setId(baseTreeNode.getId());
children.setStatus(ModuleStatus.All.name());
children.setDisabled(true);
currentModules.add(children);
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
setChildren(baseTreeNode.getChildren(), currentModules);
}
});
}
} }

View File

@ -4,7 +4,10 @@ import io.metersphere.api.domain.*;
import io.metersphere.api.dto.debug.ApiDebugRequest; import io.metersphere.api.dto.debug.ApiDebugRequest;
import io.metersphere.api.dto.debug.ModuleCreateRequest; import io.metersphere.api.dto.debug.ModuleCreateRequest;
import io.metersphere.api.dto.debug.ModuleUpdateRequest; import io.metersphere.api.dto.debug.ModuleUpdateRequest;
import io.metersphere.api.dto.definition.ApiModuleDTO;
import io.metersphere.api.dto.definition.ApiModuleRequest; import io.metersphere.api.dto.definition.ApiModuleRequest;
import io.metersphere.api.dto.definition.EnvApiModuleRequest;
import io.metersphere.api.dto.definition.EnvApiTreeDTO;
import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.mapper.*; import io.metersphere.api.mapper.*;
import io.metersphere.api.service.definition.ApiDefinitionModuleService; import io.metersphere.api.service.definition.ApiDefinitionModuleService;
@ -868,6 +871,53 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, URL_MODULE_TRASH_COUNT, request); requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, URL_MODULE_TRASH_COUNT, request);
} }
@Test
@Order(13)
public void getTree() throws Exception {
MvcResult result = this.requestPostWithOkAndReturn("/api/definition/module/env/tree", new EnvApiModuleRequest() {{
this.setProjectId(project.getId());
}});
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
EnvApiTreeDTO envApiTreeDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), EnvApiTreeDTO.class);
List<BaseTreeNode> baseTreeNodes = envApiTreeDTO.getModuleTree();
List<ApiModuleDTO> apiModuleDTOS = new ArrayList<>();
BaseTreeNode a1a1Node = getNodeByName(baseTreeNodes, "500-test-root-20");
assert a1a1Node != null;
ApiModuleDTO apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a1a1Node.getId());
apiModuleDTO.setStatus("None");
apiModuleDTOS.add(apiModuleDTO);
BaseTreeNode a40Node = getNodeByName(baseTreeNodes, "500-test-root-40");
assert a40Node != null;
apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a40Node.getId());
apiModuleDTO.setStatus("All");
apiModuleDTOS.add(apiModuleDTO);
BaseTreeNode a50Node = getNodeByName(baseTreeNodes, "500-test-root-50");
assert a50Node != null;
apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a50Node.getId());
apiModuleDTO.setStatus("Current");
apiModuleDTOS.add(apiModuleDTO);
BaseTreeNode a100Node = getNodeByName(baseTreeNodes, "500-test-root-100");
assert a100Node != null;
apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a100Node.getId());
apiModuleDTO.setStatus("All");
apiModuleDTOS.add(apiModuleDTO);
result = this.requestPostWithOkAndReturn("/api/definition/module/env/tree", new EnvApiModuleRequest() {{
this.setProjectId(project.getId());
this.setSelectedModules(apiModuleDTOS);
}});
returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
envApiTreeDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), EnvApiTreeDTO.class);
envApiTreeDTO.getModuleTree();
envApiTreeDTO.getSelectedModules();
}
private List<BaseTreeNode> getModuleTreeNode() throws Exception { private List<BaseTreeNode> getModuleTreeNode() throws Exception {
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_TREE, new ApiModuleRequest() {{ MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_TREE, new ApiModuleRequest() {{

View File

@ -5,7 +5,7 @@ import io.metersphere.project.dto.environment.GlobalParamsRequest;
import io.metersphere.project.service.GlobalParamsLogService; import io.metersphere.project.service.GlobalParamsLogService;
import io.metersphere.project.service.GlobalParamsService; import io.metersphere.project.service.GlobalParamsService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.domain.ProjectParameters; import io.metersphere.sdk.domain.ProjectParameter;
import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
@ -32,7 +32,7 @@ public class GlobalParamsController {
@Operation(summary = "项目管理-环境-全局参数-新增") @Operation(summary = "项目管理-环境-全局参数-新增")
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_ADD) @RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_ADD)
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = GlobalParamsLogService.class) @Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = GlobalParamsLogService.class)
public ProjectParameters add(@Validated({Created.class}) @RequestBody GlobalParamsRequest request) { public ProjectParameter add(@Validated({Created.class}) @RequestBody GlobalParamsRequest request) {
return globalParamsService.add(request, SessionUtils.getUserId()); return globalParamsService.add(request, SessionUtils.getUserId());
} }
@ -40,7 +40,7 @@ public class GlobalParamsController {
@Operation(summary = "项目管理-环境-全局参数-修改") @Operation(summary = "项目管理-环境-全局参数-修改")
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_UPDATE) @RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = GlobalParamsLogService.class) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = GlobalParamsLogService.class)
public ProjectParameters update(@Validated({Updated.class}) @RequestBody GlobalParamsRequest request) { public ProjectParameter update(@Validated({Updated.class}) @RequestBody GlobalParamsRequest request) {
return globalParamsService.update(request, SessionUtils.getUserId()); return globalParamsService.update(request, SessionUtils.getUserId());
} }

View File

@ -17,7 +17,7 @@ public class CleanupEnvironmentResourceService implements CleanupProjectResource
@Resource @Resource
private EnvironmentBlobMapper environmentBlobMapper; private EnvironmentBlobMapper environmentBlobMapper;
@Resource @Resource
private ProjectParametersMapper projectParametersMapper; private ProjectParameterMapper projectParametersMapper;
@Resource @Resource
private EnvironmentGroupMapper environmentGroupMapper; private EnvironmentGroupMapper environmentGroupMapper;
@Resource @Resource
@ -29,7 +29,7 @@ public class CleanupEnvironmentResourceService implements CleanupProjectResource
environmentExample.createCriteria().andProjectIdEqualTo(projectId); environmentExample.createCriteria().andProjectIdEqualTo(projectId);
environmentMapper.deleteByExample(environmentExample); environmentMapper.deleteByExample(environmentExample);
environmentBlobMapper.deleteByPrimaryKey(projectId); environmentBlobMapper.deleteByPrimaryKey(projectId);
ProjectParametersExample projectExample = new ProjectParametersExample(); ProjectParameterExample projectExample = new ProjectParameterExample();
projectExample.createCriteria().andProjectIdEqualTo(projectId); projectExample.createCriteria().andProjectIdEqualTo(projectId);
projectParametersMapper.deleteByExample(projectExample); projectParametersMapper.deleteByExample(projectExample);
EnvironmentGroupExample environmentGroupExample = new EnvironmentGroupExample(); EnvironmentGroupExample environmentGroupExample = new EnvironmentGroupExample();

View File

@ -17,7 +17,6 @@ import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.mapper.EnvironmentBlobMapper; import io.metersphere.sdk.mapper.EnvironmentBlobMapper;
import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.mapper.EnvironmentMapper;
import io.metersphere.sdk.mapper.ProjectParametersMapper;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
@ -68,8 +67,6 @@ public class EnvironmentService {
@Resource @Resource
private ExtEnvironmentMapper extEnvironmentMapper; private ExtEnvironmentMapper extEnvironmentMapper;
public static final Long ORDER_STEP = 5000L; public static final Long ORDER_STEP = 5000L;
@Resource
private ProjectParametersMapper projectParametersMapper;
private static final String USERNAME = "user"; private static final String USERNAME = "user";
private static final String PASSWORD = "password"; private static final String PASSWORD = "password";

View File

@ -3,13 +3,12 @@ package io.metersphere.project.service;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.project.dto.environment.GlobalParamsRequest; import io.metersphere.project.dto.environment.GlobalParamsRequest;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.domain.ProjectParameters; import io.metersphere.sdk.domain.ProjectParameter;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.sdk.mapper.ProjectParameterMapper;
import io.metersphere.sdk.mapper.ProjectParametersMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -19,7 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
public class GlobalParamsLogService { public class GlobalParamsLogService {
@Resource @Resource
private ProjectParametersMapper projectParametersMapper; private ProjectParameterMapper projectParametersMapper;
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@ -49,7 +48,7 @@ public class GlobalParamsLogService {
OperationLogType.UPDATE.name(), OperationLogType.UPDATE.name(),
OperationLogModule.PROJECT_MANAGEMENT_ENVIRONMENT, OperationLogModule.PROJECT_MANAGEMENT_ENVIRONMENT,
null); null);
ProjectParameters projectParameters = projectParametersMapper.selectByPrimaryKey(request.getId()); ProjectParameter projectParameters = projectParametersMapper.selectByPrimaryKey(request.getId());
dto.setOriginalValue(projectParameters.getParameters()); dto.setOriginalValue(projectParameters.getParameters());
dto.setModifiedValue(JSON.toJSONBytes(request.getGlobalParams())); dto.setModifiedValue(JSON.toJSONBytes(request.getGlobalParams()));
return dto; return dto;

View File

@ -5,10 +5,10 @@ import io.metersphere.project.dto.environment.GlobalParams;
import io.metersphere.project.dto.environment.GlobalParamsDTO; import io.metersphere.project.dto.environment.GlobalParamsDTO;
import io.metersphere.project.dto.environment.GlobalParamsRequest; import io.metersphere.project.dto.environment.GlobalParamsRequest;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.domain.ProjectParameters; import io.metersphere.sdk.domain.ProjectParameter;
import io.metersphere.sdk.domain.ProjectParametersExample; import io.metersphere.sdk.domain.ProjectParameterExample;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.mapper.ProjectParametersMapper; import io.metersphere.sdk.mapper.ProjectParameterMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
@ -32,57 +32,57 @@ import java.util.List;
public class GlobalParamsService { public class GlobalParamsService {
@Resource @Resource
private ProjectParametersMapper projectParametersMapper; private ProjectParameterMapper projectParameterMapper;
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
public ProjectParameters add(GlobalParamsRequest globalParamsRequest, String userId) { public ProjectParameter add(GlobalParamsRequest globalParamsRequest, String userId) {
ProjectParameters projectParameters = new ProjectParameters(); ProjectParameter projectParameter = new ProjectParameter();
projectParameters.setProjectId(globalParamsRequest.getProjectId()); projectParameter.setProjectId(globalParamsRequest.getProjectId());
checkExist(globalParamsRequest.getProjectId()); checkExist(globalParamsRequest.getProjectId());
checkProjectExist(globalParamsRequest.getProjectId()); checkProjectExist(globalParamsRequest.getProjectId());
projectParameters.setId(IDGenerator.nextStr()); projectParameter.setId(IDGenerator.nextStr());
projectParameters.setCreateUser(userId); projectParameter.setCreateUser(userId);
projectParameters.setUpdateUser(userId); projectParameter.setUpdateUser(userId);
projectParameters.setCreateTime(System.currentTimeMillis()); projectParameter.setCreateTime(System.currentTimeMillis());
projectParameters.setUpdateTime(System.currentTimeMillis()); projectParameter.setUpdateTime(System.currentTimeMillis());
projectParameters.setParameters(JSON.toJSONBytes(globalParamsRequest.getGlobalParams())); projectParameter.setParameters(JSON.toJSONBytes(globalParamsRequest.getGlobalParams()));
projectParametersMapper.insert(projectParameters); projectParameterMapper.insert(projectParameter);
globalParamsRequest.setId(projectParameters.getId()); globalParamsRequest.setId(projectParameter.getId());
return projectParameters; return projectParameter;
} }
public ProjectParameters update(GlobalParamsRequest globalParamsRequest, String userId) { public ProjectParameter update(GlobalParamsRequest globalParamsRequest, String userId) {
ProjectParameters projectParameters = new ProjectParameters(); ProjectParameter projectParameter = new ProjectParameter();
projectParameters.setProjectId(globalParamsRequest.getProjectId()); projectParameter.setProjectId(globalParamsRequest.getProjectId());
checkDataExist(globalParamsRequest.getProjectId()); checkDataExist(globalParamsRequest.getProjectId());
checkProjectExist(globalParamsRequest.getProjectId()); checkProjectExist(globalParamsRequest.getProjectId());
projectParameters.setId(globalParamsRequest.getId()); projectParameter.setId(globalParamsRequest.getId());
projectParameters.setUpdateUser(userId); projectParameter.setUpdateUser(userId);
projectParameters.setUpdateTime(System.currentTimeMillis()); projectParameter.setUpdateTime(System.currentTimeMillis());
projectParameters.setParameters(JSON.toJSONBytes(globalParamsRequest.getGlobalParams())); projectParameter.setParameters(JSON.toJSONBytes(globalParamsRequest.getGlobalParams()));
projectParametersMapper.updateByPrimaryKeySelective(projectParameters); projectParameterMapper.updateByPrimaryKeySelective(projectParameter);
return projectParameters; return projectParameter;
} }
private void checkDataExist(String projectId) { private void checkDataExist(String projectId) {
ProjectParametersExample example = new ProjectParametersExample(); ProjectParameterExample example = new ProjectParameterExample();
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
List<ProjectParameters> projectParameters = projectParametersMapper.selectByExample(example); List<ProjectParameter> projectParameter = projectParameterMapper.selectByExample(example);
if (projectParameters.isEmpty()) { if (projectParameter.isEmpty()) {
throw new MSException(Translator.get("global_parameters_is_not_exist")); throw new MSException(Translator.get("global_parameters_is_not_exist"));
} }
} }
public GlobalParamsDTO get(String projectId) { public GlobalParamsDTO get(String projectId) {
ProjectParametersExample example = new ProjectParametersExample(); ProjectParameterExample example = new ProjectParameterExample();
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
List<ProjectParameters> projectParametersList = projectParametersMapper.selectByExampleWithBLOBs(example); List<ProjectParameter> projectParameters = projectParameterMapper.selectByExampleWithBLOBs(example);
if (CollectionUtils.isNotEmpty(projectParametersList)) { if (CollectionUtils.isNotEmpty(projectParameters)) {
GlobalParamsDTO globalParamsDTO = new GlobalParamsDTO(); GlobalParamsDTO globalParamsDTO = new GlobalParamsDTO();
globalParamsDTO.setProjectId(projectId); globalParamsDTO.setProjectId(projectId);
globalParamsDTO.setId(projectParametersList.get(0).getId()); globalParamsDTO.setId(projectParameters.get(0).getId());
globalParamsDTO.setGlobalParams(JSON.parseObject(new String(projectParametersList.get(0).getParameters()), GlobalParams.class)); globalParamsDTO.setGlobalParams(JSON.parseObject(new String(projectParameters.get(0).getParameters()), GlobalParams.class));
return globalParamsDTO; return globalParamsDTO;
} else { } else {
return null; return null;
@ -91,9 +91,9 @@ public class GlobalParamsService {
} }
private void checkExist(String projectId) { private void checkExist(String projectId) {
ProjectParametersExample example = new ProjectParametersExample(); ProjectParameterExample example = new ProjectParameterExample();
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
List<ProjectParameters> projectParameters = projectParametersMapper.selectByExample(example); List<ProjectParameter> projectParameters = projectParameterMapper.selectByExample(example);
if (!projectParameters.isEmpty()) { if (!projectParameters.isEmpty()) {
throw new MSException(Translator.get("global_parameters_already_exist")); throw new MSException(Translator.get("global_parameters_already_exist"));
} }
@ -109,9 +109,9 @@ public class GlobalParamsService {
try { try {
Project project = projectMapper.selectByPrimaryKey(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
//查询全局参数 //查询全局参数
ProjectParametersExample projectParametersExample = new ProjectParametersExample(); ProjectParameterExample projectParameterExample = new ProjectParameterExample();
projectParametersExample.createCriteria().andProjectIdEqualTo(projectId); projectParameterExample.createCriteria().andProjectIdEqualTo(projectId);
List<ProjectParameters> projectParameters = projectParametersMapper.selectByExampleWithBLOBs(projectParametersExample); List<ProjectParameter> projectParameters = projectParameterMapper.selectByExampleWithBLOBs(projectParameterExample);
byte[] bytes = new byte[0]; byte[] bytes = new byte[0];
if (CollectionUtils.isNotEmpty(projectParameters)) { if (CollectionUtils.isNotEmpty(projectParameters)) {
GlobalParamsDTO globalParamsDTO = new GlobalParamsDTO(); GlobalParamsDTO globalParamsDTO = new GlobalParamsDTO();
@ -141,20 +141,20 @@ public class GlobalParamsService {
inputStream.close(); inputStream.close();
//参数是一个对象 //参数是一个对象
GlobalParamsDTO globalParamsDTO = JSON.parseObject(content, GlobalParamsDTO.class); GlobalParamsDTO globalParamsDTO = JSON.parseObject(content, GlobalParamsDTO.class);
ProjectParametersExample projectParametersExample = new ProjectParametersExample(); ProjectParameterExample projectParameterExample = new ProjectParameterExample();
projectParametersExample.createCriteria().andProjectIdEqualTo(currentProjectId); projectParameterExample.createCriteria().andProjectIdEqualTo(currentProjectId);
if (projectParametersMapper.countByExample(projectParametersExample) > 0) { if (projectParameterMapper.countByExample(projectParameterExample) > 0) {
projectParametersMapper.deleteByExample(projectParametersExample); projectParameterMapper.deleteByExample(projectParameterExample);
} }
ProjectParameters projectParameters = new ProjectParameters(); ProjectParameter projectParameter = new ProjectParameter();
projectParameters.setId(IDGenerator.nextStr()); projectParameter.setId(IDGenerator.nextStr());
projectParameters.setProjectId(currentProjectId); projectParameter.setProjectId(currentProjectId);
projectParameters.setCreateUser(userId); projectParameter.setCreateUser(userId);
projectParameters.setUpdateUser(userId); projectParameter.setUpdateUser(userId);
projectParameters.setCreateTime(System.currentTimeMillis()); projectParameter.setCreateTime(System.currentTimeMillis());
projectParameters.setUpdateTime(System.currentTimeMillis()); projectParameter.setUpdateTime(System.currentTimeMillis());
projectParameters.setParameters(JSON.toJSONBytes(globalParamsDTO.getGlobalParams())); projectParameter.setParameters(JSON.toJSONBytes(globalParamsDTO.getGlobalParams()));
projectParametersMapper.insert(projectParameters); projectParameterMapper.insert(projectParameter);
} catch (Exception e) { } catch (Exception e) {
LogUtils.error("获取文件输入流异常", e); LogUtils.error("获取文件输入流异常", e);
throw new RuntimeException("获取文件输入流异常", e); throw new RuntimeException("获取文件输入流异常", e);

View File

@ -27,7 +27,6 @@ import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.mapper.EnvironmentBlobMapper; import io.metersphere.sdk.mapper.EnvironmentBlobMapper;
import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.mapper.EnvironmentMapper;
import io.metersphere.sdk.mapper.ProjectParametersMapper;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
@ -96,8 +95,6 @@ public class EnvironmentControllerTests extends BaseTest {
private EnvironmentMapper environmentMapper; private EnvironmentMapper environmentMapper;
@Resource @Resource
private EnvironmentBlobMapper environmentBlobMapper; private EnvironmentBlobMapper environmentBlobMapper;
@Resource
private ProjectParametersMapper projectParametersMapper;
@Value("${spring.datasource.url}") @Value("${spring.datasource.url}")
private String dburl; private String dburl;
@Value("${spring.datasource.username}") @Value("${spring.datasource.username}")

View File

@ -10,9 +10,9 @@ import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.constants.VariableTypeConstants; import io.metersphere.sdk.constants.VariableTypeConstants;
import io.metersphere.sdk.domain.ProjectParameters; import io.metersphere.sdk.domain.ProjectParameter;
import io.metersphere.sdk.domain.ProjectParametersExample; import io.metersphere.sdk.domain.ProjectParameterExample;
import io.metersphere.sdk.mapper.ProjectParametersMapper; import io.metersphere.sdk.mapper.ProjectParameterMapper;
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;
@ -69,7 +69,7 @@ public class GlobalParamsControllerTests extends BaseTest {
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError(); private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
@Resource @Resource
private ProjectParametersMapper projectParametersMapper; private ProjectParameterMapper projectParametersMapper;
private final ProjectServiceInvoker serviceInvoker; private final ProjectServiceInvoker serviceInvoker;
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@ -260,9 +260,9 @@ public class GlobalParamsControllerTests extends BaseTest {
globalParams.setCommonVariables(getEnvVariables(1)); globalParams.setCommonVariables(getEnvVariables(1));
request.setGlobalParams(globalParams); request.setGlobalParams(globalParams);
MvcResult mvcResult = this.responsePost(add, request); MvcResult mvcResult = this.responsePost(add, request);
ProjectParameters globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameters.class); ProjectParameter globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameter.class);
Assertions.assertNotNull(globalParamsRequest); Assertions.assertNotNull(globalParamsRequest);
ProjectParameters projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId()); ProjectParameter projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId());
Assertions.assertNotNull(projectParameters); Assertions.assertNotNull(projectParameters);
Assertions.assertEquals("projectId1", projectParameters.getProjectId()); Assertions.assertEquals("projectId1", projectParameters.getProjectId());
Assertions.assertEquals(1, JSON.parseObject(new String(projectParameters.getParameters()), GlobalParams.class).getHeaders().size()); Assertions.assertEquals(1, JSON.parseObject(new String(projectParameters.getParameters()), GlobalParams.class).getHeaders().size());
@ -276,7 +276,7 @@ public class GlobalParamsControllerTests extends BaseTest {
globalParams.setCommonVariables(new ArrayList<>()); globalParams.setCommonVariables(new ArrayList<>());
request.setGlobalParams(globalParams); request.setGlobalParams(globalParams);
mvcResult = this.responsePost(add, request); mvcResult = this.responsePost(add, request);
globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameters.class); globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameter.class);
Assertions.assertNotNull(globalParamsRequest); Assertions.assertNotNull(globalParamsRequest);
projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId()); projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId());
Assertions.assertNotNull(projectParameters); Assertions.assertNotNull(projectParameters);
@ -292,7 +292,7 @@ public class GlobalParamsControllerTests extends BaseTest {
globalParams.setCommonVariables(getEnvVariables(1)); globalParams.setCommonVariables(getEnvVariables(1));
request.setGlobalParams(globalParams); request.setGlobalParams(globalParams);
mvcResult = this.responsePost(add, request); mvcResult = this.responsePost(add, request);
globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameters.class); globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameter.class);
Assertions.assertNotNull(globalParamsRequest); Assertions.assertNotNull(globalParamsRequest);
projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId()); projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId());
Assertions.assertNotNull(projectParameters); Assertions.assertNotNull(projectParameters);
@ -308,7 +308,7 @@ public class GlobalParamsControllerTests extends BaseTest {
globalParams.setCommonVariables(new ArrayList<>()); globalParams.setCommonVariables(new ArrayList<>());
request.setGlobalParams(globalParams); request.setGlobalParams(globalParams);
mvcResult = this.responsePost(add, request); mvcResult = this.responsePost(add, request);
globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameters.class); globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameter.class);
Assertions.assertNotNull(globalParamsRequest); Assertions.assertNotNull(globalParamsRequest);
projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId()); projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId());
Assertions.assertNotNull(projectParameters); Assertions.assertNotNull(projectParameters);
@ -320,7 +320,7 @@ public class GlobalParamsControllerTests extends BaseTest {
request.setProjectId("projectId5"); request.setProjectId("projectId5");
request.setGlobalParams(new GlobalParams()); request.setGlobalParams(new GlobalParams());
mvcResult = this.responsePost(add, request); mvcResult = this.responsePost(add, request);
globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameters.class); globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameter.class);
Assertions.assertNotNull(globalParamsRequest); Assertions.assertNotNull(globalParamsRequest);
//校验日志 //校验日志
checkLog(globalParamsRequest.getId(), OperationLogType.ADD); checkLog(globalParamsRequest.getId(), OperationLogType.ADD);
@ -363,9 +363,9 @@ public class GlobalParamsControllerTests extends BaseTest {
@Order(3) @Order(3)
public void testUpdateSuccess() throws Exception { public void testUpdateSuccess() throws Exception {
//修改全局参数 有headers 有envVariables //修改全局参数 有headers 有envVariables
ProjectParametersExample example = new ProjectParametersExample(); ProjectParameterExample example = new ProjectParameterExample();
example.createCriteria().andProjectIdEqualTo("projectId1"); example.createCriteria().andProjectIdEqualTo("projectId1");
List<ProjectParameters> projectParametersList = projectParametersMapper.selectByExample(example); List<ProjectParameter> projectParametersList = projectParametersMapper.selectByExample(example);
GlobalParamsRequest request = new GlobalParamsRequest(); GlobalParamsRequest request = new GlobalParamsRequest();
request.setProjectId("projectId1"); request.setProjectId("projectId1");
request.setId(projectParametersList.get(0).getId()); request.setId(projectParametersList.get(0).getId());
@ -374,11 +374,11 @@ public class GlobalParamsControllerTests extends BaseTest {
globalParams.setCommonVariables(getEnvVariables(2)); globalParams.setCommonVariables(getEnvVariables(2));
request.setGlobalParams(globalParams); request.setGlobalParams(globalParams);
MvcResult mvcResult = this.responsePost(update, request); MvcResult mvcResult = this.responsePost(update, request);
ProjectParameters globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameters.class); ProjectParameter globalParamsRequest = parseObjectFromMvcResult(mvcResult, ProjectParameter.class);
Assertions.assertNotNull(globalParamsRequest); Assertions.assertNotNull(globalParamsRequest);
//校验日志 //校验日志
checkLog(globalParamsRequest.getId(), OperationLogType.UPDATE); checkLog(globalParamsRequest.getId(), OperationLogType.UPDATE);
ProjectParameters projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId()); ProjectParameter projectParameters = projectParametersMapper.selectByPrimaryKey(globalParamsRequest.getId());
Assertions.assertNotNull(projectParameters); Assertions.assertNotNull(projectParameters);
Assertions.assertEquals("projectId1", projectParameters.getProjectId()); Assertions.assertEquals("projectId1", projectParameters.getProjectId());
Assertions.assertEquals(2, JSON.parseObject(new String(projectParameters.getParameters()), GlobalParams.class).getHeaders().size()); Assertions.assertEquals(2, JSON.parseObject(new String(projectParameters.getParameters()), GlobalParams.class).getHeaders().size());
@ -386,7 +386,7 @@ public class GlobalParamsControllerTests extends BaseTest {
//校验权限 //校验权限
request = new GlobalParamsRequest(); request = new GlobalParamsRequest();
example = new ProjectParametersExample(); example = new ProjectParameterExample();
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID); example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID);
projectParametersList = projectParametersMapper.selectByExample(example); projectParametersList = projectParametersMapper.selectByExample(example);
request.setProjectId(DEFAULT_PROJECT_ID); request.setProjectId(DEFAULT_PROJECT_ID);
@ -415,7 +415,7 @@ public class GlobalParamsControllerTests extends BaseTest {
request.setProjectId("projectId1111"); request.setProjectId("projectId1111");
this.requestPost(update, request, ERROR_REQUEST_MATCHER); this.requestPost(update, request, ERROR_REQUEST_MATCHER);
ProjectParametersExample example = new ProjectParametersExample(); ProjectParameterExample example = new ProjectParameterExample();
example.createCriteria().andProjectIdEqualTo("projectId2"); example.createCriteria().andProjectIdEqualTo("projectId2");
projectParametersMapper.deleteByExample(example); projectParametersMapper.deleteByExample(example);
// 修改全局参数 全局参数不存在 // 修改全局参数 全局参数不存在