学生添加、删除、查询

master
mzh820631607 4 years ago
parent d6d4ef9b92
commit 424cf6daa0
  1. 386
      src/main/java/com/yipin/liuwanr/controller/StudentController.java
  2. 229
      src/main/java/com/yipin/liuwanr/controller/UserInfoController.java
  3. 85
      src/main/java/com/yipin/liuwanr/entity/StudentInfo.java
  4. 4
      src/main/java/com/yipin/liuwanr/mapper/OrganizationRelationshipMapper.java
  5. 99
      src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java
  6. 26
      src/main/java/com/yipin/liuwanr/service/UserInfoService.java
  7. 23
      src/test/java/com/yipin/liuwanr/service/StudentServiceTest.java

@ -1,14 +1,13 @@
package com.yipin.liuwanr.controller; package com.yipin.liuwanr.controller;
import com.yipin.liuwanr.entity.Response; import com.yipin.liuwanr.entity.*;
import com.yipin.liuwanr.entity.Student;
import com.yipin.liuwanr.entity.UserM;
import com.yipin.liuwanr.helper.QueryStudentUtils; import com.yipin.liuwanr.helper.QueryStudentUtils;
import com.yipin.liuwanr.helper.RedisHelper; import com.yipin.liuwanr.helper.RedisHelper;
import com.yipin.liuwanr.service.StudentService; import com.yipin.liuwanr.service.StudentService;
import com.yipin.liuwanr.service.UserInfoService;
import com.yipin.liuwanr.service.UserService; import com.yipin.liuwanr.service.UserService;
import com.yipin.liuwanr.vo.UserInfoVO;
import com.yipin.liuwanr.vo.UserVO; import com.yipin.liuwanr.vo.UserVO;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -28,6 +27,9 @@ public class StudentController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private UserInfoService userInfoService;
@Autowired @Autowired
RedisHelper redisHelper; RedisHelper redisHelper;
@ -58,42 +60,42 @@ public class StudentController {
} }
/** // /**
* 添加学生 // * 添加学生
*/ // */
@Transactional // @Transactional
@PostMapping("/addStudent") // @PostMapping("/addStudent")
Response addStudent(@RequestBody UserVO vo) { // Response addStudent(@RequestBody UserVO vo) {
Response resp = new Response(); // Response resp = new Response();
Student student = vo.getStudent(); // Student student = vo.getStudent();
UserM user = vo.getUser(); // UserM user = vo.getUser();
if (student.getPhone()==null) { // if (student.getPhone()==null) {
resp.setStatus(300); // resp.setStatus(300);
resp.setErrmessage("Parameter Invalid"); // resp.setErrmessage("Parameter Invalid");
} else { // } else {
HashMap<String, Object> ret = studentService.addStudent(student); // HashMap<String, Object> ret = studentService.addStudent(student);
int status = (int) ret.get("retcode"); // int status = (int) ret.get("retcode");
if (200 == status) { // if (200 == status) {
resp.setStatus(status); // resp.setStatus(status);
resp.setMessage(ret.get("retvalue")); // resp.setMessage(ret.get("retvalue"));
HashMap<String, Object> ret1 = userService.addUser(user); // HashMap<String, Object> ret1 = userService.addUser(user);
int status1 = (int)ret.get("retcode"); // int status1 = (int)ret.get("retcode");
if (status1 == 200){ // if (status1 == 200){
resp.setStatus(status1); // resp.setStatus(status1);
resp.setMessage(ret1.get("retvalue")); // resp.setMessage(ret1.get("retvalue"));
}else { // }else {
resp.setStatus(status1); // resp.setStatus(status1);
resp.setErrmessage(ret1.get("retvalue").toString()); // resp.setErrmessage(ret1.get("retvalue").toString());
throw new RuntimeException(); // throw new RuntimeException();
} // }
} else { // } else {
resp.setStatus(status); // resp.setStatus(status);
resp.setErrmessage(ret.get("retvalue").toString()); // resp.setErrmessage(ret.get("retvalue").toString());
throw new RuntimeException(); // throw new RuntimeException();
} // }
} // }
return resp; // return resp;
} // }
/** /**
@ -118,102 +120,102 @@ public class StudentController {
} }
return resp; return resp;
} }
//
/** // /**
* 根据professionalIds专业id查询所有学生 // * 根据professionalIds(专业id)查询所有学生
* @param schoolId 必须 // * @param schoolId 必须
* @param professionalId // * @param professionalId
* @param pageNo // * @param pageNo
* @param pageSize // * @param pageSize
* @return // * @return
*/ // */
@GetMapping("queryStudent/byProfessionalIds") // @GetMapping("queryStudent/byProfessionalIds")
Response queryStudentByProfessionalIds(@RequestParam Integer schoolId,@RequestParam Integer professionalId,Integer pageNo,Integer pageSize){ // Response queryStudentByProfessionalIds(@RequestParam Integer schoolId,@RequestParam Integer professionalId,Integer pageNo,Integer pageSize){
Response resp = new Response(); // Response resp = new Response();
if (schoolId == null){ // if (schoolId == null){
resp.setMessage(300); // resp.setMessage(300);
resp.setErrmessage("学校id为空,查询失败!"); // resp.setErrmessage("学校id为空,查询失败!");
}else{ // }else{
HashMap<String, Object> ret = studentService.queryStudentByProfessionalIds(professionalId, pageNo, pageSize, schoolId); // HashMap<String, Object> ret = studentService.queryStudentByProfessionalIds(professionalId, pageNo, pageSize, schoolId);
QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue"); // QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue");
} // }
return resp; // return resp;
} // }
//
/** // /**
* 根据年级id查询所有学生信息 // * 根据年级id查询所有学生信息
* @param schoolId // * @param schoolId
* @param gradeId // * @param gradeId
* @param pageNo // * @param pageNo
* @param pageSize // * @param pageSize
* @return // * @return
*/ // */
@GetMapping("queryStudent/byGradeId") // @GetMapping("queryStudent/byGradeId")
Response queryStudentByGradeId(@RequestParam Integer schoolId, @RequestParam Integer gradeId, Integer pageNo, Integer pageSize){ // Response queryStudentByGradeId(@RequestParam Integer schoolId, @RequestParam Integer gradeId, Integer pageNo, Integer pageSize){
Response resp = new Response(); // Response resp = new Response();
if (schoolId == null){ // if (schoolId == null){
resp.setMessage(300); // resp.setMessage(300);
resp.setErrmessage("学校id为空,查询失败!"); // resp.setErrmessage("学校id为空,查询失败!");
}else { // }else {
HashMap<String, Object> ret = studentService.queryStudentByGradeIds(gradeId, pageNo, pageSize, schoolId); // HashMap<String, Object> ret = studentService.queryStudentByGradeIds(gradeId, pageNo, pageSize, schoolId);
QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue"); // QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue");
} // }
return resp; // return resp;
} // }
/** // /**
* 根据班级id查询所有学生信息 // * 根据班级id查询所有学生信息
* @param schoolId // * @param schoolId
* @param classId // * @param classId
* @param pageNo // * @param pageNo
* @param pageSize // * @param pageSize
* @return // * @return
*/ // */
@GetMapping("queryStudent/byClassIds") // @GetMapping("queryStudent/byClassIds")
Response queryStudentByClassIds(@RequestParam Integer schoolId,@RequestParam Integer classId,Integer pageNo,Integer pageSize){ // Response queryStudentByClassIds(@RequestParam Integer schoolId,@RequestParam Integer classId,Integer pageNo,Integer pageSize){
//
Response resp = new Response(); // Response resp = new Response();
if (schoolId == null){ // if (schoolId == null){
resp.setMessage(300); // resp.setMessage(300);
resp.setErrmessage("学校id为空,查询失败!"); // resp.setErrmessage("学校id为空,查询失败!");
}else { // }else {
HashMap<String, Object> ret = studentService.queryStudentByClassIds(classId, pageNo, pageSize, schoolId); // HashMap<String, Object> ret = studentService.queryStudentByClassIds(classId, pageNo, pageSize, schoolId);
QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue"); // QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue");
} // }
return resp; // return resp;
} // }
//
/** // /**
* 删除学生 // * 删除学生
*/ // */
@PostMapping("/deleteStudent") // @PostMapping("/deleteStudent")
Response deleteStudent(@RequestBody List<Student> studentList) { // Response deleteStudent(@RequestBody List<Student> studentList) {
Response resp = new Response(); // Response resp = new Response();
int size = studentList.size(); // int size = studentList.size();
for (int i=0;i<size;i++){ // for (int i=0;i<size;i++){
Student student = studentList.get(i); // Student student = studentList.get(i);
Integer studentId = student.getStudentId(); // Integer studentId = student.getStudentId();
String phone = student.getPhone(); // String phone = student.getPhone();
if (studentId==null) { // if (studentId==null) {
resp.setStatus(300); // resp.setStatus(300);
resp.setErrmessage("学生id为空,删除失败!"); // resp.setErrmessage("学生id为空,删除失败!");
}else if (phone == null || phone == ""){ // }else if (phone == null || phone == ""){
resp.setStatus(300); // resp.setStatus(300);
resp.setErrmessage("学生电话为空,删除失败!"); // resp.setErrmessage("学生电话为空,删除失败!");
} // }
else { // else {
HashMap<String, Object> ret = studentService.deleteStudent(studentId,phone); // HashMap<String, Object> ret = studentService.deleteStudent(studentId,phone);
int status = (int) ret.get("retcode"); // int status = (int) ret.get("retcode");
if (200 == status) { // if (200 == status) {
resp.setStatus(status); // resp.setStatus(status);
resp.setMessage(ret.get("retvalue")); // resp.setMessage(ret.get("retvalue"));
} else { // } else {
resp.setStatus(status); // resp.setStatus(status);
resp.setErrmessage(ret.get("retvalue").toString()); // resp.setErrmessage(ret.get("retvalue").toString());
} // }
} // }
} // }
return resp; // return resp;
} // }
/** /**
* 更新学生 * 更新学生
@ -244,4 +246,116 @@ public class StudentController {
} }
return resp; 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;
}
} }

@ -33,127 +33,116 @@ public class UserInfoController {
RedisHelper redisHelper; RedisHelper redisHelper;
/** // /**
* 接收参数 // * 接收参数:
* UserInfo:account,userName,roleId,uniqueIdentificationAccount,phone,email // * UserInfo:account,userName,roleId,uniqueIdentificationAccount,phone,email
* OrganizationRelationship:workNumber,professionalClassId,gradeId,classId // * OrganizationRelationship:workNumber,professionalClassId,gradeId,classId
*/ // */
// @Transactional
@PostMapping("/addStudent") // @PostMapping("/addStudent")
Response addUserInfo(@RequestBody UserInfoVO vo) { // Response addStudent(@RequestBody UserInfoVO vo) {
Response response = new Response(); // Response response = new Response();
// Student student = vo.getStudent(); //// Student student = vo.getStudent();
UserInfo userInfo = vo.getUserInfo(); // UserInfo userInfo = vo.getUserInfo();
OrganizationRelationship organizationRelationship = vo.getOrganizationRelationship(); // OrganizationRelationship organizationRelationship = vo.getOrganizationRelationship();
String account = userInfo.getAccount(); // String account = userInfo.getAccount();
String userName = userInfo.getUserName(); // String userName = userInfo.getUserName();
Integer roleId = userInfo.getRoleId(); // Integer roleId = userInfo.getRoleId();
String uniqueIdentificationAccount = userInfo.getUniqueIdentificationAccount(); // String uniqueIdentificationAccount = userInfo.getUniqueIdentificationAccount();
String phone = userInfo.getPhone(); // String phone = userInfo.getPhone();
String email = userInfo.getEmail(); // String email = userInfo.getEmail();
String workNumber = organizationRelationship.getWorkNumber(); // String workNumber = organizationRelationship.getWorkNumber();
Integer professionalId = organizationRelationship.getProfessionalId(); // Integer professionalId = organizationRelationship.getProfessionalId();
Integer gradeId = organizationRelationship.getGradeId(); // Integer gradeId = organizationRelationship.getGradeId();
Integer classId = organizationRelationship.getClassId(); // Integer classId = organizationRelationship.getClassId();
//
// UserM user = vo.getUser(); //// UserM user = vo.getUser();
if (account==null||userName==null||roleId!=4||uniqueIdentificationAccount==null||workNumber==null||professionalId<=0||gradeId<=0||classId<=0) { // if (account==null||userName==null||roleId!=4||uniqueIdentificationAccount==null||workNumber==null||professionalId<=0||gradeId<=0||classId<=0) {
response.setStatus(300); // response.setStatus(300);
response.setErrmessage("Parameter Invalid"); // response.setErrmessage("Parameter Invalid");
} else { // } else {
HashMap<String, Object> ret = userInfoService.addUserInfo(userInfo); // HashMap<String, Object> ret = userInfoService.addUserInfo(userInfo);
int status = (int) ret.get("retcode"); // int status = (int) ret.get("retcode");
if (200 == status) { // if (200 == status) {
response.setStatus(status); // response.setStatus(status);
response.setMessage(ret.get("retvalue")); // response.setMessage(ret.get("retvalue"));
HashMap<String, Object> ret1 = userInfoService.addOrganizationRelationship(organizationRelationship); // Integer userId = userInfo.getUserId();
int status1 = (int)ret.get("retcode"); // organizationRelationship.setUserId(userId);
if (status1 == 200){ // HashMap<String, Object> ret1 = userInfoService.addOrganizationRelationship(organizationRelationship);
response.setStatus(status1); // int status1 = (int)ret.get("retcode");
response.setMessage(ret1.get("retvalue")); // if (status1 == 200){
}else { // response.setStatus(status1);
response.setStatus(status1); // response.setMessage(ret1.get("retvalue"));
response.setErrmessage(ret1.get("retvalue").toString()); // }else {
throw new RuntimeException(); // response.setStatus(status1);
} // response.setErrmessage(ret1.get("retvalue").toString());
} else { // throw new RuntimeException();
response.setStatus(status); // }
response.setErrmessage(ret.get("retvalue").toString()); // } else {
throw new RuntimeException(); // response.setStatus(status);
} // response.setErrmessage(ret.get("retvalue").toString());
} // throw new RuntimeException();
return response; // }
} // }
// return response;
/** // }
* 查询学生信息 //
* @param schoolId // /**
* @param professionalIds // * 查询学生信息
* @param searchContent // * @param schoolId
* @param gradeIds // * @param professionalIds
* @param classIds // * @param searchContent
* @param pageNo // * @param gradeIds
* @param pageSize // * @param classIds
* @return // * @param pageNo
*/ // * @param pageSize
@GetMapping("/queryStudent") // * @return
Response queryStudent(@RequestParam Integer schoolId, Integer[] professionalIds, String searchContent, Integer[] gradeIds, Integer[] classIds, Integer pageNo, Integer pageSize) { // */
Response response = new Response(); // @GetMapping("/queryStudent")
UserInfo userInfo = new UserInfo(); // Response queryStudent(@RequestParam Integer schoolId, String professionalIds, String searchContent, String gradeIds, String classIds, Integer pageNo, Integer pageSize) {
OrganizationRelationship ship = new OrganizationRelationship(); // Response response = new Response();
HashMap<Object, Object> ids = new HashMap<>(8); // StudentInfo studentInfo = new StudentInfo();
if (schoolId == null) { // if (schoolId == null) {
response.setStatus(300); // response.setStatus(300);
response.setErrmessage("学校信息为空"); // response.setErrmessage("学校信息为空");
} else { // } else {
if (searchContent != null && searchContent != "") { // if (searchContent != null && searchContent != "") {
userInfo.setSearchContent(searchContent); // studentInfo.setSearchContent(searchContent);
} // }
if (professionalIds.length > 0) { // if (professionalIds!=null&&professionalIds!="") {
// List<Integer> professionalList = Arrays.asList(professionalId); // studentInfo.setProfessionalIds(professionalIds);
for (Integer professionalId:professionalIds){ // }
ship.setProfessionalId(professionalId); // if (gradeIds!=null&&gradeIds!="") {
} // studentInfo.setGradeIds(gradeIds);
} // }
if (gradeIds.length > 0) { // if (classIds!=null&&classIds!="") {
// List<Integer> gradeList = Arrays.asList(gradeIds); // studentInfo.setClassIds(classIds);
for (Integer gradeId:gradeIds){ // }
ship.setGradeId(gradeId); // studentInfo.setSchoolId(schoolId);
} // HashMap map = userInfoService.queryStudent(studentInfo,pageNo,pageSize);
}
if (classIds.length > 0) {
// List<Integer> classList = Arrays.asList(classIds);
for (Integer classId:classIds){
ship.setClassId(classId);
}
}
userInfo.setSchoolId(schoolId);
// HashMap map = userInfoService.queryStudent(userInfo,ship,pageNo,pageSize);
// QueryStudentUtils.statusInformationController(response,map, "retcode", "retvalue"); // QueryStudentUtils.statusInformationController(response,map, "retcode", "retvalue");
} // }
// return response;
// }
return response; //
} // /**
// * 批量删除学生
/** // *
* 批量删除学生 // * @param ids 用户id
* // * @return
* @param ids 用户id // */
* @return // @GetMapping("/deleteStudent")
*/ // Response deleteStudent(Integer[] ids) {
@GetMapping("/deleteStudent") // Response response = new Response();
Response deleteStudent(Integer[] ids) { // if (ids.length > 0) {
Response response = new Response(); // userInfoService.deleteStudent(ids);
if (ids.length > 0) { // response.setStatus(200);
userInfoService.deleteStudent(ids); // } else {
response.setStatus(200); // response.setStatus(500);
} else { // response.setErrmessage("学生id不能为空");
response.setStatus(500); // }
response.setErrmessage("学生id不能为空"); // return response;
} // }
return response;
}
/** /**
* 添加用户 * 添加用户

@ -0,0 +1,85 @@
package com.yipin.liuwanr.entity;
public class StudentInfo {
private Integer schoolId;
private String professionalIds;
private String classIds;
private String gradeIds;
private String searchContent;
private String logInNumber;
private String userName;
private String lastLoginTime;
private Integer roleId;
public Integer getSchoolId() {
return schoolId;
}
public void setSchoolId(Integer schoolId) {
this.schoolId = schoolId;
}
public String getProfessionalIds() {
return professionalIds;
}
public void setProfessionalIds(String professionalIds) {
this.professionalIds = professionalIds;
}
public String getClassIds() {
return classIds;
}
public void setClassIds(String classIds) {
this.classIds = classIds;
}
public String getGradeIds() {
return gradeIds;
}
public void setGradeIds(String gradeIds) {
this.gradeIds = gradeIds;
}
public String getSearchContent() {
return searchContent;
}
public void setSearchContent(String searchContent) {
this.searchContent = searchContent;
}
public String getLogInNumber() {
return logInNumber;
}
public void setLogInNumber(String logInNumber) {
this.logInNumber = logInNumber;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(String lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
}

@ -13,8 +13,8 @@ import java.util.List;
public interface OrganizationRelationshipMapper{ public interface OrganizationRelationshipMapper{
@Insert({"<script>" + @Insert({"<script>" +
"INSERT INTO hr_organization_relationship(roleId,workNumber,professionalId,gradeId,classId,isdel)", "INSERT INTO hr_organization_relationship(userId,roleId,workNumber,professionalId,gradeId,classId,isdel,schoolId,platformId)",
"VALUES(#{roleId},#{workNumber},#{professionalId},#{gradeId},#{classId},0)", "VALUES(#{userId},4,#{workNumber},#{professionalId},#{gradeId},#{classId},0,#{schoolId},1)",
"</script>"}) "</script>"})
Integer insertOrganizationRelationship(OrganizationRelationship organizationRelationship); Integer insertOrganizationRelationship(OrganizationRelationship organizationRelationship);

@ -13,26 +13,33 @@ public interface UserInfoMapper{
@Insert("INSERT INTO hr_user_info(userName,uniqueIdentificationAccount,documentType,IDNumber,provinceId,cityId,countries,dateBirth,educationDegree,schoolId,phone,weChatID,email,account,password,creationTime,logInNumber,sex,userAvatars,isdel)" @Insert("INSERT INTO hr_user_info(userName,uniqueIdentificationAccount,documentType,IDNumber,provinceId,cityId,countries,dateBirth,educationDegree,schoolId,phone,weChatID,email,account,password,creationTime,logInNumber,sex,userAvatars,isdel)"
+ " VALUES(#{userName},#{uniqueIdentificationAccount},#{documentType},#{IDNumber},#{provinceId},#{cityId},#{countries},#{dateBirth},#{educationDegree},#{schoolId},#{phone},#{weChatID},#{email},#{account},#{password},now(),#{logInNumber},#{sex},#{userAvatars},0)") + " VALUES(#{userName},#{uniqueIdentificationAccount},#{documentType},#{IDNumber},#{provinceId},#{cityId},#{countries},#{dateBirth},#{educationDegree},#{schoolId},#{phone},#{weChatID},#{email},#{account},#{password},now(),#{logInNumber},#{sex},#{userAvatars},0)")
@Options(useGeneratedKeys=true, keyProperty="userId", keyColumn="userId")
Integer insertUserInfo(UserInfo userInfo); Integer insertUserInfo(UserInfo userInfo);
/** @Select({"<script>" ,
* 批量查询学生信息 "SELECT DISTINCT\n" +
* @param "\tu.logInNumber,\n" +
* @return "\tu.userName,\n" +
*/ "\tu.lastLoginTime,\n" +
@Select({ "<script>" , "\to.roleId,\n" +
"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 o.roleId = 4 AND u.schoolId = #{schoolId} AND u.isdel = 0", "\to.gradeId,\n" +
"\to.classId,\n" +
"\to.workNumber,\n" +
"\to.professionalId \n" +
"FROM\n" +
"\thr_user_info u,\n" +
"\thr_organization_relationship o \n" +
"WHERE\n" +
"\to.roleId = 4 \n" +
"\tAND u.schoolId = 1 \n" +
"\tAND u.isdel = 0 \n",
"<if test='searchContent!=null'>AND (u.userName like CONCAT('%',#{searchContent},'%') or u.userId like CONCAT('%',#{searchContent},'%'))</if>", "<if test='searchContent!=null'>AND (u.userName like CONCAT('%',#{searchContent},'%') or u.userId like CONCAT('%',#{searchContent},'%'))</if>",
// "<if test='professionalIds.size()>0'> OR o.professionalId IN <foreach collection='professionalIds' item='professionalId' open='(' separator=',' close=')'>#{professionalId}</foreach></if>" , "<if test='gradeIds!=null'>and FIND_IN_SET(o.gradeId,#{gradeIds})</if>",
// "<if test='gradeIds.size()>0'>OR o.gradeId IN <foreach collection='gradeIds' item='gradeId' open='(' separator=',' close=')'>#{gradeId}</foreach></if>" , "<if test='professionalIds!=null'>and FIND_IN_SET(o.professionalId,#{professionalIds})</if>",
// "<if test='classIds.size()>0'>OR o.classId IN <foreach collection='classIds' item='classId' open='(' separator=',' close=')'>#{classId}</foreach></if>" , "<if test='classIds!=null'>and FIND_IN_SET(o.classId,#{classIds})</if>",
"<if test='professionalId>0'> OR o.professionalId = #{professionalId}</if>" , "ORDER BY o.classId desc",
"<if test='gradeId>0'>OR o.gradeId = #{gradeId}</if>" ,
"<if test='classId>0'>OR o.classId = #{classId}</if>" ,
"ORDER BY o.professionalId desc,o.gradeId desc,o.classId desc",
"</script>"}) "</script>"})
// List queryStudent(UserInfo userInfo,OrganizationRelationship organizationRelationship); List<StudentInfo> queryStudent(StudentInfo studentInfo);
List queryStudent(String searchContent,Integer schoolId,Integer gradeId,Integer classId,Integer professionalId);
@Update({"<script>" + @Update({"<script>" +
"UPDATE hr_user_info SET isdel=1 WHERE userId IN " + "UPDATE hr_user_info SET isdel=1 WHERE userId IN " +
@ -41,18 +48,18 @@ public interface UserInfoMapper{
Integer updateStudentInfo(List list); Integer updateStudentInfo(List list);
@Update({ "<script>", @Update({ "<script>",
"UPDATE lw_user SET", "UPDATE lw_user SET",
"<when test='mobile!=null'>", "mobile=#{mobile},", "</when>", "<when test='mobile!=null'>", "mobile=#{mobile},", "</when>",
"<when test='email!=null'>", "email=#{email},", "</when>", "<when test='email!=null'>", "email=#{email},", "</when>",
"<when test='nickname!=null'>", "nickname=#{nickname},", "</when>", "<when test='nickname!=null'>", "nickname=#{nickname},", "</when>",
"<when test='sex!=-1'>", "sex=#{sex},", "</when>", "<when test='sex!=-1'>", "sex=#{sex},", "</when>",
"<when test='sign!=null'>", "sign=#{sign},", "</when>", "<when test='sign!=null'>", "sign=#{sign},", "</when>",
"<when test='birthday!=null'>", "birthday=#{birthday},", "</when>", "<when test='birthday!=null'>", "birthday=#{birthday},", "</when>",
"<when test='avatar!=null'>", "avatar=#{avatar},", "</when>", "<when test='avatar!=null'>", "avatar=#{avatar},", "</when>",
"<when test='country!=null'>", "country=#{country},", "</when>", "<when test='country!=null'>", "country=#{country},", "</when>",
"<when test='province!=null'>", "province=#{province},", "</when>", "<when test='province!=null'>", "province=#{province},", "</when>",
"<when test='city!=null'>", "city=#{city},", "</when>", "<when test='city!=null'>", "city=#{city},", "</when>",
"updatetime=now() WHERE uuid =#{uuid}", "updatetime=now() WHERE uuid =#{uuid}",
"</script>"}) "</script>"})
void update(User user); void update(User user);
@ -155,8 +162,8 @@ public interface UserInfoMapper{
//查询用户详情 //查询用户详情
@Select({"<script>", @Select({"<script>",
"SELECT * from hr_user_info where isdel = 0 and userId = #{userId}", "SELECT * from hr_user_info where isdel = 0 and userId = #{userId}",
"</script> "}) "</script> "})
UserInfo queryUserInfoDetails(Integer userId); UserInfo queryUserInfoDetails(Integer userId);
//查询用户详情 //查询用户详情
@ -178,33 +185,33 @@ public interface UserInfoMapper{
List<OrganizationRelationship> queryUserIdOR(Integer userId); List<OrganizationRelationship> queryUserIdOR(Integer userId);
//模糊查询客户 //模糊查询客户
@Select({"<script>", @Select({"<script>",
"SELECT customerId,customerName,schoolId FROM customer where isdel = 0", "SELECT customerId,customerName,schoolId FROM customer where isdel = 0",
" <if test='searchContent!=null and searchContent !=\"\" '>and customerName like CONCAT('%',#{searchContent},'%')</if>", " <if test='searchContent!=null and searchContent !=\"\" '>and customerName like CONCAT('%',#{searchContent},'%')</if>",
" <if test='customerIds!=null'>" " <if test='customerIds!=null'>"
+ "<foreach collection='customerIds' item='customerIds' open='and customerId not in (' separator=',' close=')'> #{customerIds}" + "<foreach collection='customerIds' item='customerIds' open='and customerId not in (' separator=',' close=')'> #{customerIds}"
+"</foreach>" +"</foreach>"
+ "</if>", + "</if>",
"</script> "}) "</script> "})
List<Customer> queryCustomer(@Param("searchContent")String searchContent, @Param("customerIds")List<Integer> customerIds); List<Customer> queryCustomer(@Param("searchContent")String searchContent, @Param("customerIds")List<Integer> customerIds);
/** /**
* 批量插入用户 * 批量插入用户
* @param users * @param users
*/ */
@Insert({ @Insert({
"<script>", "<script>",
"insert into user(name, password,accountRole,workNumber,phone,uniqueIdentificationAccount,creationTime,isdel) values ", "insert into user(name, password,accountRole,workNumber,phone,uniqueIdentificationAccount,creationTime,isdel) values ",
"<foreach collection='users' item='user' index='index' separator=','>", "<foreach collection='users' item='user' index='index' separator=','>",
"(#{user.name}, #{user.password}, #{user.accountRole}, #{user.workNumber} ,#{user.phone},#{user.uniqueIdentificationAccount},now(),0)", "(#{user.name}, #{user.password}, #{user.accountRole}, #{user.workNumber} ,#{user.phone},#{user.uniqueIdentificationAccount},now(),0)",
"</foreach>", "</foreach>",
"</script>" "</script>"
}) })
void addUserM(@Param("users") List<UserM> users); void addUserM(@Param("users") List<UserM> users);
//修改用户头像 //修改用户头像
@Update("update hr_user_info set userAvatars=#{userAvatars} where userId=#{userId}") @Update("update hr_user_info set userAvatars=#{userAvatars} where userId=#{userId}")
void updateUserAvatars(@Param("userAvatars") String userAvatars, @Param("userId") Integer userId); void updateUserAvatars(@Param("userAvatars") String userAvatars, @Param("userId") Integer userId);
//更新用户登录次数和最后一次登录时间 //更新用户登录次数和最后一次登录时间
@Update({ "UPDATE user SET logInNumber=logInNumber+1, lastTimeOfLanding=now() WHERE userId=#{userId}"}) @Update({ "UPDATE user SET logInNumber=logInNumber+1, lastTimeOfLanding=now() WHERE userId=#{userId}"})
@ -268,6 +275,6 @@ public interface UserInfoMapper{
//删除用户组织架构关系 //删除用户组织架构关系
@Update( {"<script>", @Update( {"<script>",
"UPDATE hr_organization_relationship set isdel=1 where userId = #{userId}", "UPDATE hr_organization_relationship set isdel=1 where userId = #{userId}",
"</script>" }) "</script>" })
void deleteOrganizationRelationship(Integer userId); void deleteOrganizationRelationship(Integer userId);
} }

@ -84,18 +84,18 @@ public class UserInfoService {
public HashMap<String,Object> addUserInfo(UserInfo userInfo){ public HashMap<String,Object> addUserInfo(UserInfo userInfo){
HashMap<String, Object> resp = new HashMap<>(); HashMap<String, Object> resp = new HashMap<>();
try { try {
userInfo.setPassword("hanran999"); userInfo.setPassword("hanran123");
int insert = userInfoMapper.insertUserInfo(userInfo); int insert = userInfoMapper.insertUserInfo(userInfo);
if (insert>0){ if (insert>0){
resp.put(RETCODE,200); resp.put(RETCODE,200);
}else{ }else{
resp.put(RETCODE,400); resp.put(RETCODE,400);
resp.put(RETVALUE,"student/insert Invalid"); resp.put(RETVALUE,"student/insertUSERINFO Invalid");
} }
}catch (RuntimeException e){ }catch (RuntimeException e){
logger.error(e); logger.error(e);
resp.put(RETCODE,500); resp.put(RETCODE,500);
resp.put(RETVALUE,"student/insert Invalid"); resp.put(RETVALUE,"student/insertUSERINFO abnormal");
} }
return resp; return resp;
} }
@ -109,11 +109,11 @@ public class UserInfoService {
resp.put(RETCODE,200); resp.put(RETCODE,200);
}else{ }else{
resp.put(RETCODE,400); resp.put(RETCODE,400);
resp.put(RETVALUE,"student/insert Invalid"); resp.put(RETVALUE,"student/insertORGANIZA Invalid");
} }
}catch (RuntimeException e){ }catch (RuntimeException e){
resp.put(RETCODE,500); resp.put(RETCODE,500);
resp.put(RETVALUE,"student/insert Invalid"); resp.put(RETVALUE,"student/insertORGANIZA abnormal");
} }
return resp; return resp;
} }
@ -122,21 +122,13 @@ public class UserInfoService {
* 批量查询学生信息 * 批量查询学生信息
*/ */
@Transactional @Transactional
public HashMap<String,Object> queryStudent(UserInfo userInfo,OrganizationRelationship ship,Integer pageNo,Integer pageSize){ public HashMap<String,Object> queryStudent(StudentInfo studentInfo,Integer pageNo,Integer pageSize){
HashMap<String, Object> resp = new HashMap<String, Object>(); HashMap<String, Object> resp = new HashMap<String, Object>();
// UserInfo user = new UserInfo();
// OrganizationRelationship organizationRelationship = new OrganizationRelationship();
String searchContent = userInfo.getSearchContent();
Integer schoolId = userInfo.getSchoolId();
Integer gradeId = ship.getGradeId();
Integer classId = ship.getClassId();
Integer professionalId = ship.getProfessionalId();
try { try {
if(pageNo!=null&&pageSize!=null) { if(pageNo!=null&&pageSize!=null) {
PageHelper.startPage(pageNo, pageSize); PageHelper.startPage(pageNo, pageSize);
List list = userInfoMapper.queryStudent(searchContent, schoolId, gradeId, classId, professionalId); List<StudentInfo> list = userInfoMapper.queryStudent(studentInfo);
PageInfo info=new PageInfo(list); PageInfo<StudentInfo> info=new PageInfo(list);
int total1 = (int) info.getTotal(); int total1 = (int) info.getTotal();
int totalPages; int totalPages;
totalPages = total1 / pageSize; totalPages = total1 / pageSize;
@ -147,7 +139,7 @@ public class UserInfoService {
resp.put("retvalue", new PageResult(total, list,totalPages)); resp.put("retvalue", new PageResult(total, list,totalPages));
resp.put("retcode", 200); resp.put("retcode", 200);
}else { }else {
List<UserInfo> list = userInfoMapper.queryStudent(searchContent,schoolId,gradeId,classId,professionalId); List<StudentInfo> list = userInfoMapper.queryStudent(studentInfo);
resp.put("retvalue", list); resp.put("retvalue", list);
resp.put("retcode", 200); resp.put("retcode", 200);
} }

@ -1,6 +1,7 @@
package com.yipin.liuwanr.service; package com.yipin.liuwanr.service;
import com.yipin.liuwanr.entity.OrganizationRelationship; import com.yipin.liuwanr.entity.OrganizationRelationship;
import com.yipin.liuwanr.entity.StudentInfo;
import com.yipin.liuwanr.entity.UserInfo; import com.yipin.liuwanr.entity.UserInfo;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -50,26 +51,16 @@ public class StudentServiceTest {
*/ */
@Test @Test
public void queryStudent(){ public void queryStudent(){
UserInfo userInfo = new UserInfo(); StudentInfo studentInfo = new StudentInfo();
OrganizationRelationship organizationRelationship = new OrganizationRelationship(); OrganizationRelationship organizationRelationship = new OrganizationRelationship();
userInfo.setSchoolId(1); studentInfo.setSchoolId(1);
userInfo.setSearchContent("1"); studentInfo.setSearchContent("8");
Integer[] a = {1,2};
Integer[] b = {1,2};
Integer[] c = {1,2};
for (Integer aa: a){
organizationRelationship.setProfessionalId(aa);
}
for (Integer bb:b){
organizationRelationship.setGradeId(bb);
}
for (Integer cc:c){
organizationRelationship.setClassId(cc);
}
Integer pageNo = 1; Integer pageNo = 1;
Integer pageSize = 3; Integer pageSize = 3;
HashMap<String, Object> map = userInfoService.queryStudent(userInfo, organizationRelationship, pageNo, pageSize); HashMap<String, Object> map = userInfoService.queryStudent(studentInfo, pageNo, pageSize);
for (String s : map.keySet()) { for (String s : map.keySet()) {
System.out.println("key:" + s + "," + "value:" + map.get(s)); System.out.println("key:" + s + "," + "value:" + map.get(s));
} }

Loading…
Cancel
Save