woals 07-26
240726 권민수 학생 정보 조회 api에 제일 최근 학습 3개까지 조회하는 기능 추가
@6614e06068a0dcb7acceeaeb725a580a84242deb
src/main/java/com/takensoft/ai_lms/lms/student/dao/StudentInfoDAO.java
--- src/main/java/com/takensoft/ai_lms/lms/student/dao/StudentInfoDAO.java
+++ src/main/java/com/takensoft/ai_lms/lms/student/dao/StudentInfoDAO.java
@@ -4,6 +4,8 @@
 import org.apache.ibatis.annotations.Param;
 import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
 
+import java.util.List;
+
 /**
  * @author 권민수
  * @since 2024.07.25
src/main/java/com/takensoft/ai_lms/lms/student/service/Impl/StudentInfoServiceImpl.java
--- src/main/java/com/takensoft/ai_lms/lms/student/service/Impl/StudentInfoServiceImpl.java
+++ src/main/java/com/takensoft/ai_lms/lms/student/service/Impl/StudentInfoServiceImpl.java
@@ -6,6 +6,8 @@
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * @author 권민수
  * @since 2024.07.25
@@ -21,6 +23,8 @@
 
     @Override
     public StudentInfoVO getStudentInfo(String userId) {
+//        List<StudentInfoVO> studentInfos = studentInfoDAO.getStudentInfo(userId);
+//        return studentInfos.isEmpty() ? null : studentInfos.get(0);
         return studentInfoDAO.getStudentInfo(userId);
     }
 
 
src/main/java/com/takensoft/ai_lms/lms/student/vo/HistoryVO.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/student/vo/HistoryVO.java
@@ -0,0 +1,23 @@
+package com.takensoft.ai_lms.lms.student.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.sql.Timestamp;
+
+/**
+ * @author 권민수
+ * @since 2024.07.26
+ *
+ * 학생 최근 학습 정보 VO 클래스
+ */
+
+@Getter
+@Setter
+public class HistoryVO {
+
+    private String bookName;
+    private String unitName;
+    private Timestamp completionTime;
+
+}
src/main/java/com/takensoft/ai_lms/lms/student/vo/StudentInfoVO.java
--- src/main/java/com/takensoft/ai_lms/lms/student/vo/StudentInfoVO.java
+++ src/main/java/com/takensoft/ai_lms/lms/student/vo/StudentInfoVO.java
@@ -3,6 +3,8 @@
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.List;
+
 /**
  * @author 권민수
  * @since 2024.07.25
@@ -13,11 +15,13 @@
 @Setter
 @Getter
 public class StudentInfoVO {
+
     private String studentName;
     private String institutionName;
-    private String grade;
+    private int grade;
     private String className;
     private String studentQuestion;
+    private List<HistoryVO> history;
 
 }
 
src/main/resources/mybatis/mapper/lms/student-SQL.xml
--- src/main/resources/mybatis/mapper/lms/student-SQL.xml
+++ src/main/resources/mybatis/mapper/lms/student-SQL.xml
@@ -14,19 +14,40 @@
         <result property="grade" column="grade"/>
         <result property="className" column="className"/>
         <result property="studentQuestion" column="studentQuestion"/>
+        <collection property="history" ofType="com.takensoft.ai_lms.lms.student.vo.HistoryVO">
+            <result property="bookName" column="bookName"/>
+            <result property="unitName" column="unitName"/>
+            <result property="completionTime" column="completionTime"/>
+        </collection>
     </resultMap>
 
-    <select id="getStudentInfo" resultType="com.takensoft.ai_lms.lms.student.vo.StudentInfoVO">
+    <select id="getStudentInfo" resultMap="StudentInfoResultMap">
         SELECT
             u.user_nm AS studentName,
             i.ednst_nm AS institutionName,
             ui.grd_no AS grade,
             ui.scls_nm AS className,
-            uc.stn_qna AS studentQuestion
+            uc.stn_qna AS studentQuestion,
+            hu.book_nm AS bookName,
+            hu.unit_nm AS unitName,
+            hu.cmptn_tm AS completionTime
         FROM users u
                  JOIN user_institution ui ON u.user_id = ui.user_id
                  JOIN institution i ON ui.ednst_id = i.ednst_id
                  JOIN user_class uc ON u.user_id = uc.user_id
+                 LEFT JOIN (
+            SELECT
+                uu.user_id,
+                b.book_nm,
+                un.unit_nm,
+                uu.cmptn_tm
+            FROM user_unit uu
+                     JOIN unit un ON uu.unit_id = un.unit_id
+                     JOIN book b ON un.book_id = b.book_id
+            WHERE uu.user_id = #{userId}
+            ORDER BY uu.cmptn_tm DESC
+                LIMIT 3
+        ) hu ON u.user_id = hu.user_id
         WHERE u.user_id = #{userId}
     </select>
 
Add a comment
List