From 07fa2ca51aeaadffb56364dd66fedf060b9bbe63 Mon Sep 17 00:00:00 2001 From: mzh820631607 Date: Wed, 2 Sep 2020 17:22:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=EF=BC=88=E8=A6=86=E7=9B=96?= =?UTF-8?q?queryStudent=E6=8E=A5=E5=8F=A3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liuwanr/controller/StudentController.java | 109 +++++++++++------- .../yipin/liuwanr/mapper/StudentMapper.java | 19 +-- .../yipin/liuwanr/service/StudentService.java | 80 +++++++++++-- 3 files changed, 151 insertions(+), 57 deletions(-) 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(); From 2ab6f46adfb70750bf99afd42fa797c8c43f4c74 Mon Sep 17 00:00:00 2001 From: mzh820631607 Date: Thu, 3 Sep 2020 19:38:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=EF=BC=88=E8=BD=AC=E7=A7=BB?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E6=95=B0=E6=8D=AE=E8=A1=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liuwanr/controller/StudentController.java | 6 ++-- .../liuwanr/helper/QueryStudentUtils.java | 28 +++++++++++++++++++ .../yipin/liuwanr/mapper/StudentMapper.java | 8 +++--- .../yipin/liuwanr/service/StudentService.java | 6 ++-- 4 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/yipin/liuwanr/helper/QueryStudentUtils.java diff --git a/src/main/java/com/yipin/liuwanr/controller/StudentController.java b/src/main/java/com/yipin/liuwanr/controller/StudentController.java index 8d6eae3..5d82eeb 100644 --- a/src/main/java/com/yipin/liuwanr/controller/StudentController.java +++ b/src/main/java/com/yipin/liuwanr/controller/StudentController.java @@ -122,19 +122,19 @@ public class StudentController { /** * 根据professionalIds(专业id)查询所有学生 * @param schoolId 必须 - * @param professionalIds + * @param professionalId * @param pageNo * @param pageSize * @return */ @GetMapping("queryStudent/byProfessionalIds") - Response queryStudentByProfessionalIds(@RequestParam Integer schoolId,@RequestParam Integer professionalIds,Integer pageNo,Integer pageSize){ + 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(professionalIds, pageNo, pageSize, schoolId); + HashMap ret = studentService.queryStudentByProfessionalIds(professionalId, 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 7c3828f..d327a1b 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java @@ -19,15 +19,15 @@ public interface StudentMapper { void addStudent(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); + @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 studentName,studentNumber,professionalName,gradeId,classId,roleId,loginNumber,lastLoginTime from student WHERE gradeId = #{gradeId} and schoolId = #{schoolId}") + @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 studentName,studentNumber,professionalName,gradeId,classId,roleId,loginNumber,lastLoginTime from student WHERE classId = #{classId} and schoolId = #{schoolId}") + @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} ") diff --git a/src/main/java/com/yipin/liuwanr/service/StudentService.java b/src/main/java/com/yipin/liuwanr/service/StudentService.java index 468c61a..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 queryStudentByProfessionalIds(Integer professionalIds,Integer pageNo, Integer pageSize ,Integer schoolId){ + 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.queryStudentByProfessionalIds(professionalIds,schoolId); + List list = studentMapper.queryStudentByProfessionalIds(professionalId,schoolId); PageInfo info = new PageInfo(list); int total1 = (int) info.getTotal(); int totalPages; @@ -71,7 +71,7 @@ public class StudentService { resp.put("retcode", 200); }else{ - List list = studentMapper.queryStudentByProfessionalIds(professionalIds,schoolId); + List list = studentMapper.queryStudentByProfessionalIds(professionalId,schoolId); resp.put("retcode",200); resp.put("retvalue",list); }