refactor(功能用例): 注解修改

This commit is contained in:
guoyuqi 2023-11-28 13:20:01 +08:00 committed by 刘瑞斌
parent afd5d29a63
commit f69d3eaec3
33 changed files with 94 additions and 119 deletions

View File

@ -1,4 +1,4 @@
package io.metersphere.functional.dto;
package io.metersphere.functional.constants;
public enum CommentEnum {
CASE, TEST_PLAN, CASE_REVIEW

View File

@ -15,6 +15,7 @@ import io.metersphere.project.dto.CustomFieldOptions;
import io.metersphere.project.service.ProjectTemplateService;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.TemplateScene;
import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.dto.sdk.TemplateDTO;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;

View File

@ -2,8 +2,8 @@ package io.metersphere.functional.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@ -11,9 +11,8 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class AssociationDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "类型",allowableValues = {"EMPTY","NOT_EMPTY"})

View File

@ -3,7 +3,6 @@ package io.metersphere.functional.dto;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.List;
@ -12,11 +11,8 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class BaseFunctionalCaseBatchDTO extends TableBatchProcessDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "模块id")
private List<String> moduleIds;

View File

@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
@ -13,6 +14,7 @@ import java.util.Objects;
@Data
public class CaseCustomFieldDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "字段id")

View File

@ -1,7 +1,6 @@
package io.metersphere.functional.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.List;
@ -10,7 +9,6 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class CombineDTO implements Serializable {
private String id;

View File

@ -3,7 +3,6 @@ package io.metersphere.functional.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
@ -11,7 +10,6 @@ import java.io.Serializable;
* @author guoyuqi
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class DemandDTO implements Serializable {
@Schema(description = "需求ID")

View File

@ -1,14 +1,14 @@
package io.metersphere.functional.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = false)
public class FileUploadDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

View File

@ -2,17 +2,17 @@ package io.metersphere.functional.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseAttachmentDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "ID")

View File

@ -3,8 +3,8 @@ package io.metersphere.functional.dto;
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@ -12,9 +12,9 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseDetailDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "ID")

View File

@ -4,7 +4,6 @@ import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseCustomField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@ -12,7 +11,6 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCasePageDTO extends FunctionalCase {

View File

@ -2,17 +2,17 @@ package io.metersphere.functional.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseVersionDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "用例id")

View File

