【安眼】缓存用户token及用户登录信息
This commit is contained in:
+5
-1
@@ -132,7 +132,7 @@ public interface AnYanClient {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
AnYanUserInfoResult getAnYanUserInfo(String token);
|
||||
AnYanUserInfoResult getAnYanUserInfo(String token, String username);
|
||||
|
||||
/**
|
||||
* 批量拉取安眼平台AED信息 , 用于定时任务更新本地数据的AED数据
|
||||
@@ -175,6 +175,7 @@ public interface AnYanClient {
|
||||
|
||||
/**
|
||||
* 批量更新员工关键信息接口
|
||||
*
|
||||
* @param employeeNumList
|
||||
* @return
|
||||
*/
|
||||
@@ -183,6 +184,7 @@ public interface AnYanClient {
|
||||
/**
|
||||
* 更新单个员工扩展信息
|
||||
* 是否是借调人员 这个判断是依据 数据中是否存在currentOfficeId来决定的,存在说明是借调人员,不存在说明不是借调人员
|
||||
*
|
||||
* @param employeeNum
|
||||
* @return
|
||||
*/
|
||||
@@ -190,6 +192,7 @@ public interface AnYanClient {
|
||||
|
||||
/**
|
||||
* 体检数据
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@@ -197,6 +200,7 @@ public interface AnYanClient {
|
||||
|
||||
/**
|
||||
* 根据id查询体检数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
|
||||
+6
-1
@@ -103,6 +103,9 @@ public class AnYanClientExecutor implements AnYanClient {
|
||||
ResponseEntity<AuthResult> authResult = RestTemplateUtil.postExchangeForGetTokenByPassword(AnYanApiEnum.QUERY_AUTH_TOKEN, formData, headers, AuthResult.class);
|
||||
if (HttpStatus.OK.equals(authResult.getStatusCode())
|
||||
&& ObjectUtils.isNotEmpty(authResult.getBody())) {
|
||||
String token = authResult.getBody().getAccess_token();
|
||||
int expireSeconds = ObjectUtil.isNotEmpty(authResult.getBody().getExpires_in()) ? authResult.getBody().getExpires_in() : 3600;
|
||||
redisClientUtil.set(new RedisKeyPrefix(expireSeconds, AnYanConstants.AN_YAN_API_USER_TOKEN_PREFIX), username, token);
|
||||
return authResult.getBody();
|
||||
} else {
|
||||
log.error("------安眼系统获取token失败(密码模式){}------", authResult.getBody());
|
||||
@@ -293,10 +296,11 @@ public class AnYanClientExecutor implements AnYanClient {
|
||||
*/
|
||||
@Override
|
||||
@Retryable(maxAttempts = 2)
|
||||
public AnYanUserInfoResult getAnYanUserInfo(String token) {
|
||||
public AnYanUserInfoResult getAnYanUserInfo(String token, String username) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(AnYanConstants.AUTHORIZATION, AnYanConstants.TOKEN_TYPE + token);
|
||||
ResponseEntity<AnYanUserInfoResult> exchange = RestTemplateUtil.getExchange(AnYanApiEnum.USER_INFO_UNIT_V2, headers, AnYanUserInfoResult.class);
|
||||
redisClientUtil.set(new RedisKeyPrefix(-1, AnYanConstants.AN_YAN_API_USERINFO_PREFIX), username, exchange);
|
||||
return BeanUtil.toBean(exchange.getBody(), AnYanUserInfoResult.class);
|
||||
}
|
||||
|
||||
@@ -308,6 +312,7 @@ public class AnYanClientExecutor implements AnYanClient {
|
||||
IPage<AnYanAedInfo> aedPage = new PageResultToBeanUtil<AnYanAedInfo>().transform(result, AnYanAedInfo.class);
|
||||
return aedPage.getRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Retryable(maxAttempts = 2)
|
||||
public List<CarePersonList> homeCarePersonList() {
|
||||
|
||||
+10
@@ -34,6 +34,16 @@ public interface AnYanConstants {
|
||||
*/
|
||||
String AN_YAN_API_TOKEN_PREFIX = "exterior:anyan:api:";
|
||||
|
||||
/**
|
||||
* 缓存安眼用户登录token
|
||||
*/
|
||||
String AN_YAN_API_USER_TOKEN_PREFIX = "exterior:anyan:api:access_token";
|
||||
|
||||
/**
|
||||
* 缓存安眼用户信息
|
||||
*/
|
||||
String AN_YAN_API_USERINFO_PREFIX = "exterior:anyan:api:userinfo";
|
||||
|
||||
/**
|
||||
* 部分业务接口需要代入的请求头参数Roles
|
||||
*/
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
|
||||
}
|
||||
|
||||
// 授权成功获取用户信息(统一认证的平台接口没有做统一封装,成功和失败均返回一个不同的json字符串, 这里只能判断没有获取到用户信息则认为是失败)
|
||||
AnYanUserInfoResult anYanUserInfo = anYanClient.getAnYanUserInfo(anYanAuthResult.getAccess_token());
|
||||
AnYanUserInfoResult anYanUserInfo = anYanClient.getAnYanUserInfo(anYanAuthResult.getAccess_token(), username);
|
||||
if (anYanUserInfo == null || anYanUserInfo.getEmployeeUnitDTO() == null) {
|
||||
return Result.error("登录失败,请先联系本单位掌油管理员确认个人机构信息");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user