master
zhiyong.ning 4 years ago
parent 5fc0b845cd
commit 850182956b
  1. 473
      src/main/java/com/yipin/liuwanr/controller/UserInfoController.java
  2. 11
      src/main/java/com/yipin/liuwanr/entity/UserInfo.java
  3. 11
      src/main/java/com/yipin/liuwanr/service/PracticeService.java
  4. 31
      src/main/java/com/yipin/liuwanr/service/UserService.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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<UserM> userList) {
Response resp = new Response();
int size = userList.size();
for(int i=0;i<size;i++){
UserM user = userList.get(i);
Integer userId = user.getUserId();
Integer roleId = user.getAccountRole();
String phone = user.getPhone();
if (userId==null) {
resp.setStatus(300);
resp.setErrmessage("用户id为空,删除用户失败!");
}else if (phone==null||phone==""){
resp.setStatus(300);
resp.setErrmessage("用户电话为空,删除用户失败!");
}else if (roleId==null){
resp.setStatus(300);
resp.setErrmessage("用户角色为空,删除用户失败!");
} else {
HashMap<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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必须是phonepassword)
*/
@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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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;
}
}

@ -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 + '\'' +

@ -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<String, Object> queryAllExperiment(Integer courseId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
@ -188,5 +192,4 @@ public class PracticeService {
}
return resp;
}
}

@ -170,6 +170,37 @@ public class UserService {
return resp;
}
//查询用户信息
public HashMap<String, Object> queryUserInfo(UserInfo userInfo,Integer pageNo,Integer pageSize){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
if(pageNo!=null&&pageSize!=null) {
PageHelper.startPage(pageNo, pageSize);
List<UserInfo> list = userMapper.queryUserInfo(userInfo);
PageInfo<UserInfo> info=new PageInfo<UserInfo>(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<UserInfo> 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<String, Object> deleteUser(Integer userId){
HashMap<String, Object> resp = new HashMap<String, Object>();

Loading…
Cancel
Save