feat:auth服务 用户鉴权相关
This commit is contained in:
@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
|
||||
@SpringBootApplication
|
||||
@@ -12,6 +13,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
||||
|
||||
})
|
||||
@EnableMethodSecurity(prePostEnabled = true)
|
||||
@EnableFeignClients(basePackages = {"com.xiang.xservice.auth.api.api"})
|
||||
public class AuthApplication {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AuthApplication.class);
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||
import com.xiang.xservice.auth.service.service.XDeptService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class DeptController {
|
||||
|
||||
private final XDeptService deptService;
|
||||
|
||||
@PostMapping("/private/dept/list")
|
||||
public Result<List<DeptDTO>> getDeptList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptQueryRequest request) {
|
||||
return Result.data(deptService.getDeptList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/private/dept/info/{id}")
|
||||
public Result<DeptDTO> getDeptInfo(@PathVariable Long id) {
|
||||
return Result.data(deptService.getDeptInfo(id));
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/add")
|
||||
public Result<Void> addDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptAddRequest request) {
|
||||
try {
|
||||
if (deptService.addDept(request)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("添加部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("添加部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/update")
|
||||
public Result<Void> updateDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptUpdateRequest request) {
|
||||
try {
|
||||
if (deptService.updateDept(request)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("更新部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("更新部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/del")
|
||||
public Result<Void> delDept(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
try {
|
||||
if (deptService.delDept(ids)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("删除部门异常, 请求:{}", JSON.toJSONString(ids), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("删除部门异常, 请求:{}", JSON.toJSONString(ids), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/setUser")
|
||||
public Result<Void> setUserDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptUserUpdateRequest request) {
|
||||
try {
|
||||
if (deptService.setUserDept(request)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("部门添加用户失败, 请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("部门添加用户失败, 请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.xiang.xservice.auth.api.dto.resp.RouterVo;
|
||||
import com.xiang.xservice.auth.service.service.XMenuService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2026-03-20 15:19
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class MenuController {
|
||||
|
||||
private final XMenuService menuService;
|
||||
|
||||
@GetMapping("/private/menu/getRouter")
|
||||
public Result<List<RouterVo>> getRouter(@RequestParam("userId") Long userId) {
|
||||
return Result.data(menuService.getRouter(userId));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -23,7 +22,7 @@ public class PermissionController implements PermissionApi {
|
||||
|
||||
private final XPermissionService permissionService;
|
||||
|
||||
@PostMapping("/private/permission/register")
|
||||
|
||||
public Result<Void> register(@RequestBody @NotEmpty(message = "请求参数不能为空") @Valid List<PermissionRegisterRequest> requests) {
|
||||
try {
|
||||
if (permissionService.registerAllApiPermissions(requests)) {
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RoleDTO;
|
||||
import com.xiang.xservice.auth.service.service.XRoleService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class RoleController {
|
||||
|
||||
private final XRoleService roleService;
|
||||
|
||||
@PostMapping("/private/role/list")
|
||||
public Result<List<RoleDTO>> getRoleList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleQueryRequest request) {
|
||||
return Result.data(roleService.getRoleList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/private/role/info/{id}")
|
||||
public Result<RoleDTO> getRoleInfo(@PathVariable Long id) {
|
||||
return Result.data(roleService.getRoleInfo(id));
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/add")
|
||||
public Result<Boolean> addRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleAddRequest request) {
|
||||
try {
|
||||
return Result.data(roleService.addRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/update")
|
||||
public Result<Boolean> updateRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(roleService.updateRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/del")
|
||||
public Result<Boolean> delRole(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
try {
|
||||
return Result.data(roleService.delRole(ids));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色删除异常,请求:{}", ids, e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色删除异常,请求:{}", ids, e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/setUser")
|
||||
public Result<Boolean> setUserRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleUserUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(roleService.setUserRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色用户关联异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色用户关联异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,9 @@ import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.LoginResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RouterVo;
|
||||
import com.xiang.xservice.auth.api.dto.resp.UserDTO;
|
||||
import com.xiang.xservice.auth.service.service.XMenuService;
|
||||
import com.xiang.xservice.auth.service.service.XUserService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@@ -29,6 +32,7 @@ import java.util.Objects;
|
||||
public class TokenController implements TokenApi {
|
||||
|
||||
private final XUserService userService;
|
||||
private final XMenuService menuService;
|
||||
|
||||
@PostMapping("/public/auth/login")
|
||||
public Result<LoginResp> login(@RequestBody @NotNull(message = "请求参数不能为空") @Valid LoginRequest request) {
|
||||
@@ -44,6 +48,11 @@ public class TokenController implements TokenApi {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/private/auth/getInfo")
|
||||
public Result<UserDTO> getUserInfo(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||
return Result.data(userService.getUserDetail(request.getUsername()));
|
||||
}
|
||||
|
||||
@PostMapping("/publish/auth/refresh")
|
||||
public Result<LoginResp> refresh(@RequestBody @NotNull(message = "请求参数不能为空") @Valid RefreshRequest request) {
|
||||
try {
|
||||
@@ -60,7 +69,6 @@ public class TokenController implements TokenApi {
|
||||
|
||||
@PostMapping("/public/user/userRegister")
|
||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
||||
|
||||
try {
|
||||
RegisterResp registerResp = userService.userRegister(request);
|
||||
if (Objects.nonNull(registerResp)) {
|
||||
@@ -95,8 +103,10 @@ public class TokenController implements TokenApi {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/private/auth/getInfo")
|
||||
public Result<UserDTO> getUserInfo(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||
return Result.data(userService.getUserDetail(request.getUsername()));
|
||||
|
||||
|
||||
@GetMapping("/private/menu/getRouter")
|
||||
public Result<List<RouterVo>> getRouter(@RequestParam("userId") Long userId) {
|
||||
return Result.data(menuService.getRouter(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,8 @@ package com.xiang.xservice.auth.server.controller;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserDeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserRoleUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserResetPwdRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateStatusRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.UserResp;
|
||||
@@ -85,60 +84,10 @@ public class UserController {
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/setDept")
|
||||
public Result<Boolean> setUserDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserDeptUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(userService.setUserDept(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户设置部门异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户设置部门异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/setRole")
|
||||
public Result<Boolean> setUserRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserRoleUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(userService.setUserRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户设置角色异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户设置角色异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
@PostMapping("/private/user/resetUserPwd")
|
||||
public Result<Boolean> resetPwd(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserResetPwdRequest request) {
|
||||
return Result.data(userService.resetPwd(request.getUserId(), request.getPassword()));
|
||||
}
|
||||
|
||||
|
||||
// @PostMapping("/public/user/useraddBatch")
|
||||
// public Result<Void> add() {
|
||||
// List<CompletableFuture> futures = Lists.newArrayList();
|
||||
// List<XUser> list = Lists.newCopyOnWriteArrayList();
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// int finalI = i;
|
||||
// log.info("第{}批数据生成!", finalI);
|
||||
// CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
// for (int j = 0; j < 1000; j++) {
|
||||
// log.info("第{}批的第{}条数据生成!", finalI, j);
|
||||
// XUser user = new XUser();
|
||||
// user.setName("nameTest2" + finalI + j);
|
||||
// user.setUsername("usernameTest2" + finalI + j);
|
||||
// user.setPassword(passwordEncoder.encode("123456"));
|
||||
// user.setEmail("emailTest2" + finalI + j + "@test.com");
|
||||
// user.setPhone("13800000000");
|
||||
// user.setStatus(UserStatusEnum.USING.getCode());
|
||||
// list.add(user);
|
||||
// }
|
||||
// });
|
||||
// futures.add(future);
|
||||
// }
|
||||
// CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||
// List<List<XUser>> partition = Lists.partition(list, 3000);
|
||||
// CompletableFuture.runAsync(() -> {
|
||||
// partition.stream().parallel().forEach(userMapper::insertBatch);
|
||||
// });
|
||||
// return Result.success();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user