feat:新增查询学生列表功能

This commit is contained in:
lbw
2025-12-10 19:30:08 +08:00
parent d777437e82
commit d424f72183
10 changed files with 210 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
package com.yinlihupo.enlish.service.controller;
import com.yinlihupo.enlish.service.domain.dataobject.StudentDO;
import com.yinlihupo.enlish.service.model.vo.student.FindStudentsReqVO;
import com.yinlihupo.enlish.service.model.vo.student.StudentItemRspVO;
import com.yinlihupo.enlish.service.service.StudentService;
import com.yinlihupo.framework.biz.operationlog.aspect.ApiOperationLog;
import com.yinlihupo.framework.common.response.PageResponse;
import jakarta.annotation.Resource;
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 java.util.List;
@RequestMapping("/student/")
@RestController
public class StudentController {
@Resource
private StudentService studentService;
@PostMapping("/list")
@ApiOperationLog(description = "查询学生列表")
public PageResponse<StudentItemRspVO> findStudents(@RequestBody FindStudentsReqVO findStudentsReqVO) {
Integer classId = findStudentsReqVO.getClassId();
Integer gradeId = findStudentsReqVO.getGradeId();
Integer pageNo = findStudentsReqVO.getPageNo();
Integer pageSize = findStudentsReqVO.getPageSize();
List<StudentDO> students = studentService.getStudentsByClassIdAndGradeId(classId, gradeId, pageNo, pageSize);
int allStudents = studentService.getAllStudents();
List<StudentItemRspVO> studentItemRspVOS = students.stream().map(studentDO -> StudentItemRspVO.builder()
.id(studentDO.getId())
.name(studentDO.getName())
.classId(studentDO.getClassId())
.gradeId(studentDO.getGradeId())
.build()).toList();
return PageResponse.success(studentItemRspVOS, pageNo, allStudents, pageSize);
}
}

View File

@@ -0,0 +1,26 @@
package com.yinlihupo.enlish.service.domain.dataobject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class StudentDO {
private Integer id;
private String name;
private Integer classId;
private Integer gradeId;
private Integer initialVocabularySize;
private Integer currentVocabularySize;
}

View File

@@ -0,0 +1,12 @@
package com.yinlihupo.enlish.service.domain.mapper;
import com.yinlihupo.enlish.service.domain.dataobject.StudentDO;
import java.util.List;
public interface StudentDOMapper {
List<StudentDO> selectStudentDOListByClassIdAndGradeId(Integer classId, Integer gradeId, Integer pageSize, Integer offset);
int selectStudentCount();
}

View File

@@ -0,0 +1,19 @@
package com.yinlihupo.enlish.service.model.vo.student;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class FindStudentsReqVO {
private Integer classId;
private Integer gradeId;
private Integer pageNo;
private Integer pageSize;
}

View File

@@ -0,0 +1,18 @@
package com.yinlihupo.enlish.service.model.vo.student;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class StudentItemRspVO {
private Integer id;
private String name;
private Integer classId;
private Integer gradeId;
}

View File

@@ -0,0 +1,13 @@
package com.yinlihupo.enlish.service.service;
import com.yinlihupo.enlish.service.domain.dataobject.StudentDO;
import java.util.List;
public interface StudentService {
List<StudentDO> getStudentsByClassIdAndGradeId(Integer classId, Integer gradeId, Integer pageNo, Integer pageSize);
int getAllStudents();
}

View File

@@ -0,0 +1,28 @@
package com.yinlihupo.enlish.service.service.assessment;
import com.yinlihupo.enlish.service.domain.dataobject.StudentDO;
import com.yinlihupo.enlish.service.domain.mapper.StudentDOMapper;
import com.yinlihupo.enlish.service.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
@Resource
private StudentDOMapper studentDOMapper;
@Override
public List<StudentDO> getStudentsByClassIdAndGradeId(Integer classId, Integer gradeId, Integer pageNo, Integer pageSize) {
return studentDOMapper.selectStudentDOListByClassIdAndGradeId(classId, gradeId, pageSize, (pageNo - 1) * pageSize);
}
@Override
public int getAllStudents() {
return studentDOMapper.selectStudentCount();
}
}

View File

@@ -0,0 +1,12 @@
package com.yinlihupo.enlish.service.service.student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class StudentServiceImpl {
}

View File

@@ -45,7 +45,7 @@
targetProject="src/main/java"/>
<!-- 需要生成的表-实体类 -->
<table tableName="assessments" domainObjectName="AssessmentsDO"
<table tableName="student" domainObjectName="StudentDO"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yinlihupo.enlish.service.domain.mapper.StudentDOMapper">
<resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.StudentDO">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="class_id" jdbcType="INTEGER" property="classId" />
<result column="grade_id" jdbcType="INTEGER" property="gradeId" />
<result column="initial_vocabulary_size" jdbcType="INTEGER" property="initialVocabularySize" />
<result column="current_vocabulary_size" jdbcType="INTEGER" property="currentVocabularySize" />
</resultMap>
<sql id="Base_Column_List">
id, `name`, class_id, grade_id, initial_vocabulary_size, current_vocabulary_size
</sql>
<select id="selectStudentDOListByClassIdAndGradeId" resultMap="BaseResultMap">
select *
from student
where 1 = 1
<if test="classId != null">
AND class_id = #{classId}
</if>
<if test="gradeId != null">
AND grade_id = #{gradeId}
</if>
LIMIT #{offset}, #{pageSize}
</select>
<select id="selectStudentCount">
select count(1)
from student
</select>
</mapper>