diff --git a/src/main/java/com/yipin/liuwanr/controller/StaffController.java b/src/main/java/com/yipin/liuwanr/controller/StaffController.java index 90bcd16..bc46660 100644 --- a/src/main/java/com/yipin/liuwanr/controller/StaffController.java +++ b/src/main/java/com/yipin/liuwanr/controller/StaffController.java @@ -66,19 +66,6 @@ public class StaffController { Response resp = new Response(); Staff staff = vo.getStaff(); UserM user = vo.getUser(); -// user.setPassword("huoran123"); -// user.setWorkNumber(staff.getStaffWorkNumber()); -// user.setUserAccount(staff.getStaffWorkNumber()); -// user.setAccountRole(3); -// user.setName(staff.getStaffName()); -// user.setPhone(staff.getPhone()); -// user.setEmail(staff.getEmail()); -// user.setSchoolId(staff.getSchoolId()); -// Long startTs = System.currentTimeMillis(); // 当前时间戳 -// String uniqueIdentificationAccount = startTs+""; -// user.setUniqueIdentificationAccount(uniqueIdentificationAccount); -// staff.setUniqueIdentificationAccount(uniqueIdentificationAccount); -// user.setUniqueIdentificationAccount(staff.getUniqueIdentificationAccount()); if (staff.getPhone()==null) { resp.setStatus(300); resp.setErrmessage("电话为空添加失败!"); diff --git a/src/main/java/com/yipin/liuwanr/controller/StudentController.java b/src/main/java/com/yipin/liuwanr/controller/StudentController.java index 573adbf..12cf8d8 100644 --- a/src/main/java/com/yipin/liuwanr/controller/StudentController.java +++ b/src/main/java/com/yipin/liuwanr/controller/StudentController.java @@ -73,18 +73,6 @@ public class StudentController { Response resp = new Response(); Student student = vo.getStudent(); UserM user = vo.getUser(); -// user.setPassword("huoran123"); -// user.setPassword(student.getStudentPassword()); -// user.setUserAccount(student.getStudentNumber()); -// user.setAccountRole(4); -// user.setName(student.getStudentName()); -// user.setPhone(student.getPhone()); -// user.setEmail(student.getEmail()); -// user.setWorkNumber(student.getStudentNumber()); -// Long startTs = System.currentTimeMillis(); // 当前时间戳 -// String uniqueIdentificationAccount = startTs+""; -// user.setUniqueIdentificationAccount(uniqueIdentificationAccount); -// student.setUniqueIdentificationAccount(uniqueIdentificationAccount); if (student.getPhone()==null) { resp.setStatus(300); resp.setErrmessage("Parameter Invalid"); diff --git a/src/main/java/com/yipin/liuwanr/controller/UserController.java b/src/main/java/com/yipin/liuwanr/controller/UserController.java index ca1c389..0b5f74a 100644 --- a/src/main/java/com/yipin/liuwanr/controller/UserController.java +++ b/src/main/java/com/yipin/liuwanr/controller/UserController.java @@ -17,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; +import java.util.List; @RestController @RequestMapping("/user") @@ -164,35 +165,35 @@ public class UserController { resp.setStatus(300); resp.setErrmessage("学校不能为空!"); }else { - if (accountRole == 4){ - HashMap stu = studentService.addStudent(student); - int status = (int) stu.get("retcode"); - if (status == 200){ - resp.setStatus(status); - resp.setMessage(stu.get("retvalue")); - }else { - resp.setStatus(status); - resp.setErrmessage(stu.get("retvalue").toString()); - throw new RuntimeException(); - } - } - if(accountRole == 3){ - HashMap sta = staffService.addStaff(staff); - int status = (int) sta.get("retcode"); - if (status == 200){ - resp.setStatus(status); - resp.setMessage(sta.get("retvalue")); - }else { - resp.setStatus(status); - resp.setErrmessage(sta.get("retvalue").toString()); - throw new RuntimeException(); - } - } HashMap ret = userService.addUser(user); int status = (int) ret.get("retcode"); if (200 == status) { resp.setStatus(status); resp.setMessage(ret.get("retvalue")); + if (accountRole == 4){ + HashMap stu = studentService.addStudent(student); + int stuStatus = (int) stu.get("retcode"); + if (stuStatus == 200){ + resp.setStatus(stuStatus); + resp.setMessage(stu.get("retvalue")); + }else { + resp.setStatus(stuStatus); + resp.setErrmessage(stu.get("retvalue").toString()); + throw new RuntimeException(); + } + } + if(accountRole == 3){ + HashMap sta = staffService.addStaff(staff); + int staStatus = (int) sta.get("retcode"); + if (staStatus == 200){ + resp.setStatus(staStatus); + resp.setMessage(sta.get("retvalue")); + }else { + resp.setStatus(staStatus); + resp.setErrmessage(sta.get("retvalue").toString()); + throw new RuntimeException(); + } + } } else { resp.setStatus(status); resp.setErrmessage(ret.get("retvalue").toString()); @@ -260,22 +261,61 @@ public class UserController { /** * 删除用户(根据ID修改isdel状态,0可见 1不可见) */ + @Transactional @PostMapping("/deleteUser") - Response deleteUser(@RequestBody UserM user) { + Response deleteUser(@RequestBody List userList) { Response resp = new Response(); - if (user.getUser().isEmpty()) { - resp.setStatus(300); - resp.setErrmessage("参数有误,删除用户失败!"); - } else { - HashMap ret = userService.deleteUser(user); - int status = (int) ret.get("retcode"); - if (200 == status) { - resp.setStatus(status); - resp.setMessage(ret.get("retvalue")); + int size = userList.size(); + for(int i=0;i ret = userService.deleteUser(userId); + int status = (int) ret.get("retcode"); + if (200 == status) { + resp.setStatus(status); + resp.setMessage(ret.get("retvalue")); + if (roleId==3){ + HashMap sta = userService.deleteStaff(user); + int staStatus = (int) ret.get("retcode"); + if (200 == staStatus) { + resp.setStatus(staStatus); + resp.setMessage(sta.get("retvalue")); + }else{ + resp.setStatus(staStatus); + resp.setErrmessage(sta.get("retvalue").toString()); + throw new RuntimeException(); + } + } + if (roleId==4){ + HashMap stu = userService.deleteStudent(user); + int stuStatus = (int) stu.get("retcode"); + if (200 == stuStatus) { + resp.setStatus(stuStatus); + resp.setMessage(stu.get("retvalue")); + }else{ + resp.setStatus(stuStatus); + resp.setErrmessage(stu.get("retvalue").toString()); + throw new RuntimeException(); + } + } + } else { + resp.setStatus(status); + resp.setErrmessage(ret.get("retvalue").toString()); + throw new RuntimeException(); + } + } } return resp; } @@ -283,21 +323,56 @@ public class UserController { /** * 更新用户 */ + @Transactional @PostMapping("/updateUser") - Response updateUser(@RequestBody UserM user) { + Response updateUser(@RequestBody UserVO vo) { Response resp = new Response(); - if (user.getUserId()==null) { + UserM user = vo.getUser(); + Staff staff = vo.getStaff(); + Student student = vo.getStudent(); + Integer userId = user.getUserId(); + Integer roleId = user.getAccountRole(); + if (userId==null) { resp.setStatus(300); resp.setErrmessage("用户ID为空,修改用户失败!"); - } else { + }else if (roleId==null){ + resp.setStatus(300); + resp.setErrmessage("角色ID为空,修改用户失败!"); + } + else { HashMap ret = userService.updateUser(user); int status = (int) ret.get("retcode"); if (200 == status) { resp.setStatus(status); resp.setMessage(ret.get("retvalue")); + if (roleId ==3){ + HashMap sta = staffService.updateStaff(staff); + int staStatus = (int) sta.get("retcode"); + if (200 == status) { + resp.setStatus(staStatus); + resp.setMessage(sta.get("retvalue")); + }else{ + resp.setStatus(staStatus); + resp.setErrmessage(sta.get("retvalue").toString()); + throw new RuntimeException("修改员工失败!"); + } + } + if (roleId ==4){ + HashMap stu = studentService.updateStudent(student); + int stuStatus = (int) stu.get("retcode"); + if (200 == status) { + resp.setStatus(stuStatus); + resp.setMessage(stu.get("retvalue")); + }else{ + resp.setStatus(stuStatus); + resp.setErrmessage(stu.get("retvalue").toString()); + throw new RuntimeException("修改学生失败!"); + } + } } else { resp.setStatus(status); resp.setErrmessage(ret.get("retvalue").toString()); + throw new RuntimeException("修改用户失败!"); } } return resp; @@ -334,15 +409,16 @@ public class UserController { * 查询用户详情(ID) */ @GetMapping("/queryUserDetails") - Response queryUserDetails(@RequestParam Integer userId) { + Response queryUserDetails(@RequestParam Integer userId,Integer roleId) { Response resp = new Response(); - if (userId==null) {//前台传来的值是否为空 + if (roleId == null){ + resp.setStatus(300); + resp.setErrmessage("用户角色id为空!查询失败!"); + }else if (userId==null) { resp.setStatus(300); resp.setErrmessage("用户id为空!查询失败!"); }else { - HashMap ret = userService.queryUserDetails(userId); - resp.setStatus(200); - resp.setErrmessage("查询成功!"); + HashMap ret = userService.queryUserDetails(userId,roleId); int status = (int) ret.get("retcode"); if (200 == status) { resp.setStatus(status); diff --git a/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java b/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java index c6a7dee..f3ea98f 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java @@ -3,9 +3,8 @@ package com.yipin.liuwanr.mapper; import java.util.List; import com.yipin.liuwanr.entity.UserM; -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Select; -import org.apache.ibatis.annotations.Update; +import com.yipin.liuwanr.vo.UserVO; +import org.apache.ibatis.annotations.*; import com.yipin.liuwanr.entity.Staff; import com.yipin.liuwanr.entity.StaffGrade; @@ -34,10 +33,26 @@ public interface StaffMapper { void deleteStaff(@Param("staffId")List staffId); @Select({" "}) - List queryStaffDetails(Integer staffId); - + List queryStaffDetails(Integer staffId); + + //查询学生详情 + @Select({ " " }) + @Results({ + @Result(property = "staff", column = "staffId",one = @One(select = "com.yipin.liuwanr.mapper.StaffMapper.queryStaffDetails")), + @Result(property = "user", column = "staffId",one = @One(select = "com.yipin.liuwanr.mapper.StaffMapper.queryStaffDetailsU")) + }) + List queryStaffDetailsUser(Integer staffId); + + //查询学生详情 + @Select({ " " }) + List queryStaffDetailsU(Integer staffId); + @Update("UPDATE staff SET staffName = #{staffName},staffWorkNumber = #{staffWorkNumber},phone = #{phone},email = #{email},staffProfessionalArchitectureId = #{staffProfessionalArchitectureId}," + "staffProfessionalArchitectureId = #{staffProfessionalArchitectureId},staffGradeId = #{staffGradeId},roleId = #{roleId} where staffId = #{staffId}") void updateStaff(Staff staff); diff --git a/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java b/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java index 1ce3e13..d008af2 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/StudentMapper.java @@ -3,9 +3,8 @@ package com.yipin.liuwanr.mapper; import java.util.List; import com.yipin.liuwanr.entity.UserM; -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Select; -import org.apache.ibatis.annotations.Update; +import com.yipin.liuwanr.vo.UserVO; +import org.apache.ibatis.annotations.*; import com.yipin.liuwanr.entity.Student; @@ -42,8 +41,24 @@ public interface StudentMapper { " " }) List queryStudentDetails(Integer studentId); + //查询学生详情 + @Select({ " " }) + @Results({ + @Result(property = "student", column = "studentId",one = @One(select = "com.yipin.liuwanr.mapper.StudentMapper.queryStudentDetails")), + @Result(property = "user", column = "studentId",one = @One(select = "com.yipin.liuwanr.mapper.StudentMapper.queryStudentDetailsU")) + }) + List queryStudentDetailsUser(Integer studentId); + + //查询学生详情 + @Select({ " " }) + List queryStudentDetailsU(Integer studentId); + //修改学生 - @Update("UPDATE student SET studentName = #{studentName},studentWorkNumber = #{studentWorkNumber},phone = #{phone},email = #{email},roleId = #{roleId}" + @Update("UPDATE student SET studentName = #{studentName},studentNumber = #{studentNumber},phone = #{phone},email = #{email},roleId = #{roleId}" + ",schoolId = #{schoolId},professionalId = #{professionalId},gradeId = #{gradeId},classId = #{classId} where studentId = #{studentId}") void updateStudent(Student student); diff --git a/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java b/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java index 38abb54..54bcc26 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java @@ -1,6 +1,7 @@ package com.yipin.liuwanr.mapper; import com.yipin.liuwanr.entity.*; +import com.yipin.liuwanr.vo.UserVO; import org.apache.ibatis.annotations.*; import org.apache.ibatis.mapping.FetchType; @@ -129,31 +130,85 @@ public interface UserMapper { " "}) List queryUser(UserM user); + @Update("UPDATE user SET isdel = 1 where userId = #{userId}") + void deleteUser(Integer userId); + + //批量删除员工 @Update({ "" }) - void deleteUser(UserM user); - + "UPDATE staff SET isdel = 1 where phone = #{phone} ", + "" }) + void deleteStaff(UserM user); + + //批量删除学生 + @Update({ "" }) + void deleteStudent(UserM user); + @Update("UPDATE user SET name = #{name},sex = #{sex},documentType = #{documentType},countries = #{countries},educationDegree = #{educationDegree}," + "IDNumber = #{IDNumber},accountRole = #{accountRole},provinceId = #{provinceId},subjectsTaught = #{subjectsTaught},cityId = #{cityId}," + "phone = #{phone},teachingProfessional = #{teachingProfessional},WeChatID = #{WeChatID},dateBirth = #{dateBirth},email = #{email},schoolId = #{schoolId},disciplineId = #{disciplineId},professionalId = #{professionalId},professionalClassId = #{professionalClassId} where userId = #{userId}") void updateUser(UserM user); - - + + @Update("UPDATE user SET name = #{name},sex = #{sex},documentType = #{documentType},countries = #{countries},educationDegree = #{educationDegree}," + + "IDNumber = #{IDNumber},accountRole = #{accountRole},provinceId = #{provinceId},subjectsTaught = #{subjectsTaught},cityId = #{cityId}," + + "phone = #{phone},teachingProfessional = #{teachingProfessional},WeChatID = #{WeChatID},dateBirth = #{dateBirth},email = #{email},schoolId = #{schoolId},disciplineId = #{disciplineId},professionalId = #{professionalId},professionalClassId = #{professionalClassId} where userId = #{userId}") + void updateStaff(Staff staff); + @Select("SELECT u.* from user u where isdel=0 and phone = #{phone} and password = #{password}") UserM logins(UserM user); @Select("SELECT u.* from user u where isdel=0 and phone = #{phone}") - UserM queryPhone(String phone); + List queryPhone(String phone); @Select({" "}) List queryUserDetails(Integer userId); + @Select({" "}) + @Results({ + @Result(property = "user", column = "userId",one = @One(select = "com.yipin.liuwanr.mapper.UserMapper.queryUserDetailss")), + }) + List queryUserDetailsAdmin(Integer userId); + + @Select({" "}) + List queryUserDetailss(Integer userId); + + @Select({" "}) + @Results({ + @Result(property = "user", column = "userId",one = @One(select = "com.yipin.liuwanr.mapper.UserMapper.queryUserDetails")), + @Result(property = "staff", column = "userId",one = @One(select = "com.yipin.liuwanr.mapper.UserMapper.queryUserDetailsSta")) + }) + List queryUserDetailsStaff(Integer userId); + //查询用户详情学生角色 + //查询学生用户详情 + + @Select({" "}) + @Results({ + @Result(property = "user", column = "userId",one = @One(select = "com.yipin.liuwanr.mapper.UserMapper.queryUserDetails")), + @Result(property = "student", column = "userId",one = @One(select = "com.yipin.liuwanr.mapper.UserMapper.queryUserDetailsStu")) + }) + List queryUserDetailsStudent(Integer userId); + @Select({" "}) + List queryUserDetailsStu(Integer userId); + + //查询老师用户详情 + @Select({" "}) + List queryUserDetailsSta(Integer userId); + @Select({" "}) diff --git a/src/main/java/com/yipin/liuwanr/service/StaffService.java b/src/main/java/com/yipin/liuwanr/service/StaffService.java index a4c1a8e..7d9a3cd 100644 --- a/src/main/java/com/yipin/liuwanr/service/StaffService.java +++ b/src/main/java/com/yipin/liuwanr/service/StaffService.java @@ -159,7 +159,7 @@ public class StaffService { public HashMap queryStaffDetails(Integer staffId){ HashMap resp = new HashMap(); try { - resp.put("retvalue", staffMapper.queryStaffDetails(staffId)); + resp.put("retvalue", staffMapper.queryStaffDetailsUser(staffId)); resp.put("retcode", 200); } catch (RuntimeException e) { logger.error(e.getMessage()); diff --git a/src/main/java/com/yipin/liuwanr/service/StudentService.java b/src/main/java/com/yipin/liuwanr/service/StudentService.java index 2019351..5906365 100644 --- a/src/main/java/com/yipin/liuwanr/service/StudentService.java +++ b/src/main/java/com/yipin/liuwanr/service/StudentService.java @@ -97,7 +97,7 @@ public class StudentService { public HashMap queryStudentDetails(Integer studentId) { HashMap resp = new HashMap(); try { - resp.put("retvalue", studentMapper.queryStudentDetails(studentId)); + resp.put("retvalue", studentMapper.queryStudentDetailsUser(studentId)); resp.put("retcode", 200); } catch (RuntimeException e) { logger.error(e.getMessage()); @@ -116,7 +116,7 @@ public class StudentService { } catch (RuntimeException e) { logger.error(e.getMessage()); resp.put("retcode", 500); - resp.put("retvalue", "Inquiry Failed"); + resp.put("retvalue", "修改学生失败!"); return resp; } return resp; diff --git a/src/main/java/com/yipin/liuwanr/service/UserService.java b/src/main/java/com/yipin/liuwanr/service/UserService.java index 7b0ebe5..c478f79 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserService.java @@ -14,6 +14,7 @@ import org.jboss.logging.Logger; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import com.aliyun.oss.OSSClient; @@ -127,8 +128,6 @@ public class UserService { HashMap resp = new HashMap(); try { user.setPassword("huoran123");//设置默认密码 - String uniqueIdentificationAccount = System.currentTimeMillis()+""; - user.setUniqueIdentificationAccount(uniqueIdentificationAccount); userMapper.addUser(user); resp.put("retcode", 200); } catch (RuntimeException e) { @@ -172,10 +171,10 @@ public class UserService { } //删除用户 - public HashMap deleteUser(UserM user){ + public HashMap deleteUser(Integer userId){ HashMap resp = new HashMap(); try { - userMapper.deleteUser(user); + userMapper.deleteUser(userId); resp.put("retcode", 200); } catch (RuntimeException e) { logger.error(e.getMessage()); @@ -186,7 +185,38 @@ public class UserService { return resp; } + //批量删除员工 + public HashMap deleteStaff(UserM user){ + HashMap resp = new HashMap(); + try { + userMapper.deleteStaff(user); + resp.put("retcode", 200); + } catch (RuntimeException e) { + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "删除员工失败"); + return resp; + } + return resp; + } + + //批量删除学生 + public HashMap deleteStudent(UserM user){ + HashMap resp = new HashMap(); + try { + userMapper.deleteStudent(user); + resp.put("retcode", 200); + } catch (RuntimeException e) { + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "删除学生失败"); + return resp; + } + return resp; + } + //更新用户 + @Transactional public HashMap updateUser(UserM user){ HashMap resp = new HashMap(); try { @@ -196,7 +226,7 @@ public class UserService { logger.error(e.getMessage()); resp.put("retcode", 500); resp.put("retvalue", "更新用户失败!"); - return resp; + throw new RuntimeException(); } return resp; } @@ -250,11 +280,19 @@ public class UserService { } //查询用户详情 - public HashMap queryUserDetails(Integer userId){ + public HashMap queryUserDetails(Integer userId,Integer roleId){ HashMap resp = new HashMap(); try { - resp.put("retvalue", userMapper.queryUserDetails(userId)); - resp.put("retcode", 200); + if (roleId == 3){ + resp.put("retvalue", userMapper.queryUserDetailsStaff(userId)); + resp.put("retcode", 200); + }else if (roleId == 4){ + resp.put("retvalue", userMapper.queryUserDetailsStudent(userId)); + resp.put("retcode", 200); + }else{ + resp.put("retvalue", userMapper.queryUserDetailsAdmin(userId)); + resp.put("retcode", 200); + } } catch (RuntimeException e) { logger.error(e.getMessage()); resp.put("retcode", 500);