fix(缺陷管理): 评论富文本图片处理

--bug=1041226 --user=宋昌昌 【缺陷管理】缺陷评论富文本框中上传图片,查看评论图片,图片过期不显示 https://www.tapd.cn/55049933/s/1522342
This commit is contained in:
song-cc-rock 2024-05-28 17:40:50 +08:00 committed by Craftsman
parent 718ec6c03e
commit 5bf0d63b01
3 changed files with 20 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotBlank;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
@Data @Data
public class BugCommentEditRequest implements Serializable { public class BugCommentEditRequest implements Serializable {
@ -33,4 +34,7 @@ public class BugCommentEditRequest implements Serializable {
@Schema(description = "任务事件(仅评论: COMMENT; 评论并@: AT; 回复评论/回复并@: REPLY;)", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "任务事件(仅评论: COMMENT; 评论并@: AT; 回复评论/回复并@: REPLY;)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{bug_comment.event.not_blank}", groups = {Created.class}) @NotBlank(message = "{bug_comment.event.not_blank}", groups = {Created.class})
private String event; private String event;
@Schema(description = "富文本临时文件ID")
private List<String> richTextTmpFileIds;
} }

View File

@ -9,5 +9,9 @@ public enum BugAttachmentSourceType {
/** /**
* 富文本 * 富文本
*/ */
RICH_TEXT RICH_TEXT,
/**
* 评论
*/
COMMENT
} }

View File

@ -6,6 +6,7 @@ import io.metersphere.bug.domain.BugCommentExample;
import io.metersphere.bug.dto.request.BugCommentEditRequest; import io.metersphere.bug.dto.request.BugCommentEditRequest;
import io.metersphere.bug.dto.response.BugCommentDTO; import io.metersphere.bug.dto.response.BugCommentDTO;
import io.metersphere.bug.dto.response.BugCommentNoticeDTO; import io.metersphere.bug.dto.response.BugCommentNoticeDTO;
import io.metersphere.bug.enums.BugAttachmentSourceType;
import io.metersphere.bug.mapper.BugCommentMapper; import io.metersphere.bug.mapper.BugCommentMapper;
import io.metersphere.bug.mapper.BugMapper; import io.metersphere.bug.mapper.BugMapper;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
@ -37,6 +38,8 @@ public class BugCommentService {
private BugCommentMapper bugCommentMapper; private BugCommentMapper bugCommentMapper;
@Resource @Resource
private BugCommentNoticeService bugCommentNoticeService; private BugCommentNoticeService bugCommentNoticeService;
@Resource
private BugAttachmentService bugAttachmentService;
/** /**
* 获取缺陷评论 * 获取缺陷评论
@ -112,8 +115,10 @@ public class BugCommentService {
* @return 缺陷评论 * @return 缺陷评论
*/ */
public BugComment addComment(BugCommentEditRequest request, String currentUser) { public BugComment addComment(BugCommentEditRequest request, String currentUser) {
checkBug(request.getBugId()); Bug bug = checkBug(request.getBugId());
BugComment bugComment = getBugComment(request, currentUser, false); BugComment bugComment = getBugComment(request, currentUser, false);
// 评论富文本附件处理
bugAttachmentService.transferTmpFile(bug.getId(), bug.getProjectId(), request.getRichTextTmpFileIds(), currentUser, BugAttachmentSourceType.COMMENT.name());
if (StringUtils.equals(request.getEvent(), NoticeConstants.Event.REPLY)) { if (StringUtils.equals(request.getEvent(), NoticeConstants.Event.REPLY)) {
return addBugCommentAndReplyNotice(request, bugComment, currentUser); return addBugCommentAndReplyNotice(request, bugComment, currentUser);
} else { } else {
@ -128,8 +133,11 @@ public class BugCommentService {
* @return 缺陷评论 * @return 缺陷评论
*/ */
public BugComment updateComment(BugCommentEditRequest request, String currentUser) { public BugComment updateComment(BugCommentEditRequest request, String currentUser) {
Bug bug = checkBug(request.getBugId());
checkComment(request.getId(), currentUser); checkComment(request.getId(), currentUser);
BugComment bugComment = getBugComment(request, currentUser, true); BugComment bugComment = getBugComment(request, currentUser, true);
// 评论富文本附件处理
bugAttachmentService.transferTmpFile(bug.getId(), bug.getProjectId(), request.getRichTextTmpFileIds(), currentUser, BugAttachmentSourceType.COMMENT.name());
return updateBugCommentAndNotice(request, bugComment, currentUser); return updateBugCommentAndNotice(request, bugComment, currentUser);
} }
@ -262,11 +270,12 @@ public class BugCommentService {
* 校验缺陷是否存在 * 校验缺陷是否存在
* @param bugId 缺陷ID * @param bugId 缺陷ID
*/ */
private void checkBug(String bugId) { private Bug checkBug(String bugId) {
Bug bug = bugMapper.selectByPrimaryKey(bugId); Bug bug = bugMapper.selectByPrimaryKey(bugId);
if (bug == null) { if (bug == null) {
throw new IllegalArgumentException(Translator.get("bug_not_exist")); throw new IllegalArgumentException(Translator.get("bug_not_exist"));
} }
return bug;
} }
/** /**