diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMemberValidator.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMemberValidator.java index 7db1a8ff40..8462a0c6ac 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMemberValidator.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMemberValidator.java @@ -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 diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 662c29c76e..be8dc350e4 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -763,12 +763,12 @@ public class FunctionalCaseService { private void batchSendNotice(String projectId, List 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 subList = ids.subList(fromIndex, toIndex); @@ -1091,7 +1091,7 @@ public class FunctionalCaseService { /** * 组装通知数据 * - * @param noticeList xiao + * @param noticeList xiao * @param functionalCaseExcelData * @param request * @param userId @@ -1153,7 +1153,7 @@ public class FunctionalCaseService { caseBlobMapper.insertSelective(caseBlob); //自定义字段 - List customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap); + List 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 handleImportCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map customFieldsMap) { + private List handleImportCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map customFieldsMap, String userId) { List customFields = new ArrayList<>(); //需要保存的自定义字段 Map 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 customFields = handleUpdateCustomField(functionalCaseExcelData, functionalCase.getId(), customFieldMapper, customFieldsMap); + List 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 handleUpdateCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map customFieldsMap) { + private List handleUpdateCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map customFieldsMap, String userId) { FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample(); fieldExample.createCriteria().andCaseIdEqualTo(caseId); customFieldMapper.deleteByExample(fieldExample); - List customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap); + List customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap, userId); return customFields; } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml index a8934c8c82..3e8b929abc 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml @@ -41,7 +41,8 @@