Compare commits
3 Commits
master
...
feat/commo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8583ddcb25 | ||
|
|
fce3ed71f4 | ||
|
|
a89b71fe80 |
4
pom.xml
4
pom.xml
@@ -27,10 +27,6 @@
|
|||||||
<spring.boot.version>2.7.18</spring.boot.version>
|
<spring.boot.version>2.7.18</spring.boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 系统二方包 -->
|
<!-- 系统二方包 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.xiang.xs.api.client;
|
|
||||||
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
|
|
||||||
@FeignClient(name = "xservice-auth-center", fallback = TokenApiFallback.class)
|
|
||||||
public interface TokenApi {
|
|
||||||
|
|
||||||
@GetMapping("/private/user/getUserId/{token}")
|
|
||||||
Long getUserId(@PathVariable("token") String token);
|
|
||||||
|
|
||||||
@GetMapping("/private/user/getTenantId/{token}")
|
|
||||||
Long getTenantId(@PathVariable("token") String token);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.xiang.xs.api.client;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class TokenApiFallback implements TokenApi {
|
|
||||||
@Override
|
|
||||||
public Long getUserId(String token) {
|
|
||||||
log.warn("[rpc] 请求auth center 获取userId 异常, time:{}", System.currentTimeMillis());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long getTenantId(String token) {
|
|
||||||
log.warn("[rpc] 请求auth center tenantId 异常, time:{}", System.currentTimeMillis());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.xiang.xs.api.code;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.exception.code.BaseErrorCode;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum Code01UserErrorCode implements BaseErrorCode {
|
||||||
|
|
||||||
|
USER_NOT_EXISTS("A1000101", "用户不存在"),
|
||||||
|
USER_EXISTS("A1000102", "用户已存在"),
|
||||||
|
USER_LOGIN_ERROR("A1000103", "用户登录失败!"),
|
||||||
|
USER_REGISTER_ERROR("1000104", "用户注册失败!"),
|
||||||
|
REFRESH_TOKEN_NOT_EXISTS("1000105", "refreshToken不匹配"),
|
||||||
|
TOKEN_NOT_VALID("1000106", "token校验失败"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.xiang.xs.api.code;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.exception.code.BaseErrorCode;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:27
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum Code02RoleErrorCode implements BaseErrorCode {
|
||||||
|
|
||||||
|
ROLE_NOT_EXISTS("A1000201", "角色不存在"),
|
||||||
|
USER_ROLE_NOT_EXISTS("A1000202", "用户角色权限不存在!")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xiang.xs.api.code;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.exception.code.BaseErrorCode;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:27
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum Code03DeptErrorCode implements BaseErrorCode {
|
||||||
|
|
||||||
|
DEPT_NOT_EXISTS("A1000301", "部门不存在"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PermissionRegisterRequest {
|
||||||
|
|
||||||
|
private String serviceName;
|
||||||
|
/**
|
||||||
|
* 类名+方法名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 服务名称+方法+接口地址
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
/**
|
||||||
|
* 接口地址
|
||||||
|
*/
|
||||||
|
private String apiPath;
|
||||||
|
/**
|
||||||
|
* 请求方式
|
||||||
|
*/
|
||||||
|
private String method;
|
||||||
|
/**
|
||||||
|
* 类型 接口为3
|
||||||
|
*/
|
||||||
|
private Integer type = 3; // 接口
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Email;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RegisterRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(昵称)
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "用户名(昵称)不能为空")
|
||||||
|
@Size(min = 0, max = 20, message = "用户名长度不能超过20")
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "用户名不能为空")
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "密码不能为空")
|
||||||
|
@Size(min = 6, max = 18, message = "密码长度需要在6-18位")
|
||||||
|
private String password;
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
@Email(message = "邮箱验证不能通过")
|
||||||
|
private String email;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "手机号码不能为空")
|
||||||
|
@Size(min = 11, max = 11, message = "手机号码长度验证失败")
|
||||||
|
private String phone;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "验证码不能为空")
|
||||||
|
private String code;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.user;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserAddRequest extends BaseRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(昵称)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态(0:禁用, 1:启用)
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.user;
|
||||||
|
|
||||||
|
public class UserDeptUpdateRequest {
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.user;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserQueryRequest extends BaseRequest {
|
||||||
|
/**
|
||||||
|
* 用户名(昵称)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态(0:禁用, 1:启用)
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.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,22 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.user;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserRoleUpdateRequest {
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色id集合
|
||||||
|
*/
|
||||||
|
private List<Long> roleIds;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.user;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserUpdateRequest extends UserAddRequest {
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.xiang.xs.api.pojo.request.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserUpdateStatusRequest {
|
||||||
|
@NotNull(message = "id不能为空")
|
||||||
|
private Long id;
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
103
xs-api/src/main/java/com/xiang/xs/api/pojo/resp/MenuVO.java
Normal file
103
xs-api/src/main/java/com/xiang/xs/api/pojo/resp/MenuVO.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package com.xiang.xs.api.pojo.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,29 @@
|
|||||||
|
package com.xiang.xs.api.pojo.resp;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RegisterResp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(昵称)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.xiang.xs.api.pojo.resp;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserResp {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(昵称)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后登陆ip
|
||||||
|
*/
|
||||||
|
private String loginIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后登陆时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime loginDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态(0:禁用, 1:启用)
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户id
|
||||||
|
*/
|
||||||
|
private Long tenantId;
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = "com.xiang.xs")
|
@SpringBootApplication(scanBasePackages = "com.xiang.xs")
|
||||||
@EnableFeignClients
|
@EnableFeignClients(basePackages = "com.xiang.xs.api")
|
||||||
@MapperScan("com.xiang.xs.service.repository.mapper")
|
@MapperScan("com.xiang.xs.service.repository.mapper")
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ public class SysDeptController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping(value = "/{deptId}")
|
@GetMapping(value = "/{deptId}")
|
||||||
public Result<SysDept> getInfo(@PathVariable Long deptId, HttpServletRequest request) {
|
public Result<SysDept> getInfo(@PathVariable Long deptId, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
deptService.checkDeptDataScope(deptId, token);
|
deptService.checkDeptDataScope(deptId, Long.parseLong(userId));
|
||||||
return Result.data(deptService.selectDeptById(deptId));
|
return Result.data(deptService.selectDeptById(deptId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,8 @@ public class SysDeptController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public Result<Boolean> edit(@Validated @RequestBody SysDept dept, HttpServletRequest request) {
|
public Result<Boolean> edit(@Validated @RequestBody SysDept dept, HttpServletRequest request) {
|
||||||
Long deptId = dept.getDeptId();
|
Long deptId = dept.getDeptId();
|
||||||
deptService.checkDeptDataScope(deptId, getToken(request));
|
String userId = request.getHeader("X-User-Id");
|
||||||
|
deptService.checkDeptDataScope(deptId, Long.parseLong(userId));
|
||||||
if (!deptService.checkDeptNameUnique(dept)) {
|
if (!deptService.checkDeptNameUnique(dept)) {
|
||||||
return Result.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
return Result.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||||
} else if (dept.getParentId().equals(deptId)) {
|
} else if (dept.getParentId().equals(deptId)) {
|
||||||
@@ -100,7 +101,8 @@ public class SysDeptController {
|
|||||||
if (deptService.checkDeptExistUser(deptId)) {
|
if (deptService.checkDeptExistUser(deptId)) {
|
||||||
return Result.error("部门存在用户,不允许删除");
|
return Result.error("部门存在用户,不允许删除");
|
||||||
}
|
}
|
||||||
deptService.checkDeptDataScope(deptId, token);
|
String userId = request.getHeader("X-User-Id");
|
||||||
|
deptService.checkDeptDataScope(deptId, Long.parseLong(userId));
|
||||||
return Result.data(deptService.deleteDeptById(deptId) > 0);
|
return Result.data(deptService.deleteDeptById(deptId) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.xiang.xs.server.controller;
|
package com.xiang.xs.server.controller;
|
||||||
|
|
||||||
import com.xiang.xs.api.client.TokenApi;
|
|
||||||
import com.xiang.xs.service.biz.ISysMenuService;
|
import com.xiang.xs.service.biz.ISysMenuService;
|
||||||
import com.xiang.xs.service.contants.UserConstants;
|
import com.xiang.xs.service.contants.UserConstants;
|
||||||
import com.xiang.xs.service.entity.SysMenu;
|
import com.xiang.xs.service.entity.SysMenu;
|
||||||
import com.xiang.xs.service.entity.TreeSelect;
|
import com.xiang.xs.service.entity.TreeSelect;
|
||||||
import com.xiang.xs.service.entity.vo.RoleTreeVo;
|
import com.xiang.xs.service.entity.vo.RoleTreeVo;
|
||||||
|
import com.xiang.xs.service.entity.vo.RouterVo;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import com.xiang.xservice.basic.utils.MyStringUtils;
|
import com.xiang.xservice.basic.utils.MyStringUtils;
|
||||||
import lombok.extern.java.Log;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
@@ -18,6 +17,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -33,16 +33,14 @@ import java.util.List;
|
|||||||
public class SysMenuController {
|
public class SysMenuController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysMenuService menuService;
|
private ISysMenuService menuService;
|
||||||
@Autowired
|
|
||||||
private TokenApi tokenApi;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单列表
|
* 获取菜单列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Result<List<SysMenu>> list(SysMenu menu, HttpServletRequest request) {
|
public Result<List<SysMenu>> list(SysMenu menu, HttpServletRequest request) {
|
||||||
Long userId = tokenApi.getUserId(request.getHeader("Authorization"));
|
String userId = request.getHeader("X-User_id");
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
List<SysMenu> menus = menuService.selectMenuList(menu, Long.parseLong(userId));
|
||||||
return Result.data(menus);
|
return Result.data(menus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +57,8 @@ public class SysMenuController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public Result<List<TreeSelect>> treeselect(SysMenu menu, HttpServletRequest request) {
|
public Result<List<TreeSelect>> treeselect(SysMenu menu, HttpServletRequest request) {
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, tokenApi.getUserId(request.getHeader("Authorization")));
|
String userId = request.getHeader("X-User_id");
|
||||||
|
List<SysMenu> menus = menuService.selectMenuList(menu, Long.parseLong(userId));
|
||||||
return Result.data(menuService.buildMenuTreeSelect(menus));
|
return Result.data(menuService.buildMenuTreeSelect(menus));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +67,8 @@ public class SysMenuController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||||
public Result<RoleTreeVo> roleMenuTreeselect(@PathVariable("roleId") Long roleId, HttpServletRequest request) {
|
public Result<RoleTreeVo> roleMenuTreeselect(@PathVariable("roleId") Long roleId, HttpServletRequest request) {
|
||||||
List<SysMenu> menus = menuService.selectMenuList(tokenApi.getUserId(request.getHeader("Authorization")));
|
String userId = request.getHeader("X-User_id");
|
||||||
|
List<SysMenu> menus = menuService.selectMenuList(Long.parseLong(userId));
|
||||||
return Result.data(new RoleTreeVo(menuService.selectMenuListByRoleId(roleId), menuService.buildMenuTreeSelect(menus)));
|
return Result.data(new RoleTreeVo(menuService.selectMenuListByRoleId(roleId), menuService.buildMenuTreeSelect(menus)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,4 +113,9 @@ public class SysMenuController {
|
|||||||
}
|
}
|
||||||
return Result.data(menuService.deleteMenuById(menuId) > 0);
|
return Result.data(menuService.deleteMenuById(menuId) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/private/menu/getRouter")
|
||||||
|
public Result<List<RouterVo>> getRouter(@RequestParam("userId") Long userId) {
|
||||||
|
return Result.data(menuService.getRouter(userId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,8 @@ public class SysRoleController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping(value = "/{roleId}")
|
@GetMapping(value = "/{roleId}")
|
||||||
public Result<SysRole> getInfo(@PathVariable Long roleId, HttpServletRequest request) {
|
public Result<SysRole> getInfo(@PathVariable Long roleId, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
roleService.checkRoleDataScope(token, roleId);
|
roleService.checkRoleDataScope(Long.parseLong(userId), roleId);
|
||||||
return Result.data(roleService.selectRoleById(roleId));
|
return Result.data(roleService.selectRoleById(roleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,9 +75,9 @@ public class SysRoleController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public Result<Boolean> edit(@Validated @RequestBody SysRole role, HttpServletRequest request) {
|
public Result<Boolean> edit(@Validated @RequestBody SysRole role, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
roleService.checkRoleDataScope(token, role.getRoleId());
|
roleService.checkRoleDataScope(Long.parseLong(userId), role.getRoleId());
|
||||||
if (!roleService.checkRoleNameUnique(role)) {
|
if (!roleService.checkRoleNameUnique(role)) {
|
||||||
return Result.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
return Result.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||||
} else if (!roleService.checkRoleKeyUnique(role)) {
|
} else if (!roleService.checkRoleKeyUnique(role)) {
|
||||||
@@ -92,9 +92,9 @@ public class SysRoleController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/dataScope")
|
@PutMapping("/dataScope")
|
||||||
public Result<Boolean> dataScope(@RequestBody SysRole role, HttpServletRequest request) {
|
public Result<Boolean> dataScope(@RequestBody SysRole role, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
roleService.checkRoleDataScope(token, role.getRoleId());
|
roleService.checkRoleDataScope(Long.parseLong(userId), role.getRoleId());
|
||||||
return Result.data(roleService.authDataScope(role) > 0);
|
return Result.data(roleService.authDataScope(role) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +103,9 @@ public class SysRoleController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/changeStatus")
|
@PutMapping("/changeStatus")
|
||||||
public Result<Boolean> changeStatus(@RequestBody SysRole role, HttpServletRequest request) {
|
public Result<Boolean> changeStatus(@RequestBody SysRole role, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
roleService.checkRoleDataScope(token, role.getRoleId());
|
roleService.checkRoleDataScope(Long.parseLong(userId), role.getRoleId());
|
||||||
return Result.data(roleService.updateRoleStatus(role) > 0);
|
return Result.data(roleService.updateRoleStatus(role) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +114,8 @@ public class SysRoleController {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping("/{roleIds}")
|
@DeleteMapping("/{roleIds}")
|
||||||
public Result<Boolean> remove(@PathVariable Long[] roleIds, HttpServletRequest request) {
|
public Result<Boolean> remove(@PathVariable Long[] roleIds, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
return Result.data(roleService.deleteRoleByIds(token, roleIds) > 0);
|
return Result.data(roleService.deleteRoleByIds(Long.parseLong(userId), roleIds) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,8 +165,8 @@ public class SysRoleController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/authUser/selectAll")
|
@PutMapping("/authUser/selectAll")
|
||||||
public Result<Boolean> selectAuthUserAll(Long roleId, Long[] userIds, HttpServletRequest request) {
|
public Result<Boolean> selectAuthUserAll(Long roleId, Long[] userIds, HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String userId = request.getHeader("X-User-Id");
|
||||||
roleService.checkRoleDataScope(token, roleId);
|
roleService.checkRoleDataScope(Long.parseLong(userId), roleId);
|
||||||
return Result.data(roleService.insertAuthUsers(roleId, userIds) > 0);
|
return Result.data(roleService.insertAuthUsers(roleId, userIds) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.xiang.xs.server.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xiang.xs.service.biz.ISysDeptService;
|
||||||
|
import com.xiang.xs.service.biz.ISysRoleService;
|
||||||
|
import com.xiang.xs.service.biz.ISysUserService;
|
||||||
|
import com.xiang.xs.service.entity.SysDept;
|
||||||
|
import com.xiang.xs.service.entity.SysRole;
|
||||||
|
import com.xiang.xs.service.entity.SysUser;
|
||||||
|
import com.xiang.xs.service.entity.TreeSelect;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/user")
|
||||||
|
public class SysUserController {
|
||||||
|
@Autowired
|
||||||
|
private ISysUserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysRoleService roleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysDeptService deptService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户编号获取授权角色
|
||||||
|
*/
|
||||||
|
@GetMapping("/authRole/{userId}")
|
||||||
|
public Result<JSONObject> authRole(@PathVariable("userId") Long userId) {
|
||||||
|
JSONObject ajax = new JSONObject();
|
||||||
|
SysUser user = userService.selectUserById(userId);
|
||||||
|
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
||||||
|
ajax.put("user", user);
|
||||||
|
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
||||||
|
return Result.data(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户授权角色
|
||||||
|
*/
|
||||||
|
@PutMapping("/authRole")
|
||||||
|
public Result<Void> insertAuthRole(Long userId, Long[] roleIds) {
|
||||||
|
userService.checkUserDataScope(userId);
|
||||||
|
roleService.checkRoleDataScope(userId, roleIds);
|
||||||
|
userService.insertUserAuth(userId, roleIds);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门树列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/deptTree")
|
||||||
|
public Result<List<TreeSelect>> deptTree(SysDept dept) {
|
||||||
|
return Result.data(deptService.selectDeptTreeList(dept));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package com.xiang.xs.server.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserAddRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserQueryRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserResetPwdRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserUpdateRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserUpdateStatusRequest;
|
||||||
|
import com.xiang.xs.api.pojo.resp.UserResp;
|
||||||
|
import com.xiang.xs.service.biz.XUserService;
|
||||||
|
import com.xiang.xs.service.entity.vo.UserDTO;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
private final XUserService userService;
|
||||||
|
|
||||||
|
@PostMapping("/private/user/list")
|
||||||
|
public Result<Page<UserResp>> getUserList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||||
|
return Result.data(userService.getUserList(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/private/user/info/{id}")
|
||||||
|
public Result<UserResp> getUserById(@PathVariable("id") Long id) {
|
||||||
|
return Result.data(userService.getUserInfo(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/private/user/add")
|
||||||
|
public Result<Boolean> addUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserAddRequest request) {
|
||||||
|
try {
|
||||||
|
return Result.data(userService.addUser(request));
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
log.error("用户新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("用户新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||||
|
}
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
@PostMapping("/private/user/updateStatus")
|
||||||
|
public Result<Boolean> updateStatus(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateStatusRequest request) {
|
||||||
|
return Result.data(userService.updateStatus(request.getId(), request.getStatus()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/private/user/update")
|
||||||
|
public Result<Boolean> updateUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateRequest request) {
|
||||||
|
try {
|
||||||
|
return Result.data(userService.updateUser(request));
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
log.error("用户编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("用户编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||||
|
}
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/private/user/del")
|
||||||
|
public Result<Boolean> delUser(@RequestBody @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||||
|
try {
|
||||||
|
return Result.data(userService.delUser(ids));
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
log.error("用户删除异常,请求:{}", JSON.toJSONString(ids), e);
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("用户删除异常,请求:{}", JSON.toJSONString(ids), e);
|
||||||
|
}
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/private/user/resetUserPwd")
|
||||||
|
public Result<Boolean> resetPwd(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserResetPwdRequest request) {
|
||||||
|
return Result.data(userService.resetPwd(request.getUserId(), request.getPassword()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/private/auth/getInfo")
|
||||||
|
public Result<UserDTO> getUserInfo(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||||
|
return Result.data(userService.getUserDetail(request.getUsername()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,9 +11,26 @@ spring:
|
|||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
headless: true
|
headless: true
|
||||||
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
retry:
|
||||||
|
enabled: false
|
||||||
|
cache:
|
||||||
|
enabled: true
|
||||||
|
cache:
|
||||||
|
type: caffeine
|
||||||
|
caffeine:
|
||||||
|
spec: initialCapacity=100,maximumSize=1000,expireAfterWrite=30s
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
- classpath*:mapper/*/*.xml
|
- classpath*:mapper/*/*.xml
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
|
|
||||||
|
feign:
|
||||||
|
client:
|
||||||
|
config:
|
||||||
|
default:
|
||||||
|
connectTimeout: 1000
|
||||||
|
readTimeout: 3000
|
||||||
@@ -107,7 +107,7 @@ public interface ISysDeptService {
|
|||||||
*
|
*
|
||||||
* @param deptId 部门id
|
* @param deptId 部门id
|
||||||
*/
|
*/
|
||||||
void checkDeptDataScope(Long deptId, String token);
|
void checkDeptDataScope(Long deptId, Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增保存部门信息
|
* 新增保存部门信息
|
||||||
|
|||||||
@@ -158,4 +158,6 @@ public interface ISysMenuService {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
boolean checkMenuNameUnique(SysMenu menu);
|
boolean checkMenuNameUnique(SysMenu menu);
|
||||||
|
|
||||||
|
List<RouterVo> getRouter(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public interface ISysRoleService {
|
|||||||
*
|
*
|
||||||
* @param roleIds 角色id
|
* @param roleIds 角色id
|
||||||
*/
|
*/
|
||||||
void checkRoleDataScope(String token, Long... roleIds);
|
void checkRoleDataScope(Long userId, Long... roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过角色ID查询角色使用数量
|
* 通过角色ID查询角色使用数量
|
||||||
@@ -158,7 +158,7 @@ public interface ISysRoleService {
|
|||||||
*
|
*
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
int deleteRoleByIds(String token, Long[] roleIds);
|
int deleteRoleByIds(Long userId, Long[] roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消授权用户角色
|
* 取消授权用户角色
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.xiang.xs.service.biz;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.xiang.xs.api.pojo.request.LoginRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.RegisterRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserAddRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserQueryRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserUpdateRequest;
|
||||||
|
import com.xiang.xs.api.pojo.resp.LoginResp;
|
||||||
|
import com.xiang.xs.api.pojo.resp.RegisterResp;
|
||||||
|
import com.xiang.xs.api.pojo.resp.UserResp;
|
||||||
|
import com.xiang.xs.service.entity.vo.UserDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface XUserService {
|
||||||
|
|
||||||
|
RegisterResp userRegister(RegisterRequest request);
|
||||||
|
Page<UserResp> getUserList(UserQueryRequest request);
|
||||||
|
UserResp getUserInfo(Long id);
|
||||||
|
Boolean addUser(UserAddRequest request);
|
||||||
|
Boolean updateUser(UserUpdateRequest request);
|
||||||
|
Boolean delUser(List<Long> ids);
|
||||||
|
UserDTO getUserDetail(String username);
|
||||||
|
Boolean updateStatus(Long id, Integer status);
|
||||||
|
Boolean resetPwd(Long userId, String password);
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.xiang.xs.service.biz.impl;
|
package com.xiang.xs.service.biz.impl;
|
||||||
|
|
||||||
import com.xiang.xs.api.client.TokenApi;
|
|
||||||
import com.xiang.xs.service.biz.ISysDeptService;
|
import com.xiang.xs.service.biz.ISysDeptService;
|
||||||
import com.xiang.xs.service.contants.UserConstants;
|
import com.xiang.xs.service.contants.UserConstants;
|
||||||
import com.xiang.xs.service.entity.SysDept;
|
import com.xiang.xs.service.entity.SysDept;
|
||||||
@@ -35,9 +34,6 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleMapper roleMapper;
|
private SysRoleMapper roleMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TokenApi tokenApi;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门管理数据
|
* 查询部门管理数据
|
||||||
*
|
*
|
||||||
@@ -186,8 +182,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||||||
* @param deptId 部门id
|
* @param deptId 部门id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkDeptDataScope(Long deptId, String token) {
|
public void checkDeptDataScope(Long deptId, Long userId) {
|
||||||
if (!SysUser.isAdmin(tokenApi.getUserId(token)) && Objects.nonNull(deptId)) {
|
|
||||||
|
if (!SysUser.isAdmin(userId) && Objects.nonNull(deptId)) {
|
||||||
SysDept dept = new SysDept();
|
SysDept dept = new SysDept();
|
||||||
dept.setDeptId(deptId);
|
dept.setDeptId(deptId);
|
||||||
List<SysDept> depts = selectDeptList(dept);
|
List<SysDept> depts = selectDeptList(dept);
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.xiang.xs.service.biz.impl;
|
package com.xiang.xs.service.biz.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.xs.service.biz.ISysMenuService;
|
import com.xiang.xs.service.biz.ISysMenuService;
|
||||||
import com.xiang.xs.service.contants.Constants;
|
import com.xiang.xs.service.contants.Constants;
|
||||||
import com.xiang.xs.service.contants.UserConstants;
|
import com.xiang.xs.service.contants.UserConstants;
|
||||||
|
import com.xiang.xs.service.converter.XMenuConverter;
|
||||||
import com.xiang.xs.service.entity.SysMenu;
|
import com.xiang.xs.service.entity.SysMenu;
|
||||||
import com.xiang.xs.service.entity.SysRole;
|
import com.xiang.xs.service.entity.SysRole;
|
||||||
import com.xiang.xs.service.entity.SysUser;
|
import com.xiang.xs.service.entity.SysUser;
|
||||||
@@ -46,6 +50,9 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleMenuMapper roleMenuMapper;
|
private SysRoleMenuMapper roleMenuMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private XMenuConverter menuConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户查询系统菜单列表
|
* 根据用户查询系统菜单列表
|
||||||
*
|
*
|
||||||
@@ -328,6 +335,22 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
return UserConstants.UNIQUE;
|
return UserConstants.UNIQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RouterVo> getRouter(Long userId) {
|
||||||
|
List<SysMenu> xMenuDOS = Lists.newArrayList();
|
||||||
|
// 超级管理员 admin
|
||||||
|
if (Objects.equals(userId, 1L)) {
|
||||||
|
LambdaQueryWrapper<SysMenu> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||||
|
lambdaQueryWrapper.eq(SysMenu::getStatus, 0);
|
||||||
|
lambdaQueryWrapper.in(SysMenu::getMenuType, 'M', 'C');
|
||||||
|
lambdaQueryWrapper.orderByAsc(SysMenu::getParentId, SysMenu::getOrderNum);
|
||||||
|
xMenuDOS = menuMapper.selectList(lambdaQueryWrapper);
|
||||||
|
} else {
|
||||||
|
xMenuDOS = menuMapper.selectMenuTreeByUserId(userId);
|
||||||
|
}
|
||||||
|
return buildMenus(getChildPerms(xMenuDOS, 0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取路由名称
|
* 获取路由名称
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.xiang.xs.service.biz.impl;
|
package com.xiang.xs.service.biz.impl;
|
||||||
|
|
||||||
import com.xiang.xs.api.client.TokenApi;
|
|
||||||
import com.xiang.xs.service.biz.ISysRoleService;
|
import com.xiang.xs.service.biz.ISysRoleService;
|
||||||
import com.xiang.xs.service.contants.UserConstants;
|
import com.xiang.xs.service.contants.UserConstants;
|
||||||
import com.xiang.xs.service.entity.SysRole;
|
import com.xiang.xs.service.entity.SysRole;
|
||||||
@@ -12,7 +11,6 @@ import com.xiang.xs.service.repository.mapper.SysRoleDeptMapper;
|
|||||||
import com.xiang.xs.service.repository.mapper.SysRoleMapper;
|
import com.xiang.xs.service.repository.mapper.SysRoleMapper;
|
||||||
import com.xiang.xs.service.repository.mapper.SysRoleMenuMapper;
|
import com.xiang.xs.service.repository.mapper.SysRoleMenuMapper;
|
||||||
import com.xiang.xs.service.repository.mapper.SysUserRoleMapper;
|
import com.xiang.xs.service.repository.mapper.SysUserRoleMapper;
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -44,9 +42,6 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleDeptMapper roleDeptMapper;
|
private SysRoleDeptMapper roleDeptMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TokenApi tokenApi;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询角色数据
|
* 根据条件分页查询角色数据
|
||||||
*
|
*
|
||||||
@@ -186,9 +181,9 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||||||
* @param roleIds 角色id
|
* @param roleIds 角色id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkRoleDataScope(String token, Long... roleIds) {
|
public void checkRoleDataScope(Long userId, Long... roleIds) {
|
||||||
|
|
||||||
if (!SysUser.isAdmin(tokenApi.getUserId(token))) {
|
if (!SysUser.isAdmin(userId)) {
|
||||||
for (Long roleId : roleIds) {
|
for (Long roleId : roleIds) {
|
||||||
SysRole role = new SysRole();
|
SysRole role = new SysRole();
|
||||||
role.setRoleId(roleId);
|
role.setRoleId(roleId);
|
||||||
@@ -342,10 +337,10 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public int deleteRoleByIds(String token, Long[] roleIds) {
|
public int deleteRoleByIds(Long userId, Long[] roleIds) {
|
||||||
for (Long roleId : roleIds) {
|
for (Long roleId : roleIds) {
|
||||||
checkRoleAllowed(new SysRole(roleId));
|
checkRoleAllowed(new SysRole(roleId));
|
||||||
checkRoleDataScope(token, roleId);
|
checkRoleDataScope(userId, roleId);
|
||||||
SysRole role = selectRoleById(roleId);
|
SysRole role = selectRoleById(roleId);
|
||||||
if (countUserRoleByRoleId(roleId) > 0) {
|
if (countUserRoleByRoleId(roleId) > 0) {
|
||||||
throw new com.xiang.xservice.basic.exception.BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName()));
|
throw new com.xiang.xservice.basic.exception.BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName()));
|
||||||
|
|||||||
@@ -0,0 +1,191 @@
|
|||||||
|
package com.xiang.xs.service.biz.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.Sets;
|
||||||
|
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||||
|
import com.xiang.xs.api.code.Code01UserErrorCode;
|
||||||
|
import com.xiang.xs.api.code.Code02RoleErrorCode;
|
||||||
|
import com.xiang.xs.api.code.Code03DeptErrorCode;
|
||||||
|
import com.xiang.xs.api.pojo.request.RegisterRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserAddRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserQueryRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserUpdateRequest;
|
||||||
|
import com.xiang.xs.api.pojo.resp.RegisterResp;
|
||||||
|
import com.xiang.xs.api.pojo.resp.UserResp;
|
||||||
|
import com.xiang.xs.service.biz.XUserService;
|
||||||
|
import com.xiang.xs.service.converter.XUserConvert;
|
||||||
|
import com.xiang.xs.service.entity.SysRole;
|
||||||
|
import com.xiang.xs.service.entity.SysUserRole;
|
||||||
|
import com.xiang.xs.service.entity.XUser;
|
||||||
|
import com.xiang.xs.service.entity.vo.UserDTO;
|
||||||
|
import com.xiang.xs.service.enums.UserStatusEnum;
|
||||||
|
import com.xiang.xs.service.repository.mapper.SysDeptMapper;
|
||||||
|
import com.xiang.xs.service.repository.mapper.SysRoleMapper;
|
||||||
|
import com.xiang.xs.service.repository.mapper.SysUserRoleMapper;
|
||||||
|
import com.xiang.xs.service.repository.mapper.XUserMapper;
|
||||||
|
import com.xiang.xservice.basic.enums.DelStatusEnum;
|
||||||
|
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.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class XUserServiceImpl implements XUserService {
|
||||||
|
|
||||||
|
private final XUserMapper userMapper;
|
||||||
|
private final XUserConvert userConvert;
|
||||||
|
private final SysRoleMapper roleMapper;
|
||||||
|
private final SysUserRoleMapper userRoleMapper;
|
||||||
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RegisterResp userRegister(RegisterRequest request) {
|
||||||
|
// todo 手机号验证码校验
|
||||||
|
XUser user = userMapper.selectByUsername(request.getUsername());
|
||||||
|
if (Objects.nonNull(user)) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.USER_EXISTS);
|
||||||
|
}
|
||||||
|
user = new XUser();
|
||||||
|
user.setName(request.getName());
|
||||||
|
user.setUsername(request.getUsername());
|
||||||
|
user.setPassword(passwordEncoder.encode(request.getPassword()));
|
||||||
|
user.setEmail(request.getEmail());
|
||||||
|
user.setPhone(request.getPhone());
|
||||||
|
user.setAvatar(request.getAvatar());
|
||||||
|
user.setStatus(UserStatusEnum.USING.getCode());
|
||||||
|
user.setDelFlag(DelStatusEnum.NOT_DELETED.getCode());
|
||||||
|
user.setCreateBy("admin");
|
||||||
|
user.setCreateTime(LocalDateTime.now());
|
||||||
|
user.setUpdateBy("admin");
|
||||||
|
user.setUpdateTime(LocalDateTime.now());
|
||||||
|
user.setUserType(2);
|
||||||
|
user.setTenantId(8000000000000000L + SnowflakeIdGenerator.of16(RandomCodeUtils.getRandomNumber(1)).nextId());
|
||||||
|
|
||||||
|
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.setName(user.getName());
|
||||||
|
registerResp.setUsername(user.getUsername());
|
||||||
|
registerResp.setEmail(user.getEmail());
|
||||||
|
registerResp.setPhone(user.getPhone());
|
||||||
|
return registerResp;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<UserResp> getUserList(UserQueryRequest request) {
|
||||||
|
Page<XUser> page = new Page<>(request.getCurrent(), request.getPageSize());
|
||||||
|
LambdaQueryWrapper<XUser> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||||
|
lambdaQueryWrapper.eq(XUser::getDelFlag, DelStatusEnum.NOT_DELETED.getCode());
|
||||||
|
if (StringUtils.isNotBlank(request.getName())) {
|
||||||
|
lambdaQueryWrapper.like(XUser::getName, request.getName());
|
||||||
|
}
|
||||||
|
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
|
||||||
|
public UserResp getUserInfo(Long id) {
|
||||||
|
XUser user = userMapper.getUserById(id);
|
||||||
|
return userConvert.toResp(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean addUser(UserAddRequest request) {
|
||||||
|
XUser user = userConvert.toDO(request);
|
||||||
|
user.setTenantId(PrimaryKeyUtils.snowflakeId());
|
||||||
|
user.setCreateBy(request.getOperator());
|
||||||
|
user.setCreateTime(request.getDateTime());
|
||||||
|
user.setUpdateBy(request.getOperator());
|
||||||
|
user.setUpdateTime(request.getDateTime());
|
||||||
|
return userMapper.insert(user) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateUser(UserUpdateRequest request) {
|
||||||
|
XUser user = userConvert.toDO(request);
|
||||||
|
user.setCreateBy(request.getOperator());
|
||||||
|
user.setCreateTime(request.getDateTime());
|
||||||
|
user.setUpdateBy(request.getOperator());
|
||||||
|
user.setUpdateTime(request.getDateTime());
|
||||||
|
return userMapper.updateById(user) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delUser(List<Long> ids) {
|
||||||
|
return userMapper.deleteBatch(ids, LocalDateTime.now(), "System") > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDTO getUserDetail(String username) {
|
||||||
|
UserDTO dto = new UserDTO();
|
||||||
|
XUser user = userMapper.selectByUsername(username);
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
dto.setUser(userConvert.toResp(user));
|
||||||
|
List<SysUserRole> userRoles = userRoleMapper.getByUserId(user.getId());
|
||||||
|
List<Long> roleIds = userRoles.stream().map(SysUserRole::getRoleId).toList();
|
||||||
|
List<SysRole> roles = roleMapper.getRoleByIds(roleIds);
|
||||||
|
if (CollectionUtils.isEmpty(roles)) {
|
||||||
|
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
dto.setRoles(roles);
|
||||||
|
dto.setPermissions(Sets.newHashSet("*:*:*"));
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.xiang.xs.service.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class PasswordConfig {
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.xiang.xs.service.converter;
|
||||||
|
|
||||||
|
import com.xiang.xs.api.pojo.resp.MenuVO;
|
||||||
|
import com.xiang.xs.service.entity.SysMenu;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-03-20 15:39
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface XMenuConverter {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.xiang.xs.service.converter;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserAddRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserQueryRequest;
|
||||||
|
import com.xiang.xs.api.pojo.request.user.UserUpdateRequest;
|
||||||
|
import com.xiang.xs.api.pojo.resp.UserResp;
|
||||||
|
import com.xiang.xs.service.entity.XUser;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface XUserConvert {
|
||||||
|
XUserConvert INSTANCE = Mappers.getMapper(XUserConvert.class);
|
||||||
|
|
||||||
|
XUser toDO (UserQueryRequest request);
|
||||||
|
XUser toDO (UserAddRequest request);
|
||||||
|
XUser toDO (UserUpdateRequest request);
|
||||||
|
|
||||||
|
UserResp toResp(XUser user);
|
||||||
|
|
||||||
|
Page<UserResp> toPage(Page<XUser> page);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xs.service.entity;
|
package com.xiang.xs.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;
|
||||||
@@ -15,6 +16,7 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@TableName("sys_menu")
|
||||||
public class SysMenu extends BaseEntity {
|
public class SysMenu extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|||||||
112
xs-service/src/main/java/com/xiang/xs/service/entity/XUser.java
Normal file
112
xs-service/src/main/java/com/xiang/xs/service/entity/XUser.java
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
package com.xiang.xs.service.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class XUser implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户id
|
||||||
|
*/
|
||||||
|
private Long tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名(昵称)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后登陆ip
|
||||||
|
*/
|
||||||
|
private String loginIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后登陆时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime loginDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态(0:禁用, 1:启用)
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标识(0:未删除 1:已删除)
|
||||||
|
*/
|
||||||
|
private Integer delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
/**
|
||||||
|
* 刷新token
|
||||||
|
*/
|
||||||
|
private String refreshToken;
|
||||||
|
/**
|
||||||
|
* 1:后台用户、2:中台用户、3:前台用户
|
||||||
|
*/
|
||||||
|
private Integer userType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.xiang.xs.service.entity.vo;
|
||||||
|
|
||||||
|
import com.xiang.xs.api.pojo.resp.UserResp;
|
||||||
|
import com.xiang.xs.service.entity.SysDept;
|
||||||
|
import com.xiang.xs.service.entity.SysRole;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserDTO {
|
||||||
|
|
||||||
|
private List<SysRole> roles;
|
||||||
|
private UserResp user;
|
||||||
|
private SysDept dept;
|
||||||
|
// private List<PermissionDTO> permissionRoles;
|
||||||
|
private Set<String> permissions;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.xiang.xs.service.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum UserStatusEnum {
|
||||||
|
|
||||||
|
DISABLED(0, "禁用"),
|
||||||
|
USING(1, "启用"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
private final String msg;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xs.service.repository.mapper;
|
package com.xiang.xs.service.repository.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.xiang.xs.service.entity.SysMenu;
|
import com.xiang.xs.service.entity.SysMenu;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
@@ -14,7 +15,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
public interface SysMenuMapper {
|
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||||
/**
|
/**
|
||||||
* 查询系统菜单列表
|
* 查询系统菜单列表
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.xiang.xs.service.repository.mapper;
|
|||||||
|
|
||||||
import com.xiang.xs.service.entity.SysRole;
|
import com.xiang.xs.service.entity.SysRole;
|
||||||
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;
|
import java.util.List;
|
||||||
@@ -119,4 +120,7 @@ public interface SysRoleMapper {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
int deleteRoleByIds(Long[] roleIds);
|
int deleteRoleByIds(Long[] roleIds);
|
||||||
|
|
||||||
|
|
||||||
|
List<SysRole> getRoleByIds(@Param("list") List<Long> roleIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,4 +69,7 @@ public interface SysUserRoleMapper {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
||||||
|
|
||||||
|
|
||||||
|
List<SysUserRole> getByUserId(@Param("userId") Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.xiang.xs.service.repository.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.xiang.xs.service.entity.XUser;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
@Mapper
|
||||||
|
public interface XUserMapper extends BaseMapper<XUser> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名查询用户
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
XUser selectByUsername(String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户列表
|
||||||
|
* @param user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<XUser> getUserList(XUser user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户详情
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
XUser getUserById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
* @param ids
|
||||||
|
* @param time
|
||||||
|
* @param operator
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deleteBatch(@Param("ids") List<Long> ids, @Param("time") LocalDateTime time, @Param("operator") String operator);
|
||||||
|
}
|
||||||
@@ -87,6 +87,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<include refid="selectRoleVo"/>
|
<include refid="selectRoleVo"/>
|
||||||
where r.role_key=#{roleKey} and r.del_flag = '0' limit 1
|
where r.role_key=#{roleKey} and r.del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getRoleByIds" resultType="com.xiang.xs.service.entity.SysRole">
|
||||||
|
select * from sys_role where id in
|
||||||
|
<foreach collection="list" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertRole" parameterType="com.xiang.xs.service.entity.SysRole" useGeneratedKeys="true" keyProperty="roleId">
|
<insert id="insertRole" parameterType="com.xiang.xs.service.entity.SysRole" useGeneratedKeys="true" keyProperty="roleId">
|
||||||
insert into sys_role(
|
insert into sys_role(
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<select id="countUserRoleByRoleId" resultType="Integer">
|
<select id="countUserRoleByRoleId" resultType="Integer">
|
||||||
select count(1) from sys_user_role where role_id=#{roleId}
|
select count(1) from sys_user_role where role_id=#{roleId}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getByUserId" resultType="com.xiang.xs.service.entity.SysUserRole">
|
||||||
|
select * from sys_user_role where user_id = #{userId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<delete id="deleteUserRole" parameterType="Long">
|
<delete id="deleteUserRole" parameterType="Long">
|
||||||
delete from sys_user_role where user_id in
|
delete from sys_user_role where user_id in
|
||||||
|
|||||||
115
xs-service/src/main/resources/mapper/XUserMapper.xml
Normal file
115
xs-service/src/main/resources/mapper/XUserMapper.xml
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?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.xs.service.repository.mapper.XUserMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.xiang.xs.service.entity.XUser" >
|
||||||
|
<result column="id" property="id" />
|
||||||
|
<result column="name" property="name" />
|
||||||
|
<result column="username" property="username" />
|
||||||
|
<result column="password" property="password" />
|
||||||
|
<result column="email" property="email" />
|
||||||
|
<result column="phone" property="phone" />
|
||||||
|
<result column="avatar" property="avatar" />
|
||||||
|
<result column="login_ip" property="loginIp" />
|
||||||
|
<result column="login_date" property="loginDate" />
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<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="tenant_id" property="tenantId"/>
|
||||||
|
<result column="token" property="token"/>
|
||||||
|
<result column="refresh_token" property="refreshToken"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
email,
|
||||||
|
phone,
|
||||||
|
avatar,
|
||||||
|
login_ip,
|
||||||
|
login_date,
|
||||||
|
status,
|
||||||
|
del_flag,
|
||||||
|
create_by,
|
||||||
|
create_time,
|
||||||
|
update_by,
|
||||||
|
update_time,
|
||||||
|
tenant_id,
|
||||||
|
token,
|
||||||
|
refresh_token
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<update id="del" >
|
||||||
|
update x_user set del_flag = 1 where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="deleteBatch">
|
||||||
|
update x_user set del_flag = 1, update_time = #{time}, update_by = #{operator} where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_user
|
||||||
|
where username = #{username} and del_flag = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getUserList" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_user
|
||||||
|
<trim prefix="AND">
|
||||||
|
<where>
|
||||||
|
<if test="name != null and name != ''">
|
||||||
|
AND name LIKE CONCAT('%', #{name}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="username != null and username != ''">
|
||||||
|
AND username = #{username}
|
||||||
|
</if>
|
||||||
|
<if test="email != null and email != ''">
|
||||||
|
AND email = #{email}
|
||||||
|
</if>
|
||||||
|
<if test="phone != null and phone != ''">
|
||||||
|
AND phone = #{phone}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
AND status = #{status}
|
||||||
|
</if>
|
||||||
|
<if test="delFlag != null">
|
||||||
|
AND del_flag = #{delFlag}
|
||||||
|
</if>
|
||||||
|
<if test="loginIp != null and loginIp != ''">
|
||||||
|
AND login_ip = #{loginIp}
|
||||||
|
</if>
|
||||||
|
<if test="loginDate != null">
|
||||||
|
AND login_date = #{loginDate}
|
||||||
|
</if>
|
||||||
|
<if test="createBy != null and createBy != ''">
|
||||||
|
AND create_by = #{createBy}
|
||||||
|
</if>
|
||||||
|
<if test="updateBy != null and updateBy != ''">
|
||||||
|
AND update_by = #{updateBy}
|
||||||
|
</if>
|
||||||
|
<if test="createTime != null">
|
||||||
|
AND create_time >= #{createTime}
|
||||||
|
</if>
|
||||||
|
<if test="updateTime != null">
|
||||||
|
AND update_time <= #{updateTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</trim>
|
||||||
|
</select>
|
||||||
|
<select id="getUserById" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_user
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user