|
|
@@ -10,11 +10,15 @@ import com.fs.common.utils.CloudHostUtils;
|
|
|
import com.fs.common.utils.PubFun;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyDept;
|
|
|
import com.fs.company.domain.CompanyMiniapp;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyDeptMapper;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.company.service.ICompanyMiniappService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
+import com.fs.company.util.MiniAppIdResolver;
|
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
|
@@ -185,6 +189,12 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
@Autowired
|
|
|
private CompanyMapper companyMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyDeptMapper companyDeptMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private AsyncCourseWatchFinishService asyncCourseWatchFinishService;
|
|
|
|
|
|
@@ -358,7 +368,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
List<CompanyMiniapp> miniList = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().orderByAsc("sort_num"));
|
|
|
|
|
|
Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap = miniList.stream().collect(Collectors.groupingBy(CompanyMiniapp::getCompanyId, Collectors.groupingBy(CompanyMiniapp::getType)));
|
|
|
-
|
|
|
+ Map<Long, CompanyDept> deptMiniAppMap = MiniAppIdResolver.buildDeptMiniAppMap(companyDeptMapper.queryDeptDataAll());
|
|
|
+ Map<Long, Long> companyUserDeptMap = MiniAppIdResolver.buildCompanyUserDeptMap(companyUserMapper.selectAllCompanyUserList());
|
|
|
|
|
|
List<Company> companies = companyMapper.selectCompanyAllList();
|
|
|
|
|
|
@@ -369,7 +380,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,miniMap,companies);
|
|
|
+ processSopGroupAsync(sopId, userLogsVos, sopGroupLatch,currentTime, groupChatMap,config,miniMap,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
}
|
|
|
|
|
|
// 等待所有 SOP 分组处理完成
|
|
|
@@ -391,9 +402,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
)
|
|
|
public void processSopGroupAsync(String sopId, List<SopUserLogsVo> userLogsVos, CountDownLatch latch ,LocalDateTime currentTime,
|
|
|
Map<String, QwGroupChat> groupChatMap,CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
- List<Company> companies) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
try {
|
|
|
- processSopGroup(sopId, userLogsVos,currentTime, groupChatMap, config,miniMap,companies);
|
|
|
+ processSopGroup(sopId, userLogsVos,currentTime, groupChatMap, config,miniMap,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理 SOP ID {} 时发生异常: {}", sopId, e.getMessage(), e);
|
|
|
} finally {
|
|
|
@@ -404,7 +415,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
private void processSopGroup(String sopId, List<SopUserLogsVo> userLogsVos,LocalDateTime currentTime, Map<String,
|
|
|
QwGroupChat> groupChatMap,CourseConfig config,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
- List<Company> companies) throws Exception {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) throws Exception {
|
|
|
QwSopRuleTimeVO ruleTimeVO = sopMapper.selectQwSopByClickHouseId(sopId);
|
|
|
|
|
|
if (ruleTimeVO == null) {
|
|
|
@@ -447,7 +458,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,miniMap,companies);
|
|
|
+ config,miniMap,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
}
|
|
|
|
|
|
// 等待所有用户日志处理完成
|
|
|
@@ -469,9 +480,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,Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
- List<Company> companies) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
try {
|
|
|
- processUserLog(logVo, ruleTimeVO, tempSettings,currentTime, groupChatMap, miniAppId, config,miniMap,companies);
|
|
|
+ processUserLog(logVo, ruleTimeVO, tempSettings,currentTime, groupChatMap, miniAppId, config,miniMap,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理用户日志 {} 时发生异常: {}", logVo.getId(), e.getMessage(), e);
|
|
|
} finally {
|
|
|
@@ -483,7 +494,7 @@ 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) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
try {
|
|
|
|
|
|
LocalDate startDate = LocalDate.parse(logVo.getStartTime(), DATE_FORMATTER);
|
|
|
@@ -740,7 +751,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
|
|
|
insertSopUserLogs(sopUserLogsInfos, logVo, sendTime, ruleTimeVO, content, qwUserId,
|
|
|
companyUserId, companyId, qwUserByRedis.getWelcomeText(),qwUserByRedis.getQwUserName(),
|
|
|
- groupChatMap, miniAppId,config,miniMap, sendMsgType,companies);
|
|
|
+ groupChatMap, miniAppId,config,miniMap, sendMsgType,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -786,7 +797,7 @@ 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) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
String formattedSendTime = sendTime.toInstant()
|
|
|
.atZone(ZoneId.systemDefault())
|
|
|
.format(DATE_TIME_FORMATTER);
|
|
|
@@ -866,7 +877,7 @@ 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);
|
|
|
+ null, true, miniAppId, groupChat,config, miniMap, null, sendMsgType,companies,liveId, deptMiniAppMap, companyUserDeptMap);
|
|
|
}
|
|
|
// if (content.getIndex() == 0) {
|
|
|
// QwSopLogs sopLogs = createBaseLog(formattedSendTime, logVo, ruleTimeVO, groupChat.getChatId(), groupChat.getName(), null, isOfficial, null);
|
|
|
@@ -915,7 +926,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,liveId);
|
|
|
+ null,config, miniMap, grade, sendMsgType,companies,liveId, deptMiniAppMap, companyUserDeptMap);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("处理 externalContactId {} 时发生异常", contactId, e);
|
|
|
@@ -1074,7 +1085,8 @@ 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 ,Long liveId) {
|
|
|
+ Integer grade, Integer sendMsgType ,List<Company> companies ,Long liveId,
|
|
|
+ Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
handleNormalMessage(sopLogs, content,companyUserId,companyId,isGroupChat,qwUserId,groupChat,externalId,logVo);
|
|
|
@@ -1082,7 +1094,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,miniMap, grade, sendMsgType,companies);
|
|
|
+ isGroupChat, miniAppId, groupChat,config,miniMap, grade, sendMsgType,companies, deptMiniAppMap, companyUserDeptMap);
|
|
|
break;
|
|
|
case 3:
|
|
|
handleOrderMessage(sopLogs, content);
|
|
|
@@ -1300,7 +1312,7 @@ 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) {
|
|
|
+ List<Company> companies, Map<Long, CompanyDept> deptMiniAppMap, Map<Long, Long> companyUserDeptMap) {
|
|
|
QwExternalContact contact = null;
|
|
|
if(logVo.getExternalId() != null){
|
|
|
contact = qwExternalContactMapper.selectById(logVo.getExternalId());
|
|
|
@@ -1428,8 +1440,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
setting.setMiniprogramAppid(miniAppId);
|
|
|
}else {
|
|
|
int miniType = getLevel(grade);
|
|
|
- //算主备小程序
|
|
|
- String finalAppId = getAppIdFromMiniMap(miniMap, companyId, sendMsgType, grade);
|
|
|
+ Long deptId = MiniAppIdResolver.getDeptId(Long.parseLong(companyUserId), companyUserDeptMap);
|
|
|
+ String finalAppId = getAppIdFromMiniMap(miniMap, companyId, sendMsgType, grade, deptId, deptMiniAppMap);
|
|
|
|
|
|
if (StringUtil.strIsNullOrEmpty(finalAppId)) {
|
|
|
finalAppId = miniAppId;
|
|
|
@@ -1545,7 +1557,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
setting.setMiniprogramAppid(miniAppId);
|
|
|
}else {
|
|
|
int miniType = getLevel(grade);
|
|
|
- String finalAppId = getAppIdFromMiniMap(miniMap, companyId, sendMsgType, grade);
|
|
|
+ Long deptIdArticle = MiniAppIdResolver.getDeptId(Long.parseLong(companyUserId), companyUserDeptMap);
|
|
|
+ String finalAppId = getAppIdFromMiniMap(miniMap, companyId, sendMsgType, grade, deptIdArticle, deptMiniAppMap);
|
|
|
|
|
|
if (StringUtil.strIsNullOrEmpty(finalAppId)) {
|
|
|
finalAppId = articleSysConfig.getAppId();
|
|
|
@@ -1593,27 +1606,12 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
private String getAppIdFromMiniMap(Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap,
|
|
|
String companyId,
|
|
|
Integer sendMsgType,
|
|
|
- Integer grade) {
|
|
|
- if (miniMap == null || miniMap.isEmpty() || sendMsgType == null || sendMsgType != 1) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- Map<Integer, List<CompanyMiniapp>> gradeMap = miniMap.get(Long.valueOf(companyId));
|
|
|
- if (gradeMap == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
+ Integer grade,
|
|
|
+ Long deptId,
|
|
|
+ Map<Long, CompanyDept> deptMiniAppMap) {
|
|
|
int listIndex = getLevel(grade);
|
|
|
- List<CompanyMiniapp> miniapps = gradeMap.get(listIndex);
|
|
|
-
|
|
|
- if (miniapps == null || miniapps.isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- CompanyMiniapp companyMiniapp = miniapps.get(0);
|
|
|
- return (companyMiniapp != null && !StringUtil.strIsNullOrEmpty(companyMiniapp.getAppId()))
|
|
|
- ? companyMiniapp.getAppId()
|
|
|
- : null;
|
|
|
+ return MiniAppIdResolver.resolveMiniAppId(
|
|
|
+ deptId, Long.valueOf(companyId), listIndex, sendMsgType, miniMap, deptMiniAppMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2779,6 +2777,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
Date dataTime = new Date();
|
|
|
List<CompanyMiniapp> miniList = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().orderByAsc("sort_num"));
|
|
|
Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap = miniList.stream().collect(Collectors.groupingBy(CompanyMiniapp::getCompanyId, Collectors.groupingBy(CompanyMiniapp::getType)));
|
|
|
+ Map<Long, CompanyDept> deptMiniAppMap = MiniAppIdResolver.buildDeptMiniAppMap(companyDeptMapper.queryDeptDataAll());
|
|
|
+ Map<Long, Long> companyUserDeptMap = MiniAppIdResolver.buildCompanyUserDeptMap(companyUserMapper.selectAllCompanyUserList());
|
|
|
|
|
|
QwCompany qwCompany = iQwCompanyService.getQwCompanyByRedis(sopLogs.getCorpId());
|
|
|
QwUser qwUser = qwExternalContactService.getQwUserByRedis(sopLogs.getCorpId(), sopLogs.getQwUserid());
|
|
|
@@ -2804,21 +2804,10 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
String.valueOf(qwUser.getId()), qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString(), sopLogs.getExternalId(), config);
|
|
|
|
|
|
|
|
|
- String miniAppId = null;
|
|
|
- if (!miniMap.isEmpty() && qwUser.getSendMsgType() == 1) {
|
|
|
- Map<Integer, List<CompanyMiniapp>> integerListMap = miniMap.get(Long.valueOf(qwUser.getCompanyId()));
|
|
|
- if (integerListMap != null) {
|
|
|
- int listIndex = getLevel(grade);
|
|
|
- List<CompanyMiniapp> miniapps = integerListMap.get(listIndex);
|
|
|
-
|
|
|
- if (miniapps != null && !miniapps.isEmpty()) {
|
|
|
- CompanyMiniapp companyMiniapp = miniapps.get(0);
|
|
|
- if (companyMiniapp != null && !StringUtil.strIsNullOrEmpty(companyMiniapp.getAppId())) {
|
|
|
- miniAppId = companyMiniapp.getAppId();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ int listIndex = getLevel(grade);
|
|
|
+ Long deptId = MiniAppIdResolver.getDeptId(qwUser.getCompanyUserId(), companyUserDeptMap);
|
|
|
+ String miniAppId = MiniAppIdResolver.resolveMiniAppId(
|
|
|
+ deptId, qwUser.getCompanyId(), listIndex, qwUser.getSendMsgType(), miniMap, deptMiniAppMap);
|
|
|
|
|
|
if (StringUtil.strIsNullOrEmpty(miniAppId) && !StringUtil.strIsNullOrEmpty(qwCompany.getMiniAppId())) {
|
|
|
miniAppId = qwCompany.getMiniAppId();
|