From cec60cbe7121179d263f55d3ebb348d84d8f86da Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Wed, 14 Aug 2024 15:39:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BC=BA=E9=99=B7=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8E=EF=BC=8C=E7=BC=BA=E9=99=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E5=AD=97=E6=AE=B5=E5=80=BC=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1045011 --user=陈建星 [项目管理]GitHub#32558在缺陷模板中,对状态字段进行修改新增了枚举值,保存模版后。缺陷管理中已提交缺陷的状态字段全部失效。 https://www.tapd.cn/55049933/s/1562594 --- .../io/metersphere/service/IssuesService.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index e0ece349bc..3361aaea0b 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -87,6 +87,7 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -159,6 +160,8 @@ public class IssuesService { private BasePluginService basePluginService; @Resource private MdFileService mdFileService; + @Resource + private CustomFieldMapper customFieldMapper; private static final String SYNC_THIRD_PARTY_ISSUES_KEY = "ISSUE:SYNC"; private static final String SYNC_THIRD_PARTY_ISSUES_ERROR_KEY = "ISSUE:SYNC:ERROR"; @@ -757,19 +760,64 @@ public class IssuesService { } Map> fieldMap = customFieldIssuesService.getMapByResourceIds(data.stream().map(IssuesDao::getId).collect(Collectors.toList())); + + Map globalProjectIdMap = getGlobalProjectIdMap(data.get(0).getProjectId()); + + fieldMap.values().forEach(fields -> + fields.forEach(field -> { + // 如果是全局字段, 并且项目中有对应的字段, 则替换为项目字段 + if (globalProjectIdMap.containsKey(field.getId())) { + field.setId(globalProjectIdMap.get(field.getId())); + } + }) + ); + data.forEach(i -> i.setFields(fieldMap.get(i.getId()))); } + + private Map getGlobalProjectIdMap(String projectId) { + // 查询全局的内置字段 + CustomFieldExample example = new CustomFieldExample(); + example.createCriteria().andGlobalEqualTo(true).andSystemEqualTo(true).andSceneEqualTo(CustomFieldScene.ISSUE.name()); + List globalSystemFiles = customFieldMapper.selectByExample(example); + + // 查询对应的项目下字段 + example.clear(); + example.createCriteria().andGlobalEqualTo(false) + .andSystemEqualTo(true).andSceneEqualTo(CustomFieldScene.ISSUE.name()) + .andProjectIdEqualTo(projectId); + List projectSystemFiles = customFieldMapper.selectByExample(example); + Map projectSystemFilesMap = projectSystemFiles.stream().collect(Collectors.toMap(CustomField::getName, Function.identity())); + + // 全局字段与项目字段的ID映射 + Map globalProjectIdMap = new HashMap<>(globalSystemFiles.size()); + for (CustomField globalSystemFile : globalSystemFiles) { + String fileName = globalSystemFile.getName(); + if (projectSystemFilesMap.get(fileName) != null) { + globalProjectIdMap.put(globalSystemFile.getId(), projectSystemFilesMap.get(fileName).getId()); + } + } + return globalProjectIdMap; + } + private void buildCustomField(IssuesDao data) { CustomFieldIssuesExample example = new CustomFieldIssuesExample(); example.createCriteria().andResourceIdEqualTo(data.getId()); List customFieldTestCases = customFieldIssuesMapper.selectByExample(example); List fields = new ArrayList<>(); + + Map globalProjectIdMap = getGlobalProjectIdMap(data.getProjectId()); + customFieldTestCases.forEach(i -> { CustomFieldDao customFieldDao = new CustomFieldDao(); customFieldDao.setId(i.getFieldId()); customFieldDao.setValue(i.getValue()); customFieldDao.setTextValue(i.getTextValue()); + if (globalProjectIdMap.containsKey(i.getFieldId())) { + // 如果是全局字段, 并且项目中有对应的字段, 则替换为项目字段 + customFieldDao.setId(globalProjectIdMap.get(i.getFieldId())); + } fields.add(customFieldDao); }); data.setFields(fields); @@ -842,6 +890,16 @@ public class IssuesService { } } + Map globalProjectIdMap = getGlobalProjectIdMap(data.get(0).getProjectId()); + fieldMap.values().forEach(fields -> + fields.forEach(field -> { + // 如果是全局字段, 并且项目中有对应的字段, 则替换为项目字段 + if (globalProjectIdMap.containsKey(field.getId())) { + field.setId(globalProjectIdMap.get(field.getId())); + } + }) + ); + data.forEach(i -> i.setFields(fieldMap.get(i.getId()))); } catch (Exception e) { MSException.throwException(e.getMessage());