Преглед изворни кода

问答回复添加用户相关信息提交

zsy пре 1 месец
родитељ
комит
6e9c212d3d

+ 10 - 0
src/main/java/com/rf/help/task/dao/model/ReplyEntity.java

@@ -9,6 +9,7 @@ import lombok.NoArgsConstructor;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 /**
  * @author zsy
@@ -27,10 +28,19 @@ public class ReplyEntity extends BaseEntity {
     @Column(name = "task_id", columnDefinition = "varchar(36) not null comment '所属任务ID'")
     private String taskId;
 
+    @Column(name = "user_id", columnDefinition = "varchar(36) not null comment '用户ID'")
+    private String userId;
+
     @Column(name = "reply_content", columnDefinition = "text not null comment '回答内容'")
     private String replyContent;
 
     @Column(name = "reply_status", columnDefinition = "varchar(2) not null comment '状态(1:无状态;2:有用;3:无用)'")
     private String replyStatus;
 
+    @Transient
+    private String avatar;//评论人头像
+
+    @Transient
+    private String userName;//评论人名称
+
 }

+ 9 - 0
src/main/java/com/rf/help/task/rest/ReplyController.java

@@ -31,6 +31,9 @@ public class ReplyController extends BaseController {
     @Autowired
     private ReplyService replyService;
 
+    @Autowired
+    private UserService userService;
+
     @PostMapping("/publishReply")
     @ApiOperation(value = "发布回答和修改状态", notes = "ReplyEntity对象")
     public Result publishReply(@RequestBody String json) {
@@ -56,6 +59,12 @@ public class ReplyController extends BaseController {
     @ApiOperation(value = "回答内容列表查询", notes = "参数包括:beginNum:页码,pageSize:每页条数,taskId:任务Id,searchKey:搜索信息")
     public Result findReplyList(String taskId, String searchKey,int beginNum, int pageSize) {
         Page<ReplyEntity> replyEntities = this.replyService.findReplyByTaskId(taskId, searchKey, beginNum, pageSize);
+        UserEntity userEntity;
+        for (int i = 0; i < replyEntities.getContent().size(); i++) {
+            userEntity = this.userService.findById(replyEntities.getContent().get(i).getUserId());
+            replyEntities.getContent().get(i).setAvatar(userEntity.getAvatar());
+            replyEntities.getContent().get(i).setUserName(userEntity.getUserName());
+        }
         return success(replyEntities);
     }