|
@@ -2,17 +2,21 @@ package cn.com.qmth.examcloud.service.core.api;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
import cn.com.qmth.examcloud.service.core.entity.User;
|
|
|
+import cn.com.qmth.examcloud.service.core.enums.UserScope;
|
|
|
import cn.com.qmth.examcloud.service.core.enums.UserType;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.UserRepo;
|
|
|
import cn.com.qmth.examcloud.service.core.service.UserService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
@@ -31,11 +35,19 @@ public class UserApi {
|
|
|
UserRepo userRepo;
|
|
|
|
|
|
|
|
|
-// @ApiOperation(value="查询所有用户")
|
|
|
-// @GetMapping
|
|
|
-// public ResponseEntity getAllUser(){
|
|
|
-// return new ResponseEntity(userRepo.findAll(), HttpStatus.OK);
|
|
|
-// }
|
|
|
+ @ApiOperation(value="查询所有用户",notes="分页带查询")
|
|
|
+ @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
+ public ResponseEntity getAllUser(@ModelAttribute User userCriteria,
|
|
|
+ @PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize,
|
|
|
+ HttpServletRequest request){
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if(accessUser != null){
|
|
|
+ userCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ }
|
|
|
+ return new ResponseEntity(userService.findAll(userCriteria,
|
|
|
+ new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
|
|
|
+ }
|
|
|
|
|
|
@ApiOperation(value="按id查询用户",notes="id查询")
|
|
|
@GetMapping("/{id}")
|
|
@@ -59,7 +71,13 @@ public class UserApi {
|
|
|
|
|
|
@ApiOperation(value="新增用户",notes="新增")
|
|
|
@PostMapping
|
|
|
- public ResponseEntity addUser(@RequestBody User user){
|
|
|
+ public ResponseEntity addUser(@RequestBody User user,HttpServletRequest request){
|
|
|
+ AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
|
|
|
+ if(accessUser != null){
|
|
|
+ user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ }
|
|
|
+ user.setScope(UserScope.ORG);
|
|
|
+ user.setType(UserType.NOT_STUDENT);
|
|
|
return new ResponseEntity(userRepo.save(user), HttpStatus.CREATED);
|
|
|
}
|
|
|
|
|
@@ -71,8 +89,38 @@ public class UserApi {
|
|
|
|
|
|
@ApiOperation(value="重置用户密码",notes="重置密码")
|
|
|
@PutMapping("/resetPass/{id}")
|
|
|
- public ResponseEntity resetPass(@PathVariable long id){
|
|
|
- userService.initPassword(id);
|
|
|
+ public ResponseEntity resetPass(@PathVariable String id){
|
|
|
+ List<Long> ids = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for(Long userId:ids){
|
|
|
+ userService.initPassword(userId);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="启用用户",notes="启用用户")
|
|
|
+ @PutMapping("/enable/{ids}")
|
|
|
+ public ResponseEntity enableUser(@PathVariable String ids){
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for(Long userId:userIds){
|
|
|
+ User user = userRepo.findOne(userId);
|
|
|
+ user.setEnable(true);
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="禁用用户",notes="禁用用户")
|
|
|
+ @PutMapping("/disable/{ids}")
|
|
|
+ public ResponseEntity disableUser(@PathVariable String ids){
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for(Long userId:userIds){
|
|
|
+ User user = userRepo.findOne(userId);
|
|
|
+ user.setEnable(false);
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
@@ -84,9 +132,13 @@ public class UserApi {
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="按id删除用户",notes="删除")
|
|
|
- @DeleteMapping("/{id}")
|
|
|
- public ResponseEntity deleteUser(@PathVariable long id){
|
|
|
- userRepo.delete(id);
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public ResponseEntity deleteUser(@PathVariable String ids){
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for(Long userId:userIds){
|
|
|
+ userRepo.delete(userId);
|
|
|
+ }
|
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
|
}
|
|
|
|