|
|
@@ -74,10 +74,23 @@ public class IpadSendServer {
|
|
|
|
|
|
// 发送参数原本的appid
|
|
|
String appid = content.getMiniprogramAppid();
|
|
|
+ List<CompanyMiniapp> listAll = Collections.emptyList();
|
|
|
+ Set<String> companyAppIds = Collections.emptySet();
|
|
|
+ boolean forceCompanyApp = false;
|
|
|
+ if (companyId != null && miniMap != null && !miniMap.isEmpty()) {
|
|
|
+ companyAppIds = miniMap.values().stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(cfg -> isConfigBoundToCompany(cfg, companyId))
|
|
|
+ .map(FsCoursePlaySourceConfig::getAppid)
|
|
|
+ .filter(StringUtils::isNotEmpty)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ forceCompanyApp = !companyAppIds.isEmpty();
|
|
|
+ }
|
|
|
+ final Set<String> allowedCompanyAppIds = companyAppIds;
|
|
|
// 判断销售工时ID不为空并且有小程序类型
|
|
|
if (companyId != null && content.getMiniType() != null) {
|
|
|
// 获取销售公司下面绑定的主备小程序,并且根据当前应该发送的主备类型查询出数据
|
|
|
- List<CompanyMiniapp> listAll = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().eq("company_id", companyId));
|
|
|
+ listAll = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().eq("company_id", companyId));
|
|
|
List<CompanyMiniapp> list = listAll.stream().filter(e -> e.getType().equals(content.getMiniType())).collect(Collectors.toList());
|
|
|
// 判断当前绑定的最新的小程序,并且覆盖以前的值(可以达到实时替换小程序的功能)
|
|
|
if (!list.isEmpty() && list.get(0) != null && StringUtils.isNotEmpty(list.get(0).getAppId())) {
|
|
|
@@ -107,6 +120,11 @@ public class IpadSendServer {
|
|
|
}
|
|
|
// 根据小程序ID查询小程序列表
|
|
|
List<FsCoursePlaySourceConfig> configList = playSourceConfigService.selectByAppIds(miniAppList);
|
|
|
+ if (forceCompanyApp) {
|
|
|
+ configList = configList.stream()
|
|
|
+ .filter(e -> allowedCompanyAppIds.contains(e.getAppid()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
configList.sort(Comparator.comparing(e -> miniSortMap.getOrDefault(e.getAppid(), 100)));
|
|
|
// 过滤掉完全封禁(status=2)的小程序,只保留正常(status=0)和半封禁(status=1)的小程序
|
|
|
List<FsCoursePlaySourceConfig> availableList = configList.stream()
|
|
|
@@ -174,13 +192,41 @@ public class IpadSendServer {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (forceCompanyApp && StringUtils.isNotEmpty(appid) && !allowedCompanyAppIds.contains(appid)) {
|
|
|
+ Optional<String> preferredAppId = listAll.stream()
|
|
|
+ .filter(e -> e.getType().equals(content.getMiniType()) && StringUtils.isNotEmpty(e.getAppId()))
|
|
|
+ .map(CompanyMiniapp::getAppId)
|
|
|
+ .filter(allowedCompanyAppIds::contains)
|
|
|
+ .findFirst();
|
|
|
+ if (!preferredAppId.isPresent()) {
|
|
|
+ preferredAppId = allowedCompanyAppIds.stream().findFirst();
|
|
|
+ }
|
|
|
+ if (preferredAppId.isPresent()) {
|
|
|
+ appid = preferredAppId.get();
|
|
|
+ log.info("ID:{}, companyId:{},命中公司隔离规则,改用本公司小程序:{}", vo.getId(), companyId, appid);
|
|
|
+ }
|
|
|
+ }
|
|
|
FsCoursePlaySourceConfig courseMaConfig = miniMap.get(appid);
|
|
|
+ if (forceCompanyApp && courseMaConfig != null && !isConfigBoundToCompany(courseMaConfig, companyId)) {
|
|
|
+ courseMaConfig = null;
|
|
|
+ }
|
|
|
if (courseMaConfig == null) {
|
|
|
List<CompanyMiniapp> list = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().eq("company_id", companyId).eq("type", 1));
|
|
|
if (!list.isEmpty() && list.get(0) != null && StringUtils.isNotEmpty(list.get(0).getAppId())) {
|
|
|
courseMaConfig = miniMap.get(list.get(0).getAppId());
|
|
|
}
|
|
|
}
|
|
|
+ if (courseMaConfig == null && forceCompanyApp) {
|
|
|
+ Optional<FsCoursePlaySourceConfig> companyConfig = miniMap.values().stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(cfg -> StringUtils.isNotEmpty(cfg.getAppid()))
|
|
|
+ .filter(cfg -> allowedCompanyAppIds.contains(cfg.getAppid()))
|
|
|
+ .findFirst();
|
|
|
+ if (companyConfig.isPresent()) {
|
|
|
+ courseMaConfig = companyConfig.get();
|
|
|
+ appid = courseMaConfig.getAppid();
|
|
|
+ }
|
|
|
+ }
|
|
|
if (courseMaConfig == null) {
|
|
|
throw new BaseException("未找到小程序配置:{}", appid);
|
|
|
}
|
|
|
@@ -205,8 +251,17 @@ public class IpadSendServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean isConfigBoundToCompany(FsCoursePlaySourceConfig config, Long companyId) {
|
|
|
+ if (config == null || companyId == null || StringUtils.isEmpty(config.getCompanyIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String targetCompanyId = String.valueOf(companyId);
|
|
|
+ return Arrays.stream(config.getCompanyIds().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .anyMatch(targetCompanyId::equals);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 个微 SOP 的 contentJson 中每条消息可能来自 {@link com.fs.sop.domain.QwSopTempContent},
|
|
|
* 业务字段在 {@code content} 嵌套 JSON 里;未合并时 fileUrl/fileName 为空,
|
|
|
* 发送文件会退回用 URL 路径名(如 1775377962733.xlsx)作为展示名。
|
|
|
*/
|