@ -1,14 +1,13 @@
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.entity.* ;
import com.yipin.liuwanr.helper.QueryStudentUtils ;
import com.yipin.liuwanr.helper.RedisHelper ;
import com.yipin.liuwanr.service.StudentService ;
import com.yipin.liuwanr.service.UserInfoService ;
import com.yipin.liuwanr.service.UserService ;
import com.yipin.liuwanr.vo.UserInfoVO ;
import com.yipin.liuwanr.vo.UserVO ;
import org.apache.kafka.common.protocol.types.Field ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.StringUtils ;
@ -28,6 +27,9 @@ public class StudentController {
@Autowired
private UserService userService ;
@Autowired
private UserInfoService userInfoService ;
@Autowired
RedisHelper redisHelper ;
@ -58,42 +60,42 @@ public class StudentController {
}
/ * *
* 添加学生
* /
@Transactional
@PostMapping ( "/addStudent" )
Response addStudent ( @RequestBody UserVO vo ) {
Response resp = new Response ( ) ;
Student student = vo . getStudent ( ) ;
UserM user = vo . getUser ( ) ;
if ( student . getPhone ( ) = = null ) {
resp . setStatus ( 300 ) ;
resp . setErrmessage ( "Parameter Invalid" ) ;
} else {
HashMap < String , Object > ret = studentService . addStudent ( student ) ;
int status = ( int ) ret . get ( "retcode" ) ;
if ( 200 = = status ) {
resp . setStatus ( status ) ;
resp . setMessage ( ret . get ( "retvalue" ) ) ;
HashMap < String , Object > ret1 = userService . addUser ( user ) ;
int status1 = ( int ) ret . get ( "retcode" ) ;
if ( status1 = = 200 ) {
resp . setStatus ( status1 ) ;
resp . setMessage ( ret1 . get ( "retvalue" ) ) ;
} else {
resp . setStatus ( status1 ) ;
resp . setErrmessage ( ret1 . get ( "retvalue" ) . toString ( ) ) ;
throw new RuntimeException ( ) ;
}
} else {
resp . setStatus ( status ) ;
resp . setErrmessage ( ret . get ( "retvalue" ) . toString ( ) ) ;
throw new RuntimeException ( ) ;
}
}
return resp ;
}
// /**
// * 添加学生
// */
// @Transactional
// @PostMapping("/addStudent")
// Response addStudent(@RequestBody UserVO vo) {
// Response resp = new Response();
// Student student = vo.getStudent();
// UserM user = vo.getUser();
// if (student.getPhone()==null) {
// resp.setStatus(300);
// resp.setErrmessage("Parameter Invalid");
// } else {
// HashMap<String, Object> ret = studentService.addStudent(student);
// int status = (int) ret.get("retcode");
// if (200 == status) {
// resp.setStatus(status);
// resp.setMessage(ret.get("retvalue"));
// HashMap<String, Object> ret1 = userService.addUser(user);
// int status1 = (int)ret.get("retcode");
// if (status1 == 200){
// resp.setStatus(status1);
// resp.setMessage(ret1.get("retvalue"));
// }else {
// resp.setStatus(status1);
// resp.setErrmessage(ret1.get("retvalue").toString());
// throw new RuntimeException();
// }
// } else {
// resp.setStatus(status);
// resp.setErrmessage(ret.get("retvalue").toString());
// throw new RuntimeException();
// }
// }
// return resp;
// }
/ * *
@ -118,102 +120,102 @@ public class StudentController {
}
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 < String , Object > ret = studentService . queryStudentByProfessionalIds ( professionalId , pageNo , pageSize , schoolId ) ;
QueryStudentUtils . statusInformationEntity ( 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 . statusInformationEntity ( 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 . statusInformationEntity ( resp , ret , "retcode" , "retvalue" ) ;
}
return resp ;
}
/ * *
* 删除学生
* /
@PostMapping ( "/deleteStudent" )
Response deleteStudent ( @RequestBody List < Student > studentList ) {
Response resp = new Response ( ) ;
int size = studentList . size ( ) ;
for ( int i = 0 ; i < size ; i + + ) {
Student student = studentList . get ( i ) ;
Integer studentId = student . getStudentId ( ) ;
String phone = student . getPhone ( ) ;
if ( studentId = = null ) {
resp . setStatus ( 300 ) ;
resp . setErrmessage ( "学生id为空,删除失败!" ) ;
} else if ( phone = = null | | phone = = "" ) {
resp . setStatus ( 300 ) ;
resp . setErrmessage ( "学生电话为空,删除失败!" ) ;
}
else {
HashMap < String , Object > ret = studentService . deleteStudent ( studentId , phone ) ;
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 ;
}
//
// /**
// * 根据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<String, Object> ret = studentService.queryStudentByProfessionalIds(professionalId, pageNo, pageSize, schoolId);
// QueryStudentUtils.statusInformationEntity(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.statusInformationEntity(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.statusInformationEntity(resp, ret, "retcode", "retvalue");
// }
// return resp;
// }
//
// /**
// * 删除学生
// */
// @PostMapping("/deleteStudent")
// Response deleteStudent(@RequestBody List<Student> studentList) {
// Response resp = new Response();
// int size = studentList.size();
// for (int i=0;i<size;i++){
// Student student = studentList.get(i);
// Integer studentId = student.getStudentId();
// String phone = student.getPhone();
// if (studentId==null) {
// resp.setStatus(300);
// resp.setErrmessage("学生id为空,删除失败!");
// }else if (phone == null || phone == ""){
// resp.setStatus(300);
// resp.setErrmessage("学生电话为空,删除失败!");
// }
// else {
// HashMap<String, Object> ret = studentService.deleteStudent(studentId,phone);
// 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;
// }
/ * *
* 更新学生
@ -244,4 +246,116 @@ public class StudentController {
}
return resp ;
}
/ * *
* 添加学生信息
* 接收参数 :
* UserInfo : account , userName , roleId , uniqueIdentificationAccount , phone , email , schoolId
* OrganizationRelationship : workNumber , professionalClassId , gradeId , classId , schoolId
* /
@Transactional
@PostMapping ( "/addStudent" )
Response addStudent ( @RequestBody UserInfoVO vo ) {
Response response = new Response ( ) ;
// Student student = vo.getStudent();
UserInfo userInfo = vo . getUserInfo ( ) ;
OrganizationRelationship organizationRelationship = vo . getOrganizationRelationship ( ) ;
String account = userInfo . getAccount ( ) ;
String userName = userInfo . getUserName ( ) ;
Integer roleId = userInfo . getRoleId ( ) ;
String uniqueIdentificationAccount = userInfo . getUniqueIdentificationAccount ( ) ;
String phone = userInfo . getPhone ( ) ;
String email = userInfo . getEmail ( ) ;
String workNumber = organizationRelationship . getWorkNumber ( ) ;
Integer professionalId = organizationRelationship . getProfessionalId ( ) ;
Integer gradeId = organizationRelationship . getGradeId ( ) ;
Integer classId = organizationRelationship . getClassId ( ) ;
// UserM user = vo.getUser();
if ( account = = null | | userName = = null | | roleId ! = 4 | | uniqueIdentificationAccount = = null | | workNumber = = null | | professionalId < = 0 | | gradeId < = 0 | | classId < = 0 ) {
response . setStatus ( 300 ) ;
response . setErrmessage ( "Parameter Invalid" ) ;
} else {
HashMap < String , Object > ret = userInfoService . addUserInfo ( userInfo ) ;
int status = ( int ) ret . get ( "retcode" ) ;
if ( 200 = = status ) {
response . setStatus ( status ) ;
response . setMessage ( ret . get ( "retvalue" ) ) ;
Integer userId = userInfo . getUserId ( ) ;
organizationRelationship . setUserId ( userId ) ;
HashMap < String , Object > ret1 = userInfoService . addOrganizationRelationship ( organizationRelationship ) ;
int status1 = ( int ) ret . get ( "retcode" ) ;
if ( status1 = = 200 ) {
response . setStatus ( status1 ) ;
response . setMessage ( ret1 . get ( "retvalue" ) ) ;
} else {
response . setStatus ( status1 ) ;
response . setErrmessage ( ret1 . get ( "retvalue" ) . toString ( ) ) ;
throw new RuntimeException ( ) ;
}
} else {
response . setStatus ( status ) ;
response . setErrmessage ( ret . get ( "retvalue" ) . toString ( ) ) ;
throw new RuntimeException ( ) ;
}
}
return response ;
}
/ * *
* 查询学生信息
* @param schoolId
* @param professionalIds
* @param searchContent
* @param gradeIds
* @param classIds
* @param pageNo
* @param pageSize
* @return
* /
@GetMapping ( "/queryStudent" )
Response queryStudent ( @RequestParam Integer schoolId , String professionalIds , String searchContent , String gradeIds , String classIds , Integer pageNo , Integer pageSize ) {
Response response = new Response ( ) ;
StudentInfo studentInfo = new StudentInfo ( ) ;
if ( schoolId = = null ) {
response . setStatus ( 300 ) ;
response . setErrmessage ( "学校信息为空" ) ;
} else {
if ( searchContent ! = null & & searchContent ! = "" ) {
studentInfo . setSearchContent ( searchContent ) ;
}
if ( professionalIds ! = null & & professionalIds ! = "" ) {
studentInfo . setProfessionalIds ( professionalIds ) ;
}
if ( gradeIds ! = null & & gradeIds ! = "" ) {
studentInfo . setGradeIds ( gradeIds ) ;
}
if ( classIds ! = null & & classIds ! = "" ) {
studentInfo . setClassIds ( classIds ) ;
}
studentInfo . setSchoolId ( schoolId ) ;
HashMap map = userInfoService . queryStudent ( studentInfo , pageNo , pageSize ) ;
QueryStudentUtils . statusInformationController ( response , map , "retcode" , "retvalue" ) ;
}
return response ;
}
/ * *
* 批量删除学生
*
* @param userId 用户id
* @return
* /
@GetMapping ( "/deleteStudent" )
Response deleteStudent ( Integer [ ] userId ) {
Response response = new Response ( ) ;
if ( userId ! = null & & userId . length > 0 ) {
userInfoService . deleteStudent ( userId ) ;
response . setStatus ( 200 ) ;
} else {
response . setStatus ( 500 ) ;
response . setErrmessage ( "学生id不能为空" ) ;
}
return response ;
}
}