From 6426d1429d8174919e3c0f244b19b4343842ef39 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 18 Apr 2024 13:34:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=88=90=E5=91=98=E7=B1=BB=E5=9E=8B=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039660 --user=王旭 【用例管理】功能用例-Excel导入-有成员字段-导入的Excel提示填写ID或邮箱-事实上现在用户没有ID,并且输入邮箱导入也成功不了,现在输入用户姓名可以导入成功 https://www.tapd.cn/55049933/s/1500724 --- .../validate/CustomFieldMemberValidator.java | 2 +- .../service/FunctionalCaseService.java | 33 +++++++++++-------- .../mapper/ExtProjectUserRoleMapper.xml | 3 +- 3 files changed, 23 insertions(+), 15 deletions(-) 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 @@