|
@@ -1,12 +1,14 @@
|
|
-package com.gihon.security.controller;
|
|
|
|
|
|
+package com.gihon.user.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import com.gihon.common.http.HttpResult;
|
|
|
|
|
|
+import com.gihon.common.web.response.PageBean;
|
|
|
|
+import com.gihon.common.web.response.PageResponse;
|
|
|
|
+import com.gihon.common.web.response.Response;
|
|
|
|
+import com.gihon.common.web.response.ResponseStatus;
|
|
import com.gihon.security.encoder.MyPasswordEncoder;
|
|
import com.gihon.security.encoder.MyPasswordEncoder;
|
|
-import com.gihon.security.pojo.User;
|
|
|
|
-import com.gihon.security.service.UserService;
|
|
|
|
|
|
+import com.gihon.user.entity.User;
|
|
|
|
+import com.gihon.user.service.UserService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -29,14 +31,14 @@ public class UserController {
|
|
* @description 分页查看用户
|
|
* @description 分页查看用户
|
|
* @param page 页数
|
|
* @param page 页数
|
|
* @param rows 页小大
|
|
* @param rows 页小大
|
|
- * @return com.gihon.common.http.HttpResult
|
|
|
|
|
|
+ * @return com.gihon.common.http.Response
|
|
*/
|
|
*/
|
|
//@Secured(value = {"ROLE_管理员", "ROLE_超级管理员"})
|
|
//@Secured(value = {"ROLE_管理员", "ROLE_超级管理员"})
|
|
@GetMapping("/getUsersByPage")
|
|
@GetMapping("/getUsersByPage")
|
|
- public HttpResult<User> getUsersByPage(
|
|
|
|
- @RequestParam(name = "page", defaultValue = "0") int page,
|
|
|
|
- @RequestParam(name = "page", defaultValue = "10") int rows) {
|
|
|
|
- HttpResult<User> byPage = userService.findByPage(page, rows);
|
|
|
|
|
|
+ public PageResponse<PageBean<User>> getUsersByPage(
|
|
|
|
+ @RequestParam(required = false,defaultValue = "0") int page,
|
|
|
|
+ @RequestParam(required = false, defaultValue = "10") int rows) {
|
|
|
|
+ PageResponse byPage = userService.getByPage(page, rows);
|
|
return byPage;
|
|
return byPage;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -46,13 +48,26 @@ public class UserController {
|
|
* @description 根据用户主键
|
|
* @description 根据用户主键
|
|
* 查找用户信息
|
|
* 查找用户信息
|
|
* @param id
|
|
* @param id
|
|
- * @return com.gihon.common.http.HttpResult
|
|
|
|
|
|
+ * @return com.gihon.common.http.Response
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@GetMapping("/userByID")
|
|
@GetMapping("/userByID")
|
|
- public HttpResult userFindOne(@RequestParam Long id){
|
|
|
|
|
|
+ public Response userFindOne(@RequestParam Long id){
|
|
User userInfo = userService.getById(id);
|
|
User userInfo = userService.getById(id);
|
|
- return HttpResult.ok(userInfo);
|
|
|
|
|
|
+ return Response.ok(userInfo);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 主要功能:
|
|
|
|
+ * @description 根据用户id 查找对应权限
|
|
|
|
+ * @author: dl
|
|
|
|
+ * @data 2021/2/20 14:24
|
|
|
|
+ * @param id 用户id
|
|
|
|
+ * @return com.gihon.common.http.Response<java.util.List<java.lang.String>>
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/getPermissionsByUserId")
|
|
|
|
+ public Response<List<String>> getPermissionsByUserId(Long id){
|
|
|
|
+ List<String> permissions = userService.findPermissionsByUserId(id);
|
|
|
|
+ return Response.ok(permissions);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 主要功能:增加用户
|
|
* 主要功能:增加用户
|
|
@@ -63,15 +78,31 @@ public class UserController {
|
|
* 使用自定义加密器加密用户输入密码后 存储
|
|
* 使用自定义加密器加密用户输入密码后 存储
|
|
*
|
|
*
|
|
* @param user
|
|
* @param user
|
|
- * @return com.gihon.common.http.HttpResult
|
|
|
|
|
|
+ * @return com.gihon.common.http.Response
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
|
|
//@Secured(value = {"addUser"})
|
|
//@Secured(value = {"addUser"})
|
|
@PostMapping("/addUser")
|
|
@PostMapping("/addUser")
|
|
- public HttpResult<User> addUser(@RequestBody User user) {
|
|
|
|
- HttpResult<User> addUser = userService.addUser(user);
|
|
|
|
- return HttpResult.ok();
|
|
|
|
|
|
+ public Response<User> addUser(@RequestBody User user) {
|
|
|
|
+ Response<User> addUser = userService.addUser(user);
|
|
|
|
+ return Response.ok();
|
|
|
|
+ }
|
|
|
|
+ //增加用户角色
|
|
|
|
+ /**
|
|
|
|
+ * 主要功能:
|
|
|
|
+ * @description 用户ById 增加 角色ById
|
|
|
|
+ * @author: dl
|
|
|
|
+ * @data 2021/2/23 15:12
|
|
|
|
+ * @param user
|
|
|
|
+ * @param RoleIds
|
|
|
|
+ * @return com.gihon.common.web.response.Response
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/addRole4User")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public Response addRole4User(@RequestBody User user,@RequestParam("RoleIds") Long[] RoleIds){
|
|
|
|
+ Response response = userService.addRole4User(user,RoleIds);
|
|
|
|
+ return Response.ok();
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 主要功能:删除用户
|
|
* 主要功能:删除用户
|
|
@@ -80,22 +111,21 @@ public class UserController {
|
|
* @description 根据用户主键
|
|
* @description 根据用户主键
|
|
* 删除用户信息
|
|
* 删除用户信息
|
|
* @param id
|
|
* @param id
|
|
- * @return com.gihon.common.http.HttpResult
|
|
|
|
- *
|
|
|
|
|
|
+ * @return com.gihon.common.http.Response
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@GetMapping(value = "/deleteUser")
|
|
@GetMapping(value = "/deleteUser")
|
|
- public HttpResult deleteUser(@RequestParam Long id) {
|
|
|
|
|
|
+ public Response deleteUser(@RequestParam Long id) {
|
|
boolean b = userService.removeById(id);
|
|
boolean b = userService.removeById(id);
|
|
//添加数据失败
|
|
//添加数据失败
|
|
if (!b) {
|
|
if (!b) {
|
|
- return HttpResult.error("删除用户失败");
|
|
|
|
|
|
+ return Response.error(ResponseStatus.MAPPER_ERROR,"删除用户失败");
|
|
}
|
|
}
|
|
- return HttpResult.ok();
|
|
|
|
|
|
+ return Response.ok();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- @PreAuthorize("hasAuthority('updateUser')")
|
|
|
|
|
|
+ //@PreAuthorize("hasAuthority('updateUser')")
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@PostMapping(value = "/setUser")
|
|
@PostMapping(value = "/setUser")
|
|
/**
|
|
/**
|
|
@@ -106,10 +136,10 @@ public class UserController {
|
|
* 修改用户密码
|
|
* 修改用户密码
|
|
* @param username
|
|
* @param username
|
|
* @param password
|
|
* @param password
|
|
- * @return com.gihon.common.http.HttpResult<com.gihon.security.pojo.User>
|
|
|
|
|
|
+ * @return com.gihon.common.http.Response<com.gihon.user.entity.User>
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- public HttpResult<User> modifyUser(String username, String password) {
|
|
|
|
|
|
+ public Response<User> modifyUser(String username, String password) {
|
|
//修改新密码
|
|
//修改新密码
|
|
MyPasswordEncoder encoder = new MyPasswordEncoder();
|
|
MyPasswordEncoder encoder = new MyPasswordEncoder();
|
|
User user = User.builder().username(username).build();
|
|
User user = User.builder().username(username).build();
|
|
@@ -118,27 +148,11 @@ public class UserController {
|
|
boolean update = userService.update(user, new QueryWrapper<User>()
|
|
boolean update = userService.update(user, new QueryWrapper<User>()
|
|
.eq("username", user.getUsername())
|
|
.eq("username", user.getUsername())
|
|
);
|
|
);
|
|
- //userService.lambdaUpdate().eq(User::getId,1)
|
|
|
|
- // .set(User::getId,1)
|
|
|
|
- // .set(User::getUsername,"213")
|
|
|
|
- // .update();
|
|
|
|
//修改结果
|
|
//修改结果
|
|
if (!update) {
|
|
if (!update) {
|
|
- return HttpResult.error("修改密码访问数据库失败");
|
|
|
|
|
|
+ return Response.error(ResponseStatus.MAPPER_ERROR,"修改密码访问数据库失败");
|
|
}
|
|
}
|
|
- return HttpResult.ok();
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 主要功能:
|
|
|
|
- * @description 根据用户id 查找对应权限
|
|
|
|
- * @author: dl
|
|
|
|
- * @data 2021/2/20 14:24
|
|
|
|
- * @param id 用户id
|
|
|
|
- * @return com.gihon.common.http.HttpResult<java.util.List<java.lang.String>>
|
|
|
|
- */
|
|
|
|
- @RequestMapping("/getPermissionsByUserId")
|
|
|
|
- public HttpResult<List<String>> getPermissionsByUserId(Long id){
|
|
|
|
- List<String> permissions = userService.findPermissionsByUserId(id);
|
|
|
|
- return HttpResult.ok(permissions);
|
|
|
|
|
|
+ return Response.ok();
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|