|
|
@ -84,15 +84,15 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
private static final String CERTIFICATE = "OXYwHSWAc22UPHxfIUM0SSFZwziCLmBfOzBaN+PCNp0SNfV3ewYIaWLJCCrYToCU46x3PJO8t4TXV57bGpbiqClld5DiAkQ3EX1qqxoyaE9J0HAsfnp/PkPurKMQewBHICM2oEPRyLU5GUQjTCucfLvO4xT3DKlelbjBsIkKLqs=";
|
|
|
|
private static final String CERTIFICATE = "OXYwHSWAc22UPHxfIUM0SSFZwziCLmBfOzBaN+PCNp0SNfV3ewYIaWLJCCrYToCU46x3PJO8t4TXV57bGpbiqClld5DiAkQ3EX1qqxoyaE9J0HAsfnp/PkPurKMQewBHICM2oEPRyLU5GUQjTCucfLvO4xT3DKlelbjBsIkKLqs=";
|
|
|
|
|
|
|
|
|
|
|
|
public void executeSync(String queryFromTime,String queryToTime) {
|
|
|
|
public void executeSync(String queryFromTime,String queryToTime) {
|
|
|
|
CJTJobContext context = new CJTJobContext(CJT_APP_KEY, CJT_APP_SECRET);
|
|
|
|
CJTJobContext context = new CJTJobContext();
|
|
|
|
context.setQueryFromTime(queryFromTime);
|
|
|
|
context.setQueryFromTime(queryFromTime);
|
|
|
|
context.setQueryToTime(queryToTime);
|
|
|
|
context.setQueryToTime(queryToTime);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
log.info("===================== {} strat ======================",this.getClassName());
|
|
|
|
log.info("===================== {} strat ======================",this.getClassName());
|
|
|
|
//重置ticket
|
|
|
|
|
|
|
|
resetTicket(context);
|
|
|
|
|
|
|
|
//初始化飞书信息及相关配置
|
|
|
|
//初始化飞书信息及相关配置
|
|
|
|
initLarkInfo(context);
|
|
|
|
initLarkInfo(context);
|
|
|
|
|
|
|
|
//重置ticket
|
|
|
|
|
|
|
|
resetTicket(context);
|
|
|
|
//执行分页同步
|
|
|
|
//执行分页同步
|
|
|
|
sync(context);
|
|
|
|
sync(context);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
@ -339,19 +339,30 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
return erpLarkRelation;
|
|
|
|
return erpLarkRelation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String buildCacheUniqueKey(String key,String appKey){
|
|
|
|
|
|
|
|
return String.format("%s:%s",key,appKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取ticket,失效前重置
|
|
|
|
* 获取ticket,失效前重置
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void resetTicket(CJTJobContext context) {
|
|
|
|
private void resetTicket(CJTJobContext context) {
|
|
|
|
Long expireTime = redisCache.getExpireTime(RedisConstants.CJT_TICKET_CACHE_KEY);
|
|
|
|
String ticketCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TICKET_CACHE_KEY, context.getAppKey());
|
|
|
|
|
|
|
|
Long expireTime = redisCache.getExpireTime(ticketCacheKey);
|
|
|
|
//重置ticket存在响应时间,提前十秒重置
|
|
|
|
//重置ticket存在响应时间,提前十秒重置
|
|
|
|
if (expireTime == null || expireTime < 10) {
|
|
|
|
if (expireTime == null || expireTime < 10) {
|
|
|
|
|
|
|
|
log.info("重置ticket");
|
|
|
|
CJTRequest cjtRequest = new CJTRequest(REQUEST_RESET_TICKET_PATH
|
|
|
|
CJTRequest cjtRequest = new CJTRequest(REQUEST_RESET_TICKET_PATH
|
|
|
|
, context.getAppKey()
|
|
|
|
, context.getAppKey()
|
|
|
|
, context.getAppSecret());
|
|
|
|
, context.getAppSecret());
|
|
|
|
post(cjtRequest);
|
|
|
|
post(cjtRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String ticket = (String) redisCache.getCacheObject(RedisConstants.CJT_TICKET_CACHE_KEY);
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String ticket = (String) redisCache.getCacheObject(ticketCacheKey);
|
|
|
|
context.setTicket(ticket);
|
|
|
|
context.setTicket(ticket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -359,7 +370,8 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
* 生成调用接口的token信息
|
|
|
|
* 生成调用接口的token信息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String generateToken(CJTJobContext context) {
|
|
|
|
private String generateToken(CJTJobContext context) {
|
|
|
|
String openToken = (String) redisCache.getCacheObject(RedisConstants.CJT_TOKEN_CACHE_KEY);
|
|
|
|
String tokenCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, context.getAppKey());
|
|
|
|
|
|
|
|
String openToken = (String) redisCache.getCacheObject(tokenCacheKey);
|
|
|
|
if (StringUtils.isEmpty(openToken)){
|
|
|
|
if (StringUtils.isEmpty(openToken)){
|
|
|
|
CJTRequest cjtRequest = new CJTRequest(REQUEST_GENERATE_TOKEN_PATH
|
|
|
|
CJTRequest cjtRequest = new CJTRequest(REQUEST_GENERATE_TOKEN_PATH
|
|
|
|
, context.getAppKey()
|
|
|
|
, context.getAppKey()
|
|
|
@ -371,7 +383,7 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
JSONObject value = body.getJSONObject("value");
|
|
|
|
JSONObject value = body.getJSONObject("value");
|
|
|
|
String token = value.getString("accessToken");
|
|
|
|
String token = value.getString("accessToken");
|
|
|
|
context.setOpenToken(token);
|
|
|
|
context.setOpenToken(token);
|
|
|
|
redisCache.setCacheObject(RedisConstants.CJT_TOKEN_CACHE_KEY,token,5, TimeUnit.MINUTES);
|
|
|
|
redisCache.setCacheObject(tokenCacheKey,token,5, TimeUnit.MINUTES);
|
|
|
|
return token;
|
|
|
|
return token;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
context.setOpenToken(openToken);
|
|
|
|
context.setOpenToken(openToken);
|
|
|
@ -396,6 +408,10 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(tableRelationQuery);
|
|
|
|
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(tableRelationQuery);
|
|
|
|
LarkTableRelation tableRelation = larkTableRelations.get(0);
|
|
|
|
LarkTableRelation tableRelation = larkTableRelations.get(0);
|
|
|
|
context.setTableRelation(tableRelation);
|
|
|
|
context.setTableRelation(tableRelation);
|
|
|
|
|
|
|
|
String remark = companyRelation.getRemark();
|
|
|
|
|
|
|
|
String[] arr = remark.split("_");
|
|
|
|
|
|
|
|
context.setAppKey(arr[0]);
|
|
|
|
|
|
|
|
context.setAppSecret(arr[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|