refactor(测试计划): 功能用例关联缺陷列表增加创建人

This commit is contained in:
wxg0103 2024-05-23 18:52:24 +08:00 committed by Craftsman
parent 1735124242
commit 705122cf87
4 changed files with 67 additions and 62 deletions

View File

@ -34,6 +34,9 @@ public class BugProviderDTO implements Serializable {
@Schema(description = "创建人") @Schema(description = "创建人")
private String createUser; private String createUser;
@Schema(description = "创建人名称")
private String createUserName;
@Schema(description = "处理人名称") @Schema(description = "处理人名称")
private String handleUserName; private String handleUserName;

View File

@ -475,11 +475,10 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
} }
if (modelByRef != null) { if (modelByRef != null) {
if (modelByRef instanceof ArraySchema arraySchema) { return switch (modelByRef) {
return parseArraySchema(arraySchema.getItems(), false); case ArraySchema arraySchema -> parseArraySchema(arraySchema.getItems(), false);
} else if (modelByRef instanceof ObjectSchema objectSchema) { case ObjectSchema objectSchema -> parseObject(objectSchema, false);
return parseObject(objectSchema, false); default -> {
} else {
JsonSchemaItem jsonSchemaItem = new JsonSchemaItem(); JsonSchemaItem jsonSchemaItem = new JsonSchemaItem();
Map<String, JsonSchemaItem> jsonSchemaProperties = new LinkedHashMap<>(); Map<String, JsonSchemaItem> jsonSchemaProperties = new LinkedHashMap<>();
if (MapUtils.isNotEmpty(modelByRef.getProperties())) { if (MapUtils.isNotEmpty(modelByRef.getProperties())) {
@ -489,10 +488,10 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
}); });
} }
jsonSchemaItem.setProperties(jsonSchemaProperties); jsonSchemaItem.setProperties(jsonSchemaProperties);
return jsonSchemaItem; yield jsonSchemaItem;
} }
};
} }
} }
return null; return null;
} }
@ -541,56 +540,49 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
} }
private JsonSchemaItem parseProperty(Schema<?> value, boolean onlyOnce) { private JsonSchemaItem parseProperty(Schema<?> value, boolean onlyOnce) {
if (value instanceof IntegerSchema integerSchema) { if (StringUtils.equals(value.getType(), PropertyConstant.NULL)) {
return parseInteger(integerSchema); return parseNull();
} }
if (value instanceof StringSchema stringSchema) {
return parseString(stringSchema); return switch (value) {
} case IntegerSchema integerSchema -> parseInteger(integerSchema);
if (value instanceof NumberSchema numberSchema) { case StringSchema stringSchema -> parseString(stringSchema);
return parseNumber(numberSchema); case NumberSchema numberSchema -> parseNumber(numberSchema);
} case BooleanSchema booleanSchema -> parseBoolean(booleanSchema);
if (value instanceof BooleanSchema booleanSchema) { case ArraySchema arraySchema -> {
return parseBoolean(booleanSchema);
}
if (value instanceof ArraySchema arraySchema) {
if (onlyOnce) { if (onlyOnce) {
JsonSchemaItem arrayItem = new JsonSchemaItem(); JsonSchemaItem arrayItem = new JsonSchemaItem();
arrayItem.setId(IDGenerator.nextStr()); arrayItem.setId(IDGenerator.nextStr());
arrayItem.setType(PropertyConstant.ARRAY); arrayItem.setType(PropertyConstant.ARRAY);
arrayItem.setItems(new JsonSchemaItem()); arrayItem.setItems(new JsonSchemaItem());
return arrayItem; yield arrayItem;
} }
return isRef(arraySchema.getItems(), 0) ? parseArraySchema(arraySchema.getItems(), true) : yield isRef(arraySchema.getItems(), 0) ? parseArraySchema(arraySchema.getItems(), true) :
parseArraySchema(arraySchema.getItems(), false); parseArraySchema(arraySchema.getItems(), false);
} }
if (value instanceof ObjectSchema objectSchema) { case ObjectSchema objectSchema -> {
if (onlyOnce) { if (onlyOnce) {
JsonSchemaItem objectItem = new JsonSchemaItem(); JsonSchemaItem objectItem = new JsonSchemaItem();
objectItem.setId(IDGenerator.nextStr()); objectItem.setId(IDGenerator.nextStr());
objectItem.setType(PropertyConstant.OBJECT); objectItem.setType(PropertyConstant.OBJECT);
objectItem.setProperties(new LinkedHashMap<>()); objectItem.setProperties(new LinkedHashMap<>());
return objectItem; yield objectItem;
} }
return isRef(objectSchema, 0) ? parseObject(objectSchema, true) : yield isRef(objectSchema, 0) ? parseObject(objectSchema, true) :
parseObject(objectSchema, false); parseObject(objectSchema, false);
} }
if (StringUtils.equals(value.getType(), PropertyConstant.NULL)) { case MapSchema mapSchema -> parseMapObject(mapSchema);
return parseNull(); case Schema<?> items -> {
}
if (value instanceof MapSchema mapSchema) {
return parseMapObject(mapSchema);
}
if (value instanceof Schema<?> items) {
if (isRef(items, 0)) { if (isRef(items, 0)) {
JsonSchemaItem arrayItem = new JsonSchemaItem(); JsonSchemaItem arrayItem = new JsonSchemaItem();
arrayItem.setId(IDGenerator.nextStr()); arrayItem.setId(IDGenerator.nextStr());
arrayItem.setType(PropertyConstant.OBJECT); arrayItem.setType(PropertyConstant.OBJECT);
return arrayItem; yield arrayItem;
} }
return parseSchema(items); yield parseSchema(items);
} }
return new JsonSchemaItem(); };
} }

