|
@@ -2,10 +2,13 @@ package com.fs.app.taskService.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.app.taskService.SopLogsTaskService;
|
|
|
import com.fs.common.utils.BatchUtils;
|
|
|
import com.fs.common.utils.PubFun;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
|
import com.fs.course.mapper.FsCourseDomainNameMapper;
|
|
@@ -17,6 +20,7 @@ import com.fs.fastgptApi.vo.AudioVO;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.service.IQwExternalContactService;
|
|
|
import com.fs.qw.vo.QwSopCourseFinishTempSetting;
|
|
|
import com.fs.qw.vo.QwSopRuleTimeVO;
|
|
|
import com.fs.qw.vo.QwSopTempSetting;
|
|
@@ -122,6 +126,10 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
@Autowired
|
|
|
private QwSopTempMapper qwSopTempMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyUserService companyUserService;
|
|
|
+ @Autowired
|
|
|
+ private IQwExternalContactService qwExternalContactService;
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
@@ -244,7 +252,35 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 查询销售二级域名
|
|
|
+ Set<Long> ids = sopUserLogsVos.stream().map(s -> {
|
|
|
+ String[] userKey = s.getUserId().split("\\|");
|
|
|
+ if (userKey.length < 3) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return Long.parseLong(userKey[1]);
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ List<CompanyUser> companyUserList;
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ companyUserList = new ArrayList<>();
|
|
|
+ } else {
|
|
|
+ companyUserList = companyUserService.selectCompanyUserByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
Map<String, List<SopUserLogsVo>> sopLogsGroupedById = sopUserLogsVos.stream()
|
|
|
+ .peek(s -> {
|
|
|
+ String[] userKey = s.getUserId().split("\\|");
|
|
|
+ if (userKey.length < 3) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 销售ID
|
|
|
+ Long companyUserId = Long.parseLong(userKey[1]);
|
|
|
+ CompanyUser companyUser = companyUserList.stream().filter(cu -> Objects.equals(cu.getUserId(), companyUserId)).findFirst().orElse(null);
|
|
|
+ if (Objects.nonNull(companyUser)) {
|
|
|
+ s.setDomain(companyUser.getDomain());
|
|
|
+ }
|
|
|
+ })
|
|
|
.collect(Collectors.groupingBy(SopUserLogsVo::getSopId));
|
|
|
|
|
|
log.info("共分组 {} 个 SOP ID 进行处理。", sopLogsGroupedById.size());
|
|
@@ -466,6 +502,18 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
List<SopUserLogsInfo> sopUserLogsInfos = sopUserLogsInfoMapper.selectSopUserLogsInfoList(userLogsInfo);
|
|
|
|
|
|
+ // 获取fsUserId
|
|
|
+ Set<Long> externalIds = sopUserLogsInfos.stream().map(SopUserLogsInfo::getExternalId).collect(Collectors.toSet());
|
|
|
+ if (!externalIds.isEmpty()) {
|
|
|
+ List<QwExternalContact> externalContactList = qwExternalContactService.list(Wrappers.<QwExternalContact>lambdaQuery().in(QwExternalContact::getId, externalIds));
|
|
|
+ sopUserLogsInfos.forEach(s -> {
|
|
|
+ QwExternalContact qwExternalContact = externalContactList.stream().filter(e -> Objects.equals(s.getExternalId(), e.getId())).findFirst().orElse(null);
|
|
|
+ if (Objects.nonNull(qwExternalContact)) {
|
|
|
+ s.setFsUserId(qwExternalContact.getFsUserId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
insertSopUserLogs(sopUserLogsInfos, logVo, sendTime, ruleTimeVO, content);
|
|
|
|
|
|
}
|
|
@@ -570,7 +618,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
Long fsUserId = contactId.getFsUserId();
|
|
|
QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, contactId.getExternalContactId(), externalUserName, fsUserId);
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
- type, qwUserId, companyUserId, companyId, externalId);
|
|
|
+ type, qwUserId, companyUserId, companyId, externalId, fsUserId);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理 externalContactId {} 时发生异常: {}", contactId, e.getMessage(), e);
|
|
|
}
|
|
@@ -622,14 +670,14 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
private void handleLogBasedOnType(QwSopLogs sopLogs, QwSopTempSetting.Content content,
|
|
|
SopUserLogsVo logVo, Date sendTime, Long courseId,
|
|
|
Long videoId, int type, String qwUserId,
|
|
|
- String companyUserId, String companyId, String externalId) {
|
|
|
+ String companyUserId, String companyId, String externalId, Long fsUserId) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
handleNormalMessage(sopLogs, content,companyUserId);
|
|
|
break;
|
|
|
case 2:
|
|
|
handleCourseMessage(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
- qwUserId, companyUserId, companyId, externalId);
|
|
|
+ qwUserId, companyUserId, companyId, externalId, fsUserId);
|
|
|
break;
|
|
|
case 3:
|
|
|
handleOrderMessage(sopLogs, content);
|
|
@@ -661,7 +709,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
private void handleCourseMessage(QwSopLogs sopLogs, QwSopTempSetting.Content content,
|
|
|
SopUserLogsVo logVo, Date sendTime, Long courseId,
|
|
|
Long videoId, String qwUserId, String companyUserId,
|
|
|
- String companyId, String externalId) {
|
|
|
+ String companyId, String externalId, Long fsUserId) {
|
|
|
// 深拷贝 Content 对象,避免使用 JSON
|
|
|
QwSopTempSetting.Content clonedContent = deepCopyContent(content);
|
|
|
if (clonedContent == null) {
|
|
@@ -684,7 +732,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
if ("1".equals(setting.getIsBindUrl())&&("3".equals(setting.getContentType())||"1".equals(setting.getContentType()))) {
|
|
|
addWatchLogIfNeeded(sopLogs, videoId, courseId, sendTime, qwUserId, companyUserId, companyId, externalId,logVo);
|
|
|
String sortLink = generateShortLink(setting, logVo, sendTime, courseId, videoId,
|
|
|
- qwUserId, companyUserId, companyId, externalId);
|
|
|
+ qwUserId, companyUserId, companyId, externalId, fsUserId);
|
|
|
if (StringUtils.isNotEmpty(sortLink)) {
|
|
|
if ("3".equals(setting.getContentType())) {
|
|
|
setting.setLinkUrl(sortLink);
|
|
@@ -725,7 +773,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
private String generateShortLink(QwSopTempSetting.Content.Setting setting, SopUserLogsVo logVo, Date sendTime,
|
|
|
Long courseId, Long videoId, String qwUserId,
|
|
|
- String companyUserId, String companyId, String externalId) {
|
|
|
+ String companyUserId, String companyId, String externalId, Long fsUserId) {
|
|
|
// 获取缓存的配置
|
|
|
CourseConfig config;
|
|
|
synchronized(configLock) {
|
|
@@ -757,6 +805,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
courseMap.setCourseId(link.getCourseId());
|
|
|
courseMap.setQwExternalId(link.getQwExternalId());
|
|
|
courseMap.setLinkType(0);
|
|
|
+ courseMap.setFsUserId(fsUserId);
|
|
|
|
|
|
String courseJson = JSON.toJSONString(courseMap);
|
|
|
String realLinkFull = REAL_LINK_PREFIX + courseJson;
|
|
@@ -777,17 +826,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
link.setUpdateTime(updateTime);
|
|
|
|
|
|
- // 从缓存中随机选择一个域名
|
|
|
- FsCourseDomainName fsCourseDomainName;
|
|
|
- if (cachedDomainNames == null || cachedDomainNames.isEmpty()) {
|
|
|
- log.error("No domain names available for short link generation.");
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- int randomIndex = ThreadLocalRandom.current().nextInt(cachedDomainNames.size());
|
|
|
- fsCourseDomainName = cachedDomainNames.get(randomIndex);
|
|
|
-
|
|
|
- String sortLink = "https://" + fsCourseDomainName.getDomainName() + "/s/" + link.getLink();
|
|
|
+ String sortLink = "https://" + logVo.getDomain() + "/s/" + link.getLink();
|
|
|
enqueueCourseLink(link);
|
|
|
return sortLink;
|
|
|
}
|