1.add comment dto

main
Gary 10 months ago
parent 7e1af4eceb
commit 749e0469f9

@ -7,8 +7,10 @@ import java.util.Set;
import java.util.stream.Collectors;
import com.luoo.music.dao.CommentDao;
import com.luoo.music.dto.mapper.CommentMapper;
import com.luoo.music.dto.mapper.JournalMapper;
import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalFilterDTO;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.TagDTO;
@ -113,6 +115,9 @@ public class JournalController {
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user && !journalService.isLatest10ByJournalId(id)) {
return Result.unauthorized(null);
}
Journal journal = journalService.findById(id);
JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,commentDao);
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL);
@ -120,6 +125,19 @@ public class JournalController {
return Result.success(journalRespDTO);
}
@ApiOperation(value = "3.1 根据期刊id查询评论信息")
@GetMapping("/comment/{id}")
@GlobalInterceptor
public Result<CommentDTO> findCommentById(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user && !journalService.isLatest10ByJournalId(id)) {
return Result.unauthorized(null);
}
return Result.success(CommentMapper.getCommentDTO(id,mongoTemplate,commentDao));
}
@ApiOperation(value = "4.获取期刊筛选条件")
@GetMapping("/filter")
@GlobalInterceptor(checkAppUserLogin = true)

@ -74,7 +74,7 @@ public class SongController {
}
private boolean isLatest10(String journalNo) {
return journalService.isLatest10(journalNo);
return journalService.isLatest10ByJournalNo(journalNo);
}
@ApiOperation(value = "2.查询收藏歌曲信息")

@ -44,7 +44,10 @@ public interface JournalDao extends JpaRepository<Journal,String>,JpaSpecificati
List<Journal> orderByField(List<String> objectIds);
@Query(value = "select 1 from tb_journal where ?1 in (select journal_no_tmp.journal_no from (select * from tb_journal order by ABS(journal_no) desc limit 10) as journal_no_tmp) limit 1", nativeQuery = true)
Integer isLatest10(String journalNo);
Integer isLatest10ByJournalNo(String journalNo);
@Query(value = "select 1 from tb_journal where ?1 in (select journal_no_tmp.id from (select * from tb_journal order by ABS(journal_no) desc limit 10) as journal_no_tmp) limit 1", nativeQuery = true)
Integer isLatest10ByJournalId(String journalId);
@Modifying
@Transactional

@ -0,0 +1,45 @@
package com.luoo.music.dto.mapper;
import java.util.List;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import com.luoo.music.dao.CommentDao;
import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.TotalCommentVo;
import com.luoo.music.pojo.Comment;
public class CommentMapper {
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao) {
CommentDTO commentDTO=new CommentDTO();
List<Comment> commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
commentDTO.setCommentList(commentList);
/**
*
*/
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();
commentDTO.setTotalCommentReply(total + "");
if (total > 99) {
commentDTO.setTotalCommentReply("99+");
}
}
return commentDTO;
}
}

@ -15,16 +15,11 @@ import java.util.stream.Collectors;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import com.apifan.common.random.RandomSource;
import com.apifan.common.random.entity.Poem;
import com.luoo.music.dao.CommentDao;
import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.TotalCommentVo;
import com.luoo.music.pojo.Comment;
import com.luoo.music.pojo.Journal;
import constants.Constants;
import enums.DateTimePatternEnum;
@ -56,7 +51,7 @@ public class JournalMapper {
}
public static JournalRespDTO getJournalRespDTO(Journal journal) {
return getJournalRespDTO(journal,Collections.emptySet());
return getJournalRespDTO(journal, Collections.emptySet());
}
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
@ -82,40 +77,13 @@ public class JournalMapper {
}
return journalRespDTO;
}
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet,
MongoTemplate mongoTemplate, CommentDao commentDao) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal,journalCollectSet);
/**
* 5...
*/
List<Comment> commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journal.getId());
journalRespDTO.setCommentList(commentList);
/**
*
*/
Criteria criteria = Criteria.where("journalId").is(journal.getId());
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();
journalRespDTO.setTotalCommentReply("0");
List<Comment> list = commentDao.findByJournalId(journal.getId());
int total = 0;
if (null != list && list.size() > 0) {
total = list.size();
}
if (null != totalCommentVo) {
total = total + totalCommentVo.getTotalComment();
journalRespDTO.setTotalCommentReply(total + "");
if (total > 99) {
journalRespDTO.setTotalCommentReply("99+");
}
}
JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao);
journalRespDTO.setCommentList(commentDTO.getCommentList());
journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply());
return journalRespDTO;
}

@ -0,0 +1,16 @@
package com.luoo.music.dto.response;
import java.util.List;
import com.luoo.music.pojo.Comment;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class CommentDTO {
@ApiModelProperty(value = "期刊评论top5")
private List<Comment> commentList;
@ApiModelProperty(value = "期刊总评论数,大于99显示99+")
private String totalCommentReply;
}

@ -213,8 +213,8 @@ public class JournalService {
public boolean isLatest10(String journalNo) {
return null!=journalDao.isLatest10(journalNo);
public boolean isLatest10ByJournalNo(String journalNo) {
return null!=journalDao.isLatest10ByJournalNo(journalNo);
}
public List<Journal> orderByField(List<String> objectIds) {
@ -281,4 +281,9 @@ public class JournalService {
// TODO Auto-generated method stub
return Collections.emptyList();
}
public boolean isLatest10ByJournalId(String journalId) {
return null!=journalDao.isLatest10ByJournalId(journalId);
}
}

Loading…
Cancel
Save