重构学生查询接口(覆盖queryStudent接口)

master
mzh820631607 4 years ago
parent 82a8abb906
commit 07fa2ca51a
  1. 101
      src/main/java/com/yipin/liuwanr/controller/StudentController.java
  2. 19
      src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java
  3. 80
      src/main/java/com/yipin/liuwanr/service/StudentService.java

@ -3,6 +3,7 @@ package com.yipin.liuwanr.controller;
import com.yipin.liuwanr.entity.Response;
import com.yipin.liuwanr.entity.Student;
import com.yipin.liuwanr.entity.UserM;
import com.yipin.liuwanr.helper.QueryStudentUtils;
import com.yipin.liuwanr.helper.RedisHelper;
import com.yipin.liuwanr.service.StudentService;
import com.yipin.liuwanr.service.UserService;
@ -34,7 +35,6 @@ public class StudentController {
/**
* 批量导入学生
* @param file
* @param classId
* @return
*/
@PostMapping("/readStudent")
@ -95,42 +95,6 @@ public class StudentController {
return resp;
}
/**
* 查询学生
*/
@GetMapping("/queryStudent")
Response queryStudent(@RequestParam Integer schoolId,String searchContent,Integer pageNo,Integer pageSize,String professionalIds,String gradeIds,String classIds) {
Response resp = new Response();
Student student = new Student();
if (schoolId==null){
resp.setStatus(300);
resp.setErrmessage("学校id为空,查询失败!");
}else{
if (searchContent!=null&&searchContent!="") {
student.setSearchContent(searchContent);
}
if (professionalIds!=null&&professionalIds!="") {
student.setProfessionalIds(professionalIds);
}
if (gradeIds!=null&&gradeIds!="") {
student.setGradeIds(gradeIds);
}
if (classIds!=null&&classIds!="") {
student.setClassIds(classIds);
}
student.setSchoolId(schoolId);
HashMap<String, Object> ret = studentService.queryStudent(student,pageNo,pageSize);
int status = (int) ret.get("retcode");
if (200 == status) {
resp.setStatus(status);
resp.setMessage(ret.get("retvalue"));
} else {
resp.setStatus(status);
resp.setErrmessage(ret.get("retvalue").toString());
}
}
return resp;
}
/**
* 查询学生详情
@ -155,6 +119,69 @@ public class StudentController {
return resp;
}
/**
* 根据professionalIds专业id查询所有学生
* @param schoolId 必须
* @param professionalIds
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("queryStudent/byProfessionalIds")
Response queryStudentByProfessionalIds(@RequestParam Integer schoolId,@RequestParam Integer professionalIds,Integer pageNo,Integer pageSize){
Response resp = new Response();
if (schoolId == null){
resp.setMessage(300);
resp.setErrmessage("学校id为空,查询失败!");
}else{
HashMap<String, Object> ret = studentService.queryStudentByProfessionalIds(professionalIds, pageNo, pageSize, schoolId);
QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue");
}
return resp;
}
/**
* 根据年级id查询所有学生信息
* @param schoolId
* @param gradeId
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("queryStudent/byGradeId")
Response queryStudentByGradeId(@RequestParam Integer schoolId, @RequestParam Integer gradeId, Integer pageNo, Integer pageSize){
Response resp = new Response();
if (schoolId == null){
resp.setMessage(300);
resp.setErrmessage("学校id为空,查询失败!");
}else {
HashMap<String, Object> ret = studentService.queryStudentByGradeIds(gradeId, pageNo, pageSize, schoolId);
QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue");
}
return resp;
}
/**
* 根据班级id查询所有学生信息
* @param schoolId
* @param classId
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("queryStudent/byClassIds")
Response queryStudentByClassIds(@RequestParam Integer schoolId,@RequestParam Integer classId,Integer pageNo,Integer pageSize){
Response resp = new Response();
if (schoolId == null){
resp.setMessage(300);
resp.setErrmessage("学校id为空,查询失败!");
}else {
HashMap<String, Object> ret = studentService.queryStudentByClassIds(classId, pageNo, pageSize, schoolId);
QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue");
}
return resp;
}
/**
* 删除学生
*/

@ -18,14 +18,17 @@ public interface StudentMapper {
+ "VALUES(#{studentName},#{studentNumber},#{phone},#{email},#{roleId},#{schoolId},#{professionalId},#{gradeId},#{classId},0,#{uniqueIdentificationAccount})")
void addStudent(Student student);
//查询学生
@Select({ "<script>",
"SELECT stu.stuProfessionalArchitectureName,g.gradeName,cla.className,t.loginNumber,t.lastLoginTime,t.uniqueIdentificationAccount,t.studentId,t.studentName,t.studentNumber,t.phone,t.email,t.roleId,t.schoolId,t.professionalId,t.gradeId,t.classId,t.experimentalClassId,(SELECT GROUP_CONCAT(c.experimentalClassName) FROM experimental_class_ning c WHERE FIND_IN_SET(c.experimentalClassId,t.experimentalClassId)) AS experimentName FROM student t,class cla,grade g,stu_professional_architecture stu WHERE t.isdel =0 and t.classId = cla.classId and t.gradeId = g.gradeId and t.professionalId = stu.stuProfessionalArchitectureId and t.schoolId=#{schoolId}",
" <if test='searchContent!=null'> and t.studentName like CONCAT('%',#{searchContent},'%') or t.studentNumber like CONCAT('%',#{searchContent},'%')</if>",
" <if test='professionalIds!=null'> and FIND_IN_SET(t.professionalId,#{professionalIds})</if>",
" <if test='gradeIds!=null'> and FIND_IN_SET(t.gradeId,#{gradeIds}) </if>",
" <if test='classIds!=null'> and FIND_IN_SET(t.classId,#{classIds})</if>", "</script> " })
List<Student> queryStudent(Student student);
//通过专业id查询所有学生信息
@Select("SELECT studentName,studentNumber,professionalName,gradeId,classId,roleId,loginNumber,lastLoginTime from student WHERE professionalId = #{professionalIds} and schoolId = #{schoolId}")
List<Student> queryStudentByProfessionalIds(Integer professionalIds, Integer schoolId);
//通过年级id查询所有学生信息
@Select("SELECT studentName,studentNumber,professionalName,gradeId,classId,roleId,loginNumber,lastLoginTime from student WHERE gradeId = #{gradeId} and schoolId = #{schoolId}")
List<Student> queryStudentByGradeIds(Integer gradeId, Integer schoolId);
//通过班级id查询所有学生信息
@Select("SELECT studentName,studentNumber,professionalName,gradeId,classId,roleId,loginNumber,lastLoginTime from student WHERE classId = #{classId} and schoolId = #{schoolId}")
List<Student> queryStudentByClassIds(Integer classId, Integer schoolId);
@Select("select s.studentId,studentName from experimental_class_student ecs left join student s on ecs.studentId=s.studentId where ecs.experimentalClassId=#{experimentalClassId} ")
List<Student> getByStudents(Integer experimentalClassId);

@ -53,12 +53,12 @@ public class StudentService {
return resp;
}
public HashMap<String, Object> queryStudent(Student student, Integer pageNo, Integer pageSize) {
public HashMap<String, Object> queryStudentByProfessionalIds(Integer professionalIds,Integer pageNo, Integer pageSize ,Integer schoolId){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
if (pageNo != null && pageSize != null) {
PageHelper.startPage(pageNo, pageSize);
List<Student> list = studentMapper.queryStudent(student);
List<Student> list = studentMapper.queryStudentByProfessionalIds(professionalIds,schoolId);
PageInfo<Student> info = new PageInfo<Student>(list);
int total1 = (int) info.getTotal();
int totalPages;
@ -69,19 +69,83 @@ public class StudentService {
long total = total1;
resp.put("retvalue", new PageResult(total, list, totalPages));
resp.put("retcode", 200);
} else {
List<Student> list = studentMapper.queryStudent(student);
resp.put("retvalue", list);
}else{
List<Student> list = studentMapper.queryStudentByProfessionalIds(professionalIds,schoolId);
resp.put("retcode",200);
resp.put("retvalue",list);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
resp.put("retcode",500);
resp.put("retvalue","Inquiry Failed");
return resp;
}
return resp;
}
public HashMap<String, Object> queryStudentByGradeIds(Integer gradeId,Integer pageNo, Integer pageSize ,Integer schoolId){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
if (pageNo != null && pageSize != null) {
PageHelper.startPage(pageNo, pageSize);
List<Student> list = studentMapper.queryStudentByProfessionalIds(gradeId,schoolId);
PageInfo<Student> info = new PageInfo<Student>(list);
int total1 = (int) info.getTotal();
int totalPages;
totalPages = total1 / pageSize;
if (total1 % pageSize != 0) {
totalPages++;
}
long total = total1;
resp.put("retvalue", new PageResult(total, list, totalPages));
resp.put("retcode", 200);
}else{
List<Student> list = studentMapper.queryStudentByGradeIds(gradeId,schoolId);
resp.put("retcode",200);
resp.put("retvalue",list);
}
} catch (RuntimeException e) {
}catch (RuntimeException e){
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
resp.put("retcode",500);
resp.put("retvalue","Inquiry Failed");
return resp;
}
return resp;
// List<Student> list = studentMapper.queryStudentByProfessionalIds(professionalIds,schoolId);
}
public HashMap<String, Object> queryStudentByClassIds(Integer classId,Integer pageNo, Integer pageSize ,Integer schoolId){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
if (pageNo != null && pageSize != null) {
PageHelper.startPage(pageNo, pageSize);
List<Student> list = studentMapper.queryStudentByClassIds(classId,schoolId);
PageInfo<Student> info = new PageInfo<Student>(list);
int total1 = (int) info.getTotal();
int totalPages;
totalPages = total1 / pageSize;
if (total1 % pageSize != 0) {
totalPages++;
}
long total = total1;
resp.put("retvalue", new PageResult(total, list, totalPages));
resp.put("retcode", 200);
}else{
List<Student> list = studentMapper.queryStudentByClassIds(classId,schoolId);
resp.put("retcode",200);
resp.put("retvalue",list);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
resp.put("retcode",500);
resp.put("retvalue","Inquiry Failed");
return resp;
}
return resp;
}
public HashMap<String, Object> deleteStudent(Integer studentId,String phone) {
HashMap<String, Object> resp = new HashMap<String, Object>();

Loading…
Cancel
Save