Compare commits
5 Commits
4ea369b33d
...
feat/auth_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b8d33b50d | ||
|
|
8866d152d7 | ||
|
|
cb9ddf4681 | ||
|
|
6ebdec199b | ||
|
|
ace15206ec |
@@ -2,13 +2,17 @@ package com.xiang.xservice.auth.api.api;
|
|||||||
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.permission.PermissionRegisterRequest;
|
import com.xiang.xservice.auth.api.dto.req.permission.PermissionRegisterRequest;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@FeignClient(name = "xservice-auth-center", contextId = "PermissionApi", fallback = PermissionApiFallback.class)
|
||||||
public interface PermissionApi {
|
public interface PermissionApi {
|
||||||
|
|
||||||
|
@PostMapping("/private/permission/register")
|
||||||
Result<Void> register(@RequestBody @NotEmpty(message = "请求参数不能为空") @Valid List<PermissionRegisterRequest> requests);
|
Result<Void> register(@RequestBody @NotEmpty(message = "请求参数不能为空") @Valid List<PermissionRegisterRequest> requests);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.xiang.xservice.auth.api.api;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.permission.PermissionRegisterRequest;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class PermissionApiFallback implements PermissionApi {
|
||||||
|
@Override
|
||||||
|
public Result<Void> register(List<PermissionRegisterRequest> requests) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.api.api;
|
|
||||||
|
|
||||||
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
|
||||||
import com.xiang.xservice.auth.api.dto.resp.LoginResp;
|
|
||||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public interface TokenApi {
|
|
||||||
|
|
||||||
Result<LoginResp> login(@RequestBody @NotNull(message = "请求参数不能为空") @Valid LoginRequest request);
|
|
||||||
|
|
||||||
Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request);
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,8 @@ public enum Code01UserErrorCode implements BaseErrorCode {
|
|||||||
USER_EXISTS("A1000102", "用户已存在"),
|
USER_EXISTS("A1000102", "用户已存在"),
|
||||||
USER_LOGIN_ERROR("A1000103", "用户登录失败!"),
|
USER_LOGIN_ERROR("A1000103", "用户登录失败!"),
|
||||||
USER_REGISTER_ERROR("1000104", "用户注册失败!"),
|
USER_REGISTER_ERROR("1000104", "用户注册失败!"),
|
||||||
REFRESH_TOKEN_NOT_EXISTS("1000105", "refreshToken不匹配")
|
REFRESH_TOKEN_NOT_EXISTS("1000105", "refreshToken不匹配"),
|
||||||
|
TOKEN_NOT_VALID("1000106", "token校验失败"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.req.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserResetPwdRequest {
|
||||||
|
|
||||||
|
@NotNull(message = "userId不能为空")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@NotBlank(message = "密码不能为空")
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@@ -12,6 +13,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
|||||||
|
|
||||||
})
|
})
|
||||||
@EnableMethodSecurity(prePostEnabled = true)
|
@EnableMethodSecurity(prePostEnabled = true)
|
||||||
|
@EnableFeignClients(basePackages = {"com.xiang.xservice.auth.api.api"})
|
||||||
public class AuthApplication {
|
public class AuthApplication {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(AuthApplication.class);
|
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 com.xiang.xservice.basic.exception.BusinessException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ public class PermissionController implements PermissionApi {
|
|||||||
|
|
||||||
private final XPermissionService permissionService;
|
private final XPermissionService permissionService;
|
||||||
|
|
||||||
@PostMapping("/private/permission/register")
|
|
||||||
public Result<Void> register(@RequestBody @NotEmpty(message = "请求参数不能为空") @Valid List<PermissionRegisterRequest> requests) {
|
public Result<Void> register(@RequestBody @NotEmpty(message = "请求参数不能为空") @Valid List<PermissionRegisterRequest> requests) {
|
||||||
try {
|
try {
|
||||||
if (permissionService.registerAllApiPermissions(requests)) {
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
package com.xiang.xservice.auth.server.controller;
|
package com.xiang.xservice.auth.server.controller;
|
||||||
|
|
||||||
import com.xiang.xservice.auth.api.api.TokenApi;
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
||||||
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.LoginResp;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
|
||||||
import com.xiang.xservice.auth.api.dto.resp.UserDTO;
|
|
||||||
import com.xiang.xservice.auth.service.service.XUserService;
|
import com.xiang.xservice.auth.service.service.XUserService;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
@@ -19,12 +14,11 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TokenController implements TokenApi {
|
public class TokenController {
|
||||||
|
|
||||||
private final XUserService userService;
|
private final XUserService userService;
|
||||||
|
|
||||||
@@ -55,26 +49,4 @@ public class TokenController implements TokenApi {
|
|||||||
return Result.error();
|
return Result.error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/public/user/userRegister")
|
|
||||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
RegisterResp registerResp = userService.userRegister(request);
|
|
||||||
if (Objects.nonNull(registerResp)) {
|
|
||||||
return Result.data(registerResp);
|
|
||||||
}
|
|
||||||
} catch (BusinessException e) {
|
|
||||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return Result.error("操作失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/private/auth/getInfo")
|
|
||||||
public Result<UserDTO> getUserInfo(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
|
||||||
return Result.data(userService.getUserDetail(request.getUsername()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,144 +0,0 @@
|
|||||||
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.UserUpdateRequest;
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateStatusRequest;
|
|
||||||
import com.xiang.xservice.auth.api.dto.resp.UserResp;
|
|
||||||
import com.xiang.xservice.auth.service.service.XUserService;
|
|
||||||
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.RestController;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
private final XUserService userService;
|
|
||||||
|
|
||||||
@PostMapping("/private/user/list")
|
|
||||||
public Result<Page<UserResp>> getUserList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
|
||||||
return Result.data(userService.getUserList(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/private/user/info/{id}")
|
|
||||||
public Result<UserResp> getUserById(@PathVariable("id") Long id) {
|
|
||||||
return Result.data(userService.getUserInfo(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/private/user/add")
|
|
||||||
public Result<Boolean> addUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserAddRequest request) {
|
|
||||||
try {
|
|
||||||
return Result.data(userService.addUser(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/updateStatus")
|
|
||||||
public Result<Boolean> updateStatus(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateStatusRequest request) {
|
|
||||||
return Result.data(userService.updateStatus(request.getId(), request.getStatus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/private/user/update")
|
|
||||||
public Result<Boolean> updateUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateRequest request) {
|
|
||||||
try {
|
|
||||||
return Result.data(userService.updateUser(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/del")
|
|
||||||
public Result<Boolean> delUser(@RequestBody @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
|
||||||
try {
|
|
||||||
return Result.data(userService.delUser(ids));
|
|
||||||
} 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/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("/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();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -11,14 +11,26 @@ spring:
|
|||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
headless: true
|
headless: true
|
||||||
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
retry:
|
||||||
|
enabled: false
|
||||||
|
cache:
|
||||||
|
enabled: true
|
||||||
|
cache:
|
||||||
|
type: caffeine
|
||||||
|
caffeine:
|
||||||
|
spec: initialCapacity=100,maximumSize=1000,expireAfterWrite=30s
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
- classpath*:mapper/*/*.xml
|
- classpath*:mapper/*/*.xml
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
pagehelper:
|
|
||||||
helperDialect: mysql
|
feign:
|
||||||
reasonable: true
|
client:
|
||||||
support-methods-arguments: true
|
config:
|
||||||
params: count=countSql
|
default:
|
||||||
|
connectTimeout: 1000
|
||||||
|
readTimeout: 3000
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration debug="false">
|
|
||||||
|
|
||||||
<!-- 应用名称:和统一配置中的项目代码保持一致(小写) -->
|
|
||||||
<property name="APP_NAME" value="xservice-auth-center"/>
|
|
||||||
<contextName>${APP_NAME}</contextName>
|
|
||||||
|
|
||||||
<!--日志文件保留天数 -->
|
|
||||||
<property name="LOG_MAX_HISTORY" value="30"/>
|
|
||||||
<!--应用日志文件保存路径 -->
|
|
||||||
<!--在没有定义${LOG_HOME}系统变量的时候,可以设置此本地变量。提交测试、上线时,要将其注释掉,使用系统变量。 -->
|
|
||||||
<property name="LOG_HOME" value="logs/${APP_NAME}"/>
|
|
||||||
<!--<property name="LOG_HOME" msg="/home/logs/${APP_NAME}" />-->
|
|
||||||
|
|
||||||
<!--控制台输出appender-->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<!--设置输出格式-->
|
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
|
||||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
|
||||||
<pattern>%boldGreen(%contextName): %boldCyan(%d{yyyy-MM-dd HH:mm:ss:SSS}) %highlight([%c]) %boldMagenta([%t]) %boldCyan([%L]) %highlight([traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}]) %boldGreen([%p]) - %msg%n
|
|
||||||
</pattern>
|
|
||||||
<!--设置编码-->
|
|
||||||
<charset>UTF-8</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
|
||||||
<appender name="APP_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!--日志文件输出的文件名 -->
|
|
||||||
<FileNamePattern>${LOG_HOME}/debug-%d{yyyy-MM-dd}.log</FileNamePattern>
|
|
||||||
<!--日志文件保留天数 -->
|
|
||||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
|
||||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
|
||||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
|
||||||
<charset>UTF-8</charset>
|
|
||||||
</encoder>
|
|
||||||
<!-- 此日志文件只记录debug级别的 -->
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<level>debug</level>
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
|
||||||
<appender name="APP_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!--日志文件输出的文件名 -->
|
|
||||||
<FileNamePattern>${LOG_HOME}/info-%d{yyyy-MM-dd}.log</FileNamePattern>
|
|
||||||
<!--日志文件保留天数 -->
|
|
||||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
|
||||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
|
||||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
|
||||||
<charset>UTF-8</charset>
|
|
||||||
</encoder>
|
|
||||||
|
|
||||||
<!-- 此日志文件只记录info级别的 -->
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<level>info</level>
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
|
||||||
<appender name="APP_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!--日志文件输出的文件名 -->
|
|
||||||
<FileNamePattern>${LOG_HOME}/error-%d{yyyy-MM-dd}.log</FileNamePattern>
|
|
||||||
<!--日志文件保留天数 -->
|
|
||||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
|
||||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
|
||||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
|
||||||
<charset>UTF-8</charset>
|
|
||||||
</encoder>
|
|
||||||
<!-- 此日志文件只记录error级别的 -->
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<level>error</level>
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!--日志输出到文件-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="APP_DEBUG"/>
|
|
||||||
<appender-ref ref="APP_INFO"/>
|
|
||||||
<appender-ref ref="APP_ERROR"/>
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!-- mybatis 日志级别 -->
|
|
||||||
<logger name="com.xiang" level="debug"/>
|
|
||||||
|
|
||||||
</configuration>
|
|
||||||
@@ -1,15 +1,8 @@
|
|||||||
package com.xiang.xservice.auth.service.convert;
|
package com.xiang.xservice.auth.service.convert;
|
||||||
|
|
||||||
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.resp.DeptDTO;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XDept;
|
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: xiang
|
* @Author: xiang
|
||||||
* @Date: 2025-08-29 16:54
|
* @Date: 2025-08-29 16:54
|
||||||
@@ -17,11 +10,4 @@ import java.util.List;
|
|||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface XDeptConvert {
|
public interface XDeptConvert {
|
||||||
XDeptConvert INSTANCE = Mappers.getMapper(XDeptConvert.class);
|
XDeptConvert INSTANCE = Mappers.getMapper(XDeptConvert.class);
|
||||||
|
|
||||||
XDept toDO(DeptQueryRequest request);
|
|
||||||
XDept toDO(DeptAddRequest request);
|
|
||||||
XDept toDO(DeptUpdateRequest request);
|
|
||||||
|
|
||||||
DeptDTO toDTO(XDept dept);
|
|
||||||
List<DeptDTO> toDTOList(List<XDept> dept);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.service.entity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-29 16:42
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class XDept implements Serializable {
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 名称
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 父类id
|
|
||||||
*/
|
|
||||||
private Long parentId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 路径
|
|
||||||
*/
|
|
||||||
private String treePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排序
|
|
||||||
*/
|
|
||||||
private Integer sortNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createdTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人
|
|
||||||
*/
|
|
||||||
private String createBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime updatedTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改人
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除标识(0:未删除 1:已删除)
|
|
||||||
*/
|
|
||||||
private Integer delFlag;
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.xiang.xservice.auth.service.entity;
|
package com.xiang.xservice.auth.service.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@@ -14,12 +16,13 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@TableName("x_menu")
|
@TableName("sys_menu")
|
||||||
public class XMenuDO {
|
public class XMenuDO {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 菜单ID */
|
/** 菜单ID */
|
||||||
|
@TableId
|
||||||
private Long menuId;
|
private Long menuId;
|
||||||
|
|
||||||
/** 菜单名称 */
|
/** 菜单名称 */
|
||||||
|
|||||||
@@ -1,67 +1,87 @@
|
|||||||
package com.xiang.xservice.auth.service.entity;
|
package com.xiang.xservice.auth.service.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@TableName("sys_role")
|
||||||
public class XRole implements Serializable {
|
public class XRole implements Serializable {
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id
|
* 角色id
|
||||||
*/
|
*/
|
||||||
private Long id;
|
private Long roleId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 角色名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String roleName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编码
|
* 角色权限字符串
|
||||||
*/
|
*/
|
||||||
private String code;
|
private String roleKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态(0:禁用 1:启用)
|
* 显示顺序
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer roleSort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* data_scope
|
* 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||||
*/
|
*/
|
||||||
private Integer dataScope;
|
private String dataScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 菜单树选择项是否关联显示
|
||||||
*/
|
*/
|
||||||
private LocalDateTime createdTime;
|
private Integer menuCheckStrictly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人
|
* 部门树选择项是否关联显示
|
||||||
|
*/
|
||||||
|
private Integer deptCheckStrictly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色状态(0正常 1停用)
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
*/
|
*/
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
private LocalDateTime updatedTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改人
|
* 更新者
|
||||||
*/
|
*/
|
||||||
private String updateBy;
|
private String updateBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除标识(0:未删除 1:已删除)
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
private Integer delFlag;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.service.entity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-29 16:44
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class XUserDept {
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
private Long deptId;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.service.entity;
|
package com.xiang.xservice.auth.service.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -7,6 +8,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@TableName("sys_user_role")
|
||||||
public class XUserRole {
|
public class XUserRole {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
package com.xiang.xservice.auth.service.repository.mapper;
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
import com.xiang.xservice.auth.service.entity.XDept;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: xiang
|
* @Author: xiang
|
||||||
* @Date: 2025-08-29 16:40
|
* @Date: 2025-08-29 16:40
|
||||||
@@ -15,14 +10,4 @@ import java.util.List;
|
|||||||
@Mapper
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
public interface XDeptMapper {
|
public interface XDeptMapper {
|
||||||
|
|
||||||
int insert(XDept record);
|
|
||||||
int update(XDept record);
|
|
||||||
int delBatch(@Param("ids") List<Long> ids, @Param("time") LocalDateTime time, @Param("operator") String operator);
|
|
||||||
List<XDept> getDeptList(XDept record);
|
|
||||||
XDept getDeptById(Long id);
|
|
||||||
List<XDept> getDeptByIds(@Param("ids") List<Long> ids);
|
|
||||||
List<XDept> getDeptByparentId(@Param("parentId") Long parentId);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package com.xiang.xservice.auth.service.repository.mapper;
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
import com.xiang.xservice.auth.service.entity.XUserDept;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: xiang
|
* @Author: xiang
|
||||||
* @Date: 2025-08-29 17:04
|
* @Date: 2025-08-29 17:04
|
||||||
@@ -14,9 +10,5 @@ import java.util.List;
|
|||||||
@Mapper
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
public interface XUserDeptMapper {
|
public interface XUserDeptMapper {
|
||||||
int addBatch(List<XUserDept> list);
|
|
||||||
|
|
||||||
int delByDeptId(Long deptId);
|
|
||||||
|
|
||||||
XUserDept getByUserId(@Param("id") Long userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,6 @@ public interface XUserMapper extends BaseMapper<XUser> {
|
|||||||
*/
|
*/
|
||||||
XUser selectByUsername(String username);
|
XUser selectByUsername(String username);
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量插入
|
|
||||||
* @param list
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int insertBatch(List<XUser> list);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户列表
|
* 查询用户列表
|
||||||
* @param user
|
* @param user
|
||||||
@@ -42,12 +35,6 @@ public interface XUserMapper extends BaseMapper<XUser> {
|
|||||||
*/
|
*/
|
||||||
XUser getUserById(Long id);
|
XUser getUserById(Long id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑用户
|
|
||||||
* @param user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int update(XUser user);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除
|
* 批量删除
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class CustomUserDetailsService implements UserDetailsService {
|
|||||||
List<SimpleGrantedAuthority> grantedAuthorities = Lists.newArrayList();
|
List<SimpleGrantedAuthority> grantedAuthorities = Lists.newArrayList();
|
||||||
if (CollectionUtils.isNotEmpty(roleIds)) {
|
if (CollectionUtils.isNotEmpty(roleIds)) {
|
||||||
List<XRole> roles = roleMapper.getRoleByIds(roleIds);
|
List<XRole> roles = roleMapper.getRoleByIds(roleIds);
|
||||||
grantedAuthorities.addAll(roles.stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role.getCode())).toList());
|
grantedAuthorities.addAll(roles.stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleKey())).toList());
|
||||||
}
|
}
|
||||||
return org.springframework.security.core.userdetails.User
|
return org.springframework.security.core.userdetails.User
|
||||||
.withUsername(user.getUsername())
|
.withUsername(user.getUsername())
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.service.service;
|
|
||||||
|
|
||||||
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 java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-29 16:36
|
|
||||||
*/
|
|
||||||
public interface XDeptService {
|
|
||||||
List<DeptDTO> getDeptList(DeptQueryRequest request);
|
|
||||||
|
|
||||||
DeptDTO getDeptInfo(Long id);
|
|
||||||
|
|
||||||
Boolean addDept(DeptAddRequest request);
|
|
||||||
|
|
||||||
Boolean updateDept(DeptUpdateRequest request);
|
|
||||||
|
|
||||||
Boolean delDept(List<Long> ids);
|
|
||||||
|
|
||||||
Boolean setUserDept(DeptUserUpdateRequest request);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.service.service;
|
|
||||||
|
|
||||||
|
|
||||||
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 java.util.List;
|
|
||||||
|
|
||||||
public interface XRoleService {
|
|
||||||
List<RoleDTO> getRoleList(RoleQueryRequest request);
|
|
||||||
|
|
||||||
RoleDTO getRoleInfo(Long id);
|
|
||||||
|
|
||||||
Boolean addRole(RoleAddRequest request);
|
|
||||||
|
|
||||||
Boolean updateRole(RoleUpdateRequest request);
|
|
||||||
|
|
||||||
Boolean delRole(List<Long> ids);
|
|
||||||
|
|
||||||
Boolean setUserRole(RoleUserUpdateRequest request);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,9 +5,7 @@ import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
|||||||
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserAddRequest;
|
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.UserQueryRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserRoleUpdateRequest;
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.LoginResp;
|
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.RegisterResp;
|
||||||
@@ -19,28 +17,16 @@ import java.util.List;
|
|||||||
public interface XUserService {
|
public interface XUserService {
|
||||||
|
|
||||||
LoginResp login(LoginRequest request);
|
LoginResp login(LoginRequest request);
|
||||||
|
|
||||||
UserResp getUserByUsername(String username);
|
|
||||||
|
|
||||||
RegisterResp userRegister(RegisterRequest request);
|
RegisterResp userRegister(RegisterRequest request);
|
||||||
|
|
||||||
Page<UserResp> getUserList(UserQueryRequest request);
|
Page<UserResp> getUserList(UserQueryRequest request);
|
||||||
|
|
||||||
UserResp getUserInfo(Long id);
|
UserResp getUserInfo(Long id);
|
||||||
|
|
||||||
Boolean addUser(UserAddRequest request);
|
Boolean addUser(UserAddRequest request);
|
||||||
|
|
||||||
Boolean updateUser(UserUpdateRequest request);
|
Boolean updateUser(UserUpdateRequest request);
|
||||||
|
|
||||||
Boolean delUser(List<Long> ids);
|
Boolean delUser(List<Long> ids);
|
||||||
|
|
||||||
Boolean setUserDept(UserDeptUpdateRequest request);
|
|
||||||
|
|
||||||
Boolean setUserRole(UserRoleUpdateRequest request);
|
|
||||||
|
|
||||||
UserDTO getUserDetail(String username);
|
UserDTO getUserDetail(String username);
|
||||||
|
|
||||||
LoginResp refresh(RefreshRequest request);
|
LoginResp refresh(RefreshRequest request);
|
||||||
|
|
||||||
Boolean updateStatus(Long id, Integer status);
|
Boolean updateStatus(Long id, Integer status);
|
||||||
|
Long getUserId(String token);
|
||||||
|
Long getTenantId(String token);
|
||||||
|
Boolean resetPwd(Long userId, String password);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.service.service.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.xiang.xservice.auth.api.code.Code03DeptErrorCode;
|
|
||||||
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.convert.XDeptConvert;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XDept;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XUserDept;
|
|
||||||
import com.xiang.xservice.auth.service.repository.mapper.XDeptMapper;
|
|
||||||
import com.xiang.xservice.auth.service.repository.mapper.XUserDeptMapper;
|
|
||||||
import com.xiang.xservice.auth.service.service.XDeptService;
|
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-29 16:39
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class XDeptServiceImpl implements XDeptService {
|
|
||||||
|
|
||||||
private final static int BATCH_SIZE = 500;
|
|
||||||
private final XDeptMapper deptMapper;
|
|
||||||
private final XDeptConvert deptConvert;
|
|
||||||
private final XUserDeptMapper userDeptMapper;
|
|
||||||
@Override
|
|
||||||
public List<DeptDTO> getDeptList(DeptQueryRequest request) {
|
|
||||||
return deptConvert.toDTOList(deptMapper.getDeptList(deptConvert.toDO(request)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DeptDTO getDeptInfo(Long id) {
|
|
||||||
return deptConvert.toDTO(deptMapper.getDeptById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean addDept(DeptAddRequest request) {
|
|
||||||
XDept dept = deptConvert.toDO(request);
|
|
||||||
return deptMapper.insert(dept) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateDept(DeptUpdateRequest request) {
|
|
||||||
XDept dept = deptConvert.toDO(request);
|
|
||||||
dept.setCreateBy(request.getOperator());
|
|
||||||
dept.setUpdateBy(request.getOperator());
|
|
||||||
return deptMapper.update(dept) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean delDept(List<Long> ids) {
|
|
||||||
return deptMapper.delBatch(ids, LocalDateTime.now(), "admin") > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public Boolean setUserDept(DeptUserUpdateRequest request) {
|
|
||||||
XDept dept = deptMapper.getDeptById(request.getDeptId());
|
|
||||||
if (Objects.isNull(dept)) {
|
|
||||||
log.error("查询部门信息不存在!部门id:{}", request.getDeptId());
|
|
||||||
throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
List<XUserDept> result = Lists.newArrayList();
|
|
||||||
for (Long userId : request.getUserIds()) {
|
|
||||||
XUserDept userDept = new XUserDept();
|
|
||||||
userDept.setDeptId(request.getDeptId());
|
|
||||||
userDept.setUserId(userId);
|
|
||||||
result.add(userDept);
|
|
||||||
}
|
|
||||||
boolean flag = true;
|
|
||||||
if (userDeptMapper.delByDeptId(request.getDeptId()) <= 0) {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(result)) {
|
|
||||||
if (result.size() > BATCH_SIZE) {
|
|
||||||
List<List<XUserDept>> partition = Lists.partition(result, BATCH_SIZE);
|
|
||||||
for (List<XUserDept> list : partition) {
|
|
||||||
if (userDeptMapper.addBatch(list) <= 0) {
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return userDeptMapper.addBatch(result) > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.service.service.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.xiang.xservice.auth.api.code.Code02RoleErrorCode;
|
|
||||||
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.convert.XRoleConvert;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XRole;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XUserRole;
|
|
||||||
import com.xiang.xservice.auth.service.repository.mapper.XRoleMapper;
|
|
||||||
import com.xiang.xservice.auth.service.repository.mapper.XUserRoleMapper;
|
|
||||||
import com.xiang.xservice.auth.service.service.XRoleService;
|
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class XRoleServiceImpl implements XRoleService {
|
|
||||||
private final static int BATCH_SIZE = 500;
|
|
||||||
private final XRoleMapper roleMapper;
|
|
||||||
private final XUserRoleMapper userRoleMapper;
|
|
||||||
private final XRoleConvert roleConvert;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RoleDTO> getRoleList(RoleQueryRequest request) {
|
|
||||||
List<XRole> roleList = roleMapper.getRoleList(roleConvert.toDO(request));
|
|
||||||
if (CollectionUtils.isEmpty(roleList)) {
|
|
||||||
return Lists.newArrayList();
|
|
||||||
}
|
|
||||||
return roleConvert.toDTOList(roleList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RoleDTO getRoleInfo(Long id) {
|
|
||||||
XRole role = roleMapper.getRoleById(id);
|
|
||||||
return roleConvert.toDTO(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean addRole(RoleAddRequest request) {
|
|
||||||
XRole role = roleConvert.toDO(request);
|
|
||||||
role.setCreateBy(request.getOperator());
|
|
||||||
role.setUpdateBy(request.getOperator());
|
|
||||||
return roleMapper.insert(role) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateRole(RoleUpdateRequest request) {
|
|
||||||
XRole role = roleConvert.toDO(request);
|
|
||||||
role.setCreateBy(request.getOperator());
|
|
||||||
role.setUpdateBy(request.getOperator());
|
|
||||||
return roleMapper.update(role) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean delRole(List<Long> ids) {
|
|
||||||
return roleMapper.delBatch(ids, LocalDateTime.now(), "System") > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public Boolean setUserRole(RoleUserUpdateRequest request) {
|
|
||||||
XRole role = roleMapper.getRoleById(request.getRoleId());
|
|
||||||
if (Objects.isNull(role)) {
|
|
||||||
log.error("查询角色信息不存在!角色id:{}", request.getRoleId());
|
|
||||||
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
List<XUserRole> params = Lists.newArrayList();
|
|
||||||
for (Long userId : request.getUserIds()) {
|
|
||||||
XUserRole xUserRole = new XUserRole();
|
|
||||||
xUserRole.setRoleId(request.getRoleId());
|
|
||||||
xUserRole.setUserId(userId);
|
|
||||||
params.add(xUserRole);
|
|
||||||
}
|
|
||||||
boolean flag = Boolean.TRUE;
|
|
||||||
if (userRoleMapper.delByRoleIds(Collections.singletonList(request.getRoleId())) <= 0) {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(params)) {
|
|
||||||
if (params.size() > BATCH_SIZE) {
|
|
||||||
List<List<XUserRole>> partition = Lists.partition(params, BATCH_SIZE);
|
|
||||||
for (List<XUserRole> list : partition) {
|
|
||||||
if (userRoleMapper.addBatch(list) <= 0) {
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return userRoleMapper.addBatch(params) > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,14 +8,11 @@ import com.google.common.collect.Sets;
|
|||||||
import com.xiang.xmc.service.cache.service.IRedisService;
|
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||||
import com.xiang.xservice.auth.api.code.Code01UserErrorCode;
|
import com.xiang.xservice.auth.api.code.Code01UserErrorCode;
|
||||||
import com.xiang.xservice.auth.api.code.Code02RoleErrorCode;
|
import com.xiang.xservice.auth.api.code.Code02RoleErrorCode;
|
||||||
import com.xiang.xservice.auth.api.code.Code03DeptErrorCode;
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserAddRequest;
|
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.UserQueryRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserRoleUpdateRequest;
|
|
||||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.LoginResp;
|
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.RegisterResp;
|
||||||
@@ -26,12 +23,10 @@ import com.xiang.xservice.auth.service.convert.XDeptConvert;
|
|||||||
import com.xiang.xservice.auth.service.convert.XPermissionConvert;
|
import com.xiang.xservice.auth.service.convert.XPermissionConvert;
|
||||||
import com.xiang.xservice.auth.service.convert.XRoleConvert;
|
import com.xiang.xservice.auth.service.convert.XRoleConvert;
|
||||||
import com.xiang.xservice.auth.service.convert.XUserConvert;
|
import com.xiang.xservice.auth.service.convert.XUserConvert;
|
||||||
import com.xiang.xservice.auth.service.entity.XDept;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XPermission;
|
import com.xiang.xservice.auth.service.entity.XPermission;
|
||||||
import com.xiang.xservice.auth.service.entity.XRole;
|
import com.xiang.xservice.auth.service.entity.XRole;
|
||||||
import com.xiang.xservice.auth.service.entity.XRolePermission;
|
import com.xiang.xservice.auth.service.entity.XRolePermission;
|
||||||
import com.xiang.xservice.auth.service.entity.XUser;
|
import com.xiang.xservice.auth.service.entity.XUser;
|
||||||
import com.xiang.xservice.auth.service.entity.XUserDept;
|
|
||||||
import com.xiang.xservice.auth.service.entity.XUserRole;
|
import com.xiang.xservice.auth.service.entity.XUserRole;
|
||||||
import com.xiang.xservice.auth.service.enums.UserStatusEnum;
|
import com.xiang.xservice.auth.service.enums.UserStatusEnum;
|
||||||
import com.xiang.xservice.auth.service.repository.mapper.XDeptMapper;
|
import com.xiang.xservice.auth.service.repository.mapper.XDeptMapper;
|
||||||
@@ -63,7 +58,6 @@ import org.springframework.security.oauth2.jwt.JwtDecoder;
|
|||||||
import org.springframework.security.oauth2.jwt.JwtEncoder;
|
import org.springframework.security.oauth2.jwt.JwtEncoder;
|
||||||
import org.springframework.security.oauth2.jwt.JwtEncoderParameters;
|
import org.springframework.security.oauth2.jwt.JwtEncoderParameters;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -118,7 +112,7 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
if (CollectionUtils.isEmpty(roles)) {
|
if (CollectionUtils.isEmpty(roles)) {
|
||||||
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
roleCodes.addAll(roles.stream().map(XRole::getCode).toList());
|
roleCodes.addAll(roles.stream().map(XRole::getRoleKey).toList());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(user.getToken())) {
|
if (StringUtils.isNotBlank(user.getToken())) {
|
||||||
try {
|
try {
|
||||||
@@ -171,30 +165,10 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
// 4. db 存储token
|
// 4. db 存储token
|
||||||
user.setToken(token);
|
user.setToken(token);
|
||||||
user.setRefreshToken(refreshToken);
|
user.setRefreshToken(refreshToken);
|
||||||
userMapper.update(user);
|
userMapper.updateById(user);
|
||||||
return loginResp;
|
return loginResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserResp getUserByUsername(String username) {
|
|
||||||
XUser user = userMapper.selectByUsername(username);
|
|
||||||
if (Objects.isNull(user)) {
|
|
||||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserResp userResp = new UserResp();
|
|
||||||
userResp.setName(user.getName());
|
|
||||||
userResp.setUsername(user.getUsername());
|
|
||||||
userResp.setEmail(user.getEmail());
|
|
||||||
userResp.setPhone(user.getPhone());
|
|
||||||
userResp.setAvatar(user.getAvatar());
|
|
||||||
userResp.setLoginIp(user.getLoginIp());
|
|
||||||
userResp.setLoginDate(user.getLoginDate());
|
|
||||||
userResp.setStatus(user.getStatus());
|
|
||||||
userResp.setUpdateTime(user.getUpdateTime());
|
|
||||||
return userResp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RegisterResp userRegister(RegisterRequest request) {
|
public RegisterResp userRegister(RegisterRequest request) {
|
||||||
// todo 手机号验证码校验
|
// todo 手机号验证码校验
|
||||||
@@ -283,7 +257,7 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
user.setCreateTime(request.getDateTime());
|
user.setCreateTime(request.getDateTime());
|
||||||
user.setUpdateBy(request.getOperator());
|
user.setUpdateBy(request.getOperator());
|
||||||
user.setUpdateTime(request.getDateTime());
|
user.setUpdateTime(request.getDateTime());
|
||||||
return userMapper.update(user) > 0;
|
return userMapper.updateById(user) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -291,33 +265,6 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
return userMapper.deleteBatch(ids, LocalDateTime.now(), "System") > 0;
|
return userMapper.deleteBatch(ids, LocalDateTime.now(), "System") > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public Boolean setUserDept(UserDeptUpdateRequest request) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean setUserRole(UserRoleUpdateRequest request) {
|
|
||||||
XUser user = userMapper.getUserById(request.getUserId());
|
|
||||||
if (Objects.isNull(user)) {
|
|
||||||
log.error("查询用户信息不存在!用户id:{}", request.getUserId());
|
|
||||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
List<XUserRole> params = Lists.newArrayList();
|
|
||||||
for (Long roleId : request.getRoleIds()) {
|
|
||||||
XUserRole userRole = new XUserRole();
|
|
||||||
userRole.setRoleId(roleId);
|
|
||||||
userRole.setUserId(request.getUserId());
|
|
||||||
params.add(userRole);
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(params)) {
|
|
||||||
return userRoleMapper.insertUserRole(params) > 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDTO getUserDetail(String username) {
|
public UserDTO getUserDetail(String username) {
|
||||||
UserDTO dto = new UserDTO();
|
UserDTO dto = new UserDTO();
|
||||||
@@ -333,15 +280,15 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
dto.setRoles(roleConvert.toDTOList(roles));
|
dto.setRoles(roleConvert.toDTOList(roles));
|
||||||
XUserDept userDept = userDeptMapper.getByUserId(user.getId());
|
// XUserDept userDept = userDeptMapper.getByUserId(user.getId());
|
||||||
if (Objects.nonNull(userDept)) {
|
// if (Objects.nonNull(userDept)) {
|
||||||
Long deptId = userDept.getDeptId();
|
// Long deptId = userDept.getDeptId();
|
||||||
XDept dept = deptMapper.getDeptById(deptId);
|
// XDept dept = deptMapper.getDeptById(deptId);
|
||||||
if (Objects.isNull(dept)) {
|
// if (Objects.isNull(dept)) {
|
||||||
throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
// throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
||||||
}
|
// }
|
||||||
dto.setDept(deptConvert.toDTO(dept));
|
// dto.setDept(deptConvert.toDTO(dept));
|
||||||
}
|
// }
|
||||||
List<XRolePermission> permissionsByRoleIds = rolePermissionMapper.getRolePermissionsByRoleIds(roleIds);
|
List<XRolePermission> permissionsByRoleIds = rolePermissionMapper.getRolePermissionsByRoleIds(roleIds);
|
||||||
if (CollectionUtils.isNotEmpty(permissionsByRoleIds)) {
|
if (CollectionUtils.isNotEmpty(permissionsByRoleIds)) {
|
||||||
List<Long> permissionIds = permissionsByRoleIds.stream().map(XRolePermission::getPermissionId).toList();
|
List<Long> permissionIds = permissionsByRoleIds.stream().map(XRolePermission::getPermissionId).toList();
|
||||||
@@ -378,7 +325,7 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
if (CollectionUtils.isNotEmpty(userRoles)) {
|
if (CollectionUtils.isNotEmpty(userRoles)) {
|
||||||
List<XRole> roles = roleMapper.getRoleByIds(userRoles.stream().map(XUserRole::getRoleId).collect(Collectors.toList()));
|
List<XRole> roles = roleMapper.getRoleByIds(userRoles.stream().map(XUserRole::getRoleId).collect(Collectors.toList()));
|
||||||
if (CollectionUtils.isNotEmpty(roles)) {
|
if (CollectionUtils.isNotEmpty(roles)) {
|
||||||
roleCodes.addAll(roles.stream().map(XRole::getCode).toList());
|
roleCodes.addAll(roles.stream().map(XRole::getRoleKey).toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 生成新的 accessToken
|
// 生成新的 accessToken
|
||||||
@@ -396,7 +343,7 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
// 更新 Redis 和 DB
|
// 更新 Redis 和 DB
|
||||||
redisService.set(RedisConstant.LOGIN_TOKEN + request.getUsername(), newToken, 3, TimeUnit.HOURS);
|
redisService.set(RedisConstant.LOGIN_TOKEN + request.getUsername(), newToken, 3, TimeUnit.HOURS);
|
||||||
user.setToken(newToken);
|
user.setToken(newToken);
|
||||||
userMapper.update(user);
|
userMapper.updateById(user);
|
||||||
LoginResp loginResp = new LoginResp();
|
LoginResp loginResp = new LoginResp();
|
||||||
loginResp.setToken(newToken);
|
loginResp.setToken(newToken);
|
||||||
loginResp.setUsername(request.getUsername());
|
loginResp.setUsername(request.getUsername());
|
||||||
@@ -411,6 +358,39 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
user.setStatus(status);
|
user.setStatus(status);
|
||||||
return userMapper.update(user) > 0;
|
return userMapper.updateById(user) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getUserId(String token) {
|
||||||
|
try {
|
||||||
|
Jwt jwt = jwtDecoder.decode(token);
|
||||||
|
Object userId = jwt.getClaim("userId");
|
||||||
|
return (long) userId;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.TOKEN_NOT_VALID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getTenantId(String token) {
|
||||||
|
try {
|
||||||
|
Jwt jwt = jwtDecoder.decode(token);
|
||||||
|
Object userId = jwt.getClaim("tenantId");
|
||||||
|
return (long) userId;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.TOKEN_NOT_VALID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean resetPwd(Long userId, String password) {
|
||||||
|
XUser user = userMapper.getUserById(userId);
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
String encodePwd = passwordEncoder.encode(password);
|
||||||
|
user.setPassword(encodePwd);
|
||||||
|
return userMapper.updateById(user) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,144 +3,4 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XDeptMapper">
|
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XDeptMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XDept" >
|
|
||||||
<result column="name" property="name" />
|
|
||||||
<result column="parent_id" property="parentId" />
|
|
||||||
<result column="tree_path" property="treePath" />
|
|
||||||
<result column="sort_no" property="sortNo" />
|
|
||||||
<result column="created_time" property="createdTime" />
|
|
||||||
<result column="create_by" property="createBy" />
|
|
||||||
<result column="updated_time" property="updatedTime" />
|
|
||||||
<result column="update_by" property="updateBy" />
|
|
||||||
<result column="del_flag" property="delFlag" />
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
|
||||||
name,
|
|
||||||
parent_id,
|
|
||||||
tree_path,
|
|
||||||
sort_no,
|
|
||||||
created_time,
|
|
||||||
create_by,
|
|
||||||
updated_time,
|
|
||||||
update_by,
|
|
||||||
del_flag
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XUserDept">
|
|
||||||
INSERT INTO x_dept
|
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
||||||
<if test="null != name and '' != name">
|
|
||||||
name,
|
|
||||||
</if>
|
|
||||||
<if test="null != parentId ">
|
|
||||||
parent_id,
|
|
||||||
</if>
|
|
||||||
<if test="null != treePath and '' != treePath">
|
|
||||||
tree_path,
|
|
||||||
</if>
|
|
||||||
<if test="null != sortNo ">
|
|
||||||
sort_no,
|
|
||||||
</if>
|
|
||||||
<if test="null != createdTime ">
|
|
||||||
created_time,
|
|
||||||
</if>
|
|
||||||
<if test="null != createBy and '' != createBy">
|
|
||||||
create_by,
|
|
||||||
</if>
|
|
||||||
<if test="null != updatedTime ">
|
|
||||||
updated_time,
|
|
||||||
</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">
|
|
||||||
update_by,
|
|
||||||
</if>
|
|
||||||
<if test="null != delFlag ">
|
|
||||||
del_flag
|
|
||||||
</if>
|
|
||||||
</trim>
|
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
||||||
<if test="null != name and '' != name">
|
|
||||||
#{name},
|
|
||||||
</if>
|
|
||||||
<if test="null != parentId ">
|
|
||||||
#{parentId},
|
|
||||||
</if>
|
|
||||||
<if test="null != treePath and '' != treePath">
|
|
||||||
#{treePath},
|
|
||||||
</if>
|
|
||||||
<if test="null != sortNo ">
|
|
||||||
#{sortNo},
|
|
||||||
</if>
|
|
||||||
<if test="null != createdTime ">
|
|
||||||
#{createdTime},
|
|
||||||
</if>
|
|
||||||
<if test="null != createBy and '' != createBy">
|
|
||||||
#{createBy},
|
|
||||||
</if>
|
|
||||||
<if test="null != updatedTime ">
|
|
||||||
#{updatedTime},
|
|
||||||
</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">
|
|
||||||
#{updateBy},
|
|
||||||
</if>
|
|
||||||
<if test="null != delFlag ">
|
|
||||||
#{delFlag}
|
|
||||||
</if>
|
|
||||||
</trim>
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="delBatch" >
|
|
||||||
update x_dept
|
|
||||||
SET del_flag = 1, updated_time = now(), update_by = #{updateBy}
|
|
||||||
WHERE id IN
|
|
||||||
<foreach item="item" collection="ids" separator="," open="(" close=")">
|
|
||||||
#{item}
|
|
||||||
</foreach>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XUserDept">
|
|
||||||
UPDATE x_dept
|
|
||||||
<set>
|
|
||||||
<if test="null != name and '' != name">name = #{name},</if>
|
|
||||||
<if test="null != parentId ">parent_id = #{parentId},</if>
|
|
||||||
<if test="null != treePath and '' != treePath">tree_path = #{treePath},</if>
|
|
||||||
<if test="null != sortNo ">sort_no = #{sortNo},</if>
|
|
||||||
<if test="null != createdTime ">created_time = #{createdTime},</if>
|
|
||||||
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
|
|
||||||
<if test="null != updatedTime ">updated_time = #{updatedTime},</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
|
|
||||||
<if test="null != delFlag ">del_flag = #{delFlag}</if>
|
|
||||||
</set>
|
|
||||||
WHERE id = #{id}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<select id="getDeptList" resultMap="BaseResultMap">
|
|
||||||
select <include refid="Base_Column_List"/>
|
|
||||||
from x_dept
|
|
||||||
<trim prefix="AND">
|
|
||||||
<where>
|
|
||||||
del_flag = 0
|
|
||||||
<if test="name != null and name != ''">AND name = #{name}</if>
|
|
||||||
</where>
|
|
||||||
</trim>
|
|
||||||
</select>
|
|
||||||
<select id="getDeptById" resultMap="BaseResultMap">
|
|
||||||
select <include refid="Base_Column_List"/>
|
|
||||||
from x_dept
|
|
||||||
where id = #{id}
|
|
||||||
</select>
|
|
||||||
<select id="getDeptByIds" resultMap="BaseResultMap">
|
|
||||||
select <include refid="Base_Column_List"/>
|
|
||||||
from x_dept
|
|
||||||
where id in
|
|
||||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
|
||||||
#{id}
|
|
||||||
</foreach>
|
|
||||||
</select>
|
|
||||||
<select id="getDeptByparentId" resultMap="BaseResultMap">
|
|
||||||
select <include refid="Base_Column_List"/>
|
|
||||||
from x_dept
|
|
||||||
where parent_id = #{parentId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
<resultMap type="com.xiang.xservice.auth.service.entity.XMenuDO" id="SysMenuResult">
|
<resultMap type="com.xiang.xservice.auth.service.entity.XMenuDO" id="SysMenuResult">
|
||||||
<id property="menuId" column="menu_id" />
|
<id property="menuId" column="menu_id" />
|
||||||
<result property="menuName" column="menu_name" />
|
<result property="menuName" column="menu_name" />
|
||||||
<result property="parentName" column="parent_name" />
|
|
||||||
<result property="parentId" column="parent_id" />
|
<result property="parentId" column="parent_id" />
|
||||||
<result property="orderNum" column="order_num" />
|
<result property="orderNum" column="order_num" />
|
||||||
<result property="path" column="path" />
|
<result property="path" column="path" />
|
||||||
@@ -22,12 +21,6 @@
|
|||||||
<result property="perms" column="perms" />
|
<result property="perms" column="perms" />
|
||||||
<result property="icon" column="icon" />
|
<result property="icon" column="icon" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectMenuVo">
|
|
||||||
select menu_id, menu_name, parent_id, order_num, path, component, `query`, route_name, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time
|
|
||||||
from x_menu
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
|
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
|
||||||
select distinct m.menu_id,
|
select distinct m.menu_id,
|
||||||
m.parent_id,
|
m.parent_id,
|
||||||
@@ -45,10 +38,10 @@
|
|||||||
m.icon,
|
m.icon,
|
||||||
m.order_num,
|
m.order_num,
|
||||||
m.create_time
|
m.create_time
|
||||||
from x_menu m
|
from sys_menu m
|
||||||
left join x_role_menu rm on m.menu_id = rm.menu_id
|
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||||
left join x_user_role ur on rm.role_id = ur.role_id
|
left join x_user_role ur on rm.role_id = ur.role_id
|
||||||
left join x_role ro on ur.role_id = ro.id
|
left join sys_role ro on ur.role_id = ro.id
|
||||||
left join x_user u on ur.user_id = u.id
|
left join x_user u on ur.user_id = u.id
|
||||||
where u.id = #{userId}
|
where u.id = #{userId}
|
||||||
and m.menu_type in ('M', 'C')
|
and m.menu_type in ('M', 'C')
|
||||||
|
|||||||
@@ -181,11 +181,11 @@
|
|||||||
where id = #{id}
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
<select id="loadAllPermission" resultType="com.xiang.xservice.auth.api.dto.resp.PermissionRoleDTO">
|
<select id="loadAllPermission" resultType="com.xiang.xservice.auth.api.dto.resp.PermissionRoleDTO">
|
||||||
select p.api_path api_url, p.method, r.code as role_code
|
-- select p.api_path api_url, p.method, r.code as role_code
|
||||||
from x_permission p
|
-- from x_permission p
|
||||||
join x_role_permission rp on p.id = rp.permission_id
|
-- join x_role_permission rp on p.id = rp.permission_id
|
||||||
join x_role r on rp.role_id = r.id
|
-- join x_role r on rp.role_id = r.id
|
||||||
where p.del_flag = 0 and r.del_flag = 0 and r.status = 1
|
-- where p.del_flag = 0 and r.del_flag = 0 and r.status = 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -4,126 +4,56 @@
|
|||||||
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XRoleMapper">
|
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XRoleMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XRole" >
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XRole" >
|
||||||
<result column="id" property="id" />
|
<result column="role_id" property="roleId" />
|
||||||
<result column="name" property="name" />
|
<result column="role_name" property="roleName" />
|
||||||
<result column="code" property="code" />
|
<result column="role_key" property="roleKey" />
|
||||||
<result column="status" property="status" />
|
<result column="role_sort" property="roleSort" />
|
||||||
<result column="data_scope" property="dataScope" />
|
<result column="data_scope" property="dataScope" />
|
||||||
<result column="created_time" property="createdTime" />
|
<result column="menu_check_strictly" property="menuCheckStrictly" />
|
||||||
<result column="create_by" property="createBy" />
|
<result column="dept_check_strictly" property="deptCheckStrictly" />
|
||||||
<result column="updated_time" property="updatedTime" />
|
<result column="status" property="status" />
|
||||||
<result column="update_by" property="updateBy" />
|
|
||||||
<result column="del_flag" property="delFlag" />
|
<result column="del_flag" property="delFlag" />
|
||||||
|
<result column="create_by" property="createBy" />
|
||||||
|
<result column="create_time" property="createTime" />
|
||||||
|
<result column="update_by" property="updateBy" />
|
||||||
|
<result column="update_time" property="updateTime" />
|
||||||
|
<result column="remark" property="remark" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id,
|
role_id,
|
||||||
name,
|
role_name,
|
||||||
code,
|
role_key,
|
||||||
status,
|
role_sort,
|
||||||
data_scope,
|
data_scope,
|
||||||
created_time,
|
menu_check_strictly,
|
||||||
|
dept_check_strictly,
|
||||||
|
status,
|
||||||
|
del_flag,
|
||||||
create_by,
|
create_by,
|
||||||
updated_time,
|
create_time,
|
||||||
update_by,
|
update_by,
|
||||||
del_flag
|
update_time,
|
||||||
|
remark
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XRole">
|
|
||||||
INSERT INTO x_role
|
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
||||||
<if test="null != name and '' != name">
|
|
||||||
name,
|
|
||||||
</if>
|
|
||||||
<if test="null != code and '' != code">
|
|
||||||
code,
|
|
||||||
</if>
|
|
||||||
<if test="null != status ">
|
|
||||||
status,
|
|
||||||
</if>
|
|
||||||
<if test="null != dataScope ">
|
|
||||||
data_scope,
|
|
||||||
</if>
|
|
||||||
<if test="null != createdTime ">
|
|
||||||
created_time,
|
|
||||||
</if>
|
|
||||||
<if test="null != createBy and '' != createBy">
|
|
||||||
create_by,
|
|
||||||
</if>
|
|
||||||
<if test="null != updatedTime ">
|
|
||||||
updated_time,
|
|
||||||
</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">
|
|
||||||
update_by,
|
|
||||||
</if>
|
|
||||||
<if test="null != delFlag ">
|
|
||||||
del_flag
|
|
||||||
</if>
|
|
||||||
</trim>
|
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
||||||
<if test="null != name and '' != name">
|
|
||||||
#{name},
|
|
||||||
</if>
|
|
||||||
<if test="null != code and '' != code">
|
|
||||||
#{code},
|
|
||||||
</if>
|
|
||||||
<if test="null != status ">
|
|
||||||
#{status},
|
|
||||||
</if>
|
|
||||||
<if test="null != dataScope ">
|
|
||||||
#{dataScope},
|
|
||||||
</if>
|
|
||||||
<if test="null != createdTime ">
|
|
||||||
#{createdTime},
|
|
||||||
</if>
|
|
||||||
<if test="null != createBy and '' != createBy">
|
|
||||||
#{createBy},
|
|
||||||
</if>
|
|
||||||
<if test="null != updatedTime ">
|
|
||||||
#{updatedTime},
|
|
||||||
</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">
|
|
||||||
#{updateBy},
|
|
||||||
</if>
|
|
||||||
<if test="null != delFlag ">
|
|
||||||
#{delFlag}
|
|
||||||
</if>
|
|
||||||
</trim>
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
|
|
||||||
<update id="delBatch" >
|
<update id="delBatch" >
|
||||||
update x_role set del_flag = 0, update_time = #{time}, update_by = #{operator} where id in
|
update sys_role set del_flag = 0, update_time = #{time}, update_by = #{operator} where id in
|
||||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XRole">
|
|
||||||
UPDATE x_role
|
|
||||||
<set>
|
|
||||||
<if test="null != name and '' != name">name = #{name},</if>
|
|
||||||
<if test="null != code and '' != code">code = #{code},</if>
|
|
||||||
<if test="null != status ">status = #{status},</if>
|
|
||||||
<if test="null != dataScope ">data_scope = #{dataScope},</if>
|
|
||||||
<if test="null != createdTime ">created_time = #{createdTime},</if>
|
|
||||||
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
|
|
||||||
<if test="null != updatedTime ">updated_time = #{updatedTime},</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
|
|
||||||
<if test="null != delFlag ">del_flag = #{delFlag}</if>
|
|
||||||
</set>
|
|
||||||
WHERE id = #{id}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<select id="getRoleById" resultMap="BaseResultMap">
|
<select id="getRoleById" resultMap="BaseResultMap">
|
||||||
select <include refid="Base_Column_List"/>
|
select <include refid="Base_Column_List"/>
|
||||||
from x_role
|
from sys_role
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getRoleList" resultMap="BaseResultMap">
|
<select id="getRoleList" resultMap="BaseResultMap">
|
||||||
select <include refid="Base_Column_List"/>
|
select <include refid="Base_Column_List"/>
|
||||||
from x_role
|
from sys_role
|
||||||
<trim prefix="AND">
|
<trim prefix="AND">
|
||||||
<if test="name != null and name != ''">
|
<if test="name != null and name != ''">
|
||||||
AND name = #{name}
|
AND name = #{name}
|
||||||
@@ -141,8 +71,8 @@
|
|||||||
</select>
|
</select>
|
||||||
<select id="getRoleByIds" resultMap="BaseResultMap">
|
<select id="getRoleByIds" resultMap="BaseResultMap">
|
||||||
select <include refid="Base_Column_List"/>
|
select <include refid="Base_Column_List"/>
|
||||||
from x_role
|
from sys_role
|
||||||
where id in
|
where role_id in
|
||||||
<foreach collection="ids" item="id" close=")" open="(" separator=",">
|
<foreach collection="ids" item="id" close=")" open="(" separator=",">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
|
|||||||
@@ -3,28 +3,5 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XUserDeptMapper">
|
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XUserDeptMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XUserDept" >
|
|
||||||
<result column="user_id" property="userId" />
|
|
||||||
<result column="dept_id" property="deptId" />
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
|
||||||
user_id,
|
|
||||||
dept_id
|
|
||||||
</sql>
|
|
||||||
<insert id="addBatch">
|
|
||||||
insert into x_user_data_scope_dept(user_id, dept_id) values
|
|
||||||
<foreach collection="list" item="item" separator=",">
|
|
||||||
(#{item.userId}, #{item.deptId})
|
|
||||||
</foreach>
|
|
||||||
</insert>
|
|
||||||
<delete id="delByDeptId">
|
|
||||||
delete from x_user_data_scope_dept where dept_id = #{deptId}
|
|
||||||
</delete>
|
|
||||||
<select id="getByUserId" resultMap="BaseResultMap">
|
|
||||||
select <include refid="Base_Column_List"/>
|
|
||||||
from x_user_data_scope_dept where user_id = #{id}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -44,40 +44,11 @@
|
|||||||
token,
|
token,
|
||||||
refresh_token
|
refresh_token
|
||||||
</sql>
|
</sql>
|
||||||
<insert id="insertBatch">
|
|
||||||
insert into x_user(name, username, password, email, phone, status, tenant_id) VALUES
|
|
||||||
<foreach collection="list" item="item" separator=",">
|
|
||||||
(#{item.name}, #{item.username}, #{item.password}, #{item.email}, #{item.phone}, #{item.status}, #{item.tenantId})
|
|
||||||
</foreach>
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="delete" >
|
<update id="del" >
|
||||||
update x_user set del_flag = 1 where id = #{id}
|
update x_user set del_flag = 1 where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XUser">
|
|
||||||
UPDATE x_user
|
|
||||||
<set>
|
|
||||||
<if test="null != name and '' != name">name = #{name},</if>
|
|
||||||
<if test="null != username and '' != username">username = #{username},</if>
|
|
||||||
<if test="null != password and '' != password">password = #{password},</if>
|
|
||||||
<if test="null != email and '' != email">email = #{email},</if>
|
|
||||||
<if test="null != phone and '' != phone">phone = #{phone},</if>
|
|
||||||
<if test="null != avatar and '' != avatar">avatar = #{avatar},</if>
|
|
||||||
<if test="null != loginIp and '' != loginIp">login_ip = #{loginIp},</if>
|
|
||||||
<if test="null != loginDate ">login_date = #{loginDate},</if>
|
|
||||||
<if test="null != delFlag ">del_flag = #{delFlag},</if>
|
|
||||||
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
|
|
||||||
<if test="null != createTime ">create_time = #{createTime},</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
|
|
||||||
<if test="null != updateTime ">update_time = #{updateTime},</if>
|
|
||||||
<if test="null != tenantId ">tenant_id = #{tenantId},</if>
|
|
||||||
<if test="null != token and '' != token ">token = #{token},</if>
|
|
||||||
<if test="null != refreshToken and '' != refreshToken ">refresh_token = #{refreshToken},</if>
|
|
||||||
<if test="status != null">status = #{status}</if>
|
|
||||||
</set>
|
|
||||||
WHERE id = #{id}
|
|
||||||
</update>
|
|
||||||
<update id="deleteBatch">
|
<update id="deleteBatch">
|
||||||
update x_user set del_flag = 1, update_time = #{time}, update_by = #{operator} where id in
|
update x_user set del_flag = 1, update_time = #{time}, update_by = #{operator} where id in
|
||||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
role_id
|
role_id
|
||||||
</sql>
|
</sql>
|
||||||
<insert id="insertUserRole">
|
<insert id="insertUserRole">
|
||||||
insert into x_user_role(user_id, role_id)
|
insert into sys_user_role(user_id, role_id)
|
||||||
values
|
values
|
||||||
<foreach collection="list" item="item" separator=",">
|
<foreach collection="list" item="item" separator=",">
|
||||||
(#{item.userId}, #{item.roleId})
|
(#{item.userId}, #{item.roleId})
|
||||||
@@ -21,18 +21,18 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<delete id="delByUserId">
|
<delete id="delByUserId">
|
||||||
delete from x_user_role where user_id = #{userId}
|
delete from sys_user_role where user_id = #{userId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="delByRoleIds">
|
<delete id="delByRoleIds">
|
||||||
delete from x_user_role where role_id in
|
delete from sys_user_role where role_id in
|
||||||
<foreach collection="list" item="id" open="(" close=")" separator=",">
|
<foreach collection="list" item="id" open="(" close=")" separator=",">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<insert id="addBatch">
|
<insert id="addBatch">
|
||||||
insert into x_user_role(user_id, role_id) values
|
insert into sys_user_role(user_id, role_id) values
|
||||||
<foreach collection="list" item="item" separator=",">
|
<foreach collection="list" item="item" separator=",">
|
||||||
(#{item.userId}, #{item.roleId})
|
(#{item.userId}, #{item.roleId})
|
||||||
</foreach>
|
</foreach>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
<select id="getByUserId" resultMap="BaseResultMap">
|
<select id="getByUserId" resultMap="BaseResultMap">
|
||||||
select <include refid="Base_Column_List"/>
|
select <include refid="Base_Column_List"/>
|
||||||
from x_user_role
|
from sys_user_role
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user