Compare commits
8 Commits
22f0b546ad
...
feat/auth_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b8d33b50d | ||
|
|
8866d152d7 | ||
|
|
cb9ddf4681 | ||
|
|
6ebdec199b | ||
|
|
ace15206ec | ||
|
|
4ea369b33d | ||
|
|
e7f90b8d97 | ||
|
|
816dfb2304 |
@@ -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.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 javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = "xservice-auth-center", contextId = "PermissionApi", fallback = PermissionApiFallback.class)
|
||||
public interface PermissionApi {
|
||||
|
||||
@PostMapping("/private/permission/register")
|
||||
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_LOGIN_ERROR("A1000103", "用户登录失败!"),
|
||||
USER_REGISTER_ERROR("1000104", "用户注册失败!"),
|
||||
REFRESH_TOKEN_NOT_EXISTS("1000105", "refreshToken不匹配"),
|
||||
TOKEN_NOT_VALID("1000106", "token校验失败"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -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.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -29,4 +31,6 @@ public class DeptDTO {
|
||||
* 排序
|
||||
*/
|
||||
private Integer sortNo;
|
||||
|
||||
private List<DeptDTO> children;
|
||||
}
|
||||
|
||||
@@ -12,4 +12,6 @@ public class LoginResp {
|
||||
private String username;
|
||||
|
||||
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 java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@@ -15,4 +16,5 @@ public class UserDTO {
|
||||
private UserResp user;
|
||||
private DeptDTO dept;
|
||||
private List<PermissionDTO> permissionRoles;
|
||||
private Set<String> permissions;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.time.LocalDateTime;
|
||||
@NoArgsConstructor
|
||||
public class UserResp {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名(昵称)
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
|
||||
@SpringBootApplication
|
||||
@@ -12,6 +13,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
||||
|
||||
})
|
||||
@EnableMethodSecurity(prePostEnabled = true)
|
||||
@EnableFeignClients(basePackages = {"com.xiang.xservice.auth.api.api"})
|
||||
public class AuthApplication {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AuthApplication.class);
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||
import com.xiang.xservice.auth.service.service.XDeptService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class DeptController {
|
||||
|
||||
private final XDeptService deptService;
|
||||
|
||||
@PostMapping("/private/dept/list")
|
||||
public Result<List<DeptDTO>> getDeptList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptQueryRequest request) {
|
||||
return Result.data(deptService.getDeptList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/private/dept/info/{id}")
|
||||
public Result<DeptDTO> getDeptInfo(@PathVariable Long id) {
|
||||
return Result.data(deptService.getDeptInfo(id));
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/add")
|
||||
public Result<Void> addDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptAddRequest request) {
|
||||
try {
|
||||
if (deptService.addDept(request)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("添加部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("添加部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/update")
|
||||
public Result<Void> updateDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptUpdateRequest request) {
|
||||
try {
|
||||
if (deptService.updateDept(request)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("更新部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("更新部门异常, 请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/del")
|
||||
public Result<Void> delDept(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
try {
|
||||
if (deptService.delDept(ids)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("删除部门异常, 请求:{}", JSON.toJSONString(ids), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("删除部门异常, 请求:{}", JSON.toJSONString(ids), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/setUser")
|
||||
public Result<Void> setUserDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptUserUpdateRequest request) {
|
||||
try {
|
||||
if (deptService.setUserDept(request)) {
|
||||
return Result.success();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("部门添加用户失败, 请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("部门添加用户失败, 请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -23,7 +22,7 @@ public class PermissionController implements PermissionApi {
|
||||
|
||||
private final XPermissionService permissionService;
|
||||
|
||||
@PostMapping("/private/permission/register")
|
||||
|
||||
public Result<Void> register(@RequestBody @NotEmpty(message = "请求参数不能为空") @Valid List<PermissionRegisterRequest> requests) {
|
||||
try {
|
||||
if (permissionService.registerAllApiPermissions(requests)) {
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RoleDTO;
|
||||
import com.xiang.xservice.auth.service.service.XRoleService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class RoleController {
|
||||
|
||||
private final XRoleService roleService;
|
||||
|
||||
@PostMapping("/private/role/list")
|
||||
public Result<List<RoleDTO>> getRoleList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleQueryRequest request) {
|
||||
return Result.data(roleService.getRoleList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/private/role/info/{id}")
|
||||
public Result<RoleDTO> getRoleInfo(@PathVariable Long id) {
|
||||
return Result.data(roleService.getRoleInfo(id));
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/add")
|
||||
public Result<Boolean> addRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleAddRequest request) {
|
||||
try {
|
||||
return Result.data(roleService.addRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/update")
|
||||
public Result<Boolean> updateRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(roleService.updateRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/del")
|
||||
public Result<Boolean> delRole(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
try {
|
||||
return Result.data(roleService.delRole(ids));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色删除异常,请求:{}", ids, e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色删除异常,请求:{}", ids, e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/setUser")
|
||||
public Result<Boolean> setUserRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleUserUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(roleService.setUserRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("角色用户关联异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("角色用户关联异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +1,24 @@
|
||||
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.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.RegisterResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.UserDTO;
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class TokenController implements TokenApi {
|
||||
public class TokenController {
|
||||
|
||||
private final XUserService userService;
|
||||
|
||||
@@ -41,26 +36,17 @@ public class TokenController implements TokenApi {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/user/userRegister")
|
||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
||||
|
||||
@PostMapping("/publish/auth/refresh")
|
||||
public Result<LoginResp> refresh(@RequestBody @NotNull(message = "请求参数不能为空") @Valid RefreshRequest request) {
|
||||
try {
|
||||
RegisterResp registerResp = userService.userRegister(request);
|
||||
if (Objects.nonNull(registerResp)) {
|
||||
return Result.data(registerResp);
|
||||
}
|
||||
LoginResp login = userService.refresh(request);
|
||||
return Result.data(login);
|
||||
} catch (BusinessException e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
log.error("【用户登录】用户登录失败,{}", e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
}
|
||||
return Result.error("操作失败");
|
||||
}
|
||||
|
||||
@GetMapping("/private/auth/getInfo")
|
||||
public Result<UserDTO> getUserInfo() {
|
||||
// todo token的工具类,直接获取token中的userId无需传参
|
||||
return Result.data(userService.getUserDetail(1L));
|
||||
log.error("【用户登录】用户登录失败,{}", e.getMessage(), e);
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserDeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserRoleUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.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<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/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(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
try {
|
||||
return Result.data(userService.delUser(ids));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户删除异常,请求:{}", JSON.toJSONString(ids), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户删除异常,请求:{}", JSON.toJSONString(ids), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/setDept")
|
||||
public Result<Boolean> setUserDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserDeptUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(userService.setUserDept(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户设置部门异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户设置部门异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/setRole")
|
||||
public Result<Boolean> setUserRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserRoleUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(userService.setUserRole(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户设置角色异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户设置角色异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
|
||||
// @PostMapping("/public/user/useraddBatch")
|
||||
// public Result<Void> add() {
|
||||
// List<CompletableFuture> futures = Lists.newArrayList();
|
||||
// List<XUser> list = Lists.newCopyOnWriteArrayList();
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// int finalI = i;
|
||||
// log.info("第{}批数据生成!", finalI);
|
||||
// CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
// for (int j = 0; j < 1000; j++) {
|
||||
// log.info("第{}批的第{}条数据生成!", finalI, j);
|
||||
// XUser user = new XUser();
|
||||
// user.setName("nameTest2" + finalI + j);
|
||||
// user.setUsername("usernameTest2" + finalI + j);
|
||||
// user.setPassword(passwordEncoder.encode("123456"));
|
||||
// user.setEmail("emailTest2" + finalI + j + "@test.com");
|
||||
// user.setPhone("13800000000");
|
||||
// user.setStatus(UserStatusEnum.USING.getCode());
|
||||
// list.add(user);
|
||||
// }
|
||||
// });
|
||||
// futures.add(future);
|
||||
// }
|
||||
// CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||
// List<List<XUser>> partition = Lists.partition(list, 3000);
|
||||
// CompletableFuture.runAsync(() -> {
|
||||
// partition.stream().parallel().forEach(userMapper::insertBatch);
|
||||
// });
|
||||
// return Result.success();
|
||||
// }
|
||||
}
|
||||
@@ -11,14 +11,26 @@ spring:
|
||||
main:
|
||||
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:
|
||||
mapper-locations:
|
||||
- classpath*:mapper/*/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
reasonable: true
|
||||
support-methods-arguments: true
|
||||
params: count=countSql
|
||||
|
||||
feign:
|
||||
client:
|
||||
config:
|
||||
default:
|
||||
connectTimeout: 1000
|
||||
readTimeout: 3000
|
||||
@@ -1,102 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false">
|
||||
|
||||
<!-- 应用名称:和统一配置中的项目代码保持一致(小写) -->
|
||||
<property name="APP_NAME" value="xservice-auth-center"/>
|
||||
<contextName>${APP_NAME}</contextName>
|
||||
|
||||
<!--日志文件保留天数 -->
|
||||
<property name="LOG_MAX_HISTORY" value="30"/>
|
||||
<!--应用日志文件保存路径 -->
|
||||
<!--在没有定义${LOG_HOME}系统变量的时候,可以设置此本地变量。提交测试、上线时,要将其注释掉,使用系统变量。 -->
|
||||
<property name="LOG_HOME" value="logs/${APP_NAME}"/>
|
||||
<!--<property name="LOG_HOME" msg="/home/logs/${APP_NAME}" />-->
|
||||
|
||||
<!--控制台输出appender-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!--设置输出格式-->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%boldGreen(%contextName): %boldCyan(%d{yyyy-MM-dd HH:mm:ss:SSS}) %highlight([%c]) %boldMagenta([%t]) %boldCyan([%L]) %highlight([traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}]) %boldGreen([%p]) - %msg%n
|
||||
</pattern>
|
||||
<!--设置编码-->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
||||
<appender name="APP_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/debug-%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件只记录debug级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
||||
<appender name="APP_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/info-%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!-- 此日志文件只记录info级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
||||
<appender name="APP_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/error-%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件只记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>error</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!--日志输出到文件-->
|
||||
<root level="info">
|
||||
<appender-ref ref="APP_DEBUG"/>
|
||||
<appender-ref ref="APP_INFO"/>
|
||||
<appender-ref ref="APP_ERROR"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!-- mybatis 日志级别 -->
|
||||
<logger name="com.xiang" level="debug"/>
|
||||
|
||||
</configuration>
|
||||
@@ -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;
|
||||
|
||||
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.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-08-29 16:54
|
||||
@@ -17,11 +10,4 @@ import java.util.List;
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface XDeptConvert {
|
||||
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,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;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("sys_role")
|
||||
public class XRole implements Serializable {
|
||||
@Serial
|
||||
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 LocalDateTime updatedTime;
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
* 更新者
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 删除标识(0:未删除 1:已删除)
|
||||
* 更新时间
|
||||
*/
|
||||
private Integer delFlag;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@@ -104,4 +104,9 @@ public class XUser implements Serializable {
|
||||
* 刷新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;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -7,6 +8,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("sys_user_role")
|
||||
public class XUserRole {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
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.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-08-29 16:40
|
||||
@@ -15,14 +10,4 @@ import java.util.List;
|
||||
@Mapper
|
||||
@Repository
|
||||
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;
|
||||
|
||||
import com.xiang.xservice.auth.service.entity.XUserDept;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-08-29 17:04
|
||||
@@ -14,9 +10,5 @@ import java.util.List;
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface XUserDeptMapper {
|
||||
int addBatch(List<XUserDept> list);
|
||||
|
||||
int delByDeptId(Long deptId);
|
||||
|
||||
XUserDept getByUserId(@Param("id") Long userId);
|
||||
}
|
||||
|
||||
@@ -21,20 +21,6 @@ public interface XUserMapper extends BaseMapper<XUser> {
|
||||
*/
|
||||
XUser selectByUsername(String username);
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
* @param user 用户
|
||||
* @return
|
||||
*/
|
||||
int insert(XUser user);
|
||||
|
||||
/**
|
||||
* 批量插入
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
int insertBatch(List<XUser> list);
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param user
|
||||
@@ -49,12 +35,6 @@ public interface XUserMapper extends BaseMapper<XUser> {
|
||||
*/
|
||||
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();
|
||||
if (CollectionUtils.isNotEmpty(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
|
||||
.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);
|
||||
|
||||
}
|
||||
@@ -2,11 +2,10 @@ 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.RefreshRequest;
|
||||
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.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.LoginResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
||||
@@ -18,24 +17,16 @@ import java.util.List;
|
||||
public interface XUserService {
|
||||
|
||||
LoginResp login(LoginRequest request);
|
||||
|
||||
UserResp getUserByUsername(String username);
|
||||
|
||||
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);
|
||||
|
||||
Boolean setUserDept(UserDeptUpdateRequest request);
|
||||
|
||||
Boolean setUserRole(UserRoleUpdateRequest request);
|
||||
|
||||
UserDTO getUserDetail(Long userId);
|
||||
UserDTO getUserDetail(String username);
|
||||
LoginResp refresh(RefreshRequest request);
|
||||
Boolean updateStatus(Long id, Integer status);
|
||||
Long getUserId(String token);
|
||||
Long getTenantId(String token);
|
||||
Boolean resetPwd(Long userId, String password);
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package com.xiang.xservice.auth.service.service.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.xiang.xservice.auth.api.code.Code03DeptErrorCode;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||
import com.xiang.xservice.auth.service.convert.XDeptConvert;
|
||||
import com.xiang.xservice.auth.service.entity.XDept;
|
||||
import com.xiang.xservice.auth.service.entity.XUserDept;
|
||||
import com.xiang.xservice.auth.service.repository.mapper.XDeptMapper;
|
||||
import com.xiang.xservice.auth.service.repository.mapper.XUserDeptMapper;
|
||||
import com.xiang.xservice.auth.service.service.XDeptService;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-08-29 16:39
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class XDeptServiceImpl implements XDeptService {
|
||||
|
||||
private final static int BATCH_SIZE = 500;
|
||||
private final XDeptMapper deptMapper;
|
||||
private final XDeptConvert deptConvert;
|
||||
private final XUserDeptMapper userDeptMapper;
|
||||
@Override
|
||||
public List<DeptDTO> getDeptList(DeptQueryRequest request) {
|
||||
return deptConvert.toDTOList(deptMapper.getDeptList(deptConvert.toDO(request)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeptDTO getDeptInfo(Long id) {
|
||||
return deptConvert.toDTO(deptMapper.getDeptById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addDept(DeptAddRequest request) {
|
||||
XDept dept = deptConvert.toDO(request);
|
||||
return deptMapper.insert(dept) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateDept(DeptUpdateRequest request) {
|
||||
XDept dept = deptConvert.toDO(request);
|
||||
dept.setCreateBy(request.getOperator());
|
||||
dept.setUpdateBy(request.getOperator());
|
||||
return deptMapper.update(dept) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delDept(List<Long> ids) {
|
||||
return deptMapper.delBatch(ids, LocalDateTime.now(), "admin") > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean setUserDept(DeptUserUpdateRequest request) {
|
||||
XDept dept = deptMapper.getDeptById(request.getDeptId());
|
||||
if (Objects.isNull(dept)) {
|
||||
log.error("查询部门信息不存在!部门id:{}", request.getDeptId());
|
||||
throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
||||
}
|
||||
List<XUserDept> result = Lists.newArrayList();
|
||||
for (Long userId : request.getUserIds()) {
|
||||
XUserDept userDept = new XUserDept();
|
||||
userDept.setDeptId(request.getDeptId());
|
||||
userDept.setUserId(userId);
|
||||
result.add(userDept);
|
||||
}
|
||||
boolean flag = true;
|
||||
if (userDeptMapper.delByDeptId(request.getDeptId()) <= 0) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(result)) {
|
||||
if (result.size() > BATCH_SIZE) {
|
||||
List<List<XUserDept>> partition = Lists.partition(result, BATCH_SIZE);
|
||||
for (List<XUserDept> list : partition) {
|
||||
if (userDeptMapper.addBatch(list) <= 0) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return userDeptMapper.addBatch(result) > 0;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,15 @@ 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.Sets;
|
||||
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||
import com.xiang.xservice.auth.api.code.Code01UserErrorCode;
|
||||
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.RefreshRequest;
|
||||
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.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.LoginResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
||||
@@ -24,12 +23,10 @@ import com.xiang.xservice.auth.service.convert.XDeptConvert;
|
||||
import com.xiang.xservice.auth.service.convert.XPermissionConvert;
|
||||
import com.xiang.xservice.auth.service.convert.XRoleConvert;
|
||||
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.XRole;
|
||||
import com.xiang.xservice.auth.service.entity.XRolePermission;
|
||||
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.enums.UserStatusEnum;
|
||||
import com.xiang.xservice.auth.service.repository.mapper.XDeptMapper;
|
||||
@@ -43,10 +40,13 @@ import com.xiang.xservice.auth.service.service.XUserService;
|
||||
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.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -58,7 +58,6 @@ import org.springframework.security.oauth2.jwt.JwtDecoder;
|
||||
import org.springframework.security.oauth2.jwt.JwtEncoder;
|
||||
import org.springframework.security.oauth2.jwt.JwtEncoderParameters;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -113,7 +112,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
if (CollectionUtils.isEmpty(roles)) {
|
||||
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 {
|
||||
@@ -123,6 +122,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
LoginResp loginResp = new LoginResp();
|
||||
loginResp.setToken(user.getToken());
|
||||
loginResp.setUsername(request.getUsername());
|
||||
loginResp.setRefreshToken(user.getRefreshToken());
|
||||
return loginResp;
|
||||
}
|
||||
}
|
||||
@@ -159,35 +159,16 @@ public class XUserServiceImpl implements XUserService {
|
||||
LoginResp loginResp = new LoginResp();
|
||||
loginResp.setToken(token);
|
||||
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.update(user);
|
||||
userMapper.updateById(user);
|
||||
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
|
||||
public RegisterResp userRegister(RegisterRequest request) {
|
||||
// todo 手机号验证码校验
|
||||
@@ -208,8 +189,16 @@ public class XUserServiceImpl implements XUserService {
|
||||
user.setCreateTime(LocalDateTime.now());
|
||||
user.setUpdateBy("admin");
|
||||
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.setName(user.getName());
|
||||
registerResp.setUsername(user.getUsername());
|
||||
@@ -224,6 +213,23 @@ public class XUserServiceImpl implements XUserService {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -251,7 +257,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
user.setCreateTime(request.getDateTime());
|
||||
user.setUpdateBy(request.getOperator());
|
||||
user.setUpdateTime(request.getDateTime());
|
||||
return userMapper.update(user) > 0;
|
||||
return userMapper.updateById(user) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -260,62 +266,131 @@ public class XUserServiceImpl implements XUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean setUserDept(UserDeptUpdateRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean setUserRole(UserRoleUpdateRequest request) {
|
||||
XUser user = userMapper.getUserById(request.getUserId());
|
||||
if (Objects.isNull(user)) {
|
||||
log.error("查询用户信息不存在!用户id:{}", request.getUserId());
|
||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||
}
|
||||
List<XUserRole> params = Lists.newArrayList();
|
||||
for (Long roleId : request.getRoleIds()) {
|
||||
XUserRole userRole = new XUserRole();
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.setUserId(request.getUserId());
|
||||
params.add(userRole);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(params)) {
|
||||
return userRoleMapper.insertUserRole(params) > 0;
|
||||
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO getUserDetail(Long userId) {
|
||||
public UserDTO getUserDetail(String username) {
|
||||
UserDTO dto = new UserDTO();
|
||||
XUser user = userMapper.getUserById(userId);
|
||||
XUser user = userMapper.selectByUsername(username);
|
||||
if (Objects.isNull(user)) {
|
||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||
}
|
||||
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<XRole> roles = roleMapper.getRoleByIds(roleIds);
|
||||
if (CollectionUtils.isEmpty(roles)) {
|
||||
throw new BusinessException(Code02RoleErrorCode.ROLE_NOT_EXISTS);
|
||||
}
|
||||
dto.setRoles(roleConvert.toDTOList(roles));
|
||||
XUserDept userDept = userDeptMapper.getByUserId(userId);
|
||||
if (Objects.nonNull(userDept)) {
|
||||
Long deptId = userDept.getDeptId();
|
||||
XDept dept = deptMapper.getDeptById(deptId);
|
||||
if (Objects.isNull(dept)) {
|
||||
throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
||||
}
|
||||
dto.setDept(deptConvert.toDTO(dept));
|
||||
}
|
||||
// XUserDept userDept = userDeptMapper.getByUserId(user.getId());
|
||||
// if (Objects.nonNull(userDept)) {
|
||||
// Long deptId = userDept.getDeptId();
|
||||
// XDept dept = deptMapper.getDeptById(deptId);
|
||||
// if (Objects.isNull(dept)) {
|
||||
// throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
||||
// }
|
||||
// dto.setDept(deptConvert.toDTO(dept));
|
||||
// }
|
||||
List<XRolePermission> permissionsByRoleIds = rolePermissionMapper.getRolePermissionsByRoleIds(roleIds);
|
||||
if (CollectionUtils.isNotEmpty(permissionsByRoleIds)) {
|
||||
List<Long> permissionIds = permissionsByRoleIds.stream().map(XRolePermission::getPermissionId).toList();
|
||||
List<XPermission> permissions = permissionMapper.getPermissionByIds(permissionIds);
|
||||
dto.setPermissionRoles(permissionConvert.toDTOList(permissions));
|
||||
}
|
||||
dto.setPermissions(Sets.newHashSet("*:*:*"));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,144 +3,4 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<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>
|
||||
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}
|
||||
</select>
|
||||
<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
|
||||
from x_permission p
|
||||
join x_role_permission rp on p.id = rp.permission_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
|
||||
-- select p.api_path api_url, p.method, r.code as role_code
|
||||
-- from x_permission p
|
||||
-- join x_role_permission rp on p.id = rp.permission_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
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -4,126 +4,56 @@
|
||||
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XRoleMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XRole" >
|
||||
<result column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="code" property="code" />
|
||||
<result column="status" property="status" />
|
||||
<result column="role_id" property="roleId" />
|
||||
<result column="role_name" property="roleName" />
|
||||
<result column="role_key" property="roleKey" />
|
||||
<result column="role_sort" property="roleSort" />
|
||||
<result column="data_scope" property="dataScope" />
|
||||
<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="menu_check_strictly" property="menuCheckStrictly" />
|
||||
<result column="dept_check_strictly" property="deptCheckStrictly" />
|
||||
<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="remark" property="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
name,
|
||||
code,
|
||||
status,
|
||||
role_id,
|
||||
role_name,
|
||||
role_key,
|
||||
role_sort,
|
||||
data_scope,
|
||||
created_time,
|
||||
menu_check_strictly,
|
||||
dept_check_strictly,
|
||||
status,
|
||||
del_flag,
|
||||
create_by,
|
||||
updated_time,
|
||||
create_time,
|
||||
update_by,
|
||||
del_flag
|
||||
update_time,
|
||||
remark
|
||||
</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 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=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</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 <include refid="Base_Column_List"/>
|
||||
from x_role
|
||||
from sys_role
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getRoleList" resultMap="BaseResultMap">
|
||||
select <include refid="Base_Column_List"/>
|
||||
from x_role
|
||||
from sys_role
|
||||
<trim prefix="AND">
|
||||
<if test="name != null and name != ''">
|
||||
AND name = #{name}
|
||||
@@ -141,8 +71,8 @@
|
||||
</select>
|
||||
<select id="getRoleByIds" resultMap="BaseResultMap">
|
||||
select <include refid="Base_Column_List"/>
|
||||
from x_role
|
||||
where id in
|
||||
from sys_role
|
||||
where role_id in
|
||||
<foreach collection="ids" item="id" close=")" open="(" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
@@ -3,28 +3,5 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<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>
|
||||
@@ -45,150 +45,12 @@
|
||||
refresh_token
|
||||
</sql>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XUser">
|
||||
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>
|
||||
<if test="token != null and token != ''">
|
||||
token,
|
||||
</if>
|
||||
<if test="refreshToken != null and refreshToken != ''">
|
||||
refreshToken
|
||||
</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>
|
||||
<if test="token != null and token != ''">
|
||||
#{token},
|
||||
</if>
|
||||
<if test="refreshToken != null and refreshToken != ''">
|
||||
#{refreshToken}
|
||||
</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 id="del" >
|
||||
update x_user set del_flag = 1 where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XUser">
|
||||
UPDATE x_user
|
||||
<set>
|
||||
<if test="null != name and '' != name">name = #{name},</if>
|
||||
<if test="null != username and '' != username">username = #{username},</if>
|
||||
<if test="null != password and '' != password">password = #{password},</if>
|
||||
<if test="null != email and '' != email">email = #{email},</if>
|
||||
<if test="null != phone and '' != phone">phone = #{phone},</if>
|
||||
<if test="null != avatar and '' != avatar">avatar = #{avatar},</if>
|
||||
<if test="null != loginIp and '' != loginIp">login_ip = #{loginIp},</if>
|
||||
<if test="null != loginDate ">login_date = #{loginDate},</if>
|
||||
<if test="null != delFlag ">del_flag = #{delFlag},</if>
|
||||
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
|
||||
<if test="null != createTime ">create_time = #{createTime},</if>
|
||||
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
|
||||
<if test="null != updateTime ">update_time = #{updateTime},</if>
|
||||
<if test="null != tenantId ">tenant_id = #{tenantId},</if>
|
||||
<if test="null != token and '' != token ">token = #{token},</if>
|
||||
<if test="null != refreshToken and '' != refreshToken ">refresh_token = #{refreshToken}</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
<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=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
@@ -197,7 +59,7 @@
|
||||
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||
select <include refid="Base_Column_List"/>
|
||||
from x_user
|
||||
where username = #{username} and del_flag = 0 and status = 1
|
||||
where username = #{username} and del_flag = 0
|
||||
</select>
|
||||
|
||||
<select id="getUserList" resultMap="BaseResultMap">
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
role_id
|
||||
</sql>
|
||||
<insert id="insertUserRole">
|
||||
insert into x_user_role(user_id, role_id)
|
||||
insert into sys_user_role(user_id, role_id)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.userId}, #{item.roleId})
|
||||
@@ -21,18 +21,18 @@
|
||||
</insert>
|
||||
|
||||
<delete id="delByUserId">
|
||||
delete from x_user_role where user_id = #{userId}
|
||||
delete from sys_user_role where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<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=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<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=",">
|
||||
(#{item.userId}, #{item.roleId})
|
||||
</foreach>
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
<select id="getByUserId" resultMap="BaseResultMap">
|
||||
select <include refid="Base_Column_List"/>
|
||||
from x_user_role
|
||||
from sys_user_role
|
||||
where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user