parent
5fc0b845cd
commit
850182956b
4 changed files with 522 additions and 4 deletions
@ -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必须是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<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; |
||||
} |
||||
} |
Loading…
Reference in new issue