|
|
@@ -1,16 +1,22 @@
|
|
|
package com.fs.app.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.base.BaseException;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.CompanyMiniapp;
|
|
|
import com.fs.company.service.ICompanyMiniappService;
|
|
|
import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
|
+import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
|
|
|
+import com.fs.course.service.IFsCoursePlaySourceConfigService;
|
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.ipad.IpadSendUtils;
|
|
|
import com.fs.ipad.vo.*;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
|
@@ -28,11 +34,14 @@ import com.fs.sop.service.impl.QwSopLogsServiceImpl;
|
|
|
import com.fs.wxwork.dto.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -49,44 +58,80 @@ public class IpadSendServer {
|
|
|
private final IQwUserVideoService qwUserVideoService;
|
|
|
private final RedisCache redisCache;
|
|
|
private final ICompanyMiniappService companyMiniappService;
|
|
|
-
|
|
|
+ private final IFsCoursePlaySourceConfigService playSourceConfigService;
|
|
|
+ private final FsUserMapper fsUserMapper;
|
|
|
+ private static final List<String> PROJECT_NAMES = Arrays.asList("济南联志健康", "北京存在文化");
|
|
|
private void sendMiniProgram(BaseVo vo, QwSopCourseFinishTempSetting.Setting content, Map<String, FsCoursePlaySourceConfig> miniMap, Long companyId) {
|
|
|
+ // 发送参数原本的appid
|
|
|
String appid = content.getMiniprogramAppid();
|
|
|
+ // 判断销售工时ID不为空并且有小程序类型
|
|
|
if(companyId != null && content.getMiniType() != null){
|
|
|
- log.error("1.打印企业信息------------------》:{}",companyId);
|
|
|
- List<CompanyMiniapp> list = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().eq("company_id", companyId));
|
|
|
- log.error("2.打印企小程序信息------------------》:{}",companyId);
|
|
|
- List<CompanyMiniapp> collect = list.stream().filter(e -> e.getType().equals(content.getMiniType())).collect(Collectors.toList());
|
|
|
- if(!collect.isEmpty() && collect.get(0) != null && StringUtils.isNotEmpty(collect.get(0).getAppId())){
|
|
|
- appid = collect.get(0).getAppId();
|
|
|
+ // 获取销售公司下面绑定的主备小程序,并且根据当前应该发送的主备类型查询出数据
|
|
|
+ List<CompanyMiniapp> list = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().eq("company_id", companyId).eq("type", content.getMiniType()));
|
|
|
+ // 判断当前绑定的最新的小程序,并且覆盖以前的值(可以达到实时替换小程序的功能)
|
|
|
+ if(!list.isEmpty() && list.get(0) != null && StringUtils.isNotEmpty(list.get(0).getAppId())){
|
|
|
+ appid = list.get(0).getAppId();
|
|
|
}
|
|
|
- if(!vo.isRoom()){
|
|
|
- try {
|
|
|
- log.error("3.打印查询id信息-------------------》{}",vo.getExId());
|
|
|
- QwExternalContact qwExternalContact = qwExternalContactMapper.selectOne(new LambdaQueryWrapper<QwExternalContact>().eq(QwExternalContact::getQwUserId,vo.getQwUserId()).eq(QwExternalContact::getExternalUserId,vo.getExId()));
|
|
|
- log.error("4.打印外部联系人ID-------------------》{}",qwExternalContact.getId());
|
|
|
- LocalDateTime createTime = qwExternalContact.getCreateTime() == null ? LocalDateTime.now() : DateUtil.dateToLocalDateTime(qwExternalContact.getCreateTime());
|
|
|
- LocalDateTime lastTime = LocalDateTime.of(2025, 11, 6, 23, 59, 59);
|
|
|
- int listIndex = createTime.isAfter(lastTime) ? 1 : 0 ;
|
|
|
- List<CompanyMiniapp> collect2 = list.stream().filter(e -> e.getType().equals(listIndex)).collect(Collectors.toList());
|
|
|
- if(!collect2.isEmpty() && collect2.get(0) != null && StringUtils.isNotEmpty(collect2.get(0).getAppId())){
|
|
|
- appid = collect2.get(0).getAppId();
|
|
|
- log.error("5.打印小程序信息2------------------》:{}",appid);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("6.输出外部联系人ID-------------->{}",vo.getExId());
|
|
|
- log.error("7.数据异常----------------------》{}",e.getMessage());
|
|
|
- }
|
|
|
+ // 获取配置文件里面的项目名称
|
|
|
+ String signProjectName = SpringUtils.getProperty("cloud_host.company_name");
|
|
|
+ //区分新老用户,新用户发送备用小程序,老用户发送主小程序,TODO 需要使用的项目在参数里面加上
|
|
|
+ if(PROJECT_NAMES.contains(signProjectName)){
|
|
|
+ log.info("ID:{}, qwUserId:{},externalId:{},进入区分发小程序逻辑", vo.getId(), vo.getQwUserId(), vo.getExId());
|
|
|
+ // 判断消息是否是群聊,不是群聊再进去,TODO 当权无法判断群聊是否可以发送对应的小程序
|
|
|
+ if(!vo.isRoom()){
|
|
|
+ log.info("qwUserId:{},externalId:{},不是群聊", vo.getQwUserId(), vo.getExId());
|
|
|
+ try {
|
|
|
+ // 获取当前外部联系人
|
|
|
+ QwExternalContact qwExternalContact = qwExternalContactMapper.selectOne(new LambdaQueryWrapper<QwExternalContact>().eq(QwExternalContact::getQwUserId,vo.getQwUserId()).eq(QwExternalContact::getExternalUserId,vo.getExId()).last(" limit 1"));
|
|
|
+ // 当前外部联系是否绑定用户数据,如果数据为空则是没看过小程序的新用户,不用去判断小程序,跳过判断
|
|
|
+ if(qwExternalContact.getFsUserId() != null){
|
|
|
+ // 根据用户绑定信息去查询用户信息
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(qwExternalContact.getFsUserId());
|
|
|
+ // 判断用户是否有看过其他的小程序多个
|
|
|
+ if(StringUtils.isNotEmpty(fsUser.getAppId())){
|
|
|
+ // 获取用户看过的小程序ID集合
|
|
|
+ List<String> miniAppList = Arrays.asList(fsUser.getAppId().split(","));
|
|
|
+ // 根据小程序ID查询小程序列表
|
|
|
+ List<FsCoursePlaySourceConfig> configList = playSourceConfigService.selectByAppIds(miniAppList);
|
|
|
+ // 筛选出半封禁的小程序数据,得到这个数据然后优先发这个小程序
|
|
|
+ Optional<FsCoursePlaySourceConfig> optional = configList.stream().filter(e -> e.getStatus() != null && e.getStatus() == 1).findFirst();
|
|
|
+ // 判断是否找到
|
|
|
+ if(optional.isPresent()){
|
|
|
+ // 找到半封禁并且在appid里面存在证明这个客户是打开过小程序,优先发送这个
|
|
|
+ appid = optional.get().getAppid();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 获取用户的创建时间
|
|
|
+ LocalDateTime createTime = DateUtil.dateToLocalDateTime(fsUser.getCreateTime());
|
|
|
+ log.info("ID:{}, qwUserId:{},externalId:{},已绑定小程序,判断时间:{}", vo.getId(), vo.getQwUserId(), vo.getExId(), createTime);
|
|
|
+ // 这个时间是写死的,目前判断的芳华封禁的时间,可以更具项目调整
|
|
|
+ LocalDateTime lastTime = LocalDateTime.of(2025, 11, 6, 23, 59, 59);
|
|
|
+ // 判断客户创建时间是在这个之前还是之后
|
|
|
+ int listIndex = createTime.isAfter(lastTime) ? 1 : 0 ;
|
|
|
+ // 获取公司里面的主备小程序,根据用户创建时间来发送主备,如果创建时间大于上看的时间就发送备用小程序,如果小于就发送主要小程序
|
|
|
+ List<CompanyMiniapp> collect2 = list.stream().filter(e -> e.getType().equals(listIndex)).collect(Collectors.toList());
|
|
|
+ // 判断是否获取到了配置
|
|
|
+ if(!collect2.isEmpty() && collect2.get(0) != null && StringUtils.isNotEmpty(collect2.get(0).getAppId())){
|
|
|
+ appid = collect2.get(0).getAppId();
|
|
|
+ log.info("ID:{}, qwUserId:{},externalId:{},发送小程序:{}", vo.getId(), vo.getQwUserId(), vo.getExId(), appid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("ID:{}, qwUserId:{},externalId:{},未绑定小程序用户", vo.getId(), vo.getQwUserId(), vo.getExId());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("6.输出外部联系人ID-------------->{}",vo.getExId());
|
|
|
+ log.error("7.数据异常----------------------》{}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
FsCoursePlaySourceConfig courseMaConfig = miniMap.get(appid);
|
|
|
- log.error("8.打印小程序配置信息------------------》:{}",1);
|
|
|
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());
|
|
|
- log.error("9.打印小程序配置信息--------最终------------------》:{}",courseMaConfig);
|
|
|
}
|
|
|
}
|
|
|
if(courseMaConfig == null){
|
|
|
@@ -322,7 +367,7 @@ public class IpadSendServer {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (qwSopLogs.getSendType() != 12 && noSop) {
|
|
|
+ if (qwSopLogs.getSendType() != 6 && noSop) {
|
|
|
// 客户的信息
|
|
|
// QwExternalContactHParam contactHParam = new QwExternalContactHParam();
|
|
|
// contactHParam.setUserId(qwUser.getQwUserId().trim());
|
|
|
@@ -361,7 +406,7 @@ public class IpadSendServer {
|
|
|
public void send(QwSopCourseFinishTempSetting.Setting content, QwUser qwUser, QwSopLogs qwSopLogs, Map<String, FsCoursePlaySourceConfig> miniMap, BaseVo parentVo) {
|
|
|
BaseVo vo = new BaseVo();
|
|
|
vo.setId(Long.parseLong(qwSopLogs.getId()));
|
|
|
- vo.setRoom(qwSopLogs.getSendType() == 12);
|
|
|
+ vo.setRoom(qwSopLogs.getSendType() == 6);
|
|
|
vo.setUuid(qwUser.getUid());
|
|
|
vo.setExId(qwSopLogs.getExternalUserId());
|
|
|
vo.setServerId(qwUser.getServerId());
|
|
|
@@ -409,7 +454,7 @@ public class IpadSendServer {
|
|
|
break;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error("ID:" + qwSopLogs.getId() + "-发送失败QW_SOP_ID:" + qwSopLogs.getId(), e);
|
|
|
+ log.error("ID:{}-发送失败QW_SOP_ID:{},content:{},vo:{}", qwSopLogs.getId(), qwSopLogs.getId(), JSON.toJSONString(content), JSON.toJSONString(vo), e);
|
|
|
content.setSendStatus(2);
|
|
|
content.setSendRemarks("发送失败:" + e.getMessage());
|
|
|
}
|