View File

@ -131,6 +131,7 @@
b.num as num, b.num as num,
b.title as name, b.title as name,
b.handle_user handleUser, b.handle_user handleUser,
b.create_user createUser,
b.`status`, b.`status`,
bc.description as content, bc.description as content,
brc.test_plan_id testPlanId, brc.test_plan_id testPlanId,
@ -283,6 +284,7 @@
b.num as num, b.num as num,
b.title as name, b.title as name,
b.handle_user handleUser, b.handle_user handleUser,
b.create_user createUser,
b.`status`, b.`status`,
bc.description as content, bc.description as content,
brc.test_plan_id testPlanId, brc.test_plan_id testPlanId,

View File

@ -15,14 +15,17 @@ import io.metersphere.request.AssociateBugPageRequest;
import io.metersphere.request.AssociateBugRequest; import io.metersphere.request.AssociateBugRequest;
import io.metersphere.request.BugPageProviderRequest; import io.metersphere.request.BugPageProviderRequest;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@ -40,6 +43,8 @@ public class AssociateBugProvider implements BaseAssociateBugProvider {
private BugRelateCaseCommonService bugRelateCaseCommonService; private BugRelateCaseCommonService bugRelateCaseCommonService;
@Resource @Resource
private ExtBugRelateCaseMapper extBugRelateCaseMapper; private ExtBugRelateCaseMapper extBugRelateCaseMapper;
@Resource
private UserLoginService userLoginService;
@Override @Override
@ -112,9 +117,12 @@ public class AssociateBugProvider implements BaseAssociateBugProvider {
public List<BugProviderDTO> buildAssociateBugs(List<BugProviderDTO> associateBugs, String projectId) { public List<BugProviderDTO> buildAssociateBugs(List<BugProviderDTO> associateBugs, String projectId) {
List<SelectOption> headerHandlerOption = bugCommonService.getHeaderHandlerOption(projectId); List<SelectOption> headerHandlerOption = bugCommonService.getHeaderHandlerOption(projectId);
List<SelectOption> statusOption = bugStatusService.getHeaderStatusOption(projectId); List<SelectOption> statusOption = bugStatusService.getHeaderStatusOption(projectId);
List<String> createUserList = associateBugs.stream().map(BugProviderDTO::getCreateUser).distinct().toList();
Map<String, String> userMap = userLoginService.getUserNameMap(createUserList.stream().filter(StringUtils::isNotBlank).distinct().toList());
associateBugs.forEach(item -> { associateBugs.forEach(item -> {
headerHandlerOption.stream().filter(option -> StringUtils.equals(option.getValue(), item.getHandleUser())).findFirst().ifPresent(option -> item.setHandleUserName(option.getText())); headerHandlerOption.stream().filter(option -> StringUtils.equals(option.getValue(), item.getHandleUser())).findFirst().ifPresent(option -> item.setHandleUserName(option.getText()));
statusOption.stream().filter(option -> StringUtils.equals(option.getValue(), item.getStatus())).findFirst().ifPresent(option -> item.setStatusName(option.getText())); statusOption.stream().filter(option -> StringUtils.equals(option.getValue(), item.getStatus())).findFirst().ifPresent(option -> item.setStatusName(option.getText()));
item.setCreateUserName(MapUtils.isNotEmpty(userMap) && userMap.containsKey(item.getCreateUser()) ? userMap.get(item.getCreateUser()) : StringUtils.EMPTY);
}); });
return associateBugs; return associateBugs;
} }