|
|
@@ -1,27 +1,22 @@
|
|
|
package com.xintong.visualinspection.controller;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
|
|
|
-import org.springframework.security.core.Authentication;
|
|
|
-import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
-import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.xintong.visualinspection.bean.User;
|
|
|
import com.xintong.visualinspection.err.BusinessException;
|
|
|
-import com.xintong.visualinspection.pojo.JwtAuthenticationResponse;
|
|
|
import com.xintong.visualinspection.securityTools.RedisCacheUtil;
|
|
|
import com.xintong.visualinspection.service.AuthService;
|
|
|
import com.xintong.visualinspection.service.UserService;
|
|
|
@@ -30,6 +25,14 @@ import com.xintong.visualinspection.service.UserService;
|
|
|
* 文件名:TestController
|
|
|
* 版本信息:日期:2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
|
|
|
*/
|
|
|
+/**
|
|
|
+ * @author wenhongquan
|
|
|
+ *
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * @author wenhongquan
|
|
|
+ *
|
|
|
+ */
|
|
|
@RestController
|
|
|
@RequestMapping("/user")
|
|
|
public class UserController extends BaseController {
|
|
|
@@ -52,16 +55,17 @@ public class UserController extends BaseController {
|
|
|
return returnSuccessResult("登陆成功", u);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/logout",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping(value = "/logout",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
|
|
|
public String logout(){
|
|
|
//获取用户名
|
|
|
String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
|
|
if(username!=null){
|
|
|
redisCacheUtil.removeForUserName(username);
|
|
|
}
|
|
|
- throw new BusinessException(20002);
|
|
|
//返回成功
|
|
|
-// return returnSuccessResult("退出成功");
|
|
|
+ return returnSuccessResult("退出成功");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -90,13 +94,14 @@ public class UserController extends BaseController {
|
|
|
* @exception
|
|
|
* @since 1.0.0
|
|
|
*/
|
|
|
- @RequestMapping(value = "/updateUser")
|
|
|
- public String updateUser(@RequestBody User user){
|
|
|
+ @RequestMapping(value = "/updateUser/{userid}",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
+ public String updateUser(@RequestBody User user,@PathVariable int userid){
|
|
|
try{
|
|
|
+ user.setId(userid);
|
|
|
userService.update(user);
|
|
|
return super.returnResult(0, "修改成功", null);
|
|
|
}catch(Exception e){
|
|
|
- return super.returnResult(-1, "修改失败", null);
|
|
|
+ throw new BusinessException(20003);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -108,10 +113,10 @@ public class UserController extends BaseController {
|
|
|
* @since 1.0.0
|
|
|
*/
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
- @RequestMapping(value = "/deleteUser/{userid}",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
- public String deleteUser(@PathVariable String userid){
|
|
|
+ @RequestMapping(value = "/deleteUser/{userid}",method=RequestMethod.DELETE,produces="application/json;charset=UTF-8")
|
|
|
+ public String deleteUser(@PathVariable Integer userid){
|
|
|
try{
|
|
|
- userService.delete(Long.parseLong(userid));
|
|
|
+ userService.delete((userid));
|
|
|
return returnResult(0, "删除成功", null);
|
|
|
}catch(Exception e){
|
|
|
throw new BusinessException(20002);
|
|
|
@@ -119,18 +124,22 @@ public class UserController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- @RequestMapping(value = "/refresh", method = RequestMethod.GET)
|
|
|
- public ResponseEntity<?> refreshAndGetAuthenticationToken(
|
|
|
- HttpServletRequest request) throws AuthenticationException{
|
|
|
- String token = request.getHeader(tokenHeader);
|
|
|
- String refreshedToken = authService.refresh(token);
|
|
|
- if(refreshedToken == null) {
|
|
|
- return ResponseEntity.badRequest().body(null);
|
|
|
- } else {
|
|
|
- return ResponseEntity.ok(new JwtAuthenticationResponse(refreshedToken));
|
|
|
- }
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @RequestMapping(value = "/get/all/{page}/{size}",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
|
|
|
+ public String getallUsers(@PathVariable Integer page,@PathVariable Integer size ){
|
|
|
+ try{
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+ List<User> users= userService.getAll();
|
|
|
+
|
|
|
+ return returnResult(0, "获取成功", new PageInfo(users));
|
|
|
+ }catch(Exception e){
|
|
|
+ throw new BusinessException(20001);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|