Browse Source

add:问题点赞和评论

zhongwei
luyie 2 months ago
parent
commit
46f5fd8afc
  1. 5
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/entity/QuestionAnswerCommentEntity.java
  2. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/QuestionAnswerCommentService.java
  3. 21
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/QuestionAnswerCommentServiceImpl.java
  4. 6
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/vo/AnswerCommentRequest.java
  5. 4
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/vo/AnswerPraiseRequest.java

5
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/entity/QuestionAnswerCommentEntity.java

@ -1,14 +1,11 @@
package com.hnac.gglm.bigmodel.maintenance.entity; package com.hnac.gglm.bigmodel.maintenance.entity;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import org.springblade.core.tenant.mp.TenantEntity; import org.springblade.core.tenant.mp.TenantEntity;
import org.springframework.data.annotation.Transient;
import java.io.Serializable; import java.io.Serializable;
@ -32,7 +29,7 @@ public class QuestionAnswerCommentEntity extends TenantEntity implements Seriali
@ApiModelProperty("用户id") @ApiModelProperty("用户id")
@TableField("user_id") @TableField("user_id")
private Long userId; private String userId;
@ApiModelProperty("用户账号") @ApiModelProperty("用户账号")
@TableField(exist = false) @TableField(exist = false)

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/QuestionAnswerCommentService.java

