|
@@ -8,7 +8,9 @@ import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.base.BaseException;
|
|
|
import com.fs.common.utils.PubFun;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.company.domain.CompanyMiniapp;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.service.ICompanyMiniappService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
@@ -150,7 +152,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
private IQwGroupChatService qwGroupChatService;
|
|
|
@Autowired
|
|
|
private IQwGroupChatUserService qwGroupChatUserService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ICompanyMiniappService companyMiniappService;
|
|
|
// Shutdown flags
|
|
|
private volatile boolean running = true;
|
|
|
@Autowired
|
|
@@ -304,44 +307,10 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
Map<String, List<SopUserLogsVo>> sopLogsGroupedById = sopUserLogsVos.stream()
|
|
|
.collect(Collectors.groupingBy(SopUserLogsVo::getSopId));
|
|
|
|
|
|
+ // 查询公司关联小程序数据
|
|
|
+ List<CompanyMiniapp> miniList = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().orderByAsc("sort_num"));
|
|
|
|
|
|
- // 查询销售二级域名
|
|
|
-// 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)) {
|
|
|
-// if (!StringUtil.strIsNullOrEmpty(companyUser.getDomain())) {
|
|
|
-// s.setDomain(companyUser.getDomain().trim());
|
|
|
-// } else {
|
|
|
-// s.setDomain(config.getRealLinkDomainName().trim());
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// s.setDomain(config.getRealLinkDomainName().trim());
|
|
|
-// }
|
|
|
-// })
|
|
|
-// .collect(Collectors.groupingBy(SopUserLogsVo::getSopId));
|
|
|
+ Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap = miniList.stream().collect(Collectors.groupingBy(CompanyMiniapp::getCompanyId, Collectors.groupingBy(CompanyMiniapp::getType)));
|
|
|
|
|
|
log.info("共分组 {} 个 SOP ID 进行处理。", sopLogsGroupedById.size());
|
|
|
|
|
@@ -350,7 +319,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
for (Map.Entry<String, List<SopUserLogsVo>> entry : sopLogsGroupedById.entrySet()) {
|
|
|
String sopId = entry.getKey();
|
|
|
List<SopUserLogsVo> userLogsVos = entry.getValue();
|
|
|
- processSopGroupAsync(sopId, userLogsVos, sopGroupLatch,currentTime, groupChatMap,config);
|
|
|
+ processSopGroupAsync(sopId, userLogsVos, sopGroupLatch,currentTime, groupChatMap,config,miniMap);
|
|
|
}
|
|
|
|
|
|
// 等待所有 SOP 分组处理完成
|
|
@@ -371,9 +340,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
backoff = @Backoff(delay = 2000)
|
|
|
)
|
|
|
public void processSopGroupAsync(String sopId, List<SopUserLogsVo> userLogsVos, CountDownLatch latch ,LocalDateTime currentTime,
|
|
|
- Map<String, QwGroupChat> groupChatMap,CourseConfig config) {
|
|
|
+ Map<String, QwGroupChat> groupChatMap,CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap) {
|
|
|
try {
|
|
|
- processSopGroup(sopId, userLogsVos,currentTime, groupChatMap, config);
|
|
|
+ processSopGroup(sopId, userLogsVos,currentTime, groupChatMap, config,miniMap);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理 SOP ID {} 时发生异常: {}", sopId, e.getMessage(), e);
|
|
|
} finally {
|
|
@@ -383,7 +352,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
|
|
|
private void processSopGroup(String sopId, List<SopUserLogsVo> userLogsVos,LocalDateTime currentTime, Map<String,
|
|
|
- QwGroupChat> groupChatMap,CourseConfig config) throws Exception {
|
|
|
+ QwGroupChat> groupChatMap,CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap) throws Exception {
|
|
|
QwSopRuleTimeVO ruleTimeVO = sopMapper.selectQwSopByClickHouseId(sopId);
|
|
|
|
|
|
if (ruleTimeVO == null) {
|
|
@@ -425,7 +394,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
CountDownLatch userLogsLatch = new CountDownLatch(userLogsVos.size());
|
|
|
for (SopUserLogsVo logVo : userLogsVos) {
|
|
|
- processUserLogAsync(logVo, ruleTimeVO, rulesList, userLogsLatch, currentTime, groupChatMap,qwCompany.getMiniAppId(), config);
|
|
|
+ processUserLogAsync(logVo, ruleTimeVO, rulesList, userLogsLatch, currentTime, groupChatMap,qwCompany.getMiniAppId(), config,miniMap);
|
|
|
}
|
|
|
|
|
|
// 等待所有用户日志处理完成
|
|
@@ -446,9 +415,9 @@ 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) {
|
|
|
+ String miniAppId,CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap) {
|
|
|
try {
|
|
|
- processUserLog(logVo, ruleTimeVO, tempSettings,currentTime, groupChatMap, miniAppId, config);
|
|
|
+ processUserLog(logVo, ruleTimeVO, tempSettings,currentTime, groupChatMap, miniAppId, config,miniMap);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理用户日志 {} 时发生异常: {}", logVo.getId(), e.getMessage(), e);
|
|
|
} finally {
|
|
@@ -458,7 +427,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) {
|
|
|
+ LocalDateTime currentTime, Map<String, QwGroupChat> groupChatMap,String miniAppId,
|
|
|
+ CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap) {
|
|
|
try {
|
|
|
|
|
|
LocalDate startDate = LocalDate.parse(logVo.getStartTime(), DATE_FORMATTER);
|
|
@@ -510,6 +480,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
String qwUserId = String.valueOf(qwUserByRedis.getId()).trim();
|
|
|
String companyUserId = String.valueOf(qwUserByRedis.getCompanyUserId()).trim();
|
|
|
String companyId = String.valueOf(qwUserByRedis.getCompanyId()).trim();
|
|
|
+ Integer sendMsgType = qwUserByRedis.getSendMsgType();
|
|
|
|
|
|
if (StringUtil.strIsNullOrEmpty(companyUserId) || StringUtil.strIsNullOrEmpty(companyId) || "null".equals(companyUserId)) {
|
|
|
log.error("员工未绑定销售账号或公司,跳过处理:"+qwUserId);
|
|
@@ -635,7 +606,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
insertSopUserLogs(sopUserLogsInfos, logVo, sendTime, ruleTimeVO, content, qwUserId,
|
|
|
companyUserId, companyId, qwUserByRedis.getWelcomeText(),qwUserByRedis.getQwUserName(),
|
|
|
- groupChatMap, miniAppId,config);
|
|
|
+ groupChatMap, miniAppId,config,miniMap, sendMsgType);
|
|
|
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -678,7 +649,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
private void insertSopUserLogs(List<SopUserLogsInfo> sopUserLogsInfos, SopUserLogsVo logVo, Date sendTime,
|
|
|
QwSopRuleTimeVO ruleTimeVO, QwSopTempSetting.Content content,
|
|
|
String qwUserId,String companyUserId,String companyId,String welcomeText,String qwUserName,
|
|
|
- Map<String, QwGroupChat> groupChatMap,String miniAppId,CourseConfig config) {
|
|
|
+ Map<String, QwGroupChat> groupChatMap,String miniAppId,CourseConfig config,
|
|
|
+ Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap, Integer sendMsgType) {
|
|
|
String formattedSendTime = sendTime.toInstant()
|
|
|
.atZone(ZoneId.systemDefault())
|
|
|
.format(DATE_TIME_FORMATTER);
|
|
@@ -705,7 +677,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, groupChat.getChatId(), groupChat.getName(), null, isOfficial, null);
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
type, qwUserId, companyUserId, companyId, groupChat.getChatId(), welcomeText, qwUserName,
|
|
|
- null, true, miniAppId, groupChat,config);
|
|
|
+ null, true, miniAppId, groupChat,config, miniMap, null, sendMsgType);
|
|
|
} else {
|
|
|
if(groupChat.getChatUserList() != null && !groupChat.getChatUserList().isEmpty()){
|
|
|
groupChat.getChatUserList().forEach(user -> {
|
|
@@ -714,7 +686,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, user.getUserId(), user.getName(), null, isOfficial, null);
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
type, qwUserId, companyUserId, companyId, user.getId().toString(), welcomeText, qwUserName,
|
|
|
- null, false, miniAppId, groupChat,config);
|
|
|
+ null, false, miniAppId, groupChat,config, miniMap, null, sendMsgType);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -725,9 +697,11 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
String externalId = contactId.getExternalId().toString();
|
|
|
String externalUserName = contactId.getExternalUserName();
|
|
|
Long fsUserId = contactId.getFsUserId();
|
|
|
+ Integer grade = contactId.getGrade();
|
|
|
QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, contactId.getExternalContactId(), externalUserName, fsUserId, isOfficial, contactId.getExternalId());
|
|
|
handleLogBasedOnType(sopLogs, content, logVo, sendTime, courseId, videoId,
|
|
|
- type, qwUserId, companyUserId, companyId, externalId, welcomeText, qwUserName, fsUserId, false, miniAppId, null,config);
|
|
|
+ type, qwUserId, companyUserId, companyId, externalId, welcomeText, qwUserName, fsUserId, false, miniAppId,
|
|
|
+ null,config, miniMap, grade, sendMsgType);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理 externalContactId {} 时发生异常: {}", contactId, e.getMessage(), e);
|
|
|
}
|
|
@@ -831,11 +805,12 @@ 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,
|
|
|
+ SopUserLogsVo logVo, Date sendTime, Long courseId, Long videoId, int type, String qwUserId,
|
|
|
String companyUserId, String companyId, String externalId, String welcomeText,
|
|
|
String qwUserName, Long fsUserId, boolean isGroupChat, String miniAppId,
|
|
|
- QwGroupChat groupChat,CourseConfig config) {
|
|
|
+ QwGroupChat groupChat,CourseConfig config,
|
|
|
+ Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
+ Integer grade, Integer sendMsgType ) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
handleNormalMessage(sopLogs, content,companyUserId);
|
|
@@ -843,7 +818,7 @@ 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);
|
|
|
+ isGroupChat, miniAppId, groupChat,config,miniMap, grade, sendMsgType);
|
|
|
break;
|
|
|
case 3:
|
|
|
handleOrderMessage(sopLogs, content);
|
|
@@ -873,10 +848,10 @@ 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,
|
|
|
+ SopUserLogsVo logVo, Date sendTime, Long courseId, Long videoId, String qwUserId, String companyUserId,
|
|
|
String companyId, String externalId, String welcomeText, String qwUserName,
|
|
|
- Long fsUserId, boolean isGroupChat, String miniAppId, QwGroupChat groupChat,CourseConfig config) {
|
|
|
+ Long fsUserId, boolean isGroupChat, String miniAppId, QwGroupChat groupChat,CourseConfig config,Map<Long,
|
|
|
+ Map<Integer, List<CompanyMiniapp>>> miniMap,Integer grade, Integer sendMsgType) {
|
|
|
// 深拷贝 Content 对象,避免使用 JSON
|
|
|
QwSopTempSetting.Content clonedContent = deepCopyContent(content);
|
|
|
if (clonedContent == null) {
|
|
@@ -968,10 +943,25 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
String sortLink = createLinkByMiniApp(setting, logVo, sendTime, courseId, videoId,
|
|
|
qwUserId, companyUserId, companyId, externalId,isOfficial,sopLogs.getFsUserId());
|
|
|
|
|
|
- if (!StringUtil.strIsNullOrEmpty(miniAppId)) {
|
|
|
+ if (!miniMap.isEmpty() && sendMsgType==1) {
|
|
|
+ Map<Integer, List<CompanyMiniapp>> integerListMap = miniMap.get(Long.valueOf(companyId));
|
|
|
+ if (integerListMap != null) {
|
|
|
+
|
|
|
+ int effectiveGrade = (grade == null) ? 5 : grade;
|
|
|
+ int listIndex = (effectiveGrade == 1 || effectiveGrade == 2) ? 0 : 1;
|
|
|
+ List<CompanyMiniapp> miniapps = integerListMap.get(listIndex);
|
|
|
+
|
|
|
+ if (miniapps != null && !miniapps.isEmpty()) {
|
|
|
+ CompanyMiniapp companyMiniapp = miniapps.get(0);
|
|
|
+ if (companyMiniapp != null && !StringUtil.strIsNullOrEmpty(companyMiniapp.getAppId())) {
|
|
|
+ setting.setMiniprogramAppid(companyMiniapp.getAppId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (!StringUtil.strIsNullOrEmpty(miniAppId)){
|
|
|
setting.setMiniprogramAppid(miniAppId);
|
|
|
}else {
|
|
|
- log.error("公司的小程序id为空:采用了前端传的固定值"+sopLogs.getSopId());
|
|
|
+ log.error("公司的小程序id为空:采用了前端传的固定值" + sopLogs.getSopId());
|
|
|
}
|
|
|
|
|
|
setting.setMiniprogramPage(sortLink.replaceAll("^[\\s\\u2005]+", ""));
|