From 94ddd46c1e684ea0dfa3dfd6358eb21974f782bf Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Thu, 7 Jan 2021 18:23:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/ums/api/MemberFeignService.java | 28 ++++++++----------- .../com/youlai/mall/ums/pojo/UmsMember.java | 1 - .../mall/ums/pojo/dto/AuthMemberDTO.java | 17 +++++++++++ .../youlai/mall/ums/pojo/dto/MemberDTO.java | 6 +--- .../mall/ums/pojo/dto/MemberInfoDTO.java | 13 --------- .../youlai/admin/api/UserFeignService.java | 7 ++--- .../java/com/youlai/admin/pojo/SysDept.java | 2 +- .../java/com/youlai/admin/pojo/SysDict.java | 2 +- .../com/youlai/admin/pojo/SysDictType.java | 2 +- .../java/com/youlai/admin/pojo/SysMenu.java | 4 +-- .../com/youlai/admin/pojo/SysResource.java | 2 +- .../java/com/youlai/admin/pojo/SysRole.java | 6 ++-- .../com/youlai/admin/pojo/SysRoleMenu.java | 4 +-- .../youlai/admin/pojo/SysRoleResource.java | 4 +-- .../com/youlai/admin/pojo/SysUserRole.java | 2 +- .../youlai/admin/{ => pojo}/dto/UserDTO.java | 4 +-- .../youlai/admin/{ => pojo}/vo/DeptVO.java | 2 +- .../youlai/admin/{ => pojo}/vo/MenuVO.java | 2 +- .../youlai/admin/{ => pojo}/vo/RouterVO.java | 3 +- .../admin/{ => pojo}/vo/TreeSelectVO.java | 4 +-- .../youlai/admin/{ => pojo}/vo/UserVO.java | 6 ++-- .../auth/controller/AuthController.java | 11 +++----- .../java/com/youlai/auth/domain/User.java | 6 ++-- .../auth/service/UserDetailsServiceImpl.java | 15 +++++----- .../common/core/constant/AuthConstants.java | 20 +++++++------ .../common/core/constant/SystemConstants.java | 1 - .../common/core/enums/QueryModeEnum.java | 2 ++ .../com/youlai/common/web/util/WebUtils.java | 15 ++++------ .../gateway/config/ResourceServerConfig.java | 2 +- 29 files changed, 92 insertions(+), 101 deletions(-) create mode 100644 mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java delete mode 100644 mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberInfoDTO.java rename youlai-admin/admin-api/src/main/java/com/youlai/admin/{ => pojo}/dto/UserDTO.java (80%) rename youlai-admin/admin-api/src/main/java/com/youlai/admin/{ => pojo}/vo/DeptVO.java (91%) rename youlai-admin/admin-api/src/main/java/com/youlai/admin/{ => pojo}/vo/MenuVO.java (94%) rename youlai-admin/admin-api/src/main/java/com/youlai/admin/{ => pojo}/vo/RouterVO.java (89%) rename youlai-admin/admin-api/src/main/java/com/youlai/admin/{ => pojo}/vo/TreeSelectVO.java (73%) rename youlai-admin/admin-api/src/main/java/com/youlai/admin/{ => pojo}/vo/UserVO.java (61%) diff --git a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/api/MemberFeignService.java b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/api/MemberFeignService.java index 03d4aa20c..04a2421e0 100644 --- a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/api/MemberFeignService.java +++ b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/api/MemberFeignService.java @@ -1,37 +1,33 @@ package com.youlai.mall.ums.api; import com.youlai.common.core.result.Result; -import com.youlai.mall.ums.pojo.dto.MemberDTO; -import com.youlai.mall.ums.pojo.dto.MemberInfoDTO; import com.youlai.mall.ums.pojo.UmsMember; +import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; +import com.youlai.mall.ums.pojo.dto.MemberDTO; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; +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; @FeignClient("mall-ums") public interface MemberFeignService { - @PostMapping("/members") + @PostMapping("/api.app/v1/members") Result add(@RequestBody UmsMember member); - /** * 获取会员信息 - * @param id - * @param queryMode 查询模式:2-订单会员 - * @return */ - @GetMapping("/members/{id}") - Result getMember(@PathVariable Long id, @RequestParam(value = "queryMode") Integer queryMode); + @GetMapping("/api.app/v1/members/{id}") + Result getMemberById(@PathVariable Long id); /** - * 获取会员信息 - * @param openid - * @param queryMode 查询模式:1-认证会员 - * @return + * 获取认证会员信息 */ - @GetMapping("/members/{openid}") - Result loadMemberByOpenid(@PathVariable String openid, @RequestParam(value = "queryMode") Integer queryMode); + @GetMapping("/api.app/v1/members/openid/{openid}") + Result getMemberByOpenid(@PathVariable String openid); } diff --git a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/UmsMember.java b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/UmsMember.java index df76764f9..936e2374b 100644 --- a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/UmsMember.java +++ b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/UmsMember.java @@ -3,7 +3,6 @@ package com.youlai.mall.ums.pojo; import lombok.Data; import lombok.experimental.Accessors; - import java.time.LocalDate; @Data diff --git a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java new file mode 100644 index 000000000..6b5217a86 --- /dev/null +++ b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java @@ -0,0 +1,17 @@ +package com.youlai.mall.ums.pojo.dto; + +import lombok.Data; + +@Data +public class AuthMemberDTO { + + private Long id; + private String username; + private String password; + private Integer status; + private String clientId; + + private String avatar; + private String nickname; + +} diff --git a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberDTO.java b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberDTO.java index 89b89c341..7ec8f4849 100644 --- a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberDTO.java +++ b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberDTO.java @@ -6,12 +6,8 @@ import lombok.Data; public class MemberDTO { private Long id; - private String username; - private String password; - private Integer status; - private String clientId; - private String avatar; private String nickname; + private String mobile; } diff --git a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberInfoDTO.java b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberInfoDTO.java deleted file mode 100644 index cecb1e225..000000000 --- a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/MemberInfoDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.youlai.mall.ums.pojo.dto; - -import lombok.Data; - -@Data -public class MemberInfoDTO { - - private Long id; - - private String nickname; - - private String mobile; -} diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/api/UserFeignService.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/api/UserFeignService.java index 9c35362d1..62f813f8b 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/api/UserFeignService.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/api/UserFeignService.java @@ -1,15 +1,14 @@ package com.youlai.admin.api; -import com.youlai.admin.dto.UserDTO; +import com.youlai.admin.pojo.dto.UserDTO; import com.youlai.common.core.result.Result; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; @FeignClient("youlai-admin") public interface UserFeignService { - @GetMapping("/users/{id}") - Result loadUserByUsername(@PathVariable Object id, @RequestParam Integer queryMode); + @GetMapping("/users/username/{username}") + Result getUserByUsername(@PathVariable String username); } diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDept.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDept.java index 318a6b923..0a0908a94 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDept.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDept.java @@ -9,7 +9,7 @@ import lombok.Data; public class SysDept extends BaseEntity { @TableId(type= IdType.AUTO) - private Integer id; + private Long id; private String name; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDict.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDict.java index e2f50da8d..0d6b560a7 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDict.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDict.java @@ -11,7 +11,7 @@ import lombok.experimental.Accessors; public class SysDict extends BaseEntity { @TableId(type= IdType.AUTO) - private Integer id; + private Long id; private String name; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDictType.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDictType.java index 91bf94745..eb1db4020 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDictType.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysDictType.java @@ -9,7 +9,7 @@ import lombok.Data; public class SysDictType extends BaseEntity { @TableId(type = IdType.AUTO) - private Integer id; + private Long id; private String code; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysMenu.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysMenu.java index 0cee58003..ce921bc01 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysMenu.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysMenu.java @@ -18,11 +18,11 @@ import java.util.List; public class SysMenu extends BaseEntity { @TableId(type = IdType.AUTO) - private Integer id; + private Long id; private String title; - private Integer parentId; + private Long parentId; private String name; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysResource.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysResource.java index 45b9ae687..87d3e5bab 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysResource.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysResource.java @@ -14,7 +14,7 @@ import java.util.List; public class SysResource extends BaseEntity { @TableId(type = IdType.AUTO) - private Integer id; + private Long id; private String name; private String url; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRole.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRole.java index 5e59e38f2..07783ccbc 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRole.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRole.java @@ -12,7 +12,7 @@ import java.util.List; public class SysRole extends BaseEntity { @TableId(type= IdType.AUTO) - private Integer id; + private Long id; private String name; @@ -27,9 +27,9 @@ public class SysRole extends BaseEntity { private String remark; @TableField(exist = false) - private List menuIds; + private List menuIds; @TableField(exist = false) - private List resourceIds; + private List resourceIds; } diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleMenu.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleMenu.java index c634783f5..856724108 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleMenu.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleMenu.java @@ -7,8 +7,8 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class SysRoleMenu { - private Integer roleId; + private Long roleId; - private Integer menuId; + private Long menuId; } diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleResource.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleResource.java index faebe6413..d4f8184c0 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleResource.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysRoleResource.java @@ -6,6 +6,6 @@ import lombok.experimental.Accessors; @Data @Accessors(chain = true) public class SysRoleResource { - private Integer roleId; - private Integer resourceId; + private Long roleId; + private Long resourceId; } diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysUserRole.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysUserRole.java index 86d4a8a74..dbdc91cc1 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysUserRole.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/SysUserRole.java @@ -7,6 +7,6 @@ public class SysUserRole { private Long userId; - private Integer roleId; + private Long roleId; } diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/dto/UserDTO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java similarity index 80% rename from youlai-admin/admin-api/src/main/java/com/youlai/admin/dto/UserDTO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java index 71c706595..45b11ea30 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/dto/UserDTO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java @@ -1,4 +1,4 @@ -package com.youlai.admin.dto; +package com.youlai.admin.pojo.dto; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,6 +14,6 @@ public class UserDTO { private String password; private Integer status; private String clientId; - private List roles; + private List roles; } diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/DeptVO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/DeptVO.java similarity index 91% rename from youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/DeptVO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/DeptVO.java index 394fe59b4..25fe96de3 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/DeptVO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/DeptVO.java @@ -1,4 +1,4 @@ -package com.youlai.admin.vo; +package com.youlai.admin.pojo.vo; import lombok.Data; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/MenuVO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/MenuVO.java similarity index 94% rename from youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/MenuVO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/MenuVO.java index 210871871..27f6606c0 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/MenuVO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/MenuVO.java @@ -1,4 +1,4 @@ -package com.youlai.admin.vo; +package com.youlai.admin.pojo.vo; import com.fasterxml.jackson.annotation.JsonInclude; import com.youlai.common.core.base.BaseEntity; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/RouterVO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/RouterVO.java similarity index 89% rename from youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/RouterVO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/RouterVO.java index 276599893..f34978d2a 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/RouterVO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/RouterVO.java @@ -1,7 +1,6 @@ -package com.youlai.admin.vo; +package com.youlai.admin.pojo.vo; import com.fasterxml.jackson.annotation.JsonInclude; -import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/TreeSelectVO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/TreeSelectVO.java similarity index 73% rename from youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/TreeSelectVO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/TreeSelectVO.java index b6bdbcce0..2833f9348 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/TreeSelectVO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/TreeSelectVO.java @@ -1,4 +1,4 @@ -package com.youlai.admin.vo; +package com.youlai.admin.pojo.vo; import lombok.Data; @@ -8,7 +8,7 @@ import java.util.List; @Data public class TreeSelectVO { - private Integer id; + private Long id; private String label; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/UserVO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/UserVO.java similarity index 61% rename from youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/UserVO.java rename to youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/UserVO.java index ab92139bb..2266ef499 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/vo/UserVO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/vo/UserVO.java @@ -1,4 +1,4 @@ -package com.youlai.admin.vo; +package com.youlai.admin.pojo.vo; import lombok.Data; @@ -7,12 +7,12 @@ import java.util.List; @Data public class UserVO { - private Integer id; + private Long id; private String nickname; private String avatar; - private List roles; + private List roles; } diff --git a/youlai-auth/src/main/java/com/youlai/auth/controller/AuthController.java b/youlai-auth/src/main/java/com/youlai/auth/controller/AuthController.java index 97f1eb969..44b9ee86a 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/controller/AuthController.java +++ b/youlai-auth/src/main/java/com/youlai/auth/controller/AuthController.java @@ -12,7 +12,7 @@ import com.youlai.common.core.result.ResultCode; import com.youlai.common.web.exception.BizException; import com.youlai.mall.ums.api.MemberFeignService; import com.youlai.mall.ums.pojo.UmsMember; -import com.youlai.mall.ums.pojo.dto.MemberDTO; +import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -80,9 +80,6 @@ public class AuthController { - - - private WxMaService wxService; private MemberFeignService memberFeignService; private PasswordEncoder passwordEncoder; @@ -104,7 +101,7 @@ public class AuthController { String openid = session.getOpenid(); String sessionKey = session.getSessionKey(); - Result result = memberFeignService.loadMemberByOpenid(openid, 1); + Result result = memberFeignService.getMemberByOpenid(openid); String username; if (ResultCode.USER_NOT_EXIST.getCode().equals(result.getCode())) { // 微信授权登录 会员信息不存在时 注册会员 @@ -130,8 +127,8 @@ public class AuthController { } username = openid; } else { - MemberDTO memberDTO = result.getData(); - username = memberDTO.getUsername(); + AuthMemberDTO authMemberDTO = result.getData(); + username = authMemberDTO.getUsername(); } // oauth2认证参数对应授权登录时注册会员的username、password信息,模拟通过oauth2的密码模式认证 diff --git a/youlai-auth/src/main/java/com/youlai/auth/domain/User.java b/youlai-auth/src/main/java/com/youlai/auth/domain/User.java index 0b1f69501..1ba837b7f 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/domain/User.java +++ b/youlai-auth/src/main/java/com/youlai/auth/domain/User.java @@ -1,8 +1,8 @@ package com.youlai.auth.domain; -import com.youlai.admin.dto.UserDTO; +import com.youlai.admin.pojo.dto.UserDTO; import com.youlai.common.core.constant.AuthConstants; -import com.youlai.mall.ums.pojo.dto.MemberDTO; +import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.security.core.GrantedAuthority; @@ -44,7 +44,7 @@ public class User implements UserDetails { } } - public User(MemberDTO member){ + public User(AuthMemberDTO member){ this.setId(member.getId()); this.setUsername(member.getUsername()); this.setPassword(AuthConstants.BCRYPT + member.getPassword()); diff --git a/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java b/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java index 462fa4a6d..80b13b612 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java +++ b/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java @@ -1,12 +1,12 @@ package com.youlai.auth.service; -import com.youlai.admin.dto.UserDTO; +import com.youlai.admin.pojo.dto.UserDTO; import com.youlai.admin.api.UserFeignService; import com.youlai.auth.domain.User; import com.youlai.common.core.constant.AuthConstants; import com.youlai.common.core.result.Result; import com.youlai.common.core.result.ResultCode; -import com.youlai.mall.ums.pojo.dto.MemberDTO; +import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.api.MemberFeignService; import lombok.AllArgsConstructor; import org.springframework.security.authentication.AccountExpiredException; @@ -16,7 +16,6 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; - import javax.servlet.http.HttpServletRequest; @@ -39,7 +38,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { User user = null; switch (clientId) { case AuthConstants.ADMIN_CLIENT_ID: // 后台用户 - Result userRes = userFeignService.loadUserByUsername(username, 2); + Result userRes = userFeignService.getUserByUsername(username); if (ResultCode.USER_NOT_EXIST.getCode().equals(userRes.getCode())) { throw new UsernameNotFoundException(ResultCode.USER_NOT_EXIST.getMsg()); } @@ -48,13 +47,13 @@ public class UserDetailsServiceImpl implements UserDetailsService { user = new User(userDTO); break; case AuthConstants.WEAPP_CLIENT_ID: // 小程序会员 - Result memberRes = memberFeignService.loadMemberByOpenid(username, 1); + Result memberRes = memberFeignService.getMemberByOpenid(username); if (ResultCode.USER_NOT_EXIST.getCode().equals(memberRes.getCode())) { throw new UsernameNotFoundException(ResultCode.USER_NOT_EXIST.getMsg()); } - MemberDTO memberDTO = memberRes.getData(); - memberDTO.setClientId(clientId); - user = new User(memberDTO); + AuthMemberDTO authMemberDTO = memberRes.getData(); + authMemberDTO.setClientId(clientId); + user = new User(authMemberDTO); break; } if (!user.isEnabled()) { diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/AuthConstants.java b/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/AuthConstants.java index 6e6420aeb..08834fe23 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/AuthConstants.java +++ b/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/AuthConstants.java @@ -2,15 +2,8 @@ package com.youlai.common.core.constant; public interface AuthConstants { - /** - * JWT存储权限前缀 - */ - String AUTHORITY_PREFIX = "ROLE_"; - /** - * JWT存储权限属性 - */ - String AUTHORITY_CLAIM_NAME = "authorities"; + /** * 认证信息Http请求头 @@ -56,6 +49,17 @@ public interface AuthConstants { String JWT_CLIENT_ID_KEY = "client_id"; + /** + * JWT存储权限前缀 + */ + String AUTHORITY_PREFIX = "ROLE_"; + + /** + * JWT存储权限属性 + */ + String JWT_AUTHORITIES_KEY = "authorities"; + + /** * 有来商城后台管理客户端ID */ diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/SystemConstants.java b/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/SystemConstants.java index caa8c28d1..7f65a4a32 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/SystemConstants.java +++ b/youlai-common/common-core/src/main/java/com/youlai/common/core/constant/SystemConstants.java @@ -6,6 +6,5 @@ public interface SystemConstants { Integer VISIBLE_SHOW_VALUE = 1; - String SYSTEM_TYPE_KEY = "SystemType"; } diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/core/enums/QueryModeEnum.java b/youlai-common/common-core/src/main/java/com/youlai/common/core/enums/QueryModeEnum.java index 3cb5fe61a..c2f543305 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/core/enums/QueryModeEnum.java +++ b/youlai-common/common-core/src/main/java/com/youlai/common/core/enums/QueryModeEnum.java @@ -9,6 +9,8 @@ public enum QueryModeEnum { LIST("list","列表查询"), TREE("tree","树形列表"), CASCADER("cascader","级联列表"), // 对应级联选择器的下拉格式数据 + ROUTER("router","路由列表"), + TREESELECT("treeselect","树形下拉列表") ; @Getter diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/util/WebUtils.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/util/WebUtils.java index ed36914cb..773350bad 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/util/WebUtils.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/util/WebUtils.java @@ -1,15 +1,15 @@ package com.youlai.common.web.util; -import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.youlai.common.core.constant.AuthConstants; -import com.youlai.common.core.constant.SystemConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.stream.Collectors; @Slf4j public class WebUtils extends org.springframework.web.util.WebUtils { @@ -36,12 +36,9 @@ public class WebUtils extends org.springframework.web.util.WebUtils { return clientId; } - public static Integer getSystemType() { - String systemType = getHttpServletRequest().getHeader(SystemConstants.SYSTEM_TYPE_KEY); - if (StrUtil.isNotBlank(systemType)) { - return Integer.valueOf(systemType); - } - return null; + public static List getAuthorities() { + List list = getJwtPayload().get(AuthConstants.JWT_AUTHORITIES_KEY, List.class); + List authorities = list.stream().map(Long::valueOf).collect(Collectors.toList()); + return authorities; } - } diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/config/ResourceServerConfig.java b/youlai-gateway/src/main/java/com/youlai/gateway/config/ResourceServerConfig.java index b53c94dac..69036cde8 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/config/ResourceServerConfig.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/config/ResourceServerConfig.java @@ -116,7 +116,7 @@ public class ResourceServerConfig { public Converter> jwtAuthenticationConverter() { JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter(); jwtGrantedAuthoritiesConverter.setAuthorityPrefix(AuthConstants.AUTHORITY_PREFIX); - jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName(AuthConstants.AUTHORITY_CLAIM_NAME); + jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName(AuthConstants.JWT_AUTHORITIES_KEY); JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter(); jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter);