|
@@ -108,16 +108,20 @@ public class FeiShuService {
|
|
|
for (FeishuAccount account : personalAccounts) {
|
|
for (FeishuAccount account : personalAccounts) {
|
|
|
if (account.getStatus() != 1) continue;
|
|
if (account.getStatus() != 1) continue;
|
|
|
Client client = buildClient(account);
|
|
Client client = buildClient(account);
|
|
|
|
|
+ String step = "";
|
|
|
try {
|
|
try {
|
|
|
|
|
+ step = "创建文档";
|
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle() + "-注册");
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle() + "-注册");
|
|
|
|
|
+ step = "插入链接块";
|
|
|
String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
|
|
String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
|
|
|
docApiService.createTextLinkBlock(client, docId, authUrl);
|
|
docApiService.createTextLinkBlock(client, docId, authUrl);
|
|
|
|
|
+ step = "设置文档权限";
|
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
|
return "https://www.feishu.cn/docx/" + docId;
|
|
return "https://www.feishu.cn/docx/" + docId;
|
|
|
} catch (CustomException e) {
|
|
} catch (CustomException e) {
|
|
|
Integer code = e.getCode();
|
|
Integer code = e.getCode();
|
|
|
if (code == null) {
|
|
if (code == null) {
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, step, null, e.getMessage(), 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
@@ -127,11 +131,11 @@ public class FeiShuService {
|
|
|
log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
|
|
log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
|
|
|
} else {
|
|
} else {
|
|
|
// 业务错误或其他,记录失败并返回
|
|
// 业务错误或其他,记录失败并返回
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, step, code, e.getMessage(), 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, step, null, e.getMessage(), 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -142,16 +146,20 @@ public class FeiShuService {
|
|
|
int retries = clientPool.getAvailableCount();
|
|
int retries = clientPool.getAvailableCount();
|
|
|
for (int i = 0; i < retries; i++) {
|
|
for (int i = 0; i < retries; i++) {
|
|
|
Client client = clientPool.getClient();
|
|
Client client = clientPool.getClient();
|
|
|
|
|
+ String step = "";
|
|
|
try {
|
|
try {
|
|
|
|
|
+ step = "创建文档";
|
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle() + "-注册");
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle() + "-注册");
|
|
|
|
|
+ step = "插入链接块";
|
|
|
String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
|
|
String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
|
|
|
docApiService.createTextLinkBlock(client, docId, authUrl);
|
|
docApiService.createTextLinkBlock(client, docId, authUrl);
|
|
|
|
|
+ step = "设置文档权限";
|
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
|
return "https://www.feishu.cn/docx/" + docId;
|
|
return "https://www.feishu.cn/docx/" + docId;
|
|
|
} catch (CustomException e) {
|
|
} catch (CustomException e) {
|
|
|
Integer code = e.getCode();
|
|
Integer code = e.getCode();
|
|
|
if (code == null) {
|
|
if (code == null) {
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, step, null, e.getMessage(), 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
@@ -160,15 +168,15 @@ public class FeiShuService {
|
|
|
} else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
|
|
} else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
|
|
|
log.warn("公共账号可重试错误,切换下一个");
|
|
log.warn("公共账号可重试错误,切换下一个");
|
|
|
} else {
|
|
} else {
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, step, code, e.getMessage(), 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, step, null, e.getMessage(), 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, "所有公共账号不可用", 1);
|
|
|
|
|
|
|
+ recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, "降级", null, "所有公共账号不可用", 1);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -203,11 +211,15 @@ public class FeiShuService {
|
|
|
for (FeishuAccount account : personalAccounts) {
|
|
for (FeishuAccount account : personalAccounts) {
|
|
|
if (account.getStatus() != 1) continue;
|
|
if (account.getStatus() != 1) continue;
|
|
|
Client client = buildClient(account);
|
|
Client client = buildClient(account);
|
|
|
|
|
+ String step = "";
|
|
|
try {
|
|
try {
|
|
|
|
|
+ step = "创建文档";
|
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle());
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle());
|
|
|
|
|
+ step = "插入iframe块";
|
|
|
String courseUrl = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(),
|
|
String courseUrl = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(),
|
|
|
param.getCourseId(), param.getVideoId(), param.getUserId(), param.getLink(), questionFlag);
|
|
param.getCourseId(), param.getVideoId(), param.getUserId(), param.getLink(), questionFlag);
|
|
|
docApiService.createIframeBlock(client, docId, courseUrl);
|
|
docApiService.createIframeBlock(client, docId, courseUrl);
|
|
|
|
|
+ step = "设置文档权限";
|
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
|
redisCache.setCacheObject(cacheKey, result, 24, TimeUnit.HOURS);
|
|
redisCache.setCacheObject(cacheKey, result, 24, TimeUnit.HOURS);
|
|
@@ -216,7 +228,7 @@ public class FeiShuService {
|
|
|
Integer code = e.getCode();
|
|
Integer code = e.getCode();
|
|
|
if (code == null) {
|
|
if (code == null) {
|
|
|
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(), step, null, e.getMessage(), 2);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
@@ -226,12 +238,12 @@ public class FeiShuService {
|
|
|
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(), step, code, e.getMessage(), 2);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
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(), step, null, e.getMessage(), 2);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -242,11 +254,15 @@ public class FeiShuService {
|
|
|
int retries = clientPool.getAvailableCount();
|
|
int retries = clientPool.getAvailableCount();
|
|
|
for (int i = 0; i < retries; i++) {
|
|
for (int i = 0; i < retries; i++) {
|
|
|
Client client = clientPool.getClient();
|
|
Client client = clientPool.getClient();
|
|
|
|
|
+ String step = "";
|
|
|
try {
|
|
try {
|
|
|
|
|
+ step = "创建文档";
|
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle());
|
|
String docId = docApiService.createDocument(client, userCourseVideo.getTitle());
|
|
|
|
|
+ step = "插入iframe块";
|
|
|
String courseUrl = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(),
|
|
String courseUrl = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(),
|
|
|
param.getCourseId(), param.getVideoId(), param.getUserId(), param.getLink(), questionFlag);
|
|
param.getCourseId(), param.getVideoId(), param.getUserId(), param.getLink(), questionFlag);
|
|
|
docApiService.createIframeBlock(client, docId, courseUrl);
|
|
docApiService.createIframeBlock(client, docId, courseUrl);
|
|
|
|
|
+ step = "设置文档权限";
|
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
docApiService.changeDocumentPermissions(client, docId);
|
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
String result = "https://www.feishu.cn/docx/" + docId;
|
|
|
redisCache.setCacheObject(cacheKey, result, 24, TimeUnit.HOURS);
|
|
redisCache.setCacheObject(cacheKey, result, 24, TimeUnit.HOURS);
|
|
@@ -255,7 +271,7 @@ public class FeiShuService {
|
|
|
Integer code = e.getCode();
|
|
Integer code = e.getCode();
|
|
|
if (code == null) {
|
|
if (code == null) {
|
|
|
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(), step, null, e.getMessage(), 2);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
if (FeishuErrorCode.isAccountDisable(code)) {
|
|
@@ -265,17 +281,17 @@ public class FeiShuService {
|
|
|
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(), step, code, e.getMessage(), 2);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
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(), step, null, e.getMessage(), 2);
|
|
|
return null;
|
|
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(), "降级", null, "所有公共账号不可用", 2);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -293,7 +309,8 @@ public class FeiShuService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void recordLinkError(Long videoId, Long companyId, Long courseId,
|
|
private void recordLinkError(Long videoId, Long companyId, Long courseId,
|
|
|
- Long companyUserId, String link, String errorInfo, Integer type) {
|
|
|
|
|
|
|
+ Long companyUserId, String link, String step, Integer errorCode, String errorMsg, Integer type) {
|
|
|
|
|
+ String errorInfo = (errorCode != null ? "[code=" + errorCode + "] " : "") + "[" + step + "] " + errorMsg;
|
|
|
FeishuLinkError error = new FeishuLinkError();
|
|
FeishuLinkError error = new FeishuLinkError();
|
|
|
error.setVideoId(videoId);
|
|
error.setVideoId(videoId);
|
|
|
error.setCompanyId(companyId);
|
|
error.setCompanyId(companyId);
|
|
@@ -310,7 +327,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("飞书链接创建失败已记录,step={}, videoId={}, link={}, error={}", step, videoId, link, errorInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private CourseConfig getCourseConfig() {
|
|
private CourseConfig getCourseConfig() {
|