Compare commits
19 Commits
9d34d30d25
...
feat/auth_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b8d33b50d | ||
|
|
8866d152d7 | ||
|
|
cb9ddf4681 | ||
|
|
6ebdec199b | ||
|
|
ace15206ec | ||
|
|
4ea369b33d | ||
|
|
e7f90b8d97 | ||
|
|
816dfb2304 | ||
|
|
22f0b546ad | ||
|
|
77769558ac | ||
|
|
a8d044dcb9 | ||
|
|
33c7e5fc5a | ||
|
|
8d31023505 | ||
|
|
9dbecac8ba | ||
|
|
d887faea42 | ||
|
|
813eec5e7f | ||
|
|
7e011672a1 | ||
|
|
ff79db96f7 | ||
|
|
5a2e4299b4 |
56
pom.xml
56
pom.xml
@@ -3,9 +3,9 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.xiang.pom</groupId>
|
||||||
<artifactId>xservice-basic</artifactId>
|
<artifactId>xmc-parent</artifactId>
|
||||||
<version>2.0</version>
|
<version>1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
@@ -53,29 +53,43 @@
|
|||||||
<version>5.7.11</version>
|
<version>5.7.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-common</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-mysql-starter</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-cache-starter</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mapstruct</groupId>
|
<groupId>org.mapstruct</groupId>
|
||||||
<artifactId>mapstruct</artifactId>
|
<artifactId>mapstruct</artifactId>
|
||||||
<version>1.5.5.Final</version>
|
<version>1.5.5.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 系统二方包 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-mysql-starter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-cache-starter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-common</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-message-starter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-http-starter</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-logger-starter</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -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,6 +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不匹配"),
|
||||||
|
TOKEN_NOT_VALID("1000106", "token校验失败"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class CaptchaImageRequest {
|
public class CaptchaImageRequest {
|
||||||
|
|
||||||
|
@NotBlank(message = "用户名不能为空")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
private Integer number;
|
private Integer number;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.req;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IdsRequest {
|
||||||
|
|
||||||
|
private List<Long> ids;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 13:46
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RefreshRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* refresh Token
|
||||||
|
*/
|
||||||
|
private String refreshToken;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.req.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserUpdateStatusRequest {
|
||||||
|
@NotNull(message = "id不能为空")
|
||||||
|
private Long id;
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -29,4 +31,6 @@ public class DeptDTO {
|
|||||||
* 排序
|
* 排序
|
||||||
*/
|
*/
|
||||||
private Integer sortNo;
|
private Integer sortNo;
|
||||||
|
|
||||||
|
private List<DeptDTO> children;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ public class LoginResp {
|
|||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
private String refreshToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.resp;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:24
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MenuVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单ID
|
||||||
|
*/
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单名称
|
||||||
|
*/
|
||||||
|
private String menuName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父菜单名称
|
||||||
|
*/
|
||||||
|
private String parentName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父菜单ID
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示顺序
|
||||||
|
*/
|
||||||
|
private Integer orderNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由地址
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组件路径
|
||||||
|
*/
|
||||||
|
private String component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由参数
|
||||||
|
*/
|
||||||
|
private String query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由名称,默认和路由地址相同的驼峰格式(注意:因为vue3版本的router会删除名称相同路由,为避免名字的冲突,特殊情况可以自定义)
|
||||||
|
*/
|
||||||
|
private String routeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为外链(0是 1否)
|
||||||
|
*/
|
||||||
|
private String isFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否缓存(0缓存 1不缓存)
|
||||||
|
*/
|
||||||
|
private String isCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型(M目录 C菜单 F按钮)
|
||||||
|
*/
|
||||||
|
private String menuType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示状态(0显示 1隐藏)
|
||||||
|
*/
|
||||||
|
private String visible;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单状态(0正常 1停用)
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限字符串
|
||||||
|
*/
|
||||||
|
private String perms;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子菜单
|
||||||
|
*/
|
||||||
|
private List<MenuVO> children = new ArrayList<MenuVO>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.resp;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.utils.MyStringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由显示信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class MetaVo {
|
||||||
|
/**
|
||||||
|
* 设置该路由在侧边栏和面包屑中展示的名字
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置该路由的图标,对应路径src/assets/icons/svg
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置为true,则不会被 <keep-alive>缓存
|
||||||
|
*/
|
||||||
|
private boolean noCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内链地址(http(s)://开头)
|
||||||
|
*/
|
||||||
|
private String link;
|
||||||
|
|
||||||
|
public MetaVo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaVo(String title, String icon) {
|
||||||
|
this.title = title;
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaVo(String title, String icon, boolean noCache) {
|
||||||
|
this.title = title;
|
||||||
|
this.icon = icon;
|
||||||
|
this.noCache = noCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaVo(String title, String icon, String link) {
|
||||||
|
this.title = title;
|
||||||
|
this.icon = icon;
|
||||||
|
this.link = link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaVo(String title, String icon, boolean noCache, String link) {
|
||||||
|
this.title = title;
|
||||||
|
this.icon = icon;
|
||||||
|
this.noCache = noCache;
|
||||||
|
if (MyStringUtils.isHttp(link)) {
|
||||||
|
this.link = link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNoCache() {
|
||||||
|
return noCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNoCache(boolean noCache) {
|
||||||
|
this.noCache = noCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLink() {
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLink(String link) {
|
||||||
|
this.link = link;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.resp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由配置信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
public class RouterVo {
|
||||||
|
/**
|
||||||
|
* 路由名字
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由地址
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否隐藏路由,当设置 true 的时候该路由不会再侧边栏出现
|
||||||
|
*/
|
||||||
|
private boolean hidden;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重定向地址,当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
|
||||||
|
*/
|
||||||
|
private String redirect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组件地址
|
||||||
|
*/
|
||||||
|
private String component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由参数:如 {"id": 1, "name": "ry"}
|
||||||
|
*/
|
||||||
|
private String query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
|
||||||
|
*/
|
||||||
|
private Boolean alwaysShow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他元素
|
||||||
|
*/
|
||||||
|
private MetaVo meta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子路由
|
||||||
|
*/
|
||||||
|
private List<RouterVo> children;
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.xiang.xservice.auth.api.dto.resp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Treeselect树结构实体类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class TreeSelect implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点名称
|
||||||
|
*/
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点禁用
|
||||||
|
*/
|
||||||
|
private boolean disabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子节点
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
private List<TreeSelect> children;
|
||||||
|
|
||||||
|
public TreeSelect() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeSelect(DeptDTO dept) {
|
||||||
|
this.id = dept.getId();
|
||||||
|
this.label = dept.getName();
|
||||||
|
this.disabled = true;
|
||||||
|
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeSelect(MenuVO menu) {
|
||||||
|
this.id = menu.getMenuId();
|
||||||
|
this.label = menu.getMenuName();
|
||||||
|
this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisabled() {
|
||||||
|
return disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisabled(boolean disabled) {
|
||||||
|
this.disabled = disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TreeSelect> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(List<TreeSelect> children) {
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -15,4 +16,5 @@ public class UserDTO {
|
|||||||
private UserResp user;
|
private UserResp user;
|
||||||
private DeptDTO dept;
|
private DeptDTO dept;
|
||||||
private List<PermissionDTO> permissionRoles;
|
private List<PermissionDTO> permissionRoles;
|
||||||
|
private Set<String> permissions;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import java.time.LocalDateTime;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class UserResp {
|
public class UserResp {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名(昵称)
|
* 用户名(昵称)
|
||||||
*/
|
*/
|
||||||
@@ -55,4 +57,9 @@ public class UserResp {
|
|||||||
* 修改时间
|
* 修改时间
|
||||||
*/
|
*/
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户id
|
||||||
|
*/
|
||||||
|
private Long tenantId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,24 @@
|
|||||||
package com.xiang;
|
package com.xiang;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
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.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ConfigurationPropertiesScan(basePackages = {
|
||||||
|
|
||||||
|
})
|
||||||
@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);
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(AuthApplication.class, args);
|
SpringApplication.run(AuthApplication.class, args);
|
||||||
|
log.info("auth-center start success!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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<DeptDTO> getDeptList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptQueryRequest request) {
|
|
||||||
return Result.success(deptService.getDeptList(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/private/dept/info/{id}")
|
|
||||||
public Result<DeptDTO> getDeptInfo(@PathVariable Long id) {
|
|
||||||
return Result.success(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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<RoleDTO> getRoleList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleQueryRequest request) {
|
|
||||||
return Result.success(roleService.getRoleList(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/private/role/info/{id}")
|
|
||||||
public Result<RoleDTO> getRoleInfo(@PathVariable Long id) {
|
|
||||||
return Result.success(roleService.getRoleInfo(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/private/role/add")
|
|
||||||
public Result<Boolean> addRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleAddRequest request) {
|
|
||||||
try {
|
|
||||||
return Result.success(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.success(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.success(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.success(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,29 +1,24 @@
|
|||||||
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.RegisterRequest;
|
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
||||||
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;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -31,7 +26,7 @@ public class TokenController implements TokenApi {
|
|||||||
public Result<LoginResp> login(@RequestBody @NotNull(message = "请求参数不能为空") @Valid LoginRequest request) {
|
public Result<LoginResp> login(@RequestBody @NotNull(message = "请求参数不能为空") @Valid LoginRequest request) {
|
||||||
try {
|
try {
|
||||||
LoginResp login = userService.login(request);
|
LoginResp login = userService.login(request);
|
||||||
return Result.success("操作成功", login);
|
return Result.data(login);
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
log.error("【用户登录】用户登录失败,{}", e.getMessage(), e);
|
log.error("【用户登录】用户登录失败,{}", e.getMessage(), e);
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
@@ -41,26 +36,17 @@ public class TokenController implements TokenApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/public/user/userRegister")
|
@PostMapping("/publish/auth/refresh")
|
||||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
public Result<LoginResp> refresh(@RequestBody @NotNull(message = "请求参数不能为空") @Valid RefreshRequest request) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RegisterResp registerResp = userService.userRegister(request);
|
LoginResp login = userService.refresh(request);
|
||||||
if (Objects.nonNull(registerResp)) {
|
return Result.data(login);
|
||||||
return Result.success("操作成功", registerResp);
|
|
||||||
}
|
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
log.error("【用户登录】用户登录失败,{}", e.getMessage(), e);
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
log.error("【用户登录】用户登录失败,{}", e.getMessage(), e);
|
||||||
|
return Result.error();
|
||||||
}
|
}
|
||||||
return Result.error("操作失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/private/auth/getInfo")
|
|
||||||
public Result<UserDTO> getUserInfo() {
|
|
||||||
// todo token的工具类,直接获取token中的userId无需传参
|
|
||||||
return Result.success(userService.getUserDetail(1L));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
package com.xiang.xservice.auth.server.controller;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
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.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.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 UserController {
|
|
||||||
|
|
||||||
private final XUserService userService;
|
|
||||||
|
|
||||||
@PostMapping("/private/user/list")
|
|
||||||
public Result<UserResp> getUserList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
|
||||||
return Result.success(userService.getUserList(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/private/user/info/{id}")
|
|
||||||
public Result<UserResp> getUserById(@PathVariable("id") Long id) {
|
|
||||||
return Result.success(userService.getUserInfo(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/private/user/add")
|
|
||||||
public Result<Boolean> addUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserAddRequest request) {
|
|
||||||
try {
|
|
||||||
return Result.success(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/update")
|
|
||||||
public Result<Boolean> updateUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateRequest request) {
|
|
||||||
try {
|
|
||||||
return Result.success(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(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
|
||||||
try {
|
|
||||||
return Result.success(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.success(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.success(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();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.server.controller;
|
package com.xiang.xservice.auth.server.controller;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.message.aliyun.smscode.ISmsCodeService;
|
||||||
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
|
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
|
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
|
||||||
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
|
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
|
||||||
@@ -15,6 +16,7 @@ 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
|
||||||
@@ -22,12 +24,15 @@ import javax.validation.constraints.NotNull;
|
|||||||
public class ValidationCodeController {
|
public class ValidationCodeController {
|
||||||
|
|
||||||
private final ValidCodeGenerateFactory validCodeGenerateFactory;
|
private final ValidCodeGenerateFactory validCodeGenerateFactory;
|
||||||
|
private final ISmsCodeService smsCodeService;
|
||||||
|
|
||||||
@PostMapping("/public/captchaImage")
|
@PostMapping("/public/captchaImage")
|
||||||
public Result<CaptchaDTO> getCaptchaImage(@RequestBody @NotNull(message = "请求参数不能为空") @Valid CaptchaImageRequest request) {
|
public Result<CaptchaDTO> getCaptchaImage(@RequestBody @NotNull(message = "请求参数不能为空") @Valid CaptchaImageRequest request) {
|
||||||
|
if (Objects.isNull(request.getNumber())) {
|
||||||
|
request.setNumber(4);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String randomCode = RandomCodeUtils.getNumberRandomCode(1);
|
String randomCode = RandomCodeUtils.getNumberRandomCode(1);
|
||||||
// String randomCode = "1";
|
|
||||||
CaptchaDTO captchaImage;
|
CaptchaDTO captchaImage;
|
||||||
if (StringUtils.isBlank(randomCode)) {
|
if (StringUtils.isBlank(randomCode)) {
|
||||||
captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage(request);
|
captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage(request);
|
||||||
@@ -40,7 +45,7 @@ public class ValidationCodeController {
|
|||||||
captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage(request);
|
captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result.success(captchaImage);
|
return Result.data(captchaImage);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取验证码失败", e);
|
log.error("获取验证码失败", e);
|
||||||
}
|
}
|
||||||
@@ -49,8 +54,14 @@ public class ValidationCodeController {
|
|||||||
|
|
||||||
@PostMapping("/public/getSmsCode")
|
@PostMapping("/public/getSmsCode")
|
||||||
public Result<Void> getSmsCode(@RequestBody @NotNull(message = "请求参数不能为空") @Valid CaptchaImageRequest request) {
|
public Result<Void> getSmsCode(@RequestBody @NotNull(message = "请求参数不能为空") @Valid CaptchaImageRequest request) {
|
||||||
|
if (Objects.isNull(request.getNumber())) {
|
||||||
|
request.setNumber(6);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
validCodeGenerateFactory.get(CaptchaTypeEnum.NUMBER_CAPTCHA_CODE.getType()).getCaptchaImage(request);
|
CaptchaDTO captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NUMBER_CAPTCHA_CODE.getType()).getCaptchaImage(request);
|
||||||
|
String code = captchaImage.getCaptchaImageCode();
|
||||||
|
smsCodeService.asyncSendPhoneValidCode4DaXiangNet(request.getUsername(), code);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取验证码失败", e);
|
log.error("获取验证码失败", e);
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ spring:
|
|||||||
primary: master
|
primary: master
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://rm-bp15t34gqx62jm069ro.mysql.rds.aliyuncs.com:3306/xservice-user?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
url: jdbc:mysql://120.27.153.87:3306/xservice-user?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||||
username: root
|
username: root
|
||||||
password: xb#UWqnhH24&XpX
|
password: sdkljfikdfn@123
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
sshConnect: false
|
sshConnect: false
|
||||||
redis:
|
redis:
|
||||||
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||||
port: 6379
|
port: 6379
|
||||||
password: Xiang0000 # 如果无密码可以省略
|
password: Xiang0000 # 如果无密码可以省略
|
||||||
database: 0
|
database: 10
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -39,4 +39,9 @@ user:
|
|||||||
# https://oauth.pstmn.io/v1/callback
|
# https://oauth.pstmn.io/v1/callback
|
||||||
# 移动端 APP 自定义 Scheme:
|
# 移动端 APP 自定义 Scheme:
|
||||||
# myapp://callback
|
# myapp://callback
|
||||||
redirectUrl: http://localhost:8080/login/oauth2/code/oauth-client-init
|
redirectUrl: http://localhost:8080/login/oauth2/code/oauth-client-init
|
||||||
|
|
||||||
|
aliyun:
|
||||||
|
auth:
|
||||||
|
accessKeyId: LTAI5tDMjaVF8Bbqcpp4dmvP
|
||||||
|
accessKeySecret: nkmnaNjWQy5984C5kjyS0oDmdMKGQd
|
||||||
@@ -39,4 +39,9 @@ user:
|
|||||||
# https://oauth.pstmn.io/v1/callback
|
# https://oauth.pstmn.io/v1/callback
|
||||||
# 移动端 APP 自定义 Scheme:
|
# 移动端 APP 自定义 Scheme:
|
||||||
# myapp://callback
|
# myapp://callback
|
||||||
redirectUrl: http://localhost:8080/login/oauth2/code/oauth-client-init
|
redirectUrl: http://localhost:8080/login/oauth2/code/oauth-client-init
|
||||||
|
|
||||||
|
aliyun:
|
||||||
|
auth:
|
||||||
|
accessKeyId: LTAI5tDMjaVF8Bbqcpp4dmvP
|
||||||
|
accessKeySecret: nkmnaNjWQy5984C5kjyS0oDmdMKGQd
|
||||||
@@ -8,9 +8,29 @@ spring:
|
|||||||
mvc:
|
mvc:
|
||||||
pathmatch:
|
pathmatch:
|
||||||
matching-strategy: ant_path_matcher
|
matching-strategy: ant_path_matcher
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: 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
|
||||||
|
|
||||||
|
feign:
|
||||||
|
client:
|
||||||
|
config:
|
||||||
|
default:
|
||||||
|
connectTimeout: 1000
|
||||||
|
readTimeout: 3000
|
||||||
28
xs-server/src/main/resources/keys/rsa-private.pem
Normal file
28
xs-server/src/main/resources/keys/rsa-private.pem
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQD7JdqQe8W8byYT
|
||||||
|
KuPK7STLYO5TTe5uWhHj1SLq7Xoj1y0agO+x1X3/dUA1X/k5Dd2rmkmIU2VoB/9c
|
||||||
|
aoE5naXUhVfE9wDsl5AKdWRCn1PKvuofd/0kuGFS44tNQcLGtDD7e8CQQJZJPZVS
|
||||||
|
Z8F2nlHjYSTUPVvi77hKG21qoZLEa0F+TYfqgOohabQtxeBAnyRW50/g281Bqd3w
|
||||||
|
ntfM0aKfW9fsFhJnk+AlXWaqxQKkhtzMmKVeqLNfJnXvhgUA6QbnzHPtPxF+fLEx
|
||||||
|
BNnBEPF8CsQFVdt1TtsQlfCzVMTMibZU2CcwtqHUP1maEcH5zV5whPfgkahejiNm
|
||||||
|
L08Jw74VAgMBAAECggEACJHb0pGHh4IkF/XmM6Qs6xMFYmqmvRkf0JjoTYDl9+JW
|
||||||
|
Y9RMYKfqy+Yius+GSNRjPWS7p38MHkiysGL/F7uYyCwvhwU3x+kugM2+/+gWqyaT
|
||||||
|
WnwYgZ4YXIRu2ieFr4xq1symnzO14nDny4uqB9PEZFd7wS4I0ZShe5yLM6Yai88V
|
||||||
|
0Jm6Hi9RcC5efiE4tWismBKaP13WXamAVySROW30lEaMgyI66DNYgs+RHiZgAFP7
|
||||||
|
u7raUD07xrk6eV6YnG/9EvS/oqV+IPEacY+bP3ZUqvPMI50tLTEVN1yJXrr4T3kS
|
||||||
|
W1TiApaL87rdDCYem7rtIury+JcSadaI6lwP5OhmLwKBgQD/4mSrFi30IzD6LFam
|
||||||
|
N7CYBxSleWgha2fHuycDGNGcXDCn3y4JuqTMRpV1c9F5emPPv1E3ELj4plz/NnVr
|
||||||
|
67SkCs3nqoSRjyXJKhN/kJqM/NB+Ic1UgXeI+wGMkfkUHrQ6T6SghYVxWW+hQKm8
|
||||||
|
IeV7aVJiM01/Ze938cnJuWd17wKBgQD7QumZzRTMkmnmSFCpOhs2Y3B8JYrJsJXY
|
||||||
|
PeYkxea/7brDyuIdWKt0kl9EvpsrIzTe0t4LYV3Vmmfh15PNZp4PEr30NEBxeVOO
|
||||||
|
HoglNfyJgP/nvhOGYesNhqPlK96/ajEvu7FpFHwDje5RKRWxCK5qhZneDy0ppjWb
|
||||||
|
6seshN1wOwKBgQDqNPxxP/bFu6Qrh4Oz1cs0C18RakMuO5Gc1acKhZ/tntAGBxer
|
||||||
|
XgNS2dQY0e5MYwKSdwlN/mdfZ149Vko5gl8vupfmUEPQuxYZvwJjwyZCn2/x0tyO
|
||||||
|
WYXggeZUFJPHn6bUrGsBZdTS/8pV7Mqu4NOblrYKHez0C4gY390TXzjcTwKBgQDR
|
||||||
|
mD6fYrjf8Z7PTzGiCOucUhUKKpL8rgZBbVknAcL8BYZPP1Whn07fHh7EjK+Jq4O2
|
||||||
|
AHbjTWRmA7h2Z0tPAzQEZOD57gB35/pwSj3NtJwl4+sU2LUW22WlUdQ0HoVgbWf8
|
||||||
|
ZniWrFTK7kGHiFsk45YDG9F/sG8/F/wORSotWmQR8wKBgQDqrlyvMCwiJHW7vOPs
|
||||||
|
ih+utzIvtZ8D4fxzEFluTUqubAAl3N+81NuRJuEFIJLjIAeTNOHj1IdlPj5oe0aa
|
||||||
|
IYOzoB2+xJxnLPbvI1tTat/pqgXxPY24/9c9rBoTCsJboTPb0fMh1nHxTZvny4tB
|
||||||
|
jP7d5EBvIMWnCEuTo4y39ZFsMA==
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
9
xs-server/src/main/resources/keys/rsa-public.pem
Normal file
9
xs-server/src/main/resources/keys/rsa-public.pem
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-----BEGIN PUBLIC KEY-----
|
||||||
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA+yXakHvFvG8mEyrjyu0k
|
||||||
|
y2DuU03ubloR49Ui6u16I9ctGoDvsdV9/3VANV/5OQ3dq5pJiFNlaAf/XGqBOZ2l
|
||||||
|
1IVXxPcA7JeQCnVkQp9Tyr7qH3f9JLhhUuOLTUHCxrQw+3vAkECWST2VUmfBdp5R
|
||||||
|
42Ek1D1b4u+4ShttaqGSxGtBfk2H6oDqIWm0LcXgQJ8kVudP4NvNQand8J7XzNGi
|
||||||
|
n1vX7BYSZ5PgJV1mqsUCpIbczJilXqizXyZ174YFAOkG58xz7T8RfnyxMQTZwRDx
|
||||||
|
fArEBVXbdU7bEJXws1TEzIm2VNgnMLah1D9ZmhHB+c1ecIT34JGoXo4jZi9PCcO+
|
||||||
|
FQIDAQAB
|
||||||
|
-----END PUBLIC KEY-----
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
package com.xiang.xservice.auth.service.config;
|
package com.xiang.xservice.auth.service.config;
|
||||||
|
|
||||||
import com.nimbusds.jose.jwk.JWKSet;
|
|
||||||
import com.nimbusds.jose.jwk.RSAKey;
|
|
||||||
import com.nimbusds.jose.jwk.source.JWKSource;
|
|
||||||
import com.nimbusds.jose.proc.SecurityContext;
|
|
||||||
import com.xiang.xservice.basic.exception.CustomAccessDeniedHandler;
|
|
||||||
import com.xiang.xservice.basic.exception.CustomAuthenticationEntryPoint;
|
|
||||||
import com.xiang.xservice.basic.utils.JwkUtils;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -24,9 +17,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
||||||
import org.springframework.security.oauth2.jwt.JwtDecoder;
|
|
||||||
import org.springframework.security.oauth2.jwt.JwtEncoder;
|
|
||||||
import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;
|
|
||||||
import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository;
|
import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository;
|
||||||
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
|
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
|
||||||
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
|
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
|
||||||
@@ -140,18 +130,6 @@ public class AuthorizationServerConfig {
|
|||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public JWKSource<SecurityContext> jwkSource() {
|
|
||||||
RSAKey rsaKey = JwkUtils.generateRsa();
|
|
||||||
JWKSet jwkSet = new JWKSet(rsaKey);
|
|
||||||
return (jwkSelector, securityContext) -> jwkSelector.select(jwkSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public JwtEncoder jwtEncoder(JWKSource<SecurityContext> jwkSource) {
|
|
||||||
return new NimbusJwtEncoder(jwkSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthorizationServerSettings authorizationServerSettings() {
|
public AuthorizationServerSettings authorizationServerSettings() {
|
||||||
return AuthorizationServerSettings.builder()
|
return AuthorizationServerSettings.builder()
|
||||||
@@ -159,9 +137,5 @@ public class AuthorizationServerConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
|
|
||||||
return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.xiang.xservice.auth.service.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import com.xiang.xservice.basic.exception.code.ErrorCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户403鉴权失败异常捕获
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
||||||
|
@Override
|
||||||
|
public void handle(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
AccessDeniedException accessDeniedException) throws IOException, ServletException {
|
||||||
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
|
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
log.error("======用户鉴权失败======");
|
||||||
|
Result<Void> result = Result.error(ErrorCode.USER_DENIED_ACCESS);
|
||||||
|
response.getWriter().write(new ObjectMapper().writeValueAsString(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.xiang.xservice.auth.service.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import com.xiang.xservice.basic.exception.code.ErrorCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户未鉴权异常处理器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
|
@Override
|
||||||
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
|
||||||
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
|
log.error("========用户未进行验证鉴权==========");
|
||||||
|
Result<Void> result = Result.error(ErrorCode.NOT_AUTHORIZATION);
|
||||||
|
response.getWriter().write(new ObjectMapper().writeValueAsString(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.xiang.xservice.auth.service.config;
|
||||||
|
|
||||||
|
import com.nimbusds.jose.jwk.JWKSet;
|
||||||
|
import com.nimbusds.jose.jwk.RSAKey;
|
||||||
|
import com.nimbusds.jose.jwk.source.JWKSource;
|
||||||
|
import com.nimbusds.jose.proc.SecurityContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.security.oauth2.jwt.JwtDecoder;
|
||||||
|
import org.springframework.security.oauth2.jwt.JwtEncoder;
|
||||||
|
import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;
|
||||||
|
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.KeyFactory;
|
||||||
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JwtConfig {
|
||||||
|
|
||||||
|
private RSAPrivateKey loadPrivateKey(String classpath) throws Exception {
|
||||||
|
InputStream is = new ClassPathResource(classpath).getInputStream();
|
||||||
|
String key = new String(is.readAllBytes(), StandardCharsets.UTF_8)
|
||||||
|
.replace("-----BEGIN PRIVATE KEY-----", "")
|
||||||
|
.replace("-----END PRIVATE KEY-----", "")
|
||||||
|
.replaceAll("\\s+", "");
|
||||||
|
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(key));
|
||||||
|
return (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(spec);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RSAPublicKey loadPublicKey(String classpath) throws Exception {
|
||||||
|
InputStream is = new ClassPathResource(classpath).getInputStream();
|
||||||
|
String key = new String(is.readAllBytes(), StandardCharsets.UTF_8)
|
||||||
|
.replace("-----BEGIN PUBLIC KEY-----", "")
|
||||||
|
.replace("-----END PUBLIC KEY-----", "")
|
||||||
|
.replaceAll("\\s+", "");
|
||||||
|
X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.getDecoder().decode(key));
|
||||||
|
return (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(spec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JWKSource<SecurityContext> jwkSource() throws Exception {
|
||||||
|
// 使用RSA对称加密进行加密
|
||||||
|
RSAPublicKey publicKey = loadPublicKey("keys/rsa-public.pem");
|
||||||
|
RSAPrivateKey privateKey = loadPrivateKey("keys/rsa-private.pem");
|
||||||
|
|
||||||
|
RSAKey rsaKey = new RSAKey.Builder(publicKey)
|
||||||
|
.privateKey(privateKey)
|
||||||
|
.keyID("xservice")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
JWKSet jwkSet = new JWKSet(rsaKey);
|
||||||
|
return (jwkSelector, ctx) -> jwkSelector.select(jwkSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JwtEncoder jwtEncoder(JWKSource<SecurityContext> jwkSource) {
|
||||||
|
return new NimbusJwtEncoder(jwkSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
|
||||||
|
return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.xiang.xservice.auth.service.constants;
|
|||||||
|
|
||||||
public class RedisConstant {
|
public class RedisConstant {
|
||||||
|
|
||||||
|
public static final String LOGIN_TOKEN = "login:token:";
|
||||||
public static final String XS_PERMISSION_ROLE = "auth:permission:role";
|
public static final String XS_PERMISSION_ROLE = "auth:permission:role";
|
||||||
public static final String XS_SMS_CODE_KEY = "auth:sms:code:key:";
|
public static final String XS_SMS_CODE_KEY = "auth:sms:code:key:";
|
||||||
public static final String XS_CAPTCHA_CODE_KEY = "auth:captcha:code:key:";
|
public static final String XS_CAPTCHA_CODE_KEY = "auth:captcha:code:key:";
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.xiang.xservice.auth.service.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户常量信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class UserConstants
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 平台内系统用户的唯一标志
|
||||||
|
*/
|
||||||
|
public static final String SYS_USER = "SYS_USER";
|
||||||
|
|
||||||
|
/** 正常状态 */
|
||||||
|
public static final String NORMAL = "0";
|
||||||
|
|
||||||
|
/** 异常状态 */
|
||||||
|
public static final String EXCEPTION = "1";
|
||||||
|
|
||||||
|
/** 用户封禁状态 */
|
||||||
|
public static final String USER_DISABLE = "1";
|
||||||
|
|
||||||
|
/** 角色正常状态 */
|
||||||
|
public static final String ROLE_NORMAL = "0";
|
||||||
|
|
||||||
|
/** 角色封禁状态 */
|
||||||
|
public static final String ROLE_DISABLE = "1";
|
||||||
|
|
||||||
|
/** 部门正常状态 */
|
||||||
|
public static final String DEPT_NORMAL = "0";
|
||||||
|
|
||||||
|
/** 部门停用状态 */
|
||||||
|
public static final String DEPT_DISABLE = "1";
|
||||||
|
|
||||||
|
/** 字典正常状态 */
|
||||||
|
public static final String DICT_NORMAL = "0";
|
||||||
|
|
||||||
|
/** 是否为系统默认(是) */
|
||||||
|
public static final String YES = "Y";
|
||||||
|
|
||||||
|
/** 是否菜单外链(是) */
|
||||||
|
public static final String YES_FRAME = "0";
|
||||||
|
|
||||||
|
/** 是否菜单外链(否) */
|
||||||
|
public static final String NO_FRAME = "1";
|
||||||
|
|
||||||
|
/** 菜单类型(目录) */
|
||||||
|
public static final String TYPE_DIR = "M";
|
||||||
|
|
||||||
|
/** 菜单类型(菜单) */
|
||||||
|
public static final String TYPE_MENU = "C";
|
||||||
|
|
||||||
|
/** 菜单类型(按钮) */
|
||||||
|
public static final String TYPE_BUTTON = "F";
|
||||||
|
|
||||||
|
/** Layout组件标识 */
|
||||||
|
public final static String LAYOUT = "Layout";
|
||||||
|
|
||||||
|
/** ParentView组件标识 */
|
||||||
|
public final static String PARENT_VIEW = "ParentView";
|
||||||
|
|
||||||
|
/** InnerLink组件标识 */
|
||||||
|
public final static String INNER_LINK = "InnerLink";
|
||||||
|
|
||||||
|
/** 校验是否唯一的返回标识 */
|
||||||
|
public final static boolean UNIQUE = true;
|
||||||
|
public final static boolean NOT_UNIQUE = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名长度限制
|
||||||
|
*/
|
||||||
|
public static final int USERNAME_MIN_LENGTH = 2;
|
||||||
|
|
||||||
|
public static final int USERNAME_MAX_LENGTH = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码长度限制
|
||||||
|
*/
|
||||||
|
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||||
|
|
||||||
|
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||||
|
|
||||||
|
public static boolean isAdmin(Long userId)
|
||||||
|
{
|
||||||
|
return userId != null && 1L == userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.xiang.xservice.auth.service.convert;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.MenuVO;
|
||||||
|
import com.xiang.xservice.auth.service.entity.XMenuDO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:39
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface XMenuConverter {
|
||||||
|
|
||||||
|
|
||||||
|
List<MenuVO> toVoList(List<XMenuDO> xMenuDOS);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.service.convert;
|
package com.xiang.xservice.auth.service.convert;
|
||||||
|
|
||||||
|
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.UserAddRequest;
|
||||||
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.UserUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||||
@@ -8,8 +9,6 @@ import com.xiang.xservice.auth.service.entity.XUser;
|
|||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface XUserConvert {
|
public interface XUserConvert {
|
||||||
XUserConvert INSTANCE = Mappers.getMapper(XUserConvert.class);
|
XUserConvert INSTANCE = Mappers.getMapper(XUserConvert.class);
|
||||||
@@ -18,7 +17,7 @@ public interface XUserConvert {
|
|||||||
XUser toDO (UserAddRequest request);
|
XUser toDO (UserAddRequest request);
|
||||||
XUser toDO (UserUpdateRequest request);
|
XUser toDO (UserUpdateRequest request);
|
||||||
|
|
||||||
List<UserResp> toRespList(List<XUser> list);
|
|
||||||
|
|
||||||
UserResp toResp(XUser user);
|
UserResp toResp(XUser user);
|
||||||
|
|
||||||
|
Page<UserResp> toPage(Page<XUser> page);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.xiang.xservice.auth.service.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("sys_menu")
|
||||||
|
public class XMenuDO {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 菜单ID */
|
||||||
|
@TableId
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
/** 菜单名称 */
|
||||||
|
private String menuName;
|
||||||
|
|
||||||
|
/** 父菜单ID */
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/** 显示顺序 */
|
||||||
|
private Integer orderNum;
|
||||||
|
|
||||||
|
/** 路由地址 */
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/** 组件路径 */
|
||||||
|
private String component;
|
||||||
|
|
||||||
|
/** 路由参数 */
|
||||||
|
private String query;
|
||||||
|
|
||||||
|
/** 路由名称,默认和路由地址相同的驼峰格式(注意:因为vue3版本的router会删除名称相同路由,为避免名字的冲突,特殊情况可以自定义) */
|
||||||
|
private String routeName;
|
||||||
|
|
||||||
|
/** 是否为外链(0是 1否) */
|
||||||
|
private Integer isFrame;
|
||||||
|
|
||||||
|
/** 是否缓存(0缓存 1不缓存) */
|
||||||
|
private Integer isCache;
|
||||||
|
|
||||||
|
/** 类型(M目录 C菜单 F按钮) */
|
||||||
|
private String menuType;
|
||||||
|
|
||||||
|
/** 显示状态(0显示 1隐藏) */
|
||||||
|
private String visible;
|
||||||
|
|
||||||
|
/** 菜单状态(0正常 1停用) */
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/** 权限字符串 */
|
||||||
|
private String perms;
|
||||||
|
|
||||||
|
/** 菜单图标 */
|
||||||
|
private String icon;
|
||||||
|
private String createBy;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private String updateBy;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,4 +95,18 @@ public class XUser implements Serializable {
|
|||||||
* 修改时间
|
* 修改时间
|
||||||
*/
|
*/
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
/**
|
||||||
|
* 刷新token
|
||||||
|
*/
|
||||||
|
private String refreshToken;
|
||||||
|
/**
|
||||||
|
* 1:后台用户、2:中台用户、3:前台用户
|
||||||
|
*/
|
||||||
|
private Integer userType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.xiang.xservice.auth.service.entity.XMenuDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:31
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface XMenuMapper extends BaseMapper<XMenuDO> {
|
||||||
|
List<XMenuDO> selectMenuTreeByUserId(Long userId);
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.xiang.xservice.auth.service.repository.mapper;
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.xiang.xservice.auth.service.entity.XUser;
|
import com.xiang.xservice.auth.service.entity.XUser;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
@@ -10,7 +12,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface XUserMapper {
|
public interface XUserMapper extends BaseMapper<XUser> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户名查询用户
|
* 根据用户名查询用户
|
||||||
@@ -19,26 +21,12 @@ public interface XUserMapper {
|
|||||||
*/
|
*/
|
||||||
XUser selectByUsername(String username);
|
XUser selectByUsername(String username);
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增用户
|
|
||||||
* @param user 用户
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int insert(XUser user);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量插入
|
|
||||||
* @param list
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int insertBatch(List<XUser> list);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户列表
|
* 查询用户列表
|
||||||
* @param user
|
* @param user
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<XUser> getUserList(XUser user);
|
Page<XUser> getUserList(XUser user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户详情
|
* 查询用户详情
|
||||||
@@ -47,12 +35,6 @@ public interface XUserMapper {
|
|||||||
*/
|
*/
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.xiang.xservice.auth.service.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.RouterVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:30
|
||||||
|
*/
|
||||||
|
public interface XMenuService {
|
||||||
|
|
||||||
|
List<RouterVo> getRouter(Long userId);
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.xiang.xservice.auth.service.service;
|
package com.xiang.xservice.auth.service.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
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.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;
|
||||||
@@ -17,24 +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);
|
||||||
List<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);
|
||||||
|
UserDTO getUserDetail(String username);
|
||||||
Boolean setUserDept(UserDeptUpdateRequest request);
|
LoginResp refresh(RefreshRequest request);
|
||||||
|
Boolean updateStatus(Long id, Integer status);
|
||||||
Boolean setUserRole(UserRoleUpdateRequest request);
|
Long getUserId(String token);
|
||||||
|
Long getTenantId(String token);
|
||||||
UserDTO getUserDetail(Long userId);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
package com.xiang.xservice.auth.service.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.MenuVO;
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.MetaVo;
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.RouterVo;
|
||||||
|
import com.xiang.xservice.auth.service.constants.UserConstants;
|
||||||
|
import com.xiang.xservice.auth.service.convert.XMenuConverter;
|
||||||
|
import com.xiang.xservice.auth.service.entity.XMenuDO;
|
||||||
|
import com.xiang.xservice.auth.service.repository.mapper.XMenuMapper;
|
||||||
|
import com.xiang.xservice.auth.service.service.XMenuService;
|
||||||
|
import com.xiang.xservice.basic.constants.Constants;
|
||||||
|
import com.xiang.xservice.basic.utils.MyStringUtils;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:30
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class XMenuServiceImpl implements XMenuService {
|
||||||
|
|
||||||
|
private final XMenuMapper menuMapper;
|
||||||
|
private final XMenuConverter menuConverter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RouterVo> getRouter(Long userId) {
|
||||||
|
List<XMenuDO> xMenuDOS = Lists.newArrayList();
|
||||||
|
// 超级管理员 admin
|
||||||
|
if (Objects.equals(userId, 1L)) {
|
||||||
|
LambdaQueryWrapper<XMenuDO> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||||
|
lambdaQueryWrapper.eq(XMenuDO::getStatus, 0);
|
||||||
|
lambdaQueryWrapper.in(XMenuDO::getMenuType, 'M', 'C');
|
||||||
|
lambdaQueryWrapper.orderByAsc(XMenuDO::getParentId, XMenuDO::getOrderNum);
|
||||||
|
xMenuDOS = menuMapper.selectList(lambdaQueryWrapper);
|
||||||
|
} else {
|
||||||
|
xMenuDOS = menuMapper.selectMenuTreeByUserId(userId);
|
||||||
|
}
|
||||||
|
return buildMenus(getChildPerms(menuConverter.toVoList(xMenuDOS), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RouterVo> buildMenus(List<MenuVO> menus) {
|
||||||
|
List<RouterVo> routers = new LinkedList<RouterVo>();
|
||||||
|
for (MenuVO menu : menus) {
|
||||||
|
RouterVo router = new RouterVo();
|
||||||
|
router.setHidden("1".equals(menu.getVisible()));
|
||||||
|
router.setName(getRouteName(menu));
|
||||||
|
router.setPath(getRouterPath(menu));
|
||||||
|
router.setComponent(getComponent(menu));
|
||||||
|
router.setQuery(menu.getQuery());
|
||||||
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
||||||
|
List<MenuVO> cMenus = menu.getChildren();
|
||||||
|
if (CollectionUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) {
|
||||||
|
router.setAlwaysShow(true);
|
||||||
|
router.setRedirect("noRedirect");
|
||||||
|
router.setChildren(buildMenus(cMenus));
|
||||||
|
} else if (isMenuFrame(menu)) {
|
||||||
|
router.setMeta(null);
|
||||||
|
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
||||||
|
RouterVo children = new RouterVo();
|
||||||
|
children.setPath(menu.getPath());
|
||||||
|
children.setComponent(menu.getComponent());
|
||||||
|
children.setName(getRouteName(menu.getRouteName(), menu.getPath()));
|
||||||
|
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
||||||
|
children.setQuery(menu.getQuery());
|
||||||
|
childrenList.add(children);
|
||||||
|
router.setChildren(childrenList);
|
||||||
|
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
||||||
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
||||||
|
router.setPath("/");
|
||||||
|
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
||||||
|
RouterVo children = new RouterVo();
|
||||||
|
String routerPath = innerLinkReplaceEach(menu.getPath());
|
||||||
|
children.setPath(routerPath);
|
||||||
|
children.setComponent(UserConstants.INNER_LINK);
|
||||||
|
children.setName(getRouteName(menu.getRouteName(), routerPath));
|
||||||
|
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
|
||||||
|
childrenList.add(children);
|
||||||
|
router.setChildren(childrenList);
|
||||||
|
}
|
||||||
|
routers.add(router);
|
||||||
|
}
|
||||||
|
return routers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRouteName(MenuVO menu) {
|
||||||
|
// 非外链并且是一级目录(类型为目录)
|
||||||
|
if (isMenuFrame(menu)) {
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
return getRouteName(menu.getRouteName(), menu.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取路由名称,如没有配置路由名称则取路由地址
|
||||||
|
*
|
||||||
|
* @param name 路由名称
|
||||||
|
* @param path 路由地址
|
||||||
|
* @return 路由名称(驼峰格式)
|
||||||
|
*/
|
||||||
|
public String getRouteName(String name, String path) {
|
||||||
|
String routerName = StringUtils.isNotEmpty(name) ? name : path;
|
||||||
|
return StringUtils.capitalize(routerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取路由地址
|
||||||
|
*
|
||||||
|
* @param menu 菜单信息
|
||||||
|
* @return 路由地址
|
||||||
|
*/
|
||||||
|
public String getRouterPath(MenuVO menu) {
|
||||||
|
String routerPath = menu.getPath();
|
||||||
|
// 内链打开外网方式
|
||||||
|
if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
|
||||||
|
routerPath = innerLinkReplaceEach(routerPath);
|
||||||
|
}
|
||||||
|
// 非外链并且是一级目录(类型为目录)
|
||||||
|
if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType())
|
||||||
|
&& UserConstants.NO_FRAME.equals(menu.getIsFrame())) {
|
||||||
|
routerPath = "/" + menu.getPath();
|
||||||
|
}
|
||||||
|
// 非外链并且是一级目录(类型为菜单)
|
||||||
|
else if (isMenuFrame(menu)) {
|
||||||
|
routerPath = "/";
|
||||||
|
}
|
||||||
|
return routerPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取组件信息
|
||||||
|
*
|
||||||
|
* @param menu 菜单信息
|
||||||
|
* @return 组件信息
|
||||||
|
*/
|
||||||
|
public String getComponent(MenuVO menu) {
|
||||||
|
String component = UserConstants.LAYOUT;
|
||||||
|
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
|
||||||
|
component = menu.getComponent();
|
||||||
|
} else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
|
||||||
|
component = UserConstants.INNER_LINK;
|
||||||
|
} else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
|
||||||
|
component = UserConstants.PARENT_VIEW;
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为菜单内部跳转
|
||||||
|
*
|
||||||
|
* @param menu 菜单信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public boolean isMenuFrame(MenuVO menu) {
|
||||||
|
return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
|
||||||
|
&& menu.getIsFrame().equals(UserConstants.NO_FRAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为内链组件
|
||||||
|
*
|
||||||
|
* @param menu 菜单信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public boolean isInnerLink(MenuVO menu) {
|
||||||
|
return menu.getIsFrame().equals(UserConstants.NO_FRAME) && MyStringUtils.isHttp(menu.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为parent_view组件
|
||||||
|
*
|
||||||
|
* @param menu 菜单信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public boolean isParentView(MenuVO menu) {
|
||||||
|
return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据父节点的ID获取所有子节点
|
||||||
|
*
|
||||||
|
* @param list 分类表
|
||||||
|
* @param parentId 传入的父节点ID
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public List<MenuVO> getChildPerms(List<MenuVO> list, int parentId) {
|
||||||
|
List<MenuVO> returnList = new ArrayList<MenuVO>();
|
||||||
|
for (Iterator<MenuVO> iterator = list.iterator(); iterator.hasNext(); ) {
|
||||||
|
MenuVO t = (MenuVO) iterator.next();
|
||||||
|
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||||
|
if (t.getParentId() == parentId) {
|
||||||
|
recursionFn(list, t);
|
||||||
|
returnList.add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归列表
|
||||||
|
*
|
||||||
|
* @param list 分类表
|
||||||
|
* @param t 子节点
|
||||||
|
*/
|
||||||
|
private void recursionFn(List<MenuVO> list, MenuVO t) {
|
||||||
|
// 得到子节点列表
|
||||||
|
List<MenuVO> childList = getChildList(list, t);
|
||||||
|
t.setChildren(childList);
|
||||||
|
for (MenuVO tChild : childList) {
|
||||||
|
if (hasChild(list, tChild)) {
|
||||||
|
recursionFn(list, tChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到子节点列表
|
||||||
|
*/
|
||||||
|
private List<MenuVO> getChildList(List<MenuVO> list, MenuVO t) {
|
||||||
|
List<MenuVO> tlist = new ArrayList<MenuVO>();
|
||||||
|
Iterator<MenuVO> it = list.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
MenuVO n = (MenuVO) it.next();
|
||||||
|
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
|
||||||
|
tlist.add(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有子节点
|
||||||
|
*/
|
||||||
|
private boolean hasChild(List<MenuVO> list, MenuVO t) {
|
||||||
|
return getChildList(list, t).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内链域名特殊字符替换
|
||||||
|
*
|
||||||
|
* @return 替换后的内链域名
|
||||||
|
*/
|
||||||
|
public String innerLinkReplaceEach(String path) {
|
||||||
|
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":"},
|
||||||
|
new String[]{"", "", "", "/", "/"});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +1,32 @@
|
|||||||
package com.xiang.xservice.auth.service.service.impl;
|
package com.xiang.xservice.auth.service.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
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.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;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.UserDTO;
|
import com.xiang.xservice.auth.api.dto.resp.UserDTO;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.UserResp;
|
import com.xiang.xservice.auth.api.dto.resp.UserResp;
|
||||||
|
import com.xiang.xservice.auth.service.constants.RedisConstant;
|
||||||
import com.xiang.xservice.auth.service.convert.XDeptConvert;
|
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;
|
||||||
@@ -37,25 +39,32 @@ import com.xiang.xservice.auth.service.repository.mapper.XUserRoleMapper;
|
|||||||
import com.xiang.xservice.auth.service.service.XUserService;
|
import com.xiang.xservice.auth.service.service.XUserService;
|
||||||
import com.xiang.xservice.basic.enums.DelStatusEnum;
|
import com.xiang.xservice.basic.enums.DelStatusEnum;
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
|
import com.xiang.xservice.basic.utils.PrimaryKeyUtils;
|
||||||
|
import com.xiang.xservice.basic.utils.RandomCodeUtils;
|
||||||
|
import com.xiang.xservice.basic.utils.SnowflakeIdGenerator;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.oauth2.jwt.Jwt;
|
||||||
import org.springframework.security.oauth2.jwt.JwtClaimsSet;
|
import org.springframework.security.oauth2.jwt.JwtClaimsSet;
|
||||||
|
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;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -77,6 +86,8 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
private final XRolePermissionMapper rolePermissionMapper;
|
private final XRolePermissionMapper rolePermissionMapper;
|
||||||
private final XPermissionMapper permissionMapper;
|
private final XPermissionMapper permissionMapper;
|
||||||
private final XPermissionConvert permissionConvert;
|
private final XPermissionConvert permissionConvert;
|
||||||
|
private final IRedisService redisService;
|
||||||
|
private final JwtDecoder jwtDecoder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginResp login(LoginRequest request) {
|
public LoginResp login(LoginRequest request) {
|
||||||
@@ -101,7 +112,23 @@ 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())) {
|
||||||
|
try {
|
||||||
|
Jwt jwt = jwtDecoder.decode(user.getToken());
|
||||||
|
if (Objects.nonNull(jwt.getExpiresAt())) {
|
||||||
|
if (jwt.getExpiresAt().isAfter(Instant.now())) {
|
||||||
|
LoginResp loginResp = new LoginResp();
|
||||||
|
loginResp.setToken(user.getToken());
|
||||||
|
loginResp.setUsername(request.getUsername());
|
||||||
|
loginResp.setRefreshToken(user.getRefreshToken());
|
||||||
|
return loginResp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("jwt解析token失败", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 生成 token
|
// 生成 token
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
@@ -118,34 +145,30 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
.claim("authorities", roleCodes)
|
.claim("authorities", roleCodes)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
JwtClaimsSet refreshClaims = JwtClaimsSet.builder()
|
||||||
|
// 对应 ProviderSettings.issuer
|
||||||
|
.issuedAt(now)
|
||||||
|
.expiresAt(now.plus(24, ChronoUnit.HOURS))
|
||||||
|
// 自定义 scope
|
||||||
|
.claim("tenantId", user.getTenantId())
|
||||||
|
.build();
|
||||||
|
|
||||||
// 2. 编码生成 token
|
// 2. 编码生成 token
|
||||||
String token = jwtEncoder.encode(JwtEncoderParameters.from(claims)).getTokenValue();
|
String token = jwtEncoder.encode(JwtEncoderParameters.from(claims)).getTokenValue();
|
||||||
|
String refreshToken = jwtEncoder.encode(JwtEncoderParameters.from(refreshClaims)).getTokenValue();
|
||||||
LoginResp loginResp = new LoginResp();
|
LoginResp loginResp = new LoginResp();
|
||||||
loginResp.setToken(token);
|
loginResp.setToken(token);
|
||||||
loginResp.setUsername(request.getUsername());
|
loginResp.setUsername(request.getUsername());
|
||||||
|
loginResp.setRefreshToken(refreshToken);
|
||||||
|
// 3. redis缓存token
|
||||||
|
redisService.set(RedisConstant.LOGIN_TOKEN + request.getUsername(), token, 3, TimeUnit.HOURS);
|
||||||
|
// 4. db 存储token
|
||||||
|
user.setToken(token);
|
||||||
|
user.setRefreshToken(refreshToken);
|
||||||
|
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 手机号验证码校验
|
||||||
@@ -166,8 +189,16 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
user.setCreateTime(LocalDateTime.now());
|
user.setCreateTime(LocalDateTime.now());
|
||||||
user.setUpdateBy("admin");
|
user.setUpdateBy("admin");
|
||||||
user.setUpdateTime(LocalDateTime.now());
|
user.setUpdateTime(LocalDateTime.now());
|
||||||
|
user.setUserType(2);
|
||||||
|
user.setTenantId(8000000000000000L + SnowflakeIdGenerator.of16(RandomCodeUtils.getRandomNumber(1)).nextId());
|
||||||
|
|
||||||
if (userMapper.insert(user) > 0) {
|
int i = 0;
|
||||||
|
try {
|
||||||
|
i = userMapper.insert(user);
|
||||||
|
} catch (DuplicateKeyException e) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.USER_EXISTS);
|
||||||
|
}
|
||||||
|
if (i > 0) {
|
||||||
RegisterResp registerResp = new RegisterResp();
|
RegisterResp registerResp = new RegisterResp();
|
||||||
registerResp.setName(user.getName());
|
registerResp.setName(user.getName());
|
||||||
registerResp.setUsername(user.getUsername());
|
registerResp.setUsername(user.getUsername());
|
||||||
@@ -179,12 +210,27 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserResp> getUserList(UserQueryRequest request) {
|
public Page<UserResp> getUserList(UserQueryRequest request) {
|
||||||
List<XUser> userList = userMapper.getUserList(userConvert.toDO(request));
|
Page<XUser> page = new Page<>(request.getCurrent(), request.getPageSize());
|
||||||
if (CollectionUtils.isEmpty(userList)) {
|
LambdaQueryWrapper<XUser> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||||
return Lists.newArrayList();
|
lambdaQueryWrapper.eq(XUser::getDelFlag, DelStatusEnum.NOT_DELETED.getCode());
|
||||||
|
if (StringUtils.isNotBlank(request.getName())) {
|
||||||
|
lambdaQueryWrapper.like(XUser::getName, request.getName());
|
||||||
}
|
}
|
||||||
return userConvert.toRespList(userList);
|
if (StringUtils.isNotBlank(request.getUsername())) {
|
||||||
|
lambdaQueryWrapper.eq(XUser::getUsername, request.getUsername());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(request.getEmail())) {
|
||||||
|
lambdaQueryWrapper.like(XUser::getEmail, request.getEmail());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(request.getPhone())) {
|
||||||
|
lambdaQueryWrapper.like(XUser::getPhone, request.getPhone());
|
||||||
|
}
|
||||||
|
if (Objects.nonNull(request.getStatus())) {
|
||||||
|
lambdaQueryWrapper.eq(XUser::getStatus, request.getStatus());
|
||||||
|
}
|
||||||
|
lambdaQueryWrapper.orderByDesc(XUser::getCreateTime);
|
||||||
|
return userConvert.toPage(userMapper.selectPage(page, lambdaQueryWrapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -196,6 +242,7 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean addUser(UserAddRequest request) {
|
public Boolean addUser(UserAddRequest request) {
|
||||||
XUser user = userConvert.toDO(request);
|
XUser user = userConvert.toDO(request);
|
||||||
|
user.setTenantId(PrimaryKeyUtils.snowflakeId());
|
||||||
user.setCreateBy(request.getOperator());
|
user.setCreateBy(request.getOperator());
|
||||||
user.setCreateTime(request.getDateTime());
|
user.setCreateTime(request.getDateTime());
|
||||||
user.setUpdateBy(request.getOperator());
|
user.setUpdateBy(request.getOperator());
|
||||||
@@ -210,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
|
||||||
@@ -219,62 +266,131 @@ public class XUserServiceImpl implements XUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
public UserDTO getUserDetail(String username) {
|
||||||
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
|
|
||||||
public UserDTO getUserDetail(Long userId) {
|
|
||||||
UserDTO dto = new UserDTO();
|
UserDTO dto = new UserDTO();
|
||||||
XUser user = userMapper.getUserById(userId);
|
XUser user = userMapper.selectByUsername(username);
|
||||||
if (Objects.isNull(user)) {
|
if (Objects.isNull(user)) {
|
||||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
dto.setUser(userConvert.toResp(user));
|
dto.setUser(userConvert.toResp(user));
|
||||||
List<XUserRole> userRoles = userRoleMapper.getByUserId(userId);
|
List<XUserRole> userRoles = userRoleMapper.getByUserId(user.getId());
|
||||||
List<Long> roleIds = userRoles.stream().map(XUserRole::getRoleId).toList();
|
List<Long> roleIds = userRoles.stream().map(XUserRole::getRoleId).toList();
|
||||||
List<XRole> roles = roleMapper.getRoleByIds(roleIds);
|
List<XRole> roles = roleMapper.getRoleByIds(roleIds);
|
||||||
if (CollectionUtils.isEmpty(roles)) {
|
if (CollectionUtils.isEmpty(roles)) {
|
||||||
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(userId);
|
// 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();
|
||||||
List<XPermission> permissions = permissionMapper.getPermissionByIds(permissionIds);
|
List<XPermission> permissions = permissionMapper.getPermissionByIds(permissionIds);
|
||||||
dto.setPermissionRoles(permissionConvert.toDTOList(permissions));
|
dto.setPermissionRoles(permissionConvert.toDTOList(permissions));
|
||||||
}
|
}
|
||||||
|
dto.setPermissions(Sets.newHashSet("*:*:*"));
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginResp refresh(RefreshRequest request) {
|
||||||
|
XUser user = userMapper.selectByUsername(request.getUsername());
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(user.getRefreshToken()) || !user.getRefreshToken().equals(request.getRefreshToken())) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.REFRESH_TOKEN_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
// 校验 refreshToken 是否过期
|
||||||
|
Jwt refreshJwt;
|
||||||
|
try {
|
||||||
|
refreshJwt = jwtDecoder.decode(request.getRefreshToken());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("【刷新token】refreshToken解析失败", e);
|
||||||
|
throw new BusinessException("refreshToken 无效或已过期");
|
||||||
|
}
|
||||||
|
if (Objects.isNull(refreshJwt.getExpiresAt()) || refreshJwt.getExpiresAt().isBefore(Instant.now())) {
|
||||||
|
throw new BusinessException("refreshToken 已过期,请重新登录");
|
||||||
|
}
|
||||||
|
// 查询角色
|
||||||
|
List<String> roleCodes = Lists.newArrayList();
|
||||||
|
List<XUserRole> userRoles = userRoleMapper.getByUserId(user.getId());
|
||||||
|
if (CollectionUtils.isNotEmpty(userRoles)) {
|
||||||
|
List<XRole> roles = roleMapper.getRoleByIds(userRoles.stream().map(XUserRole::getRoleId).collect(Collectors.toList()));
|
||||||
|
if (CollectionUtils.isNotEmpty(roles)) {
|
||||||
|
roleCodes.addAll(roles.stream().map(XRole::getRoleKey).toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 生成新的 accessToken
|
||||||
|
Instant now = Instant.now();
|
||||||
|
JwtClaimsSet claims = JwtClaimsSet.builder()
|
||||||
|
.issuedAt(now)
|
||||||
|
.expiresAt(now.plus(3, ChronoUnit.HOURS))
|
||||||
|
.claim("userId", user.getId())
|
||||||
|
.claim("tenantId", user.getTenantId())
|
||||||
|
.claim("timestamp", System.currentTimeMillis())
|
||||||
|
.claim("username", request.getUsername())
|
||||||
|
.claim("authorities", roleCodes)
|
||||||
|
.build();
|
||||||
|
String newToken = jwtEncoder.encode(JwtEncoderParameters.from(claims)).getTokenValue();
|
||||||
|
// 更新 Redis 和 DB
|
||||||
|
redisService.set(RedisConstant.LOGIN_TOKEN + request.getUsername(), newToken, 3, TimeUnit.HOURS);
|
||||||
|
user.setToken(newToken);
|
||||||
|
userMapper.updateById(user);
|
||||||
|
LoginResp loginResp = new LoginResp();
|
||||||
|
loginResp.setToken(newToken);
|
||||||
|
loginResp.setUsername(request.getUsername());
|
||||||
|
loginResp.setRefreshToken(request.getRefreshToken());
|
||||||
|
return loginResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateStatus(Long id, Integer status) {
|
||||||
|
XUser user = userMapper.getUserById(id);
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
user.setStatus(status);
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.xiang.xservice.auth.service.service.impl.captcha;
|
package com.xiang.xservice.auth.service.service.impl.captcha;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||||
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
|
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
|
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
|
||||||
import com.xiang.xservice.auth.service.constants.RedisConstant;
|
import com.xiang.xservice.auth.service.constants.RedisConstant;
|
||||||
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
|
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
|
||||||
import com.xiang.xservice.auth.service.service.ICaptchaService;
|
import com.xiang.xservice.auth.service.service.ICaptchaService;
|
||||||
import com.xiang.xservice.basic.utils.RandomCodeUtils;
|
import com.xiang.xservice.basic.utils.RandomCodeUtils;
|
||||||
import com.xiang.xservice.cache.service.IRedisService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.xiang.xservice.auth.service.service.impl.captcha;
|
package com.xiang.xservice.auth.service.service.impl.captcha;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||||
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
|
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
|
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
|
||||||
import com.xiang.xservice.auth.service.constants.RedisConstant;
|
import com.xiang.xservice.auth.service.constants.RedisConstant;
|
||||||
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
|
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
|
||||||
import com.xiang.xservice.auth.service.service.ICaptchaService;
|
import com.xiang.xservice.auth.service.service.ICaptchaService;
|
||||||
import com.xiang.xservice.basic.utils.RandomCodeUtils;
|
import com.xiang.xservice.basic.utils.RandomCodeUtils;
|
||||||
import com.xiang.xservice.cache.service.IRedisService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public class NumberCaptchaCode implements ICaptchaService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CaptchaDTO getCaptchaImage(CaptchaImageRequest request) {
|
public CaptchaDTO getCaptchaImage(CaptchaImageRequest request) {
|
||||||
String randomCode = RandomCodeUtils.getMixtureRandomCode(request.getNumber());
|
String randomCode = RandomCodeUtils.getNumberRandomCode(request.getNumber());
|
||||||
redisService.set(RedisConstant.XS_SMS_CODE_KEY + request.getUsername(), randomCode, 5, TimeUnit.MINUTES);
|
redisService.set(RedisConstant.XS_SMS_CODE_KEY + request.getUsername(), randomCode, 5, TimeUnit.MINUTES);
|
||||||
CaptchaDTO captchaDTO = new CaptchaDTO();
|
CaptchaDTO captchaDTO = new CaptchaDTO();
|
||||||
captchaDTO.setCaptchaImageCode(randomCode);
|
captchaDTO.setCaptchaImageCode(randomCode);
|
||||||
|
|||||||
@@ -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>
|
||||||
53
xs-service/src/main/resources/mapper/user/XMenuMapper.xml
Normal file
53
xs-service/src/main/resources/mapper/user/XMenuMapper.xml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XMenuMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.xiang.xservice.auth.service.entity.XMenuDO" id="SysMenuResult">
|
||||||
|
<id property="menuId" column="menu_id" />
|
||||||
|
<result property="menuName" column="menu_name" />
|
||||||
|
<result property="parentId" column="parent_id" />
|
||||||
|
<result property="orderNum" column="order_num" />
|
||||||
|
<result property="path" column="path" />
|
||||||
|
<result property="component" column="component" />
|
||||||
|
<result property="query" column="query" />
|
||||||
|
<result property="routeName" column="route_name" />
|
||||||
|
<result property="isFrame" column="is_frame" />
|
||||||
|
<result property="isCache" column="is_cache" />
|
||||||
|
<result property="menuType" column="menu_type" />
|
||||||
|
<result property="visible" column="visible" />
|
||||||
|
<result property="status" column="status" />
|
||||||
|
<result property="perms" column="perms" />
|
||||||
|
<result property="icon" column="icon" />
|
||||||
|
</resultMap>
|
||||||
|
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
|
||||||
|
select distinct m.menu_id,
|
||||||
|
m.parent_id,
|
||||||
|
m.menu_name,
|
||||||
|
m.path,
|
||||||
|
m.component,
|
||||||
|
m.`query`,
|
||||||
|
m.route_name,
|
||||||
|
m.visible,
|
||||||
|
m.status,
|
||||||
|
ifnull(m.perms, '') as perms,
|
||||||
|
m.is_frame,
|
||||||
|
m.is_cache,
|
||||||
|
m.menu_type,
|
||||||
|
m.icon,
|
||||||
|
m.order_num,
|
||||||
|
m.create_time
|
||||||
|
from sys_menu m
|
||||||
|
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 sys_role ro on ur.role_id = ro.id
|
||||||
|
left join x_user u on ur.user_id = u.id
|
||||||
|
where u.id = #{userId}
|
||||||
|
and m.menu_type in ('M', 'C')
|
||||||
|
and m.status = 0
|
||||||
|
AND ro.status = 0
|
||||||
|
order by m.parent_id, m.order_num
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -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>
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
<result column="update_by" property="updateBy" />
|
<result column="update_by" property="updateBy" />
|
||||||
<result column="update_time" property="updateTime" />
|
<result column="update_time" property="updateTime" />
|
||||||
<result column="tenant_id" property="tenantId"/>
|
<result column="tenant_id" property="tenantId"/>
|
||||||
|
<result column="token" property="token"/>
|
||||||
|
<result column="refresh_token" property="refreshToken"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
@@ -38,139 +40,17 @@
|
|||||||
create_time,
|
create_time,
|
||||||
update_by,
|
update_by,
|
||||||
update_time,
|
update_time,
|
||||||
tenant_id
|
tenant_id,
|
||||||
|
token,
|
||||||
|
refresh_token
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XUser">
|
<update id="del" >
|
||||||
INSERT INTO x_user
|
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
||||||
<if test="null != name and '' != name">
|
|
||||||
name,
|
|
||||||
</if>
|
|
||||||
<if test="null != username and '' != username">
|
|
||||||
username,
|
|
||||||
</if>
|
|
||||||
<if test="null != password and '' != password">
|
|
||||||
password,
|
|
||||||
</if>
|
|
||||||
<if test="null != email and '' != email">
|
|
||||||
email,
|
|
||||||
</if>
|
|
||||||
<if test="null != phone and '' != phone">
|
|
||||||
phone,
|
|
||||||
</if>
|
|
||||||
<if test="null != avatar and '' != avatar">
|
|
||||||
avatar,
|
|
||||||
</if>
|
|
||||||
<if test="null != loginIp and '' != loginIp">
|
|
||||||
login_ip,
|
|
||||||
</if>
|
|
||||||
<if test="null != loginDate ">
|
|
||||||
login_date,
|
|
||||||
</if>
|
|
||||||
<if test="null != delFlag ">
|
|
||||||
del_flag,
|
|
||||||
</if>
|
|
||||||
<if test="null != status ">
|
|
||||||
status,
|
|
||||||
</if>
|
|
||||||
<if test="null != createBy and '' != createBy">
|
|
||||||
create_by,
|
|
||||||
</if>
|
|
||||||
<if test="null != createTime ">
|
|
||||||
create_time,
|
|
||||||
</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">
|
|
||||||
update_by,
|
|
||||||
</if>
|
|
||||||
<if test="null != updateTime ">
|
|
||||||
update_time,
|
|
||||||
</if>
|
|
||||||
<if test="tenantId != null">
|
|
||||||
tenant_id
|
|
||||||
</if>
|
|
||||||
</trim>
|
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
||||||
<if test="null != name and '' != name">
|
|
||||||
#{name},
|
|
||||||
</if>
|
|
||||||
<if test="null != username and '' != username">
|
|
||||||
#{username},
|
|
||||||
</if>
|
|
||||||
<if test="null != password and '' != password">
|
|
||||||
#{password},
|
|
||||||
</if>
|
|
||||||
<if test="null != email and '' != email">
|
|
||||||
#{email},
|
|
||||||
</if>
|
|
||||||
<if test="null != phone and '' != phone">
|
|
||||||
#{phone},
|
|
||||||
</if>
|
|
||||||
<if test="null != avatar and '' != avatar">
|
|
||||||
#{avatar},
|
|
||||||
</if>
|
|
||||||
<if test="null != loginIp and '' != loginIp">
|
|
||||||
#{loginIp},
|
|
||||||
</if>
|
|
||||||
<if test="null != loginDate ">
|
|
||||||
#{loginDate},
|
|
||||||
</if>
|
|
||||||
<if test="null != delFlag ">
|
|
||||||
#{delFlag},
|
|
||||||
</if>
|
|
||||||
<if test="null != status ">
|
|
||||||
#{status},
|
|
||||||
</if>
|
|
||||||
<if test="null != createBy and '' != createBy">
|
|
||||||
#{createBy},
|
|
||||||
</if>
|
|
||||||
<if test="null != createTime ">
|
|
||||||
#{createTime},
|
|
||||||
</if>
|
|
||||||
<if test="null != updateBy and '' != updateBy">
|
|
||||||
#{updateBy},
|
|
||||||
</if>
|
|
||||||
<if test="null != updateTime ">
|
|
||||||
#{updateTime},
|
|
||||||
</if>
|
|
||||||
<if test="tenantId != null">
|
|
||||||
#{tenantId}
|
|
||||||
</if>
|
|
||||||
</trim>
|
|
||||||
</insert>
|
|
||||||
<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 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>
|
|
||||||
</set>
|
|
||||||
WHERE id = #{id}
|
|
||||||
</update>
|
|
||||||
<update id="deleteBatch">
|
<update id="deleteBatch">
|
||||||
update x_user set del_flag = 0, 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=",">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
@@ -179,7 +59,7 @@
|
|||||||
<select id="selectByUsername" resultMap="BaseResultMap">
|
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||||
select <include refid="Base_Column_List"/>
|
select <include refid="Base_Column_List"/>
|
||||||
from x_user
|
from x_user
|
||||||
where username = #{username} and del_flag = 0 and status = 1
|
where username = #{username} and del_flag = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getUserList" resultMap="BaseResultMap">
|
<select id="getUserList" resultMap="BaseResultMap">
|
||||||
|
|||||||
@@ -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