@ -12,7 +12,7 @@ import java.util.List;
* @Date: 2024/9/21 13:29 * @Date: 2024/9/21 13:29
*/ */
public interface QuestionAnswerCommentService extends IService<QuestionAnswerCommentEntity> { public interface QuestionAnswerCommentService extends IService<QuestionAnswerCommentEntity> {
QuestionAnswerCommentEntity getComment(Long userId, String questionId); QuestionAnswerCommentEntity getComment(String userId, String questionId);
Boolean comment(AnswerCommentRequest req); Boolean comment(AnswerCommentRequest req);

21
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/QuestionAnswerCommentServiceImpl.java

@ -11,7 +11,6 @@ import com.hnac.gglm.bigmodel.maintenance.vo.AnswerCommentRequest;
import com.hnac.gglm.bigmodel.maintenance.vo.AnswerPraiseRequest; import com.hnac.gglm.bigmodel.maintenance.vo.AnswerPraiseRequest;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
@ -32,7 +31,7 @@ public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswer
private final IUserClient userClient; private final IUserClient userClient;
@Override @Override
public QuestionAnswerCommentEntity getComment(Long userId, String questionId) { public QuestionAnswerCommentEntity getComment(String userId, String questionId) {
LambdaQueryWrapper<QuestionAnswerCommentEntity> queryWrapper = Wrappers.<QuestionAnswerCommentEntity>lambdaQuery() LambdaQueryWrapper<QuestionAnswerCommentEntity> queryWrapper = Wrappers.<QuestionAnswerCommentEntity>lambdaQuery()
.eq(QuestionAnswerCommentEntity::getQuestionId, questionId) .eq(QuestionAnswerCommentEntity::getQuestionId, questionId)
.eq(QuestionAnswerCommentEntity::getUserId, userId).last("limit 1"); .eq(QuestionAnswerCommentEntity::getUserId, userId).last("limit 1");
@ -41,7 +40,7 @@ public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswer
@Override @Override
public Boolean comment(AnswerCommentRequest req) { public Boolean comment(AnswerCommentRequest req) {
QuestionAnswerCommentEntity entity = getComment(AuthUtil.getUserId(), QuestionAnswerCommentEntity entity = getComment(req.getUserId(),
req.getQuestionId()); req.getQuestionId());
if (ObjectUtil.isEmpty(entity)) { if (ObjectUtil.isEmpty(entity)) {
entity = req.toEntity(); entity = req.toEntity();
@ -53,7 +52,7 @@ public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswer
@Override @Override
public Boolean praise(AnswerPraiseRequest req) { public Boolean praise(AnswerPraiseRequest req) {
QuestionAnswerCommentEntity entity = getComment(AuthUtil.getUserId(), QuestionAnswerCommentEntity entity = getComment(req.getUserId(),
req.getQuestionId()); req.getQuestionId());
if (ObjectUtil.isNotEmpty(entity)) { if (ObjectUtil.isNotEmpty(entity)) {
entity.setPraise(req.getPraise()); entity.setPraise(req.getPraise());
@ -70,10 +69,14 @@ public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswer
.eq(QuestionAnswerCommentEntity::getQuestionId, questionId) .eq(QuestionAnswerCommentEntity::getQuestionId, questionId)
.orderByAsc(QuestionAnswerCommentEntity::getCreateTime)); .orderByAsc(QuestionAnswerCommentEntity::getCreateTime));
list.forEach(item -> { list.forEach(item -> {
R<User> user = userClient.userInfoById(item.getUserId()); try {
if (user.isSuccess() && user.getData() != null) { R<User> user = userClient.userInfoById(Long.parseLong(item.getUserId()));
item.setUserName(user.getData().getName()); if (user.isSuccess() && user.getData() != null) {
item.setUserAccount(user.getData().getAccount()); item.setUserName(user.getData().getName());
item.setUserAccount(user.getData().getAccount());
}
} catch (Exception e) {
log.error("获取用户信息失败", e);
} }
}); });
return list; return list;
@ -88,7 +91,7 @@ public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswer
@Override @Override
public Boolean resetPraise(AnswerPraiseRequest req) { public Boolean resetPraise(AnswerPraiseRequest req) {
QuestionAnswerCommentEntity entity = getComment(AuthUtil.getUserId(), QuestionAnswerCommentEntity entity = getComment(req.getUserId(),
req.getQuestionId()); req.getQuestionId());
if (ObjectUtil.isNotEmpty(entity)) { if (ObjectUtil.isNotEmpty(entity)) {
entity.setPraise(0); entity.setPraise(0);

6
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/vo/AnswerCommentRequest.java

@ -4,7 +4,6 @@ import com.hnac.gglm.bigmodel.maintenance.entity.QuestionAnswerCommentEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springblade.core.secure.utils.AuthUtil;
/** /**
* @Author: ypj * @Author: ypj
@ -22,12 +21,15 @@ public class AnswerCommentRequest {
@ApiModelProperty(value = "评论内容") @ApiModelProperty(value = "评论内容")
private String content; private String content;
@ApiModelProperty(value = "用户id")
private String userId;
public QuestionAnswerCommentEntity toEntity() { public QuestionAnswerCommentEntity toEntity() {
QuestionAnswerCommentEntity entity = new QuestionAnswerCommentEntity(); QuestionAnswerCommentEntity entity = new QuestionAnswerCommentEntity();
entity.setChatId(chartId); entity.setChatId(chartId);
entity.setQuestionId(questionId); entity.setQuestionId(questionId);
entity.setContent(content); entity.setContent(content);
entity.setUserId(AuthUtil.getUserId()); entity.setUserId(userId);
return entity; return entity;
} }
} }

4
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/vo/AnswerPraiseRequest.java

@ -22,11 +22,15 @@ public class AnswerPraiseRequest {
@ApiModelProperty(value = "点赞,0取消点赞,1点赞") @ApiModelProperty(value = "点赞,0取消点赞,1点赞")
private Integer praise; private Integer praise;
@ApiModelProperty(value = "用户id")
private String userId;
public QuestionAnswerCommentEntity toEntity() { public QuestionAnswerCommentEntity toEntity() {
QuestionAnswerCommentEntity entity = new QuestionAnswerCommentEntity(); QuestionAnswerCommentEntity entity = new QuestionAnswerCommentEntity();
entity.setChatId(chartId); entity.setChatId(chartId);
entity.setQuestionId(questionId); entity.setQuestionId(questionId);
entity.setPraise(praise); entity.setPraise(praise);
entity.setUserId(userId);
return entity; return entity;
} }
} }

Loading…
Cancel
Save