fix journalList topComment avatar update

main
wangqing 9 months ago
parent b03294dbf4
commit 54fea3652c

@ -1,6 +1,7 @@
package com.luoo.music.client;
import api.Result;
import com.luoo.music.dto.response.UserInfoDTO;
import com.luoo.music.pojo.UserInfo;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
@ -42,4 +43,8 @@ public interface UserClient {
private String id;
private String loginname;
}
@GetMapping("/simple_user/user/{id}")
UserInfoDTO findByUserId(@PathVariable String id);
}

@ -2,8 +2,13 @@ package com.luoo.music.dto.mapper;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.luoo.music.client.UserClient;
import com.luoo.music.dto.response.UserInfoDTO;
import com.luoo.music.util.Constants;
import org.apache.commons.lang.StringUtils;
import org.apache.tomcat.util.bcel.classfile.Constant;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
@ -89,4 +94,93 @@ public class CommentMapper {
commentDTO.setTotalCommentReplyInt(total);
return commentDTO;
}
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao, RedisTemplate redisTemplate, UserClient userClient) {
/**
* 5...
*/
CommentDTO commentDTO=new CommentDTO();
// List<Comment> commentList = (List<Comment>) redisTemplate.opsForValue().get("JOURNAL_TOP5_COMMENT___"+journalId);
// if (null!= commentList) {
// commentDTO.setCommentList(commentList);
// } else {
// commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
// commentDTO.setCommentList(commentList);
// redisTemplate.opsForValue().set("JOURNAL_TOP5_COMMENT___"+journalId,commentList,6, TimeUnit.HOURS);
// }
List<Comment> commentList =commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
if(commentList.size()>0){
commentList= commentList.stream().map(comment -> {
UserInfoDTO userInfoDTO =userClient.findByUserId(comment.getUserId());
if(null != userInfoDTO){
comment.setNickName(userInfoDTO.getNickName());
comment.setAvatar(Constants.RESOURCE_PREFIX+userInfoDTO.getAvatar());
}
return comment;
}).collect(Collectors.toList());
}
commentDTO.setCommentList(commentList);
/**
*
*/
// String totalString = (String) redisTemplate.opsForValue().get("JOURNAL_TATAL_COMMENT_COUNT__"+journalId);
String totalString = "0";
// if (StringUtils.isNotBlank(totalString)) {
// commentDTO.setTotalCommentReply(totalString);
// }else {
//// totalString = "0";
//// Criteria criteria = Criteria.where("journalId").is(journalId);
//// Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), // 匹配条件
//// Aggregation.group().sum("commentCount").as("totalComment"));
//// AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg, "comment", TotalCommentVo.class);
//// TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
//// commentDTO.setTotalCommentReply("0");
//// List<Comment> list = commentDao.findByJournalId(journalId);
//// int total = 0;
//// if (null != list && list.size() > 0) {
//// total = list.size();
//// }
//// if (null != totalCommentVo) {
//// total = total + totalCommentVo.getTotalComment();
//// totalString = total +"";
//// if (total > 99) {
//// totalString = "99+";
//// }
//// }
//// commentDTO.setTotalCommentReply(totalString);
//// commentDTO.setTotalCommentReplyInt(total);
//// redisTemplate.opsForValue().set("JOURNAL_TATAL_COMMENT_COUNT__"+journalId,totalString,6,TimeUnit.HOURS);
// }
totalString = "0";
Criteria criteria = Criteria.where("journalId").is(journalId);
Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), // 匹配条件
Aggregation.group().sum("commentCount").as("totalComment"));
AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg, "comment", TotalCommentVo.class);
TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
commentDTO.setTotalCommentReply("0");
List<Comment> list = commentDao.findByJournalId(journalId);
int total = 0;
if (null != list && list.size() > 0) {
total = list.size();
}
if (null != totalCommentVo) {
total = total + totalCommentVo.getTotalComment();
totalString = total +"";
if (total > 99) {
totalString = "99+";
}
}
commentDTO.setTotalCommentReply(totalString);
commentDTO.setTotalCommentReplyInt(total);
return commentDTO;
}
}

@ -13,6 +13,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.luoo.music.client.UserClient;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.MongoTemplate;
import com.apifan.common.random.RandomSource;
@ -76,6 +77,18 @@ public class JournalMapper {
return journalRespDTO;
}
public static JournalRespDTO getJournalRespDTO(Journal journal,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, UserClient userClient) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate,userClient);
journalRespDTO.setCommentList(commentDTO.getCommentList());
journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply());
journalRespDTO.setTotalCommentReplyInt(commentDTO.getTotalCommentReplyInt());
return journalRespDTO;
}
private static String getPublishDate(Journal journal) {
LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime();

@ -0,0 +1,129 @@
package com.luoo.music.dto.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Id;
import java.util.Date;
@Data
public class UserInfoDTO {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@Id
private String id;
/**
*
*/
private String mobile;
/**
*
*/
private String nickName;
/**
*
*/
private String avatar;
/**
*
*/
private String signature;
/**
*
*/
private String password;
/**
*
*/
private String email;
/**
* 0: 1: 2:
*/
private Integer sex;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birthday;
/**
*
*/
private int fansCount;
/**
*
*/
private int followCount;
/**
*
*/
private int thumbUpCount;
/**
*
*/
private int songCount;
/**
*
*/
private int journalCount;
/**
*
*/
private int commentReplyCount;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date joinTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date modifyTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date lastLoginTime;
/**
* 使ID
*/
private String lastUseDeviceId;
/**
*
*/
private String lastUseDeviceBrand;
/**
* IP
*/
private String lastLoginIp;
/**
* 0: 1:
*/
private int status;
/**
* 0: 1:
*/
private int onlineStatus;
private String badges;
}

@ -9,6 +9,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import api.Result;
import com.luoo.music.client.UserClient;
import constants.Constants;
import enums.JournalPublishEnum;
import enums.JournalStatusEnum;
@ -70,6 +71,9 @@ public class JournalService {
@Autowired
private TagService tagService;
@Autowired
private UserClient userClient;
/**
*
@ -373,7 +377,7 @@ public class JournalService {
private List<JournalRespDTO> getJournalRespDTOWithComment(JournalQueryReq queryReq) {
List<Journal> pageList = queryPage(queryReq);
return pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao)).collect(Collectors.toList());
return pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient)).collect(Collectors.toList());
}

@ -69,4 +69,12 @@ public class SimpleUserController {
List<String> idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList());
return Result.success(userInfoService.getSimpleUserOrderByField(idList));
}
@GetMapping("/user/{id}")
public UserInfo findByUserId(@PathVariable String id) {
UserInfo userInfo = userInfoService.findById(id);
return userInfo;
}
}

Loading…
Cancel
Save