From e0fc0c7b388a47b5b15fa343f98e17a33cf92750 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Wed, 24 Apr 2024 16:06:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=9A=84=E5=AF=8C=E6=96=87=E6=9C=AC=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=8E=BB=E9=99=A4=E4=B8=80=E4=BA=9B=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036200 --user=宋昌昌 【缺陷管理】缺陷管理列表-导出缺陷时选中所有字段导出缺陷内容和自定义字段打开显示异常 https://www.tapd.cn/55049933/s/1507524 --- .../bug/controller/BugTrashController.java | 2 +- .../bug/dto/BugExportExcelModel.java | 16 ++++++++++-- .../service/BugRelateCaseCommonService.java | 25 +++++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java index a0ad6c357f..2209566646 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java @@ -37,7 +37,7 @@ public class BugTrashController { @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) public Pager> page(@Validated @RequestBody BugPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "delete_time desc"); + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "delete_time desc, num asc"); request.setUseTrash(true); return PageUtils.setPageInfo(page, bugService.list(request)); } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportExcelModel.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportExcelModel.java index 3845b85b86..fbc92e5816 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportExcelModel.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportExcelModel.java @@ -162,7 +162,7 @@ public class BugExportExcelModel { private String getBugContent(Map bugContents, String id) { if (bugContents.containsKey(id)) { - return bugContents.get(id).getDescription(); + return replaceRichTextHtmlTag(bugContents.get(id).getDescription()); } else { return StringUtils.EMPTY; } @@ -190,7 +190,7 @@ public class BugExportExcelModel { "回复" + StringUtils.SPACE + parseCommentUser(bugCommentDTO, bugCommentDTO.getReplyUser())); commentBuilder.append("】"); commentBuilder.append(StringUtils.LF); - commentBuilder.append(bugCommentDTO.getContent()); + commentBuilder.append(replaceRichTextHtmlTag(bugCommentDTO.getContent())); commentBuilder.append(StringUtils.LF); if (CollectionUtils.isNotEmpty(bugCommentDTO.getChildComments())) { for (BugCommentDTO childComment : bugCommentDTO.getChildComments()) { @@ -230,4 +230,16 @@ public class BugExportExcelModel { return userId; } } + + /** + * 替换富文本HTML标签(除外) + * @param sourceStr + * @return + */ + private String replaceRichTextHtmlTag(String sourceStr) { + if (StringUtils.isBlank(sourceStr)) { + return StringUtils.EMPTY; + } + return sourceStr.replaceAll("<(?!img)[^>]*>", StringUtils.EMPTY); + } } \ No newline at end of file diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugRelateCaseCommonService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugRelateCaseCommonService.java index 56b0b9f7f0..963426d55c 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugRelateCaseCommonService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugRelateCaseCommonService.java @@ -110,19 +110,28 @@ public class BugRelateCaseCommonService extends ModuleTreeService { BugRelationCaseMapper relationCaseMapper = sqlSession.getMapper(BugRelationCaseMapper.class); // 根据用例ID筛选出已通过测试计划关联的用例 BugRelationCaseExample bugRelationCaseExample = new BugRelationCaseExample(); - bugRelationCaseExample.createCriteria().andTestPlanCaseIdIn(relatedIds); + bugRelationCaseExample.createCriteria().andBugIdEqualTo(request.getSourceId()).andTestPlanCaseIdIn(relatedIds); List planRelatedCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample); Map planRelatedMap = planRelatedCases.stream().collect(Collectors.toMap(BugRelationCase::getTestPlanCaseId, BugRelationCase::getId)); - relatedIds.forEach(relatedId -> { - BugRelationCase record = new BugRelationCase(); - if (planRelatedMap.containsKey(relatedId)) { - // 计划已关联 - record.setId(planRelatedMap.get(relatedId)); + bugRelationCaseExample.clear(); + bugRelationCaseExample.createCriteria().andBugIdEqualTo(request.getSourceId()).andCaseIdIn(relatedIds); + List bugRelationCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample); + Map bugRelatedMap = bugRelationCases.stream().collect(Collectors.toMap(BugRelationCase::getCaseId, BugRelationCase::getId)); + for (String relatedId : relatedIds) { + BugRelationCase record = new BugRelationCase(); + if (bugRelatedMap.containsKey(relatedId)) { + // 重复关联 + continue; + } + if (planRelatedMap.containsKey(relatedId)) { + // 计划已关联, 补全用例ID + record.setId(planRelatedMap.get(relatedId)); record.setCaseId(relatedId); record.setUpdateTime(System.currentTimeMillis()); relationCaseMapper.updateByPrimaryKeySelective(record); } else { - record.setId(IDGenerator.nextStr()); + // 暂未关联, 新生成关联数据 + record.setId(IDGenerator.nextStr()); record.setCaseId(relatedId); record.setBugId(request.getSourceId()); record.setCaseType(request.getSourceType()); @@ -131,7 +140,7 @@ public class BugRelateCaseCommonService extends ModuleTreeService { record.setUpdateTime(System.currentTimeMillis()); relationCaseMapper.insert(record); } - }); + } sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); }