|
@@ -1,7 +1,8 @@
|
|
package cn.com.qmth.examcloud.service.core.api;
|
|
package cn.com.qmth.examcloud.service.core.api;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.service.core.dao.UserRepo;
|
|
|
|
-import cn.com.qmth.examcloud.service.core.entity.User;
|
|
|
|
|
|
+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.dao.User;
|
|
import cn.com.qmth.examcloud.service.core.service.UserService;
|
|
import cn.com.qmth.examcloud.service.core.service.UserService;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -10,6 +11,8 @@ import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 用户服务API
|
|
* 用户服务API
|
|
* Created by songyue on 17/1/13.
|
|
* Created by songyue on 17/1/13.
|
|
@@ -24,45 +27,77 @@ public class UserApi {
|
|
@Autowired
|
|
@Autowired
|
|
UserRepo userRepo;
|
|
UserRepo userRepo;
|
|
|
|
|
|
- @ApiOperation(value="查询所有用户",notes="分页")
|
|
|
|
- @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
|
- public ResponseEntity getAllUser(@ModelAttribute User userCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
|
|
|
|
- return userService.getAllUser(userCriteria,new PageRequest(curPage - 1,pageSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value="查询所有用户",notes="不分页")
|
|
|
|
- @GetMapping("/all")
|
|
|
|
- public ResponseEntity getAllUser(@ModelAttribute User userCriteria){
|
|
|
|
- return userService.getAllUser(userCriteria);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- @ApiOperation(value="查询所有用户",notes="不分页不带查询")
|
|
|
|
|
|
+ @ApiOperation(value="查询所有用户")
|
|
@GetMapping
|
|
@GetMapping
|
|
public ResponseEntity getAllUser(){
|
|
public ResponseEntity getAllUser(){
|
|
return new ResponseEntity(userRepo.findAll(), HttpStatus.OK);
|
|
return new ResponseEntity(userRepo.findAll(), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="按ID查询用户",notes="ID查询")
|
|
|
|
|
|
+ @ApiOperation(value="按id查询用户",notes="id查询")
|
|
@GetMapping("/{id}")
|
|
@GetMapping("/{id}")
|
|
- public ResponseEntity<User> getUserById(@PathVariable Long id){
|
|
|
|
- return userService.getUserById(id);
|
|
|
|
|
|
+ public ResponseEntity getUserById(@PathVariable long id){
|
|
|
|
+ return new ResponseEntity(userRepo.findById(id), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="按orgId查询用户",notes="机构id查询")
|
|
|
|
+ @GetMapping("/org/{orgId}")
|
|
|
|
+ public ResponseEntity getUserByOrgId(@PathVariable long orgId){
|
|
|
|
+ List<User> userList = userRepo.findByOrgIdAndType(orgId, UserType.NOT_STUDENT.name());
|
|
|
|
+ return new ResponseEntity(userList, HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="按rootOrgId查询用户",notes="根机构id查询")
|
|
|
|
+ @GetMapping("/rootOrg/{rootOrgId}")
|
|
|
|
+ public ResponseEntity getUserByRootOrgId(@PathVariable long rootOrgId){
|
|
|
|
+ List<User> userList = userRepo.findByRootOrgIdAndType(rootOrgId, UserType.NOT_STUDENT.name());
|
|
|
|
+ return new ResponseEntity(userList, HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value="新增用户",notes="新增")
|
|
@ApiOperation(value="新增用户",notes="新增")
|
|
@PostMapping
|
|
@PostMapping
|
|
public ResponseEntity addUser(@RequestBody User user){
|
|
public ResponseEntity addUser(@RequestBody User user){
|
|
- return userService.saveUser(user);
|
|
|
|
|
|
+ return new ResponseEntity(userRepo.save(user), HttpStatus.CREATED);
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value="更新用户",notes="更新")
|
|
@ApiOperation(value="更新用户",notes="更新")
|
|
@PutMapping
|
|
@PutMapping
|
|
public ResponseEntity updateUser(@RequestBody User user){
|
|
public ResponseEntity updateUser(@RequestBody User user){
|
|
- return userService.saveUser(user);
|
|
|
|
|
|
+ return new ResponseEntity(userRepo.save(user), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="按ID删除用户",notes="删除")
|
|
|
|
|
|
+ @ApiOperation(value="重置用户密码",notes="重置密码")
|
|
|
|
+ @PutMapping("/resetPass/{id}")
|
|
|
|
+ public ResponseEntity resetPass(@PathVariable long id){
|
|
|
|
+ userService.initPassword(id);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="修改用户密码",notes="修改密码")
|
|
|
|
+ @PutMapping("/password")
|
|
|
|
+ public ResponseEntity updatePass(@RequestParam long userId,@RequestParam String password){
|
|
|
|
+ userRepo.updatePasswordById(userId,password);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="按id删除用户",notes="删除")
|
|
@DeleteMapping("/{id}")
|
|
@DeleteMapping("/{id}")
|
|
- public ResponseEntity deleteUser(@PathVariable Long id){
|
|
|
|
- return userService.deleteUser(id);
|
|
|
|
|
|
+ public ResponseEntity deleteUser(@PathVariable long id){
|
|
|
|
+ userRepo.delete(id);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="一般登录",notes="登录")
|
|
|
|
+ @PostMapping("/login")
|
|
|
|
+ public ResponseEntity login(@RequestParam String loginName,@RequestParam String password){
|
|
|
|
+ return userService.login(loginName,password);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="二级登录",notes="二级登录")
|
|
|
|
+ @PostMapping("/login/{orgId}")
|
|
|
|
+ public ResponseEntity login(@PathVariable long orgId,
|
|
|
|
+ @RequestParam String loginName,
|
|
|
|
+ @RequestParam String password){
|
|
|
|
+ return userService.login(orgId,loginName,password);
|
|
}
|
|
}
|
|
}
|
|
}
|