|
|
@@ -694,6 +694,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
int type = content.getType();
|
|
|
Long courseId = content.getCourseId();
|
|
|
Long videoId = content.getVideoId();
|
|
|
+ Long liveId = content.getLiveId();
|
|
|
Integer isOfficial = content.getIsOfficial() != null ? Integer.valueOf(content.getIsOfficial()) : 0;
|
|
|
|
|
|
|
|
|
@@ -752,7 +753,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
ruleTimeVO.setType(2);
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
type, qwUserId, companyUserId, companyId, groupChat.getChatId(), welcomeText, qwUserName,
|
|
|
- null, true, miniAppId, groupChat,config, miniMap, null, sendMsgType,companies);
|
|
|
+ null, true, miniAppId, groupChat,config, miniMap, null, sendMsgType,companies,liveId);
|
|
|
}
|
|
|
// if (content.getIndex() == 0) {
|
|
|
// QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, groupChat.getChatId(), groupChat.getName(), null, isOfficial, null);
|
|
|
@@ -782,7 +783,7 @@ 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);
|
|
|
+ null,config, miniMap, grade, sendMsgType,companies,liveId);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理 externalContactId {} 时发生异常: {}", contactId, e.getMessage(), e);
|
|
|
}
|
|
|
@@ -898,7 +899,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
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 ) {
|
|
|
+ Integer grade, Integer sendMsgType ,List<Company> companies ,Long liveId) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
handleNormalMessage(sopLogs, content,companyUserId,companyId,isGroupChat,qwUserId,groupChat,externalId,logVo);
|
|
|
@@ -920,6 +921,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
case 7:
|
|
|
handleVoiceMessage(sopLogs, content, companyUserId);
|
|
|
break;
|
|
|
+ //直播间发送类型
|
|
|
+ case 20:
|
|
|
+ handleLiveMessage(sopLogs, content,companyUserId,companyId,isGroupChat,qwUserId,groupChat,externalId,logVo,liveId);
|
|
|
default:
|
|
|
log.error("未知的消息类型 {},跳过处理。", type);
|
|
|
break;
|
|
|
@@ -1003,6 +1007,83 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
enqueueQwSopLogs(sopLogs);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理直播消息
|
|
|
+ */
|
|
|
+ public void handleLiveMessage(QwSopLogs sopLogs,QwSopTempSetting.Content content, String companyUserId, String companyId,
|
|
|
+ boolean isGroupChat,String qwUserId,QwGroupChat groupChat,String externalId,SopUserLogsVo logVo,Long liveId){
|
|
|
+ // 深拷贝 Content 对象,避免使用 JSON
|
|
|
+ QwSopTempSetting.Content clonedContent = deepCopyContent(content);
|
|
|
+ if (clonedContent == null) {
|
|
|
+ log.error("Failed to clone content, skipping handleCourseMessage.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ clonedContent.setLiveId(liveId);
|
|
|
+ List<QwSopTempSetting.Content.Setting> settings = clonedContent.getSetting();
|
|
|
+ if (settings == null || settings.isEmpty()) {
|
|
|
+ log.error("Cloned content settings are empty, skipping.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //直播发送类型
|
|
|
+ sopLogs.setSendType(20);
|
|
|
+
|
|
|
+ // 顺序处理每个 Setting,避免过多的并行导致线程开销
|
|
|
+ for (QwSopTempSetting.Content.Setting setting : settings) {
|
|
|
+ switch (setting.getContentType()) {
|
|
|
+ //直播小程序单独
|
|
|
+ case "12":
|
|
|
+ clonedContent.setLiveId(setting.getLiveId());
|
|
|
+ String sortLiveLink;
|
|
|
+ sortLiveLink = "/pages_course/living.html?companyId=" + companyId + "&companyUserId=" + companyUserId + "&liveId=" + setting.getLiveId() + "&corpId=" + logVo.getCorpId()+"&qwUserId=" + qwUserId;
|
|
|
+ String json = configService.selectConfigByKey("his.config");
|
|
|
+ FSSysConfig sysConfig = JSON.parseObject(json, FSSysConfig.class);
|
|
|
+ if (isGroupChat) {
|
|
|
+ try {
|
|
|
+ groupChat.getChatUserList().stream().filter(e -> e.getUserList() != null && !e.getUserList().isEmpty()).forEach(e -> {
|
|
|
+ Map<String, GroupUserExternalVo> userMap = PubFun.listToMapByGroupObject(e.getUserList(), GroupUserExternalVo::getUserId);
|
|
|
+ GroupUserExternalVo vo = userMap.get(groupChat.getOwner());
|
|
|
+ if (vo != null && vo.getId() != null) {
|
|
|
+ sopLogs.setFsUserId(vo.getFsUserId());
|
|
|
+ //写入直播待看课记录
|
|
|
+ createLiveWatchLogAndEnQueue(companyId, companyUserId, vo.getId().toString(), setting.getLiveId(), sysConfig.getAppId(), 2, qwUserId,logVo.getCorpId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sortLiveLink += "&chatId=" + groupChat.getChatId();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("直播小程序群聊新增报错,{}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ createLiveWatchLogAndEnQueue(companyId, companyUserId, externalId, setting.getLiveId(), sysConfig.getAppId(), 1, qwUserId,logVo.getCorpId());
|
|
|
+ sortLiveLink += "&externalId=" + externalId;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("直播小程序个人新增报错,{}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String miniprogramLiveTitle = setting.getMiniprogramTitle();
|
|
|
+ int maxLiveLength = 17;
|
|
|
+ setting.setMiniprogramTitle(miniprogramLiveTitle.length() > maxLiveLength ? miniprogramLiveTitle.substring(0, maxLiveLength) + "..." : miniprogramLiveTitle);
|
|
|
+ setting.setMiniprogramAppid(sysConfig.getAppId());
|
|
|
+ setting.setMiniprogramPage(sortLiveLink);
|
|
|
+ setting.setContentType("4");
|
|
|
+ try {
|
|
|
+ setting.setMiniprogramPicUrl(StringUtil.strIsNullOrEmpty(setting.getMiniprogramPicUrl()) ? "https://cos.his.cdwjyyh.com/fs/20250331/ec2b4e73be8048afbd526124a655ad56.png" : setting.getMiniprogramPicUrl());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("赋值-小程序封面地址失败-" + e);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sopLogs.setContentJson(JSON.toJSONString(clonedContent));
|
|
|
+
|
|
|
+ enqueueQwSopLogs(sopLogs);
|
|
|
+ }
|
|
|
+
|
|
|
private void handleAIMessage(QwSopLogs sopLogs, QwSopTempSetting.Content content) {
|
|
|
sopLogs.setContentJson(JSON.toJSONString(content));
|
|
|
sopLogs.setSort(3);
|
|
|
@@ -1988,17 +2069,18 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
)
|
|
|
public void batchInsertLiveWatchLog(List<LiveWatchLog> liveWatchLogToInsert) {
|
|
|
try {
|
|
|
- List<LiveWatchLog> lastInsertList = new ArrayList<>();
|
|
|
+ //更改为set 避免同一批生成的消息里面有重复数据 插入会报错
|
|
|
+ Set<LiveWatchLog> lastInsertSet = new HashSet<>();
|
|
|
//判断是否存在数据 liveId + his_qw_external_contact_id + qwUserId 唯一
|
|
|
for (LiveWatchLog liveWatchLog : liveWatchLogToInsert) {
|
|
|
//判断是否存在数据 存在的数据直接更新发送时间
|
|
|
if(liveWatchLogMapper.updateLiveWatchLogCondition(liveWatchLog) > 0){
|
|
|
continue;
|
|
|
}
|
|
|
- lastInsertList.add(liveWatchLog);
|
|
|
+ lastInsertSet.add(liveWatchLog);
|
|
|
}
|
|
|
- if(!lastInsertList.isEmpty()){
|
|
|
- liveWatchLogMapper.insertLiveWatchLogBatch(lastInsertList);
|
|
|
+ if(!lastInsertSet.isEmpty()){
|
|
|
+ liveWatchLogMapper.insertLiveWatchLogBatch(new ArrayList<>(lastInsertSet));
|
|
|
}
|
|
|
// log.info("批量插入 LiveWatchLog 完成,共插入 {} 条记录。", liveWatchLogToInsert.size());
|
|
|
} catch (Exception e) {
|