diff --git a/src/main/java/com/yipin/liuwanr/controller/StudentController.java b/src/main/java/com/yipin/liuwanr/controller/StudentController.java index e909233..5d82eeb 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 professionalId + * @param pageNo + * @param pageSize + * @return + */ + @GetMapping("queryStudent/byProfessionalIds") + Response queryStudentByProfessionalIds(@RequestParam Integer schoolId,@RequestParam Integer professionalId,Integer pageNo,Integer pageSize){ + Response resp = new Response(); + if (schoolId == null){ + resp.setMessage(300); + resp.setErrmessage("学校id为空,查询失败!"); + }else{ + HashMap ret = studentService.queryStudentByProfessionalIds(professionalId, 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/helper/QueryStudentUtils.java b/src/main/java/com/yipin/liuwanr/helper/QueryStudentUtils.java new file mode 100644 index 0000000..a5bdfc6 --- /dev/null +++ b/src/main/java/com/yipin/liuwanr/helper/QueryStudentUtils.java @@ -0,0 +1,28 @@ +package com.yipin.liuwanr.helper; + +import com.yipin.liuwanr.entity.Response; + +import java.util.HashMap; +import java.util.List; + +public class QueryStudentUtils { + /** + * Controller.queryStudent之共性api + * @param resp + * @param hashMap + * @param retcode + * @param retvalue + */ + public static void queryStudentByIds(Response resp,HashMap hashMap,String retcode,String retvalue){ + + int status = (int)hashMap.get(retcode); + if (status==200){ + resp.setStatus(status); + resp.setMessage(hashMap.get(retvalue)); + }else{ + resp.setStatus(status); + resp.setMessage(hashMap.get(retvalue.toString())); + } + + } +} diff --git a/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java b/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java index 255e415..ba090e0 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 u.logInNumber,u.userName,u.lastLoginTime,o.roleId, o.gradeId, o.classId, o.professionalId FROM hr_user_info u,hr_organization_relationship o WHERE u.userId = o.userId AND o.roleId = 4 AND o.professionalId = #{professionalId} AND o.schoolId = #{schoolId}") + List queryStudentByProfessionalIds(Integer professionalId, Integer schoolId); + + //通过年级id查询所有学生信息 + @Select("SELECT u.logInNumber,u.userName,u.lastLoginTime,o.roleId, o.gradeId, o.classId, o.professionalId FROM hr_user_info u,hr_organization_relationship o WHERE u.userId = o.userId AND o.roleId = 4 AND o.gradeId = #{gradeId} AND o.schoolId = #{schoolId}") + List queryStudentByGradeIds(Integer gradeId, Integer schoolId); + + //通过班级id查询所有学生信息 + @Select("SELECT u.logInNumber,u.userName,u.lastLoginTime,o.roleId, o.gradeId, o.classId, o.professionalId FROM hr_user_info u,hr_organization_relationship o WHERE u.userId = o.userId AND o.roleId = 4 AND o.classId = #{classId} AND o.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..666fb61 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 professionalId,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(professionalId,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(professionalId,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();