mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-04 01:52:21 +08:00
refactor:代码优化
This commit is contained in:
parent
e4b45afb19
commit
94ddd46c1e
@ -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<MemberInfoDTO> getMember(@PathVariable Long id, @RequestParam(value = "queryMode") Integer queryMode);
|
||||
@GetMapping("/api.app/v1/members/{id}")
|
||||
Result<MemberDTO> getMemberById(@PathVariable Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 获取会员信息
|
||||
* @param openid
|
||||
* @param queryMode 查询模式:1-认证会员
|
||||
* @return
|
||||
* 获取认证会员信息
|
||||
*/
|
||||
@GetMapping("/members/{openid}")
|
||||
Result<MemberDTO> loadMemberByOpenid(@PathVariable String openid, @RequestParam(value = "queryMode") Integer queryMode);
|
||||
@GetMapping("/api.app/v1/members/openid/{openid}")
|
||||
Result<AuthMemberDTO> getMemberByOpenid(@PathVariable String openid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.youlai.mall.ums.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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<UserDTO> loadUserByUsername(@PathVariable Object id, @RequestParam Integer queryMode);
|
||||
@GetMapping("/users/username/{username}")
|
||||
Result<UserDTO> getUserByUsername(@PathVariable String username);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Integer> menuIds;
|
||||
private List<Long> menuIds;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Integer> resourceIds;
|
||||
private List<Long> resourceIds;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ public class SysUserRole {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Integer roleId;
|
||||
private Long roleId;
|
||||
|
||||
}
|
||||
|
@ -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<Integer> roles;
|
||||
private List<Long> roles;
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.youlai.admin.vo;
|
||||
package com.youlai.admin.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -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;
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<Integer> roles;
|
||||
private List<Long> roles;
|
||||
|
||||
}
|
@ -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<MemberDTO> result = memberFeignService.loadMemberByOpenid(openid, 1);
|
||||
Result<AuthMemberDTO> 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的密码模式认证
|
||||
|
@ -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());
|
||||
|
@ -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<UserDTO> userRes = userFeignService.loadUserByUsername(username, 2);
|
||||
Result<UserDTO> 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<MemberDTO> memberRes = memberFeignService.loadMemberByOpenid(username, 1);
|
||||
Result<AuthMemberDTO> 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()) {
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -6,6 +6,5 @@ public interface SystemConstants {
|
||||
|
||||
Integer VISIBLE_SHOW_VALUE = 1;
|
||||
|
||||
String SYSTEM_TYPE_KEY = "SystemType";
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ public enum QueryModeEnum {
|
||||
LIST("list","列表查询"),
|
||||
TREE("tree","树形列表"),
|
||||
CASCADER("cascader","级联列表"), // 对应级联选择器的下拉格式数据
|
||||
ROUTER("router","路由列表"),
|
||||
TREESELECT("treeselect","树形下拉列表")
|
||||
;
|
||||
|
||||
@Getter
|
||||
|
@ -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<Long> getAuthorities() {
|
||||
List<String> list = getJwtPayload().get(AuthConstants.JWT_AUTHORITIES_KEY, List.class);
|
||||
List<Long> authorities = list.stream().map(Long::valueOf).collect(Collectors.toList());
|
||||
return authorities;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class ResourceServerConfig {
|
||||
public Converter<Jwt, ? extends Mono<? extends AbstractAuthenticationToken>> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user