Merge branch 'uat-userinfo' into 'master'
Uat userinfo See merge request eshop/biz_service_ebtp_extend!107
This commit is contained in:
@ -1,16 +1,13 @@
|
|||||||
package com.chinaunicom.mall.ebtp.extend.userinfo.controller;
|
package com.chinaunicom.mall.ebtp.extend.userinfo.controller;
|
||||||
|
|
||||||
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
|
|
||||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.service.EbtpUserInfoService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@ -18,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
public class UserInfoController {
|
public class UserInfoController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserInfoService service;
|
private EbtpUserInfoService ebtpUserInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
@ -33,7 +30,18 @@ public class UserInfoController {
|
|||||||
log.error("access token is empty");
|
log.error("access token is empty");
|
||||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(service.getUserInfo(token));
|
return ResponseEntity.ok(ebtpUserInfoService.getUserInfo(token));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新redis缓存的信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("refresh")
|
||||||
|
public ResponseEntity<Boolean> refreshToken() {
|
||||||
|
return ResponseEntity.ok(ebtpUserInfoService.refresh());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseRole;
|
||||||
|
|
||||||
|
public interface BaseRoleMapper extends BaseMapper<BaseRole> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseUser;
|
||||||
|
|
||||||
|
public interface BaseUserMapper extends BaseMapper<BaseUser> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能模块bean
|
||||||
|
*
|
||||||
|
* @author zyx
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel
|
||||||
|
@TableName(value = "maint_base_role", autoResultMap = true)
|
||||||
|
public class BaseRole implements Serializable {
|
||||||
|
|
||||||
|
private static final Long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色")
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "备注")
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* role_id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "role_id")
|
||||||
|
private String roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "状态,0-默认")
|
||||||
|
private int status;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能模块bean
|
||||||
|
*
|
||||||
|
* @author zyx
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel
|
||||||
|
@TableName(value = "maint_base_user", autoResultMap = true)
|
||||||
|
public class BaseUser implements Serializable {
|
||||||
|
|
||||||
|
private static final Long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "编号")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "账号")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 省份
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "省份")
|
||||||
|
private String province;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色")
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "租户")
|
||||||
|
private String tenant;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.service;
|
||||||
|
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
|
|
||||||
|
public interface EbtpUserInfoService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BaseCacheUser getUserInfo(String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新redis缓存的信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean refresh();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.AuthorityEntity;
|
||||||
|
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.dao.BaseRoleMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.dao.BaseUserMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseRole;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseUser;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.service.EbtpUserInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EbtpUserInfoServiceImpl implements EbtpUserInfoService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserInfoService service;
|
||||||
|
@Autowired
|
||||||
|
private BaseUserMapper baseUserMapper;
|
||||||
|
@Autowired
|
||||||
|
private BaseRoleMapper baseRoleMapper;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
@Qualifier("cacheRedisTemplate")
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
private static final String EXTEND_USER_KEY = "ebtpUserTableCache";
|
||||||
|
private static final String USERS = "users";
|
||||||
|
private static final String ROLES = "roles";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseCacheUser getUserInfo(String token) {
|
||||||
|
//查询山分库
|
||||||
|
BaseCacheUser user = service.getUserInfo(token);
|
||||||
|
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
return new BaseCacheUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取redis缓存
|
||||||
|
Map<String, Object> userTable = getUserTable();
|
||||||
|
|
||||||
|
//获取用户信息
|
||||||
|
List<BaseUser> users = (List<BaseUser>) userTable.get(USERS);
|
||||||
|
BaseUser baseUser = users.stream().filter(u -> u.getAccount().equals(user.getLoginName())).findFirst().orElse(null);
|
||||||
|
if (Objects.isNull(baseUser)) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BaseRole> roles = (List<BaseRole>) userTable.get(ROLES);
|
||||||
|
user.setProvince(baseUser.getProvince())
|
||||||
|
//覆盖角色
|
||||||
|
.setAuthorityList(
|
||||||
|
Optional.of(roles
|
||||||
|
.stream()
|
||||||
|
.filter(r -> baseUser.getRole().contains(r.getRole()))
|
||||||
|
.map(br ->
|
||||||
|
new AuthorityEntity()
|
||||||
|
.setRoleId(br.getRoleId())
|
||||||
|
.setRoleCode(br.getRole())
|
||||||
|
.setRoleName(br.getRemarks())
|
||||||
|
.setRoleScope("EBTP")
|
||||||
|
.setAuthorities(Collections.emptyList()))
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.orElseGet(Collections::emptyList));
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String, Object> getUserTable() {
|
||||||
|
Object o = redisTemplate.opsForValue().get(EXTEND_USER_KEY);
|
||||||
|
|
||||||
|
if (Objects.isNull(o)) {
|
||||||
|
o = cacheUserTable();
|
||||||
|
}
|
||||||
|
return (Map<String, Object>) o ;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> cacheUserTable() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put(USERS, baseUserMapper.selectList(Wrappers.lambdaQuery(BaseUser.class).eq(BaseUser::getTenant, "ebtp_mall")));
|
||||||
|
map.put(ROLES, baseRoleMapper.selectList(Wrappers.emptyWrapper()));
|
||||||
|
redisTemplate.opsForValue().set(EXTEND_USER_KEY, map, 8, TimeUnit.HOURS);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除token缓存
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean refresh() {
|
||||||
|
cacheUserTable();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EbtpUserInfoServiceImpl() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
@ -36,8 +36,8 @@ spring:
|
|||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
username: mall
|
username: mall
|
||||||
password: unicom
|
password: unicom
|
||||||
jdbc-url: jdbc:mysql://10.125.160.26:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
jdbc-url: jdbc:mysql://10.125.160.30:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||||
url: jdbc:mysql://10.125.160.26:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
url: jdbc:mysql://10.125.160.30:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||||
filters: stat,wall,log4j
|
filters: stat,wall,log4j
|
||||||
maxActive: 20
|
maxActive: 20
|
||||||
initialSize: 1
|
initialSize: 1
|
||||||
@ -91,6 +91,12 @@ spring:
|
|||||||
master: eshop-redis
|
master: eshop-redis
|
||||||
nodes: 10.125.164.124:32718, 10.125.164.118:32716, 10.125.164.121:32716
|
nodes: 10.125.164.124:32718, 10.125.164.118:32716, 10.125.164.121:32716
|
||||||
password: Unicom#135
|
password: Unicom#135
|
||||||
|
database:
|
||||||
|
idempotent: 0
|
||||||
|
sharding: 1
|
||||||
|
cache: 2
|
||||||
|
backup: 3
|
||||||
|
|
||||||
|
|
||||||
# 天宫Eureka配置
|
# 天宫Eureka配置
|
||||||
eureka:
|
eureka:
|
||||||
@ -172,6 +178,8 @@ mconfig:
|
|||||||
bss:
|
bss:
|
||||||
app-id: 2ICalrrQ0F
|
app-id: 2ICalrrQ0F
|
||||||
app-secret: 1mb6n6635cJkDb3pEQPUFXc2nRJ8RPaS
|
app-secret: 1mb6n6635cJkDb3pEQPUFXc2nRJ8RPaS
|
||||||
|
app-url-test: 10.124.150.230:8000
|
||||||
|
app-url: 10.245.34.209:8000
|
||||||
document:
|
document:
|
||||||
clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749
|
clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749
|
||||||
|
|
||||||
@ -197,3 +205,14 @@ xxl:
|
|||||||
port: 18181
|
port: 18181
|
||||||
logpath: /data/applogs/xxl-job/jobhandler
|
logpath: /data/applogs/xxl-job/jobhandler
|
||||||
logretentiondays: 30
|
logretentiondays: 30
|
||||||
|
client:
|
||||||
|
clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749
|
||||||
|
allow:
|
||||||
|
apis :
|
||||||
|
- ^GET\./?v1/userinfo/get$
|
||||||
|
unifast:
|
||||||
|
sso:
|
||||||
|
public-key: 0428D625CEEB71CE823BD7D78DFEE7B122F2DA5C4D21E32253AD684D0FE21810394A799639C0CDFBFEB535A1DFD6A366A637E582CE0B1466A5FE7858841135DE6B
|
||||||
|
clientId: p6IPukcJ
|
||||||
|
redirectUrl: http://10.125.86.213:18000/redirect
|
||||||
|
getCode.url: http://10.125.86.213:18808/outer/v1.0/sso/decide
|
||||||
|
Reference in New Issue
Block a user