Commit f7b870e2 by 徐高华

重试回退

parent 3ded251e
...@@ -1289,9 +1289,10 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -1289,9 +1289,10 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
String corpid = qwDTO.getThirdCorpid(); String corpid = qwDTO.getThirdCorpid();
String userId = ""; String userId = "";
TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(wxUserId, wxEnterpriseId); TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(wxUserId, wxEnterpriseId);
List<String> list = new ArrayList<>();
if (staff == null) { if (staff == null) {
log.error("员工为空,wxUserId:{}", wxUserId); log.error("员工为空,wxUserId:{}", wxUserId);
return null; return list;
} }
if (qwDTO.needOpenUserId3th()) { if (qwDTO.needOpenUserId3th()) {
userId = staff.getWxOpenUseId(); userId = staff.getWxOpenUseId();
...@@ -1300,7 +1301,6 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -1300,7 +1301,6 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
} }
log.info("【获取第三方应用好友】wxEnterpriseId={},userId={}", wxEnterpriseId, userId); log.info("【获取第三方应用好友】wxEnterpriseId={},userId={}", wxEnterpriseId, userId);
String wxRes = qywxUserApiService.listExternalUserid(corpid, config.getWxSuiteid(), userId); String wxRes = qywxUserApiService.listExternalUserid(corpid, config.getWxSuiteid(), userId);
List<String> list = new ArrayList<>();
log.info("【查询第三方应用】res={}", wxRes); log.info("【查询第三方应用】res={}", wxRes);
if ("1".equals(wxRes)) { if ("1".equals(wxRes)) {
log.info("代表需要重试"); log.info("代表需要重试");
......
...@@ -75,9 +75,14 @@ public class FriendClerkSyncNewOperation implements BaseSyncOperation { ...@@ -75,9 +75,14 @@ public class FriendClerkSyncNewOperation implements BaseSyncOperation {
List<String> selfUserIdList = memberUnionidRelatedApiService.listSelfExterialList(wxEnterpriseId, dkWxUserId); List<String> selfUserIdList = memberUnionidRelatedApiService.listSelfExterialList(wxEnterpriseId, dkWxUserId);
List<String> delUserIdList = selfUserIdList ; List<String> delUserIdList = selfUserIdList ;
logger.info("selfUserIdList={}", JSONObject.toJSONString(selfUserIdList)); logger.info("selfUserIdList={}", JSONObject.toJSONString(selfUserIdList));
if (null == selfUserIdList) {
dealFlag = tryAgainToMq(dataPre);
reason = "企微接口失败";
return;
}
if (CollectionUtils.isEmpty(selfUserIdList)) { if (CollectionUtils.isEmpty(selfUserIdList)) {
dealFlag = false; dealFlag = false;
reason = "无外部联系人/接口失败"; reason = "无外部联系人";
return; return;
} }
String wxUserId3th = staff.getWxUserId() ; String wxUserId3th = staff.getWxUserId() ;
...@@ -88,9 +93,15 @@ public class FriendClerkSyncNewOperation implements BaseSyncOperation { ...@@ -88,9 +93,15 @@ public class FriendClerkSyncNewOperation implements BaseSyncOperation {
if(!qwDTO.isSelf()) { if(!qwDTO.isSelf()) {
userIdList = memberUnionidRelatedApiService.listExterialList(wxEnterpriseId, wxUserId3th); userIdList = memberUnionidRelatedApiService.listExterialList(wxEnterpriseId, wxUserId3th);
delUserIdList = userIdList ; delUserIdList = userIdList ;
if (null == userIdList) {
dealFlag = tryAgainToMq(dataPre);
reason = "企微接口失败";
logger.info("第三方服务商外部联系人调用失败进入重试:{}", dataPre.getDataId());
return;
}
if (CollectionUtils.isEmpty(userIdList)) { if (CollectionUtils.isEmpty(userIdList)) {
dealFlag = false; dealFlag = false;
reason = "无外部联系人/接口失败"; reason = "无外部联系人";
return; return;
} }
} }
...@@ -187,4 +198,23 @@ public class FriendClerkSyncNewOperation implements BaseSyncOperation { ...@@ -187,4 +198,23 @@ public class FriendClerkSyncNewOperation implements BaseSyncOperation {
} }
} }
private boolean tryAgainToMq(TabHaobanPreDealLog dataPre) {
logger.info("需要重试:{}", dataPre.getDataId());
String key = TRY_AGAIN + dataPre.getTaskId() + ":" + dataPre.getDataId();
Object cache = RedisUtil.getCache(key);
if (null == cache) {
RedisUtil.setCache(key, 1, 2L, TimeUnit.HOURS);
} else {
int count = Integer.parseInt(cache.toString());
RedisUtil.setCache(key, count + 1);
if (count > 4) {
return false;
}
}
HashSet<String> reTrysIds = new HashSet<>();
reTrysIds.add(dataPre.getDataId());
dealDepartmentToMq(dataPre.getTaskId(), reTrysIds, SyncTaskStatusEnum.friend_clerk_sync);
return true;
}
} }
...@@ -108,6 +108,7 @@ public class FriendSyncNewOperation implements BaseSyncOperation { ...@@ -108,6 +108,7 @@ public class FriendSyncNewOperation implements BaseSyncOperation {
dealSuccess(taskId, dataPre.getDataId(), dataPre.getpDataId(), wxEnterpriseId); dealSuccess(taskId, dataPre.getDataId(), dataPre.getpDataId(), wxEnterpriseId);
} catch (WxApiLimitException e) { } catch (WxApiLimitException e) {
logger.info("接口次数限制:{}", JSONObject.toJSONString(dataPre)); logger.info("接口次数限制:{}", JSONObject.toJSONString(dataPre));
dealFlag = tryAgainToMq(dataPre);
reason = "接口重试超出限制"; reason = "接口重试超出限制";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -150,4 +151,41 @@ public class FriendSyncNewOperation implements BaseSyncOperation { ...@@ -150,4 +151,41 @@ public class FriendSyncNewOperation implements BaseSyncOperation {
@Override @Override
public void checkDepartmentTask(String taskId) { public void checkDepartmentTask(String taskId) {
} }
private boolean tryAgainToMq(TabHaobanPreDealLog dataPre) {
String key = TRY_AGAIN + dataPre.getTaskId() + ":" + dataPre.getDataId();
Object cache = RedisUtil.getCache(key);
if (null == cache) {
RedisUtil.setCache(key, 1, 2L, TimeUnit.HOURS);
} else {
Integer count = Integer.valueOf(cache.toString());
RedisUtil.setCache(key, count + 1);
if (count > 4) {
return false;
}
}
HashSet<String> reTrysIds = new HashSet<>();
reTrysIds.add(dataPre.getDataId());
dealDepartmentToMq(dataPre.getTaskId(), reTrysIds, SyncTaskStatusEnum.friend_sync);
return true;
}
private void dealDepartmentToMq(String taskId, Set<String> dealList, SyncTaskStatusEnum syncTaskStatusEnum) {
//预处理分组任务
syncTaskService.updateTaskStatus(taskId, syncTaskStatusEnum.getVal());
List<String> ret = dealList.stream().map(relationId -> {
DealParamMqDTO dealParamMqDTO = new DealParamMqDTO();
dealParamMqDTO.setData(relationId);
dealParamMqDTO.setTaskId(taskId);
dealParamMqDTO.setType(syncTaskStatusEnum.getVal());
return JSONObject.toJSONString(dealParamMqDTO);
}).collect(Collectors.toList());
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
clientInstance.sendBatchMessages("departmentSyncDealMq", ret);
} catch (Exception e) {
logger.info("发送失败:{}", taskId, e);
e.printStackTrace();
}
}
} }
...@@ -96,7 +96,8 @@ public class SelfFriendSyncNewOperation implements BaseSyncOperation { ...@@ -96,7 +96,8 @@ public class SelfFriendSyncNewOperation implements BaseSyncOperation {
dealSuccess(taskId, dataPre.getDataId(), dataPre.getpDataId(), wxEnterpriseId); dealSuccess(taskId, dataPre.getDataId(), dataPre.getpDataId(), wxEnterpriseId);
} catch (WxApiLimitException e) { } catch (WxApiLimitException e) {
logger.info("接口次数限制:{}", JSONObject.toJSONString(dataPre)); logger.info("接口次数限制:{}", JSONObject.toJSONString(dataPre));
reason = "getCorpSelfExternalUseridInfo重试次数过多"; dealFlag = tryAgainToMq(dataPre);
reason = "重试次数过多";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.info("同步失败:{},{}", JSONObject.toJSONString(dataPre), e); logger.info("同步失败:{},{}", JSONObject.toJSONString(dataPre), e);
...@@ -135,4 +136,43 @@ public class SelfFriendSyncNewOperation implements BaseSyncOperation { ...@@ -135,4 +136,43 @@ public class SelfFriendSyncNewOperation implements BaseSyncOperation {
@Override @Override
public void checkDepartmentTask(String taskId) { public void checkDepartmentTask(String taskId) {
} }
private boolean tryAgainToMq(TabHaobanPreDealLog dataPre) {
logger.info("需要重试self:{}", dataPre.getDataId());
String key = TRY_AGAIN + dataPre.getTaskId() + ":" + dataPre.getDataId();
Object cache = RedisUtil.getCache(key);
if (null == cache) {
RedisUtil.setCache(key, 1, 2L, TimeUnit.HOURS);
} else {
Integer count = Integer.valueOf(cache.toString());
RedisUtil.setCache(key, count + 1);
if (count > 4) {
return false;
}
}
HashSet<String> reTrysIds = new HashSet<>();
reTrysIds.add(dataPre.getDataId());
dealDepartmentToMq(dataPre.getTaskId(), reTrysIds, SyncTaskStatusEnum.self_friend_sync);
return true;
}
private void dealDepartmentToMq(String taskId, Set<String> dealList, SyncTaskStatusEnum syncTaskStatusEnum) {
//预处理分组任务
syncTaskService.updateTaskStatus(taskId, syncTaskStatusEnum.getVal());
List<String> ret = dealList.stream().map(relationId -> {
DealParamMqDTO dealParamMqDTO = new DealParamMqDTO();
dealParamMqDTO.setData(relationId);
dealParamMqDTO.setTaskId(taskId);
dealParamMqDTO.setType(syncTaskStatusEnum.getVal());
return JSONObject.toJSONString(dealParamMqDTO);
}).collect(Collectors.toList());
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
Log.info("发送队列SelfFriendSyncNewOperation={}",JSON.toJSONString(ret));
clientInstance.sendBatchMessages("departmentSyncDealMq2", ret);
} catch (Exception e) {
logger.info("发送失败:{},{}", taskId);
e.printStackTrace();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment