diff --git a/src/main/java/com/yipin/liuwanr/controller/StudentController.java b/src/main/java/com/yipin/liuwanr/controller/StudentController.java index e909233..8d6eae3 100644 --- a/src/main/java/com/yipin/liuwanr/controller/StudentController.java +++ b/src/main/java/com/yipin/liuwanr/controller/StudentController.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") @@ -94,44 +94,8 @@ 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 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; -} - + + /** * 查询学生详情 */ @@ -150,11 +114,74 @@ public class StudentController { } else { resp.setStatus(status); resp.setErrmessage(ret.get("retvalue").toString()); - } + } } 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 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 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 ret = studentService.queryStudentByClassIds(classId, pageNo, pageSize, schoolId); + QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue"); + } + return resp; + } + /** * 删除学生 */ diff --git a/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java b/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java index 0b35459..7c3828f 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java @@ -18,14 +18,17 @@ public interface StudentMapper { + "VALUES(#{studentName},#{studentNumber},#{phone},#{email},#{roleId},#{schoolId},#{professionalId},#{gradeId},#{classId},0,#{uniqueIdentificationAccount})") void addStudent(Student student); - //查询学生 - @Select({ " " }) - List queryStudent(Student student); + //通过专业id查询所有学生信息 + @Select("SELECT studentName,studentNumber,professionalName,gradeId,classId,roleId,loginNumber,lastLoginTime from student WHERE professionalId = #{professionalIds} and schoolId = #{schoolId}") + List 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 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 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 getByStudents(Integer experimentalClassId); diff --git a/src/main/java/com/yipin/liuwanr/service/StudentService.java b/src/main/java/com/yipin/liuwanr/service/StudentService.java index d3d4751..468c61a 100644 --- a/src/main/java/com/yipin/liuwanr/service/StudentService.java +++ b/src/main/java/com/yipin/liuwanr/service/StudentService.java @@ -53,12 +53,12 @@ public class StudentService { return resp; } - public HashMap queryStudent(Student student, Integer pageNo, Integer pageSize) { + public HashMap queryStudentByProfessionalIds(Integer professionalIds,Integer pageNo, Integer pageSize ,Integer schoolId){ HashMap resp = new HashMap(); try { if (pageNo != null && pageSize != null) { PageHelper.startPage(pageNo, pageSize); - List list = studentMapper.queryStudent(student); + List list = studentMapper.queryStudentByProfessionalIds(professionalIds,schoolId); PageInfo info = new PageInfo(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 list = studentMapper.queryStudent(student); - resp.put("retvalue", list); + }else{ + + List 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 queryStudentByGradeIds(Integer gradeId,Integer pageNo, Integer pageSize ,Integer schoolId){ + HashMap resp = new HashMap(); + try { + if (pageNo != null && pageSize != null) { + PageHelper.startPage(pageNo, pageSize); + List list = studentMapper.queryStudentByProfessionalIds(gradeId,schoolId); + PageInfo info = new PageInfo(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 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 list = studentMapper.queryStudentByProfessionalIds(professionalIds,schoolId); + } + public HashMap queryStudentByClassIds(Integer classId,Integer pageNo, Integer pageSize ,Integer schoolId){ + HashMap resp = new HashMap(); + try { + if (pageNo != null && pageSize != null) { + PageHelper.startPage(pageNo, pageSize); + List list = studentMapper.queryStudentByClassIds(classId,schoolId); + PageInfo info = new PageInfo(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 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 deleteStudent(Integer studentId,String phone) { HashMap resp = new HashMap();