|
|
@@ -26,6 +26,7 @@ import com.fs.course.mapper.*;
|
|
|
import com.fs.course.service.IFsCourseLinkService;
|
|
|
import com.fs.course.service.IFsUserCompanyBindService;
|
|
|
import com.fs.feishu.service.FeiShuService;
|
|
|
+import com.fs.feishu.util.FeishuDirectDocShardAllocator;
|
|
|
import com.fs.live.domain.LiveWatchLog;
|
|
|
import com.fs.live.mapper.LiveWatchLogMapper;
|
|
|
import com.fs.qw.domain.*;
|
|
|
@@ -461,9 +462,10 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
}
|
|
|
|
|
|
CountDownLatch userLogsLatch = new CountDownLatch(userLogsVos.size());
|
|
|
+ FeishuDirectDocShardAllocator feishuShardAllocator = FeishuDirectDocShardAllocator.forAutoSop(config);
|
|
|
for (SopUserLogsVo logVo : userLogsVos) {
|
|
|
processUserLogAsync(logVo, ruleTimeVO, rulesList, userLogsLatch, currentTime, groupChatMap,qwCompany.getMiniAppId(),
|
|
|
- config,miniMap,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
+ config,miniMap,companies, deptMiniAppMap, companyUserDeptMap, feishuShardAllocator);
|
|
|
}
|
|
|
|
|
|
// 等待所有用户日志处理完成
|
|
|
@@ -485,9 +487,10 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
public void processUserLogAsync(SopUserLogsVo logVo, QwSopRuleTimeVO ruleTimeVO, List<QwSopTempRules> tempSettings,
|
|
|
CountDownLatch latch, LocalDateTime currentTime, Map<String, QwGroupChat> groupChatMap,
|
|
|
String miniAppId,CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
- List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap,
|
|
|
+ FeishuDirectDocShardAllocator feishuShardAllocator) {
|
|
|
try {
|
|
|
- processUserLog(logVo, ruleTimeVO, tempSettings,currentTime, groupChatMap, miniAppId, config,miniMap,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
+ processUserLog(logVo, ruleTimeVO, tempSettings,currentTime, groupChatMap, miniAppId, config,miniMap,companies, deptMiniAppMap, companyUserDeptMap, feishuShardAllocator);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理用户日志 {} 时发生异常: {}", logVo.getId(), e.getMessage(), e);
|
|
|
} finally {
|
|
|
@@ -499,7 +502,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
private void processUserLog(SopUserLogsVo logVo, QwSopRuleTimeVO ruleTimeVO, List<QwSopTempRules> tempSettings,
|
|
|
LocalDateTime currentTime, Map<String, QwGroupChat> groupChatMap,String miniAppId,
|
|
|
CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
- List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap,
|
|
|
+ FeishuDirectDocShardAllocator feishuShardAllocator) {
|
|
|
try {
|
|
|
|
|
|
LocalDate startDate = LocalDate.parse(logVo.getStartTime(), DATE_FORMATTER);
|
|
|
@@ -756,7 +760,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
insertSopUserLogs(sopUserLogsInfos, logVo, sendTime, ruleTimeVO, content, qwUserId,
|
|
|
companyUserId, companyId, qwUserByRedis.getWelcomeText(),qwUserByRedis.getQwUserName(),
|
|
|
- groupChatMap, miniAppId,config,miniMap, sendMsgType,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
+ groupChatMap, miniAppId,config,miniMap, sendMsgType,companies, deptMiniAppMap, companyUserDeptMap,
|
|
|
+ feishuShardAllocator);
|
|
|
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -802,7 +807,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
String qwUserId,String companyUserId,String companyId,String welcomeText,String qwUserName,
|
|
|
Map<String, QwGroupChat> groupChatMap,String miniAppId,CourseConfig config,
|
|
|
Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap, Integer sendMsgType,
|
|
|
- List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap,
|
|
|
+ FeishuDirectDocShardAllocator feishuShardAllocator) {
|
|
|
String formattedSendTime = sendTime.toInstant()
|
|
|
.atZone(ZoneId.systemDefault())
|
|
|
.format(DATE_TIME_FORMATTER);
|
|
|
@@ -882,7 +888,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, groupChat.getChatId(), groupChat.getName(), null, isOfficial, null,null);
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
type, qwUserId, companyUserId, companyId, groupChat.getChatId(), welcomeText, qwUserName,
|
|
|
- null, true, miniAppId, groupChat,config, miniMap, null, sendMsgType,companies,liveId, deptMiniAppMap, companyUserDeptMap);
|
|
|
+ null, true, miniAppId, groupChat,config, miniMap, null, sendMsgType,companies,liveId, deptMiniAppMap, companyUserDeptMap,
|
|
|
+ feishuShardAllocator);
|
|
|
}
|
|
|
// if (content.getIndex() == 0) {
|
|
|
// QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, groupChat.getChatId(), groupChat.getName(), null, isOfficial, null);
|
|
|
@@ -931,7 +938,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, contactId.getExternalContactId(), externalUserName, fsUserId, isOfficial, contactId.getExternalId(),contactId.getIsDaysNotStudy());
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
type, qwUserId, companyUserId, companyId, externalId, welcomeText, qwUserName, fsUserId, false, miniAppId,
|
|
|
- null,config, miniMap, grade, sendMsgType,companies,liveId, deptMiniAppMap, companyUserDeptMap);
|
|
|
+ null,config, miniMap, grade, sendMsgType,companies,liveId, deptMiniAppMap, companyUserDeptMap,
|
|
|
+ feishuShardAllocator);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("处理 externalContactId {} 时发生异常", contactId, e);
|
|
|
@@ -1091,7 +1099,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
QwGroupChat groupChat,CourseConfig config,
|
|
|
Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
Integer grade, Integer sendMsgType ,List<Company> companies ,Long liveId,
|
|
|
- Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
+ Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap,
|
|
|
+ FeishuDirectDocShardAllocator feishuShardAllocator) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
handleNormalMessage(sopLogs, content,companyUserId,companyId,isGroupChat,qwUserId,groupChat,externalId,logVo);
|
|
|
@@ -1099,7 +1108,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
case 2:
|
|
|
handleCourseMessage(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
qwUserId, companyUserId, companyId, externalId, welcomeText,qwUserName, fsUserId,
|
|
|
- isGroupChat, miniAppId, groupChat,config,miniMap, grade, sendMsgType,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
+ isGroupChat, miniAppId, groupChat,config,miniMap, grade, sendMsgType,companies, deptMiniAppMap, companyUserDeptMap,
|
|
|
+ feishuShardAllocator);
|
|
|
break;
|
|
|
case 3:
|
|
|
handleOrderMessage(sopLogs, content);
|
|
|
@@ -1317,7 +1327,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
String companyId, String externalId, String welcomeText, String qwUserName,
|
|
|
Long fsUserId, boolean isGroupChat, String miniAppId, QwGroupChat groupChat,CourseConfig config,Map<Long,
|
|
|
Map<Integer, List<CompanyMiniapp>>> miniMap,Integer grade, Integer sendMsgType,
|
|
|
- List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap,
|
|
|
+ FeishuDirectDocShardAllocator feishuShardAllocator) {
|
|
|
QwExternalContact contact = null;
|
|
|
if(logVo.getExternalId() != null){
|
|
|
contact = qwExternalContactMapper.selectById(logVo.getExternalId());
|
|
|
@@ -1613,8 +1624,13 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
qwUserId, companyUserId, companyId, externalIdLong, chatIdForFeishu, cachedCourseConfig);
|
|
|
String shortLink = feiShuLinkMap.get("link");
|
|
|
|
|
|
+ Integer directDocShard = null;
|
|
|
+ if (feishuShardAllocator != null && !FeiShuService.isAuthRequired(setting.getFeishuNeedAuth())) {
|
|
|
+ directDocShard = feishuShardAllocator.nextShard(companyUserIdLong, videoId, courseId,
|
|
|
+ setting.getFeishuAccountId());
|
|
|
+ }
|
|
|
String feishuLink = feiShuService.resolveFeishuSendLink(videoId, companyIdLong, courseId, companyUserIdLong,
|
|
|
- shortLink, setting.getFeishuAccountId(), setting.getFeishuNeedAuth());
|
|
|
+ shortLink, setting.getFeishuAccountId(), setting.getFeishuNeedAuth(), directDocShard);
|
|
|
if (StringUtils.isEmpty(feishuLink)) {
|
|
|
log.error("生成飞书注册链接失败,跳过本条: sopId={}, videoId={}, externalId={}",
|
|
|
logVo.getSopId(), videoId, externalId);
|