Merge pull request #54 from linhaojun857/dev

merge dev
master
linhaojun857 3 years ago committed by GitHub
commit caff59e334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,9 @@
{
"name": "aurora-springboot",
"version": "1.0.0",
"scripts": {
"deploy": "node deploy.js"
},
"dependencies": {
"chalk": "^4.1.2",
"dotenv": "^16.0.3",

@ -26,6 +26,8 @@ public interface CommentMapper extends BaseMapper<Comment> {
List<CommentAdminDTO> listCommentsAdmin(@Param("current") Long current, @Param("size") Long size, @Param("conditionVO") ConditionVO conditionVO);
List<CommentCountDTO> listCommentCountByTopicIds(@Param("topicIds") List<Integer> topicIds);
List<CommentCountDTO> listCommentCountByTypeAndTopicIds(@Param("type") Integer type, @Param("topicIds") List<Integer> topicIds);
CommentCountDTO listCommentCountByTypeAndTopicId(@Param("type") Integer type, @Param("topicId") Integer topicId);
}

@ -14,4 +14,5 @@ public class CommentCountDTO {
private Integer id;
private Integer commentCount;
}

@ -1,6 +1,7 @@
package com.aurora.service.impl;
import com.alibaba.fastjson.JSON;
import com.aurora.enums.CommentTypeEnum;
import com.aurora.model.dto.CommentCountDTO;
import com.aurora.model.dto.TalkAdminDTO;
import com.aurora.model.dto.TalkDTO;
@ -39,7 +40,6 @@ public class TalkServiceImpl extends ServiceImpl<TalkMapper, Talk> implements Ta
@Autowired
private CommentMapper commentMapper;
@Override
public PageResultDTO<TalkDTO> listTalks() {
Integer count = talkMapper.selectCount((new LambdaQueryWrapper<Talk>()
@ -51,7 +51,7 @@ public class TalkServiceImpl extends ServiceImpl<TalkMapper, Talk> implements Ta
List<Integer> talkIds = talkDTOs.stream()
.map(TalkDTO::getId)
.collect(Collectors.toList());
Map<Integer, Integer> commentCountMap = commentMapper.listCommentCountByTopicIds(talkIds)
Map<Integer, Integer> commentCountMap = commentMapper.listCommentCountByTypeAndTopicIds(CommentTypeEnum.TALK.getType(), talkIds)
.stream()
.collect(Collectors.toMap(CommentCountDTO::getId, CommentCountDTO::getCommentCount));
talkDTOs.forEach(item -> {
@ -72,6 +72,8 @@ public class TalkServiceImpl extends ServiceImpl<TalkMapper, Talk> implements Ta
if (Objects.nonNull(talkDTO.getImages())) {
talkDTO.setImgs(CommonUtil.castList(JSON.parseObject(talkDTO.getImages(), List.class), String.class));
}
CommentCountDTO commentCountDTO = commentMapper.listCommentCountByTypeAndTopicId(CommentTypeEnum.TALK.getType(), talkId);
talkDTO.setCommentCount(commentCountDTO.getCommentCount());
return talkDTO;
}

@ -70,7 +70,8 @@
FROM t_comment c
JOIN t_user_info u ON c.user_id = u.id
where c.is_review = 1
ORDER BY c.id DESC LIMIT 0 , 6
ORDER BY c.id DESC
LIMIT 0 , 6
</select>
<select id="countComments" resultType="java.lang.Integer">
SELECT
@ -121,20 +122,27 @@
id DESC
LIMIT #{current},#{size}
</select>
<select id="listCommentCountByTopicIds" resultType="com.aurora.model.dto.CommentCountDTO">
<select id="listCommentCountByTypeAndTopicIds" resultType="com.aurora.model.dto.CommentCountDTO">
SELECT
topic_id as id,
COUNT( 1 ) AS comment_count
FROM
t_comment
WHERE
WHERE type = #{type}
AND
topic_id IN
<foreach open="(" collection="topicIds" item="topicId" separator="," close=")">
#{topicId}
</foreach>
AND
parent_id IS NULL
GROUP BY
topic_id
</select>
<select id="listCommentCountByTypeAndTopicId" resultType="com.aurora.model.dto.CommentCountDTO">
SELECT topic_id as id,
COUNT(1) AS comment_count
FROM t_comment
WHERE type = #{type}
AND topic_id = #{topicId}
GROUP BY topic_id
</select>
</mapper>
Loading…
Cancel
Save