兼容多个畅捷通账号

沃森川job同步飞书
YXY 1 year ago
parent 280778d803
commit db5ee4ca24

@ -75,8 +75,9 @@ public class EdiController extends BaseController {
JSONObject bizContent = jsonObject.getJSONObject("bizContent");
String appTicket = bizContent.getString("appTicket");
if (StringUtils.isNotBlank(appTicket)) {
redisCache.setCacheObject(RedisConstants.CJT_TICKET_CACHE_KEY,appTicket,10, TimeUnit.MINUTES);
redisCache.deleteObject(RedisConstants.CJT_TOKEN_CACHE_KEY);
String appKey = jsonObject.getString("appKey");
redisCache.deleteObject(buildUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY,appKey));
redisCache.setCacheObject(buildUniqueKey(RedisConstants.CJT_TICKET_CACHE_KEY,appKey),appTicket,10, TimeUnit.MINUTES);
}
}catch (Exception e){
log.error("receiveWscTicket error request:{}",JSONObject.toJSONString(request),e);
@ -85,5 +86,9 @@ public class EdiController extends BaseController {
result.put("result","success");
return result;
}
private String buildUniqueKey(String key,String appKey){
return String.format("%s:%s",key,appKey);
}
}

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

Loading…
Cancel
Save