Sfoglia il codice sorgente

feat(student): 获取学生基础信息及学习进度

- 新增 StudentInfoController 中的 selectStudentInfo 方法- 在 StudentInfoDto 中添加 progress 字段
- 在 StudentInfoMapper 中添加 selectById 方法
- 在 StudentInfoMapper.xml 中实现 selectById 方法的 SQL
- 在 StudentInfoService 中添加 selectStudentInfo 方法
zhengjinbin 6 mesi fa
parent
commit
e44fc79f1b

+ 13 - 4
education-api/src/main/java/com/education/api/controller/student/StudentInfoController.java

@@ -4,6 +4,7 @@ import com.education.auth.AuthUtil;
 import com.education.auth.LoginToken;
 import com.education.business.service.education.StudentInfoService;
 import com.education.business.session.StudentSession;
+import com.education.business.session.UserSessionContext;
 import com.education.common.annotation.Param;
 import com.education.common.annotation.ParamsType;
 import com.education.common.annotation.ParamsValidate;
@@ -16,10 +17,8 @@ import com.education.common.utils.ResultCode;
 import com.education.model.dto.StudentInfoDto;
 import com.education.model.entity.StudentInfo;
 import com.education.model.request.UserLoginRequest;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 
@@ -86,4 +85,14 @@ public class StudentInfoController extends BaseController {
     public Result updateInfo(@RequestBody StudentInfo studentInfo) {
         return Result.success(studentInfoService.updateInfo(studentInfo));
     }
+    /**
+     * 获取学生基础信息
+     * @return
+     */
+    @GetMapping("selectStudentInfo")
+    public Result selectStudentInfo() {
+        return Result.success(studentInfoService.selectStudentInfo());
+    }
+
+
 }

+ 3 - 0
education-business/src/main/java/com/education/business/mapper/education/StudentInfoMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.education.model.dto.StudentInfoDto;
 import com.education.model.entity.StudentInfo;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * @author zengjintao
@@ -19,4 +20,6 @@ public interface StudentInfoMapper extends BaseMapper<StudentInfo> {
      * @return
      */
     Page<StudentInfoDto> selectPageList(Page<StudentInfoDto> page, StudentInfo studentInfo);
+
+    StudentInfoDto selectById(@Param("id") Integer id);
 }

+ 6 - 0
education-business/src/main/java/com/education/business/service/education/StudentInfoService.java

@@ -50,6 +50,8 @@ public class StudentInfoService extends BaseService<StudentInfoMapper, StudentIn
     private JwtToken jwtToken;
     @Resource
     private WebsiteConfigService websiteConfigService;
+    @Autowired
+    private StudentInfoMapper studentInfoMapper;
 
     public PageInfo<StudentInfoDto> selectPageList(PageParam pageParam, StudentInfo studentInfo) {
         Page<StudentInfoDto> page = new Page<>(pageParam.getPageNumber(), pageParam.getPageSize());
@@ -156,4 +158,8 @@ public class StudentInfoService extends BaseService<StudentInfoMapper, StudentIn
         studentInfo.setId(UserSessionContext.getStudentId());
         return super.updateById(studentInfo);
     }
+
+    public StudentInfoDto selectStudentInfo() {
+        return studentInfoMapper.selectById(UserSessionContext.getStudentId());
+    }
 }

+ 26 - 0
education-business/src/main/resources/mapper/education/StudentInfoMapper.xml

@@ -20,4 +20,30 @@
         order by student.id desc
     </select>
 
+    <select id="selectById" resultType="com.education.model.dto.StudentInfoDto">
+        SELECT
+            si.*,
+
+            CONCAT(
+                    ROUND(
+                            (
+                                SELECT COUNT(DISTINCT sgi.goal_info_id)
+                                FROM stu_goal_info sgi
+                                WHERE sgi.student_id = si.id AND sgi.correct_status >= 2
+                            ) / NULLIF(
+                                    (
+                                        SELECT COUNT( gi.id)
+                                        FROM student_course_collect scc
+                                                 JOIN goal_info gi ON scc.course_id = gi.course_id
+                                        WHERE scc.student_id = si.id AND gi.publish_flag = 1
+                                    ), 0
+                                ) * 100, 2
+                    ), '%'
+            ) AS progress
+        FROM
+            student_info si
+        WHERE
+            si.id = #{id}
+    </select>
+
 </mapper>

+ 9 - 0
education-model/src/main/java/com/education/model/dto/StudentInfoDto.java

@@ -12,6 +12,15 @@ public class StudentInfoDto extends StudentInfo {
     private String gradeName;
     private String confirmPassword;
     private String newPassword;
+    private String progress;
+
+    public String getProgress() {
+        return progress;
+    }
+
+    public void setProgress(String progress) {
+        this.progress = progress;
+    }
 
     public String getNewPassword() {
         return newPassword;