提交 ee0c6dc1 编写于 作者: minghao.wu's avatar minghao.wu

fix: 新排序规则

上级 18f04a54
......@@ -142,4 +142,24 @@ public class Reply {
public void setIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Reply other = (Reply) obj;
if (other.getId() == null) {
return false;
}
if (id == null) {
if (other.getId() != null)
return false;
} else if (!id.equals(other.getId()))
return false;
return true;
}
}
\ No newline at end of file
......@@ -24,4 +24,18 @@ public interface ReplyMapper {
Reply selectReplyByRecord(Reply record);
List<Reply> selectReplyListByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId);
/**
* 按照时间逆序获取
* @param analysisRoundExamTitleId
* @return
*/
List<Reply> selectReplyListOrderByTime(Integer analysisRoundExamTitleId);
/**
* 获取最热的五条记录
* @param analysisRoundExamTitleId
* @return
*/
List<Reply> selectFiveHottestReplyList(Integer analysisRoundExamTitleId);
}
\ No newline at end of file
......@@ -149,4 +149,11 @@ public interface CHCAnalysisService {
* @return
*/
Reply getReplyByExamTitleId(Integer examTitleId, Integer userId);
/**
* 根据考试id获取评论列表
* @param examTitleId
* @return
*/
List<Reply> getReplyList(Integer examTitleId);
}
......@@ -222,7 +222,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
@Override
public List<ReplyDto> getReplyListDtoByExamTitleId(Integer analysisRoundExamTitleId, Integer userId) {
List<Reply> replyList = replyMapper.selectReplyListByAnalysisRoundExamTitleId(analysisRoundExamTitleId);
List<Reply> replyList = getReplyList(analysisRoundExamTitleId);
List<ReplyDto> replyDtoList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
......@@ -253,7 +253,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
/**
* 1. 找到该题目下的回复列表,默认是按照点赞排序的
*/
List<Reply> replyList = replyMapper.selectReplyListByAnalysisRoundExamTitleId(reply.getAnalysisRoundExamTitleId());
List<Reply> replyList = getReplyList(reply.getAnalysisRoundExamTitleId());
/**
* 2. 找到当前回复的所在位置,返回下一个回复
......@@ -451,4 +451,32 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
reply.setUserId(userId);
return replyMapper.selectReplyByRecord(reply);
}
@Override
public List<Reply> getReplyList(Integer examTitleId) {
Integer replyCount = replyMapper.selectReplyCountByAnalysisRoundExamTitleId(examTitleId);
/**
* case 1. 按照时间排序,如果个数小于5,直接返回
*/
List<Reply> replyList = replyMapper.selectReplyListOrderByTime(examTitleId);
if (replyCount < 5) {
return replyList;
}
/**
* case 2.大于等于5的时候,根据排序 5最热+ 时间排序
*/
List<Reply> replyListFive = replyMapper.selectFiveHottestReplyList(examTitleId);
List<Reply> replyListOther = new ArrayList<>();
replyListOther.addAll(replyListFive);
for (Reply reply : replyList) {
if (!replyListFive.contains(reply))
replyListOther.add(reply);
}
return replyListOther;
}
}
......@@ -63,6 +63,25 @@
order by star_count desc, seq_no asc
</select>
<select id="selectReplyListOrderByTime" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from p_reply
where analysis_round_exam_title_id = #{analysisRoundExamTitleId,jdbcType=INTEGER}
and is_deleted = 0
order by modified_time desc, seq_no asc
</select>
<select id="selectFiveHottestReplyList" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from p_reply
where analysis_round_exam_title_id = #{analysisRoundExamTitleId,jdbcType=INTEGER}
and is_deleted = 0
order by star_count desc, modified_time desc
limit 5
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from p_reply
where id = #{id,jdbcType=INTEGER}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册