fix(用例管理): 导入成员类型自定义字段问题

--bug=1039660 --user=王旭 【用例管理】功能用例-Excel导入-有成员字段-导入的Excel提示填写ID或邮箱-事实上现在用户没有ID,并且输入邮箱导入也成功不了,现在输入用户姓名可以导入成功 https://www.tapd.cn/55049933/s/1500724
This commit is contained in:
WangXu10 2024-04-18 13:34:02 +08:00 committed by 刘瑞斌
parent ceaca62faf
commit 6426d1429d
3 changed files with 23 additions and 15 deletions

View File

@ -33,7 +33,7 @@ public class CustomFieldMemberValidator extends AbstractCustomFieldValidator {
);
userNameMap = new HashMap<>();
memberOption.stream()
.forEach(user -> userNameMap.put(user.getName().toLowerCase(), user.getId()));
.forEach(user -> userNameMap.put(user.getEmail().toLowerCase(), user.getId()));
}
@Override

View File

@ -763,12 +763,12 @@ public class FunctionalCaseService {
private void batchSendNotice(String projectId, List<String> ids, User user, String event) {
int amount = 100;//每次读取的条数
long roundTimes = Double.valueOf(Math.ceil((double) ids.size() / amount)).longValue();//循环的次数
for (int i = 0; i < (int)roundTimes; i++) {
int fromIndex = (i*amount);
int toIndex = ((i+1)*amount);
if (i == roundTimes-1){//最后一次遍历
for (int i = 0; i < (int) roundTimes; i++) {
int fromIndex = (i * amount);
int toIndex = ((i + 1) * amount);
if (i == roundTimes - 1) {//最后一次遍历
toIndex = ids.size();
} else if (toIndex > ids.size()){
} else if (toIndex > ids.size()) {
toIndex = ids.size();
}
List<String> subList = ids.subList(fromIndex, toIndex);
@ -1153,7 +1153,7 @@ public class FunctionalCaseService {
caseBlobMapper.insertSelective(caseBlob);
//自定义字段
List<FunctionalCaseCustomField> customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap);
List<FunctionalCaseCustomField> customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap, userId);
caseIds.add(functionalCase.getId());
historyLogDTOS.add(new FunctionalCaseHistoryLogDTO(functionalCase, caseBlob, customFields, new ArrayList<>(), new ArrayList<>()));
@ -1181,7 +1181,7 @@ public class FunctionalCaseService {
* @param customFieldMapper 自定义字段mapper
* @param customFieldsMap 当前默认模板的自定义字段
*/
private List<FunctionalCaseCustomField> handleImportCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap) {
private List<FunctionalCaseCustomField> handleImportCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap, String userId) {
List<FunctionalCaseCustomField> customFields = new ArrayList<>();
//需要保存的自定义字段
Map<String, Object> customData = functionalCaseExcelData.getCustomData();
@ -1191,14 +1191,21 @@ public class FunctionalCaseService {
caseCustomField.setCaseId(caseId);
caseCustomField.setFieldId(v.getFieldId());
Optional.ofNullable(value).ifPresentOrElse(v1 -> {
if((v1.toString().length()==2&&StringUtils.equals(v1.toString(),"[]"))||!StringUtils.isNotBlank(v1.toString())){
if ((v1.toString().length() == 2 && StringUtils.equals(v1.toString(), "[]")) || !StringUtils.isNotBlank(v1.toString())) {
setCustomFieldValue(v.getDefaultValue(), caseCustomField);
}else{
} else {
setCustomFieldValue(v1, caseCustomField);
}
}, () -> {
setCustomFieldValue(v.getDefaultValue(), caseCustomField);
});
if (StringUtils.equalsIgnoreCase(v.getType(), CustomFieldType.MEMBER.name()) && caseCustomField.getValue().contains("CREATE_USER")) {
caseCustomField.setValue(userId);
}
if (StringUtils.equalsIgnoreCase(v.getType(), CustomFieldType.MULTIPLE_MEMBER.name()) && caseCustomField.getValue().contains("CREATE_USER")) {
caseCustomField.setValue(caseCustomField.getValue().replace("CREATE_USER", userId));
}
customFields.add(caseCustomField);
customFieldMapper.insertSelective(caseCustomField);
});
@ -1339,7 +1346,7 @@ public class FunctionalCaseService {
caseBlobMapper.updateByPrimaryKeyWithBLOBs(caseBlob);
//自定义字段
List<FunctionalCaseCustomField> customFields = handleUpdateCustomField(functionalCaseExcelData, functionalCase.getId(), customFieldMapper, customFieldsMap);
List<FunctionalCaseCustomField> customFields = handleUpdateCustomField(functionalCaseExcelData, functionalCase.getId(), customFieldMapper, customFieldsMap, userId);
// 记录新值
historyLogDTOS.add(new FunctionalCaseHistoryLogDTO(functionalCase, caseBlob, customFields, new ArrayList<>(), new ArrayList<>()));
@ -1359,11 +1366,11 @@ public class FunctionalCaseService {
}
}
private List<FunctionalCaseCustomField> handleUpdateCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap) {
private List<FunctionalCaseCustomField> handleUpdateCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap, String userId) {
FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample();
fieldExample.createCriteria().andCaseIdEqualTo(caseId);
customFieldMapper.deleteByExample(fieldExample);
List<FunctionalCaseCustomField> customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap);
List<FunctionalCaseCustomField> customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap, userId);
return customFields;
}

View File

@ -41,7 +41,8 @@
<select id="getProjectUserList" resultType="io.metersphere.system.domain.User">
SELECT distinct
u.id,
u.NAME
u.NAME,
u.email
FROM `user` u
LEFT JOIN user_role_relation urr ON u.id = urr.user_id
WHERE urr.source_id = #{sourceId}