报表修改获取token的方式
continuous-integration/drone/push Build is passing Details

畅捷通同步方案更新
YXY 1 year ago
parent 1f05872c8f
commit 8c397edad7

@ -59,6 +59,18 @@ public class RefreshTokenJob {
return generateToken(value,ticket); return generateToken(value,ticket);
} }
public void waitForToken(CjtAccountEnum cjtAccountEnum){
try {
String refreshCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TICKET_REFRESH_CACHE_KEY, cjtAccountEnum.getAppKey());
Long expireTime = redisCache.getExpireTime(refreshCacheKey);
if (expireTime != null && expireTime > 0){
Thread.sleep(expireTime);
}
}catch (Exception e){
log.info("",e);
}
}
/** /**
* ticket, * ticket,
*/ */

@ -193,7 +193,7 @@ public abstract class SyncAccountsJobAbstract {
redisCache.deleteObject(asynchronous); redisCache.deleteObject(asynchronous);
} else { } else {
String errorInfo = buildRobotErrorCountMessage2(e, queryFromTime, queryToTime); String errorInfo = buildRobotErrorCountMessage2(e, queryFromTime, queryToTime);
if (!StringUtils.isEmpty(errorInfo) && !errorInfo.contains("openToken已失效") && !errorInfo.contains("会话过期请重新登录")) { if (!StringUtils.isEmpty(errorInfo)) {
larkRobotHelper.sendMessageByBot(ROBOT_GROUP, errorInfo); larkRobotHelper.sendMessageByBot(ROBOT_GROUP, errorInfo);
} }
// CJTRetryRequest request = new CJTRetryRequest(now, 1, cjt); // CJTRetryRequest request = new CJTRetryRequest(now, 1, cjt);
@ -590,7 +590,7 @@ public abstract class SyncAccountsJobAbstract {
String openToken = (String) redisCache.getCacheObject(tokenCacheKey); String openToken = (String) redisCache.getCacheObject(tokenCacheKey);
if (StringUtils.isEmpty(openToken)) { if (StringUtils.isEmpty(openToken)) {
CjtAccountEnum cjtAccountEnum = cjtAccount(context.getCjt()); CjtAccountEnum cjtAccountEnum = cjtAccount(context.getCjt());
waitForToken(cjtAccountEnum); refreshTokenJob.waitForToken(cjtAccountEnum);
return refreshTokenJob.getToken(cjtAccountEnum); return refreshTokenJob.getToken(cjtAccountEnum);
} else { } else {
context.setOpenToken(openToken); context.setOpenToken(openToken);
@ -598,17 +598,7 @@ public abstract class SyncAccountsJobAbstract {
} }
} }
private void waitForToken(CjtAccountEnum cjtAccountEnum){
try {
String refreshCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TICKET_REFRESH_CACHE_KEY, cjtAccountEnum.getAppKey());
Long expireTime = redisCache.getExpireTime(refreshCacheKey);
if (expireTime != null && expireTime > 0){
Thread.sleep(expireTime);
}
}catch (Exception e){
log.info("",e);
}
}
/** /**
* token * token

@ -54,6 +54,8 @@ public class SyncReportJob {
private LarkTableHelper larkTableHelper; private LarkTableHelper larkTableHelper;
@Autowired @Autowired
private LarkRobotHelper larkRobotHelper; private LarkRobotHelper larkRobotHelper;
@Autowired
private RefreshTokenJob refreshTokenJob;
@Value("${lark.robot.group}") @Value("${lark.robot.group}")
private String ROBOT_GROUP; private String ROBOT_GROUP;
@Value("${sync.flag}") @Value("${sync.flag}")
@ -94,7 +96,7 @@ public class SyncReportJob {
//初始化飞书信息及相关配置 //初始化飞书信息及相关配置
initLarkInfo(context); initLarkInfo(context);
//重置ticket //重置ticket
resetTicket(context); // resetTicket(context);
// preSync(context); // preSync(context);
cleanTableDate(context); cleanTableDate(context);
//执行分页同步 //执行分页同步
@ -382,31 +384,44 @@ public class SyncReportJob {
context.setTicket(ticket); context.setTicket(ticket);
} }
/**
* token
*/
private String generateToken(CJTJobContext context) { private String generateToken(CJTJobContext context) {
String tokenCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, context.getAppKey()); String tokenCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, context.getAppKey());
String openToken = (String) redisCache.getCacheObject(tokenCacheKey); String openToken = (String) redisCache.getCacheObject(tokenCacheKey);
if (StringUtils.isBlank(openToken)) { if (org.springframework.util.StringUtils.isEmpty(openToken)) {
CJTRequest cjtRequest = new CJTRequest(REQUEST_GENERATE_TOKEN_PATH CjtAccountEnum cjtAccountEnum = cjtAccount(context.getCjt());
, context.getAppKey() refreshTokenJob.waitForToken(cjtAccountEnum);
, context.getAppSecret() return refreshTokenJob.getToken(cjtAccountEnum);
, context.getTicket()
, context.getCertificate());
cjtRequest.buildGenerateBody();
JSONObject body = JSONObject.parseObject(post(cjtRequest));
JSONObject value = body.getJSONObject("value");
String token = value.getString("accessToken");
context.setOpenToken(token);
redisCache.setCacheObject(tokenCacheKey, token, 5, TimeUnit.MINUTES);
return token;
} else { } else {
context.setOpenToken(openToken); context.setOpenToken(openToken);
return openToken; return openToken;
} }
} }
/**
* token
*/
// private String generateToken(CJTJobContext context) {
// String tokenCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, context.getAppKey());
// String openToken = (String) redisCache.getCacheObject(tokenCacheKey);
// if (StringUtils.isBlank(openToken)) {
// CJTRequest cjtRequest = new CJTRequest(REQUEST_GENERATE_TOKEN_PATH
// , context.getAppKey()
// , context.getAppSecret()
// , context.getTicket()
// , context.getCertificate());
// cjtRequest.buildGenerateBody();
// JSONObject body = JSONObject.parseObject(post(cjtRequest));
// JSONObject value = body.getJSONObject("value");
// String token = value.getString("accessToken");
// context.setOpenToken(token);
// redisCache.setCacheObject(tokenCacheKey, token, 5, TimeUnit.MINUTES);
// return token;
// } else {
// context.setOpenToken(openToken);
// return openToken;
// }
// }
/** /**
* token * token
*/ */

Loading…
Cancel
Save