private long parentSeq;
private int boardOrder;
private long boardDepth;
<select id="getTitleVOList" parameterType="SelectVO" resultType="TitleVO">
SELECT board_seq as boardSeq
, title
, writer
, date
, count
, user_id as userId
, user_seq as userSeq
, board_del as boardDel
, parent_seq as parentSeq
, board_order as boardOrder
, board_depth as boardDept
FROM board
<include refid="searchBoard"></include>
ORDER BY parent_seq DESC, board_order ASC
LIMIT #{start}, #{length}
</select>
private PostReplyVO getMyRelpyVO(PostReplyVO parentReplyVo) throws Exception {
if (parentReplyVo == null) {
throw new LogicException(Constants.RESULT_STATE.BOARD_UNKOWN_ERROR.getState(), Constants.RESULT_STATE.BOARD_UNKOWN_ERROR.getMessage());
}
PostReplyVO myReplyVO = new PostReplyVO(); // 현재 게시물 자신의 정보
myReplyVO.setParentSeq(parentReplyVo.getParentSeq()); // 최상위 부모 seq 넣어줌
boolean isChild = isParentFirstChild(parentReplyVo.getBoardSeq());
if (!isChild) { // 자식이 존재하지 않는다
PostReplyVO lastPostReplyVO = dao.getPostReplyVO(parentReplyVo.getBoardSeq()); // 직계부모 정보를 가져와서 자신의 정보를 정한다
if (lastPostReplyVO == null) {
throw new LogicException(Constants.RESULT_STATE.BOARD_UNKOWN_ERROR.getState(), Constants.RESULT_STATE.BOARD_UNKOWN_ERROR.getMessage());
}
myReplyVO.setBoardOrder(lastPostReplyVO.getBoardOrder() + 1);
myReplyVO.setBoardDepth(lastPostReplyVO.getBoardDepth() + 1);
} else {
PostReplyVO postReplyVO = getMyParentLastChildBoardReplyVO(parentReplyVo); // 자신의 부모의 마지막 자식을 찾음
if (postReplyVO == null) {
throw new LogicException(Constants.RESULT_STATE.BOARD_UNKOWN_ERROR.getState(), Constants.RESULT_STATE.BOARD_UNKOWN_ERROR.getMessage());
}
myReplyVO.setBoardOrder(postReplyVO.getBoardOrder() + 1); // 마지막 자식의 정보를 가지고 자신의 정보를 정한다
myReplyVO.setBoardDepth(parentReplyVo.getBoardDepth() + 1); // 부모의 깊이에서 하나 더해주기
}
return myReplyVO;
}
<select id="getParentNextChildBoardCount" parameterType="PostReplyVO" resultType="int">
SELECT
count(*)
FROM board
WHERE parent_seq = #{parentSeq} and board_order = #{boardOrder} + 1 and board_depth = #{boardDepth} + 1
</select>
<select id="getLastReplyBoard" resultType="PostReplyVO" parameterType="ParamMap" >
SELECT
board_seq as boardSeq
, parent_seq as parentSeq
, board_order as boardOrder
, board_depth as boardDepth
FROM board
WHERE parent_seq = #{parentSeq} and board_depth >= #{boardDepth} + 1 and (board_order > #{boardOrder}) AND board_state IN (0, 2)
ORDER BY board_order DESC
LIMIT 0,1
</select>