fix(缺陷管理): 导出的富文本内容去除一些标签

--bug=1036200 --user=宋昌昌 【缺陷管理】缺陷管理列表-导出缺陷时选中所有字段导出缺陷内容和自定义字段打开显示异常 https://www.tapd.cn/55049933/s/1507524
This commit is contained in:
song-cc-rock 2024-04-24 16:06:07 +08:00 committed by 刘瑞斌
parent 9db5b6f79a
commit e0fc0c7b38
3 changed files with 32 additions and 11 deletions

View File

@ -37,7 +37,7 @@ public class BugTrashController {
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
public Pager<List<BugDTO>> page(@Validated @RequestBody BugPageRequest request) { public Pager<List<BugDTO>> page(@Validated @RequestBody BugPageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> 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); request.setUseTrash(true);
return PageUtils.setPageInfo(page, bugService.list(request)); return PageUtils.setPageInfo(page, bugService.list(request));
} }

View File

@ -162,7 +162,7 @@ public class BugExportExcelModel {
private String getBugContent(Map<String, BugContent> bugContents, String id) { private String getBugContent(Map<String, BugContent> bugContents, String id) {
if (bugContents.containsKey(id)) { if (bugContents.containsKey(id)) {
return bugContents.get(id).getDescription(); return replaceRichTextHtmlTag(bugContents.get(id).getDescription());
} else { } else {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
@ -190,7 +190,7 @@ public class BugExportExcelModel {
"回复" + StringUtils.SPACE + parseCommentUser(bugCommentDTO, bugCommentDTO.getReplyUser())); "回复" + StringUtils.SPACE + parseCommentUser(bugCommentDTO, bugCommentDTO.getReplyUser()));
commentBuilder.append(""); commentBuilder.append("");
commentBuilder.append(StringUtils.LF); commentBuilder.append(StringUtils.LF);
commentBuilder.append(bugCommentDTO.getContent()); commentBuilder.append(replaceRichTextHtmlTag(bugCommentDTO.getContent()));
commentBuilder.append(StringUtils.LF); commentBuilder.append(StringUtils.LF);
if (CollectionUtils.isNotEmpty(bugCommentDTO.getChildComments())) { if (CollectionUtils.isNotEmpty(bugCommentDTO.getChildComments())) {
for (BugCommentDTO childComment : bugCommentDTO.getChildComments()) { for (BugCommentDTO childComment : bugCommentDTO.getChildComments()) {
@ -230,4 +230,16 @@ public class BugExportExcelModel {
return userId; return userId;
} }
} }
/**
* 替换富文本HTML标签(<img>除外)
* @param sourceStr
* @return
*/
private String replaceRichTextHtmlTag(String sourceStr) {
if (StringUtils.isBlank(sourceStr)) {
return StringUtils.EMPTY;
}
return sourceStr.replaceAll("<(?!img)[^>]*>", StringUtils.EMPTY);
}
} }

View File

@ -110,19 +110,28 @@ public class BugRelateCaseCommonService extends ModuleTreeService {
BugRelationCaseMapper relationCaseMapper = sqlSession.getMapper(BugRelationCaseMapper.class); BugRelationCaseMapper relationCaseMapper = sqlSession.getMapper(BugRelationCaseMapper.class);
// 根据用例ID筛选出已通过测试计划关联的用例 // 根据用例ID筛选出已通过测试计划关联的用例
BugRelationCaseExample bugRelationCaseExample = new BugRelationCaseExample(); BugRelationCaseExample bugRelationCaseExample = new BugRelationCaseExample();
bugRelationCaseExample.createCriteria().andTestPlanCaseIdIn(relatedIds); bugRelationCaseExample.createCriteria().andBugIdEqualTo(request.getSourceId()).andTestPlanCaseIdIn(relatedIds);
List<BugRelationCase> planRelatedCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample); List<BugRelationCase> planRelatedCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample);
Map<String, String> planRelatedMap = planRelatedCases.stream().collect(Collectors.toMap(BugRelationCase::getTestPlanCaseId, BugRelationCase::getId)); Map<String, String> planRelatedMap = planRelatedCases.stream().collect(Collectors.toMap(BugRelationCase::getTestPlanCaseId, BugRelationCase::getId));
relatedIds.forEach(relatedId -> { bugRelationCaseExample.clear();
BugRelationCase record = new BugRelationCase(); bugRelationCaseExample.createCriteria().andBugIdEqualTo(request.getSourceId()).andCaseIdIn(relatedIds);
if (planRelatedMap.containsKey(relatedId)) { List<BugRelationCase> bugRelationCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample);
// 计划已关联 Map<String, String> bugRelatedMap = bugRelationCases.stream().collect(Collectors.toMap(BugRelationCase::getCaseId, BugRelationCase::getId));
record.setId(planRelatedMap.get(relatedId)); 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.setCaseId(relatedId);
record.setUpdateTime(System.currentTimeMillis()); record.setUpdateTime(System.currentTimeMillis());
relationCaseMapper.updateByPrimaryKeySelective(record); relationCaseMapper.updateByPrimaryKeySelective(record);
} else { } else {
record.setId(IDGenerator.nextStr()); // 暂未关联, 新生成关联数据
record.setId(IDGenerator.nextStr());
record.setCaseId(relatedId); record.setCaseId(relatedId);
record.setBugId(request.getSourceId()); record.setBugId(request.getSourceId());
record.setCaseType(request.getSourceType()); record.setCaseType(request.getSourceType());
@ -131,7 +140,7 @@ public class BugRelateCaseCommonService extends ModuleTreeService {
record.setUpdateTime(System.currentTimeMillis()); record.setUpdateTime(System.currentTimeMillis());
relationCaseMapper.insert(record); relationCaseMapper.insert(record);
} }
}); }
sqlSession.flushStatements(); sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
} }