@ -3,17 +3,17 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author guoyuqi
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class CaseReviewFollowerRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "用户id", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -5,14 +5,12 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = false)
public class CaseReviewRequest implements Serializable {
@Serial

View File

@ -3,8 +3,8 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@ -13,9 +13,9 @@ import java.util.Map;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseAddRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "项目id", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -4,7 +4,6 @@ import io.metersphere.functional.dto.BaseFunctionalCaseBatchDTO;
import io.metersphere.functional.dto.CaseCustomFieldDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@ -12,7 +11,6 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseBatchEditRequest extends BaseFunctionalCaseBatchDTO {

View File

@ -2,13 +2,11 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseBatchMoveRequest extends FunctionalCaseBatchRequest {
@Schema(description = "模块ID", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -3,13 +3,11 @@ package io.metersphere.functional.request;
import io.metersphere.functional.dto.BaseFunctionalCaseBatchDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseBatchRequest extends BaseFunctionalCaseBatchDTO {

View File

@ -5,10 +5,8 @@ import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseCommentRequest {
@Schema(description = "评论ID", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -3,16 +3,16 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseDeleteRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "用例id", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -5,7 +5,6 @@ import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@ -13,7 +12,6 @@ import java.util.List;
* @author guoyuqi
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseDemandRequest {
@Schema(description = "功能用例需求关系ID")

View File

@ -3,7 +3,6 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@ -11,7 +10,6 @@ import java.util.List;
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseEditRequest extends FunctionalCaseAddRequest {
@Schema(description = "用例id", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -2,17 +2,17 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseFileRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "项目id",requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -3,17 +3,17 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCaseFollowerRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "用户id", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -5,17 +5,18 @@ import io.metersphere.system.dto.sdk.BasePageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FunctionalCasePageRequest extends BasePageRequest {
public class FunctionalCasePageRequest extends BasePageRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -3,17 +3,17 @@ package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class TemplateFieldsRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "模板id")

View File

@ -4,7 +4,7 @@ package io.metersphere.functional.service;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseComment;
import io.metersphere.functional.domain.FunctionalCaseCommentExample;
import io.metersphere.functional.dto.CommentEnum;
import io.metersphere.functional.constants.CommentEnum;
import io.metersphere.functional.dto.FunctionalCaseCommentDTO;
import io.metersphere.functional.dto.FunctionalCaseDTO;
import io.metersphere.functional.mapper.FunctionalCaseCommentMapper;

View File

@ -10,7 +10,6 @@ import io.metersphere.functional.mapper.FunctionalCaseFollowerMapper;
import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.functional.request.*;
import io.metersphere.functional.result.CaseManagementResultCode;
import io.metersphere.functional.util.ServiceUtils;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
@ -24,8 +23,10 @@ import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
import io.metersphere.system.dto.sdk.TemplateDTO;
import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@ -633,7 +634,7 @@ public class FunctionalCaseService {
}
public void editPos(PosRequest request) {
ServiceUtils.updateOrderField(request,
ServiceUtils.updatePosField(request,
FunctionalCase.class,
functionalCaseMapper::selectByPrimaryKey,
extFunctionalCaseMapper::getPrePos,

View File

@ -1,63 +0,0 @@
package io.metersphere.functional.util;
import io.metersphere.functional.constants.MoveTypeEnum;
import io.metersphere.functional.request.PosRequest;
import io.metersphere.sdk.exception.MSException;
import java.lang.reflect.Method;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
public class ServiceUtils {
public static final int POS_STEP = 5000;
public static <T> void updateOrderField(PosRequest request, Class<T> clazz,
Function<String, T> selectByPrimaryKeyFunc,
BiFunction<String, Long, Long> getPreOrderFunc,
BiFunction<String, Long, Long> getLastOrderFunc,
Consumer<T> updateByPrimaryKeySelectiveFuc) {
Long pos;
Long lastOrPrePos;
try {
Method getPos = clazz.getMethod("getPos");
Method setId = clazz.getMethod("setId", String.class);
Method setPos = clazz.getMethod("setPos", Long.class);
// 获取移动的参考对象
T target = selectByPrimaryKeyFunc.apply(request.getTargetId());
if (target == null) {
// 如果参考对象被删除则不处理
return;
}
Long targetOrder = (Long) getPos.invoke(target);
if (request.getMoveMode().equals(MoveTypeEnum.AFTER.name())) {
// 追加到参考对象的之后
pos = targetOrder - ServiceUtils.POS_STEP;
// 因为是降序排则查找比目标 order 小的一个order
lastOrPrePos = getPreOrderFunc.apply(request.getProjectId(), targetOrder);
} else {
// 追加到前面
pos = targetOrder + ServiceUtils.POS_STEP;
// 因为是降序排则查找比目标 order 更大的一个order
lastOrPrePos = getLastOrderFunc.apply(request.getProjectId(), targetOrder);
}
if (lastOrPrePos != null) {
// 如果不是第一个或最后一个则取中间值
pos = (targetOrder + lastOrPrePos) / 2;
}
// 更新order值
T updateObj = (T) clazz.getDeclaredConstructor().newInstance();
setId.invoke(updateObj, request.getMoveId());
setPos.invoke(updateObj, pos);
updateByPrimaryKeySelectiveFuc.accept(updateObj);
} catch (Exception e) {
throw new MSException("更新 order 字段失败");
}
}
}

View File

@ -16,6 +16,7 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.CustomField;
import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.utils.Pager;

View File

@ -1,4 +1,4 @@
package io.metersphere.functional.constants;
package io.metersphere.system.dto.sdk.enums;
/**
* @author wx

View File

@ -1,4 +1,4 @@
package io.metersphere.functional.request;
package io.metersphere.system.dto.sdk.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,11 +1,20 @@
package io.metersphere.system.utils;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.dto.sdk.enums.MoveTypeEnum;
import io.metersphere.system.dto.sdk.request.PosRequest;
import java.lang.reflect.Method;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND;
public class ServiceUtils {
public static final int POS_STEP = 5000;
/**
* 保存资源名称在处理 NOT_FOUND 异常时拼接资源名称
*/
@ -33,4 +42,52 @@ public class ServiceUtils {
public static void clearResourceName() {
resourceName.remove();
}
public static <T> void updatePosField(PosRequest request, Class<T> clazz,
Function<String, T> selectByPrimaryKeyFunc,
BiFunction<String, Long, Long> getPrePosFunc,
BiFunction<String, Long, Long> getLastPosFunc,
Consumer<T> updateByPrimaryKeySelectiveFuc) {
Long pos;
Long lastOrPrePos;
try {
Method getPos = clazz.getMethod("getPos");
Method setId = clazz.getMethod("setId", String.class);
Method setPos = clazz.getMethod("setPos", Long.class);
// 获取移动的参考对象
T target = selectByPrimaryKeyFunc.apply(request.getTargetId());
if (target == null) {
// 如果参考对象被删除则不处理
return;
}
Long targetPos = (Long) getPos.invoke(target);
if (request.getMoveMode().equals(MoveTypeEnum.AFTER.name())) {
// 追加到参考对象的之后
pos = targetPos - POS_STEP;
// 因为是降序排则查找比目标 order 小的一个order
lastOrPrePos = getPrePosFunc.apply(request.getProjectId(), targetPos);
} else {
// 追加到前面
pos = targetPos + POS_STEP;
// 因为是降序排则查找比目标 order 更大的一个order
lastOrPrePos = getLastPosFunc.apply(request.getProjectId(), targetPos);
}
if (lastOrPrePos != null) {
// 如果不是第一个或最后一个则取中间值
pos = (targetPos + lastOrPrePos) / 2;
}
// 更新order值
T updateObj = (T) clazz.getDeclaredConstructor().newInstance();
setId.invoke(updateObj, request.getMoveId());
setPos.invoke(updateObj, pos);
updateByPrimaryKeySelectiveFuc.accept(updateObj);
} catch (Exception e) {
throw new MSException("更新 pos 字段失败");
}
}
}