评论接口返回参数修改

This commit is contained in:
tianfeng 2026-01-29 11:53:46 +08:00
parent d5332e29e6
commit 0840754203
4 changed files with 27 additions and 13 deletions

View File

@ -198,7 +198,7 @@ public class DynamicRestController extends BaseController {
* @eo.request-type json * @eo.request-type json
*/ */
@PostMapping("/comment") @PostMapping("/comment")
public Long comment(@RequestBody @Validated DynamicCommentCmd cmd) { public DynamicCommentListCO comment(@RequestBody @Validated DynamicCommentCmd cmd) {
return dynamicService.comment(cmd); return dynamicService.comment(cmd);
} }

View File

@ -6,6 +6,7 @@ import com.red.circle.common.business.enums.AccountStatusEnum;
import com.red.circle.common.business.enums.DynamicMessageEnum; import com.red.circle.common.business.enums.DynamicMessageEnum;
import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.app.common.room.DynamicCommon; import com.red.circle.other.app.common.room.DynamicCommon;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicCommentListCO;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicCommentCmd; import com.red.circle.other.app.dto.cmd.dynamic.DynamicCommentCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserConsumptionLevel; import com.red.circle.other.domain.model.user.UserConsumptionLevel;
@ -50,20 +51,21 @@ public class DynamicCommentCmdExe {
private final DynamicPopularService dynamicPopularService; private final DynamicPopularService dynamicPopularService;
private final UserAccountCommon userAccountCommon; private final UserAccountCommon userAccountCommon;
public Long execute(DynamicCommentCmd cmd) { public DynamicCommentListCO execute(DynamicCommentCmd cmd) {
ResponseAssert.isTrue(DynamicErrorCode.CURRENT_LEVEL_IS_TOO_LOW, commentLimit(cmd)); ResponseAssert.isTrue(DynamicErrorCode.CURRENT_LEVEL_IS_TOO_LOW, commentLimit(cmd));
DynamicContent dynamicContent = checkParams(cmd); DynamicContent dynamicContent = checkParams(cmd);
//保存评论 //保存评论
Long commentId = IdWorkerUtils.getId(); Long commentId = IdWorkerUtils.getId();
saveComment(cmd, commentId); DynamicComment dynamicComment = saveComment(cmd, commentId);
Long commentQuantity = incrCommentQuantity(cmd); incrCommentQuantity(cmd);
//评论自己创建的动态或者自己回复自己不发送消息 //评论自己创建的动态或者自己回复自己不发送消息
UserProfile userProfile = userProfileGateway.getByUserId(cmd.getReqUserId());
if (isOwnDynamic(cmd, dynamicContent)) { if (isOwnDynamic(cmd, dynamicContent)) {
return commentQuantity; return convert(dynamicComment, userProfile);
} }
dynamicPopularService.updateScore(dynamicContent.getId(), dynamicCacheService.getCommentScore(), dynamicPopularService.updateScore(dynamicContent.getId(), dynamicCacheService.getCommentScore(),
@ -72,15 +74,26 @@ public class DynamicCommentCmdExe {
//评论不属于自己的动态发送消息 //评论不属于自己的动态发送消息
if (Objects.isNull(cmd.getToUserId())) { if (Objects.isNull(cmd.getToUserId())) {
cmd.setToUserId(dynamicContent.getCreateUser()); cmd.setToUserId(dynamicContent.getCreateUser());
saveDynamicMessage(cmd, DynamicMessageEnum.COMMENT_DYNAMIC);
dynamicCommon.sendMsg(cmd.getToUserId());
return commentQuantity;
} }
//发送消息给动态被回复人 //发送消息给动态被回复人
saveDynamicMessage(cmd, DynamicMessageEnum.REPLY_COMMENT); saveDynamicMessage(cmd, DynamicMessageEnum.REPLY_COMMENT);
dynamicCommon.sendMsg(cmd.getToUserId()); return convert(dynamicComment, userProfile);
return commentQuantity; }
private DynamicCommentListCO convert(DynamicComment dynamicComment, UserProfile userProfile) {
DynamicCommentListCO commentListCO = new DynamicCommentListCO();
commentListCO.setId(dynamicComment.getId());
commentListCO.setDynamicId(dynamicComment.getDynamicContentId());
commentListCO.setToUserId(dynamicComment.getToUserId());
commentListCO.setContent(dynamicComment.getContent());
commentListCO.setCreateTime(dynamicComment.getCreateTime());
commentListCO.setRootCommentId(dynamicComment.getRootCommentId());
commentListCO.setUserId(userProfile.getId());
commentListCO.setUserAvatar(userProfile.getUserAvatar());
commentListCO.setUserNickname(userProfile.getUserNickname());
commentListCO.setUserSex(userProfile.getUserSex());
return commentListCO;
} }
private boolean commentLimit(DynamicCommentCmd cmd) { private boolean commentLimit(DynamicCommentCmd cmd) {
@ -149,7 +162,7 @@ public class DynamicCommentCmdExe {
} }
private void saveComment(DynamicCommentCmd cmd, Long commentId) { private DynamicComment saveComment(DynamicCommentCmd cmd, Long commentId) {
DynamicComment comment = new DynamicComment(); DynamicComment comment = new DynamicComment();
comment.setId(commentId); comment.setId(commentId);
@ -163,6 +176,7 @@ public class DynamicCommentCmdExe {
} }
dynamicCommentService.save(comment); dynamicCommentService.save(comment);
return comment;
} }
private boolean isNotBlank(DynamicCommentCmd cmd) { private boolean isNotBlank(DynamicCommentCmd cmd) {

View File

@ -132,7 +132,7 @@ public class DynamicServiceImpl implements DynamicService {
} }
@Override @Override
public Long comment(DynamicCommentCmd cmd) { public DynamicCommentListCO comment(DynamicCommentCmd cmd) {
return dynamicCommentExe.execute(cmd); return dynamicCommentExe.execute(cmd);
} }

View File

@ -91,7 +91,7 @@ public interface DynamicService {
* *
* @return 数量 * @return 数量
*/ */
Long comment(DynamicCommentCmd cmd); DynamicCommentListCO comment(DynamicCommentCmd cmd);
/** /**
* 点赞评论. * 点赞评论.