From 850182956bad51536b69d10601283bdb59a796ff Mon Sep 17 00:00:00 2001 From: "zhiyong.ning" <354350178@qq.com> Date: Thu, 20 Aug 2020 17:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserInfoController.java | 473 ++++++++++++++++++ .../com/yipin/liuwanr/entity/UserInfo.java | 11 + .../liuwanr/service/PracticeService.java | 11 +- .../yipin/liuwanr/service/UserService.java | 31 ++ 4 files changed, 522 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/yipin/liuwanr/controller/UserInfoController.java diff --git a/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java b/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java new file mode 100644 index 0000000..f90d850 --- /dev/null +++ b/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java @@ -0,0 +1,473 @@ +package com.yipin.liuwanr.controller; + +import com.yipin.liuwanr.entity.Staff; +import com.yipin.liuwanr.entity.Student; +import com.yipin.liuwanr.entity.UserInfo; +import com.yipin.liuwanr.entity.UserM; +import com.yipin.liuwanr.helper.RedisHelper; +import com.yipin.liuwanr.service.StaffService; +import com.yipin.liuwanr.service.StudentService; +import com.yipin.liuwanr.service.UserService; +import com.yipin.liuwanr.vo.UserVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; +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("/userInfo") +public class UserInfoController { + + @Autowired + private UserService userService; + + @Autowired + private StudentService studentService; + + @Autowired + private StaffService staffService; + + @Autowired + RedisHelper redisHelper; + + /** + * 添加用户 + */ + @Transactional + @PostMapping("/addUser") + Response addUser(@RequestBody UserVO vo) { + Response resp = new Response(); + //用户实体 + UserM user = vo.getUser(); + //学生实体 + Student student = vo.getStudent(); + //员工实体 + Staff staff = vo.getStaff(); + //用户手机号 + String phone = user.getPhone(); + //用户名称 + String name = user.getName(); + //省份id + Integer provinceId = user.getProvinceId(); + //用户角色id + Integer accountRole = user.getAccountRole(); + //城市id + Integer cityId = user.getCityId(); + //学校id + Integer schoolId = user.getSchoolId(); + if (phone==null||phone=="") { + resp.setStatus(300); + resp.setErrmessage("电话不能为空!"); + }else if(name==null||name==""){ + resp.setStatus(300); + resp.setErrmessage("姓名不能为空!"); + }else if(provinceId==null){ + resp.setStatus(300); + resp.setErrmessage("省份不能为空!"); + }else if(accountRole==null){ + resp.setStatus(300); + resp.setErrmessage("用户角色不能为空!"); + }else if(cityId==null){ + resp.setStatus(300); + resp.setErrmessage("城市不能为空!"); + }else if(schoolId==null){ + resp.setStatus(300); + resp.setErrmessage("学校不能为空!"); + }else { + 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||accountRole==2){ + 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()); + throw new RuntimeException(); + } + } + return resp; + } + + /** + * 查询用户(根据国家、省份、城市) + */ + @GetMapping("/queryUserInfo") + Response queryUserInfo(@RequestParam String countries, Integer provinceId, Integer cityId, Integer pageNo, Integer pageSize, Integer schoolId, Integer roleId, String searchContent, Integer month, String creationTime, String endTime) { + Response resp = new Response(); + UserInfo userInfo = new UserInfo(); + //设置国家 + if (countries != null&&countries!="") { + userInfo.setCountries(countries); + } + //设置省份 + if(provinceId!=null) { + userInfo.setProvinceId(provinceId); + } + //设置城市 + if(cityId!=null) { + userInfo.setCityId(cityId); + } + //学校 + if (schoolId!=null) { + userInfo.setSchoolId(schoolId); + } + //角色 + if (roleId!=null) { + userInfo.setRoleId(roleId); + } + //搜索内容 + if (searchContent!=null&&searchContent!="") { + userInfo.setSearchContent(searchContent); + } + //月份 + if (month!=null) { + userInfo.setMonth(month);; + } + //创建时间 + if (creationTime!=null&&creationTime!="") { + userInfo.setCreationTime(creationTime); + } + //结束时间 + if (endTime!=null&&endTime!="") { + userInfo.setEndTime(endTime); + } + HashMap ret = userService.queryUserInfo(userInfo,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; + } + + /** + * 删除用户(根据ID修改isdel状态,0可见 1不可见) + */ + @Transactional + @PostMapping("/deleteUserInfo") + Response deleteUser(@RequestBody List userList) { + Response resp = new Response(); + 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||roleId==2){ + 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; + } + + /** + * 更新用户 + */ + @Transactional + @PostMapping("/updateUser") + Response updateUser(@RequestBody UserVO vo) { + Response resp = new Response(); + 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 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||roleId==2){ + HashMap sta = userService.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 = userService.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; + } + + + /** + * 登陆(前台传来的key必须是phone、password) + */ + @GetMapping("/logins") + Response logins(@RequestParam("phone") String phone, @RequestParam("password") String password, + HttpServletRequest req, HttpServletResponse res) { + Response resp = new Response(); + UserM user = new UserM(); + if (phone != null) { + user.setPhone(phone); + }if(password!=null) { + user.setPassword(password); + } + HashMap ret = userService.logins(user); + 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; + } + + + /** + * 查询用户详情(ID) + */ + @GetMapping("/queryUserDetails") + Response queryUserDetails(@RequestParam Integer userId, Integer roleId) { + Response resp = new Response(); + 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,roleId); + 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; + } + + @PostMapping("/uploadUserAvatars") + Response uploadUserAvatars(MultipartFile file, Integer userId) { + Response resp = new Response(); + if (userId==null) {//前台传来的值是否为空 + resp.setStatus(300); + resp.setErrmessage("Parameter Invalid"); + }else { + HashMap ret = userService.uploadUserAvatars(file,userId); + + 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; + } + + /** + * 更新登录次数和时间 + */ + @PostMapping("/updateLogInNumber") + Response updateLogInNumber(@RequestBody UserM user) { + Response resp = new Response(); + Integer userId = user.getUserId(); + String phone = user.getPhone(); + Integer accountRole = user.getAccountRole(); + if (userId==null) { + resp.setStatus(300); + resp.setErrmessage("用户id不能为空!"); + }else if(phone==null||phone==""){ + resp.setStatus(300); + resp.setErrmessage("用户电话不能为空!"); + } else if(accountRole==null){ + resp.setStatus(300); + resp.setErrmessage("用户角色不能为空!"); + } else { + HashMap ret = userService.updateLogInNumber(user); + 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; + } + /** + * 用户模块查询客户 + */ + @GetMapping("/queryCustomer") + Response queryCustomer(@RequestParam Integer cityId, Integer provinceId) { + Response resp = new Response(); + if(provinceId == null){ + resp.setStatus(300); + resp.setErrmessage("省份id为空!查询失败!"); + }else if (cityId==null) { + resp.setStatus(300); + resp.setErrmessage("城市id为空!查询失败!"); + }else { + HashMap ret = userService.queryCustomer(cityId,provinceId); + resp.setStatus(200); + resp.setErrmessage("查询成功!"); + 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; + } + + /** + * 查询账号是否存在 + */ + @GetMapping("/queryAccountIsExist") + Response queryAccountIsExist(@RequestParam String userAccount) { + Response resp = new Response(); + if (userAccount==null) { + resp.setStatus(300); + resp.setErrmessage("账号为空!"); + }else { + HashMap ret = userService.queryAccountIsExist(userAccount); + 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; + } + + /** + * 查询学号、工号是否存在 + */ + @GetMapping("/queryWorkNumberIsExist") + Response queryWorkNumberIsExist(@RequestParam String workNumber) { + Response resp = new Response(); + if (workNumber==null) { + resp.setStatus(300); + resp.setErrmessage("账号为空!"); + }else { + HashMap ret = userService.queryWorkNumberIsExist(workNumber); + 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; + } +} \ No newline at end of file diff --git a/src/main/java/com/yipin/liuwanr/entity/UserInfo.java b/src/main/java/com/yipin/liuwanr/entity/UserInfo.java index c82e274..0762b68 100644 --- a/src/main/java/com/yipin/liuwanr/entity/UserInfo.java +++ b/src/main/java/com/yipin/liuwanr/entity/UserInfo.java @@ -10,6 +10,8 @@ import java.util.List; public class UserInfo { //用户id private Integer userId; + //角色id + private Integer roleId; //用户姓名 private String userName; //用户账号 @@ -349,10 +351,19 @@ public class UserInfo { this.professionalName = professionalName; } + public Integer getRoleId() { + return roleId; + } + + public void setRoleId(Integer roleId) { + this.roleId = roleId; + } + @Override public String toString() { return "UserInfo{" + "userId=" + userId + + ", roleId=" + roleId + ", userName='" + userName + '\'' + ", account='" + account + '\'' + ", password='" + password + '\'' + diff --git a/src/main/java/com/yipin/liuwanr/service/PracticeService.java b/src/main/java/com/yipin/liuwanr/service/PracticeService.java index 3c1f3b6..f8979d1 100644 --- a/src/main/java/com/yipin/liuwanr/service/PracticeService.java +++ b/src/main/java/com/yipin/liuwanr/service/PracticeService.java @@ -4,8 +4,12 @@ import java.net.URLEncoder; import java.util.HashMap; import java.util.List; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.yipin.liuwanr.entity.*; +import com.yipin.liuwanr.helper.RedisHelper; +import com.yipin.liuwanr.vo.UserVO; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.jboss.logging.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -13,13 +17,14 @@ import org.springframework.stereotype.Service; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; -import com.yipin.liuwanr.entity.PageResult; -import com.yipin.liuwanr.entity.Record; import com.yipin.liuwanr.helper.ExcelExportHelper; import com.yipin.liuwanr.mapper.AssesmentMapper; import com.yipin.liuwanr.mapper.RecordMapper; import com.yipin.liuwanr.vo.PracticeRecordVo; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; /** * 练习记录 @@ -172,7 +177,6 @@ public class PracticeService { return resp; } - public HashMap queryAllExperiment(Integer courseId) { HashMap resp = new HashMap(); try { @@ -188,5 +192,4 @@ public class PracticeService { } 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 cac1651..b6d8947 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserService.java @@ -170,6 +170,37 @@ public class UserService { return resp; } + //查询用户信息 + public HashMap queryUserInfo(UserInfo userInfo,Integer pageNo,Integer pageSize){ + HashMap resp = new HashMap(); + try { + if(pageNo!=null&&pageSize!=null) { + PageHelper.startPage(pageNo, pageSize); + List list = userMapper.queryUserInfo(userInfo); + 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 = userMapper.queryUserInfo(userInfo); + resp.put("retvalue", list); + resp.put("retcode", 200); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "查询用户失败!"); + return resp; + } + return resp; + } + //删除用户 public HashMap deleteUser(Integer userId){ HashMap resp = new HashMap();