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)
public Pager<List<BugDTO>> page(@Validated @RequestBody BugPageRequest request) {
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);
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) {
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标签(<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,18 +110,27 @@ 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<BugRelationCase> planRelatedCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample);
Map<String, String> planRelatedMap = planRelatedCases.stream().collect(Collectors.toMap(BugRelationCase::getTestPlanCaseId, BugRelationCase::getId));
relatedIds.forEach(relatedId -> {
bugRelationCaseExample.clear();
bugRelationCaseExample.createCriteria().andBugIdEqualTo(request.getSourceId()).andCaseIdIn(relatedIds);
List<BugRelationCase> bugRelationCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample);
Map<String, String> 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.setCaseId(relatedId);
record.setBugId(request.getSourceId());
@ -131,7 +140,7 @@ public class BugRelateCaseCommonService extends ModuleTreeService {
record.setUpdateTime(System.currentTimeMillis());
relationCaseMapper.insert(record);
}
});
}
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}