|
@@ -159,27 +159,18 @@ public class FeiShuService {
|
|
|
}
|
|
}
|
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
|
return result;
|
|
return result;
|
|
|
- } catch (CustomException e) {
|
|
|
|
|
- Integer code = e.getCode();
|
|
|
|
|
- if (code == null) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- if (FeishuErrorCode.isAccountDisable(code)) {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Integer code = FeishuErrorCode.parseCodeFromException(e);
|
|
|
|
|
+ if (code != null && FeishuErrorCode.isAccountDisable(code)) {
|
|
|
disablePersonalAccount(account, e.getMessage());
|
|
disablePersonalAccount(account, e.getMessage());
|
|
|
log.warn("个人账号[{}]被禁用,尝试下一个", account.getAppId());
|
|
log.warn("个人账号[{}]被禁用,尝试下一个", account.getAppId());
|
|
|
- } else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
|
|
|
|
|
|
|
+ } else if (code != null && (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code))) {
|
|
|
log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
|
|
log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
|
|
|
} else {
|
|
} else {
|
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
|
|
+ param.getCompanyUserId(), param.getLink(), e.getMessage(), 2, code);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- return null;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
log.warn("所有个人账号失败,降级到公共账号池");
|
|
log.warn("所有个人账号失败,降级到公共账号池");
|
|
@@ -207,31 +198,22 @@ public class FeiShuService {
|
|
|
}
|
|
}
|
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
|
return result;
|
|
return result;
|
|
|
- } catch (CustomException e) {
|
|
|
|
|
- Integer code = e.getCode();
|
|
|
|
|
- if (code == null) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- if (FeishuErrorCode.isAccountDisable(code)) {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Integer code = FeishuErrorCode.parseCodeFromException(e);
|
|
|
|
|
+ if (code != null && FeishuErrorCode.isAccountDisable(code)) {
|
|
|
clientPool.disableAccount(account, e.getMessage());
|
|
clientPool.disableAccount(account, e.getMessage());
|
|
|
log.warn("公共账号被禁用,尝试下一个");
|
|
log.warn("公共账号被禁用,尝试下一个");
|
|
|
- } else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
|
|
|
|
|
|
|
+ } else if (code != null && (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code))) {
|
|
|
log.warn("公共账号可重试错误,切换下一个");
|
|
log.warn("公共账号可重试错误,切换下一个");
|
|
|
} else {
|
|
} else {
|
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
|
|
+ param.getCompanyUserId(), param.getLink(), e.getMessage(), 2, code);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- return null;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
- param.getCompanyUserId(), param.getLink(), "所有公共账号不可用", 2);
|
|
|
|
|
|
|
+ param.getCompanyUserId(), param.getLink(), "所有公共账号不可用", 2, null);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -274,27 +256,18 @@ public class FeiShuService {
|
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
|
redisCache.setCacheObject(cacheKey, result, 72, TimeUnit.HOURS);
|
|
redisCache.setCacheObject(cacheKey, result, 72, TimeUnit.HOURS);
|
|
|
return result;
|
|
return result;
|
|
|
- } catch (CustomException e) {
|
|
|
|
|
- Integer code = e.getCode();
|
|
|
|
|
- if (code == null) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- throw new CustomException(e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- if (FeishuErrorCode.isAccountDisable(code)) {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Integer code = FeishuErrorCode.parseCodeFromException(e);
|
|
|
|
|
+ if (code != null && FeishuErrorCode.isAccountDisable(code)) {
|
|
|
disablePersonalAccount(account, e.getMessage());
|
|
disablePersonalAccount(account, e.getMessage());
|
|
|
log.warn("个人账号[{}]被禁用,尝试下一个", account.getAppId());
|
|
log.warn("个人账号[{}]被禁用,尝试下一个", account.getAppId());
|
|
|
- } else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
|
|
|
|
|
|
|
+ } else if (code != null && (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code))) {
|
|
|
log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
|
|
log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
|
|
|
} else {
|
|
} else {
|
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
|
|
+ param.getCompanyUserId(), param.getLink(), e.getMessage(), 2, code);
|
|
|
throw new CustomException(e.getMessage());
|
|
throw new CustomException(e.getMessage());
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- throw new CustomException(e.getMessage());
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
log.warn("所有个人账号失败,降级到公共账号池");
|
|
log.warn("所有个人账号失败,降级到公共账号池");
|
|
@@ -315,31 +288,22 @@ public class FeiShuService {
|
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
|
redisCache.setCacheObject(cacheKey, result, 72, TimeUnit.HOURS);
|
|
redisCache.setCacheObject(cacheKey, result, 72, TimeUnit.HOURS);
|
|
|
return result;
|
|
return result;
|
|
|
- } catch (CustomException e) {
|
|
|
|
|
- Integer code = e.getCode();
|
|
|
|
|
- if (code == null) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- throw new CustomException(e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- if (FeishuErrorCode.isAccountDisable(code)) {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Integer code = FeishuErrorCode.parseCodeFromException(e);
|
|
|
|
|
+ if (code != null && FeishuErrorCode.isAccountDisable(code)) {
|
|
|
clientPool.disableAccount(account, e.getMessage());
|
|
clientPool.disableAccount(account, e.getMessage());
|
|
|
log.warn("公共账号被禁用,尝试下一个");
|
|
log.warn("公共账号被禁用,尝试下一个");
|
|
|
- } else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
|
|
|
|
|
|
|
+ } else if (code != null && (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code))) {
|
|
|
log.warn("公共账号可重试错误,切换下一个");
|
|
log.warn("公共账号可重试错误,切换下一个");
|
|
|
} else {
|
|
} else {
|
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
|
|
+ param.getCompanyUserId(), param.getLink(), e.getMessage(), 2, code);
|
|
|
throw new CustomException(e.getMessage());
|
|
throw new CustomException(e.getMessage());
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
|
|
- param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
|
|
|
|
|
- throw new CustomException(e.getMessage());
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
|
|
|
- param.getCompanyUserId(), param.getLink(), "所有公共账号不可用", 2);
|
|
|
|
|
|
|
+ param.getCompanyUserId(), param.getLink(), "所有公共账号不可用", 2, null);
|
|
|
log.error("所有飞书账号创建文档失败");
|
|
log.error("所有飞书账号创建文档失败");
|
|
|
throw new CustomException("课程不存在或已过期,请联系管理员");
|
|
throw new CustomException("课程不存在或已过期,请联系管理员");
|
|
|
}
|
|
}
|
|
@@ -372,7 +336,8 @@ public class FeiShuService {
|
|
|
//记录错误
|
|
//记录错误
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
public void recordLinkError(Long videoId, Long companyId, Long courseId,
|
|
public void recordLinkError(Long videoId, Long companyId, Long courseId,
|
|
|
- Long companyUserId, String link, String errorInfo, Integer type) {
|
|
|
|
|
|
|
+ Long companyUserId, String link, String errorInfo,
|
|
|
|
|
+ Integer type, Integer errorCode) {
|
|
|
FeishuLinkError error = new FeishuLinkError();
|
|
FeishuLinkError error = new FeishuLinkError();
|
|
|
error.setVideoId(videoId);
|
|
error.setVideoId(videoId);
|
|
|
error.setCompanyId(companyId);
|
|
error.setCompanyId(companyId);
|
|
@@ -382,6 +347,7 @@ public class FeiShuService {
|
|
|
error.setErrorInfo(errorInfo);
|
|
error.setErrorInfo(errorInfo);
|
|
|
error.setCreateTime(DateUtils.getNowDate());
|
|
error.setCreateTime(DateUtils.getNowDate());
|
|
|
error.setType(type);
|
|
error.setType(type);
|
|
|
|
|
+ error.setErrorCode(errorCode);
|
|
|
FsCourseLink fsCourseLink = courseLinkMapper.selectFsCourseLinkByLink(link);
|
|
FsCourseLink fsCourseLink = courseLinkMapper.selectFsCourseLinkByLink(link);
|
|
|
if (fsCourseLink != null) {
|
|
if (fsCourseLink != null) {
|
|
|
error.setQwUserId(fsCourseLink.getQwUserId());
|
|
error.setQwUserId(fsCourseLink.getQwUserId());
|
|
@@ -389,7 +355,7 @@ public class FeiShuService {
|
|
|
error.setCorpId(fsCourseLink.getCorpId());
|
|
error.setCorpId(fsCourseLink.getCorpId());
|
|
|
}
|
|
}
|
|
|
feishuLinkErrorMapper.insertFeishuLinkError(error);
|
|
feishuLinkErrorMapper.insertFeishuLinkError(error);
|
|
|
- log.info("飞书链接创建失败已记录,videoId={}, link={}, error={}", videoId, link, errorInfo);
|
|
|
|
|
|
|
+ log.info("飞书链接创建失败已记录,videoId={}, link={}, code={}, error={}", videoId, link, errorCode, errorInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private CourseConfig getCourseConfig() {
|
|
private CourseConfig getCourseConfig() {
|