PsHooN7979 08-06
240806 박세훈 학생 게시판 관련 crud 추가
@8b7466849591a5f53d6ec39b724a590531021f6b
src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
--- src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
@@ -1,6 +1,7 @@
 package com.takensoft.ai_lms.lms.board.dao;
 
 
+import com.takensoft.ai_lms.lms.board.vo.BoardStudentVO;
 import com.takensoft.ai_lms.lms.board.vo.BoardVO;
 import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
 
@@ -38,6 +39,29 @@
     // 게시글 검색
     List<HashMap<String, Object>> searchBoard(HashMap<String, Object> params) throws Exception;
 
+    // 학생 게시판 등록
+    int insertBoardStudent(BoardStudentVO boardStudentVO) throws Exception;
+
+    // 학생 게시판 삭세
+    int deleteBoardStudent(String bbsId) throws Exception;
+
+    // 학생 게시판 조회
+    List<BoardStudentVO> boardStudentList(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 수 조회
+    int boardStudentCount(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 조회 여부 체크
+    int updateBoardCheck(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 조회 여부 일괄 갱신
+    int updateAllBoardCheck(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 조회 안한 게시물 수 조회
+    int checkCount(HashMap<String, Object> params) throws Exception;
+
+
+
 
 
 }
src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
--- src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
@@ -1,5 +1,6 @@
 package com.takensoft.ai_lms.lms.board.service;
 
+import com.takensoft.ai_lms.lms.board.vo.BoardStudentVO;
 import com.takensoft.ai_lms.lms.board.vo.BoardVO;
 
 import java.util.HashMap;
@@ -34,4 +35,25 @@
 
     // 게시글 검색
     List<HashMap<String, Object>> searchBoard(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 등록
+    int insertBoardStudent(BoardStudentVO boardStudentVO) throws Exception;
+
+    // 학생 게시판 삭세
+    int deleteBoardStudent(String bbsId) throws Exception;
+
+    // 학생 게시판 전체 조회
+    List<BoardStudentVO> boardStudentList(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 수 조회
+    int boardStudentCount(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 조회 여부 체크
+    int updateBoardCheck(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 조회 여부 일괄 갱신
+    int updateAllBoardCheck(HashMap<String, Object> params) throws Exception;
+
+    // 학생 게시판 조회 안한 게시물 수 조회
+    int checkCount(HashMap<String, Object> params) throws Exception;
 }
src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
--- src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
@@ -3,6 +3,7 @@
 import com.takensoft.ai_lms.common.idgen.service.IdgenService;
 import com.takensoft.ai_lms.lms.board.dao.BoardDAO;
 import com.takensoft.ai_lms.lms.board.service.BoardService;
+import com.takensoft.ai_lms.lms.board.vo.BoardStudentVO;
 import com.takensoft.ai_lms.lms.board.vo.BoardVO;
 import lombok.RequiredArgsConstructor;
 import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
@@ -24,7 +25,15 @@
     public int insertBoard(BoardVO boardVO) throws Exception {
         String boardId = boardIdgn.getNextStringId();
         boardVO.setBbsId(boardId);
-        return boardDAO.insertBoard(boardVO);
+        int result = boardDAO.insertBoard(boardVO);
+
+        if(result > 0) {
+            BoardStudentVO boardStudentVO = new BoardStudentVO();
+            boardStudentVO.setBbsId(boardId);
+            boardDAO.insertBoardStudent(boardStudentVO);
+        }
+
+        return result;
     }
     // 게시글 전체 조회
     @Override
@@ -62,7 +71,13 @@
     // 게시글 삭제
     @Override
     public int deleteBoard(String bbsId) throws Exception{
-        return boardDAO.deleteBoard(bbsId);
+        int result = boardDAO.deleteBoard(bbsId);
+
+        if(result > 0) {
+            boardDAO.deleteBoardStudent(bbsId);
+        }
+
+        return result;
     }
 
     // 게시글 검색
@@ -72,6 +87,57 @@
     }
 
 
+    // 학생 게시판 등록
+    @Override
+    public int insertBoardStudent(BoardStudentVO boardStudentVO) throws Exception {
+        return boardDAO.insertBoardStudent(boardStudentVO);
+    }
+
+    // 학생 게시판 삭세
+    @Override
+    public int deleteBoardStudent(String bbsId) throws Exception {
+        return boardDAO.deleteBoardStudent(bbsId);
+    }
+
+
+    // 학생 게시판 조회
+    @Override
+    public List<BoardStudentVO> boardStudentList(HashMap<String, Object> params) throws Exception{
+        int page = Integer.parseInt(params.get("page").toString());
+        int pageSize = Integer.parseInt(params.get("pageSize").toString());
+
+        // 조회를 위한 startIndex 계산
+        int startIndex = (page - 1) * pageSize;
+        params.put("startIndex", startIndex);
+        params.put("pageSize", pageSize);
+        System.out.println(startIndex);
+        return boardDAO.boardStudentList(params);
+    }
+
+    // 학생 게시판 수 조회
+    @Override
+    public int boardStudentCount(HashMap<String, Object> params) throws Exception {
+        return boardDAO.boardStudentCount(params);
+    }
+
+    // 학생 게시판 조회 여부 체크
+    @Override
+    public int updateBoardCheck(HashMap<String, Object> params) throws Exception{
+        return boardDAO.updateBoardCheck(params);
+    }
+
+    // 학생 게시판 조회 여부 일괄 갱신
+    @Override
+    public int updateAllBoardCheck(HashMap<String, Object> params) throws Exception{
+        return boardDAO.updateAllBoardCheck(params);
+    }
+
+    // 학생 게시판 조회 안한 게시물 수 조회
+    @Override
+    public int checkCount(HashMap<String, Object> params) throws Exception{
+        return boardDAO.checkCount(params);
+    }
+
 
 
 }
 
src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardStudentVO.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardStudentVO.java
@@ -0,0 +1,30 @@
+package com.takensoft.ai_lms.lms.board.vo;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.08.06
+ *
+ * 학생 게시판 정보 관련 VO
+ */
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class BoardStudentVO {
+
+    // 학생 아이디
+    private String stdId;
+
+    // 게시판 아이디
+    private String bbsId;
+
+    // 공지 조회 여부
+    private String checkYn;
+}
src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
--- src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
@@ -2,6 +2,7 @@
 
 
 import com.takensoft.ai_lms.lms.board.service.BoardService;
+import com.takensoft.ai_lms.lms.board.vo.BoardStudentVO;
 import com.takensoft.ai_lms.lms.board.vo.BoardVO;
 import com.takensoft.ai_lms.lms.file.service.FileService;
 import lombok.RequiredArgsConstructor;
@@ -141,5 +142,52 @@
     }
 
 
+    /**
+     * @author 박세훈
+     * @since 2024.08.06
+     *
+     * 학생 게시판 조회
+     */
+    @PostMapping("/boardStudentList.json")
+    public ResponseEntity<?> boardStudentList(@RequestBody HashMap<String, Object> params) throws Exception{
+        HashMap<String, Object> result = new HashMap<>();
+
+        // 전체 게시물 수 조회 및 추가
+        result.put("totalBoard", boardService.boardStudentCount(params));
+        result.put("result", boardService.boardStudentList(params));
+        result.put("unCheck", boardService.checkCount(params));
+
+        return new ResponseEntity<>(result, HttpStatus.OK);
+    }
+
+
+    /**
+     * @author 박세훈
+     * @since 2024.08.06
+     *
+     * 학생 게시판 조회 여부 체크
+     */
+    @PostMapping("/boardStudentCheck.json")
+    public int updateBoardCheck(@RequestBody HashMap<String, Object> params) throws Exception {
+        return boardService.updateBoardCheck(params);
+    }
+
+
+    /**
+     * @author 박세훈
+     * @since 2024.08.06
+     *
+     * 학생 게시판 조회 여부 일괄 갱신
+     */
+    @PostMapping("/allBoardStudentCheck.json")
+    public int updateAllBoardCheck(@RequestBody HashMap<String, Object> params) throws Exception {
+        return boardService.updateAllBoardCheck(params);
+    }
+
+
+
+
+
+
 
 }
src/main/resources/mybatis/mapper/lms/board-SQL.xml
--- src/main/resources/mybatis/mapper/lms/board-SQL.xml
+++ src/main/resources/mybatis/mapper/lms/board-SQL.xml
@@ -63,6 +63,12 @@
         </collection>
     </resultMap>
 
+    <resultMap id="boardStudentResultMap" type="BoardStudentVO">
+        <result property="stdId" column="std_id" />
+        <result property="bbsId" column="bbs_id" />
+        <result property="checkYn" column="check_yn" />
+    </resultMap>
+
     <!--
         작성자 : 박세훈
         작성일 : 2024.07.25
@@ -102,16 +108,7 @@
         내 용 : 게시글 전체 조회
     -->
     <select id="findAllBoard"  resultMap="boardResultMap">
-        SELECT  b.bbs_id,
-                b.bbs_ttl,
-                b.bbs_cls,
-                b.bbs_cnt,
-                b.bbs_tm,
-                b.file_mng_id,
-                c.scls_id,
-                c.scls_nm,
-                u.user_id,
-                u.user_nm
+        SELECT  *
         FROM board b
         LEFT JOIN class c ON b.scls_id = c.scls_id
         LEFT JOIN users u ON c.user_id = u.user_id
@@ -141,16 +138,7 @@
         내 용 : 게시글 검색
     -->
     <select id="searchBoard" resultMap="boardResultMap">
-        SELECT  b.bbs_id,
-                b.bbs_ttl,
-                b.bbs_cls,
-                b.bbs_cnt,
-                b.bbs_tm,
-                b.file_mng_id,
-                c.scls_id,
-                c.scls_nm,
-                u.user_id,
-                u.user_nm
+        SELECT  *
         FROM board b
         LEFT JOIN class c ON b.scls_id = c.scls_id
         LEFT JOIN users u ON c.user_id = u.user_id
@@ -196,5 +184,97 @@
         DELETE FROM board WHERE bbs_id = #{bbsId}
     </delete>
 
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 등록
+    -->
+    <insert id="insertBoardStudent" parameterType="BoardStudentVO">
+        INSERT INTO user_board (std_id,
+                                bbs_id,
+                                check_yn)
+        SELECT u.std_id, b.bbs_id, 'F'
+        FROM user_class u
+        JOIN board b ON u.scls_id = b.scls_id
+        ON CONFLICT (std_id, bbs_id)
+        DO NOTHING;
+    </insert>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 삭제
+    -->
+    <delete id="deleteBoardStudent" parameterType="String">
+        DELETE FROM user_board
+        WHERE bbs_id = #{bbsId}
+    </delete>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 조회
+    -->
+    <select id="boardStudentList" resultMap="boardResultMap" >
+        SELECT  *
+        FROM user_class uc
+        JOIN board b ON uc.scls_id = b.scls_id
+        LEFT JOIN class c ON b.scls_id = c.scls_id
+        LEFT JOIN users u ON c.user_id = u.user_id
+        WHERE uc.std_id = #{stdId}
+        ORDER BY b.bbs_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
+    </select>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 조회 여부 갱신
+    -->
+    <update id="updateBoardCheck" parameterType="BoardStudentVO">
+        UPDATE user_board
+        set check_yn = 'T'
+        WHERE bbs_id = #{bbsId}
+         AND std_id = #{stdId}
+         AND check_yn = 'F'
+    </update>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 조회 여부 일괄 갱신
+    -->
+    <update id="updateAllBoardCheck" parameterType="BoardStudentVO">
+        UPDATE user_board
+        set check_yn = 'T'
+        WHERE std_id = #{stdId}
+         AND check_yn = 'F'
+    </update>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 게시물 수 확인
+    -->
+    <select id="boardStudentCount" resultType="Integer">
+        SELECT COUNT(*)
+        FROM user_board
+        WHERE std_id = #{stdId}
+    </select>
+
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.08.06
+        내 용 : 학생 게시판 미조회 게시물 수 확인
+    -->
+    <select id="checkCount" resultType="Integer">
+        SELECT COUNT(*)
+        FROM user_board
+        WHERE check_yn = 'F' AND std_id = #{stdId}
+    </select>
+
+
 </mapper>
 
Add a comment
List