|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.app.service;
|
|
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.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
@@ -11,6 +12,8 @@ import com.fs.company.domain.CompanyMiniapp;
|
|
|
import com.fs.company.service.ICompanyMiniappService;
|
|
import com.fs.company.service.ICompanyMiniappService;
|
|
|
import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
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.course.service.IFsCourseWatchLogService;
|
|
|
import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
@@ -31,14 +34,14 @@ import com.fs.sop.service.impl.QwSopLogsServiceImpl;
|
|
|
import com.fs.wxwork.dto.*;
|
|
import com.fs.wxwork.dto.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -53,38 +56,65 @@ public class IpadSendServer {
|
|
|
private final QwExternalContactMapper qwExternalContactMapper;
|
|
private final QwExternalContactMapper qwExternalContactMapper;
|
|
|
private final IFsCourseWatchLogService watchLogService;
|
|
private final IFsCourseWatchLogService watchLogService;
|
|
|
private final IQwUserVideoService qwUserVideoService;
|
|
private final IQwUserVideoService qwUserVideoService;
|
|
|
- private final FsUserMapper fsUserMapper;
|
|
|
|
|
private final RedisCache redisCache;
|
|
private final RedisCache redisCache;
|
|
|
private final ICompanyMiniappService companyMiniappService;
|
|
private final ICompanyMiniappService companyMiniappService;
|
|
|
-
|
|
|
|
|
- private final List<String> projectNames = Arrays.asList("济南联志健康", "北京存在文化");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ 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) {
|
|
private void sendMiniProgram(BaseVo vo, QwSopCourseFinishTempSetting.Setting content, Map<String, FsCoursePlaySourceConfig> miniMap, Long companyId) {
|
|
|
|
|
+ // 发送参数原本的appid
|
|
|
String appid = content.getMiniprogramAppid();
|
|
String appid = content.getMiniprogramAppid();
|
|
|
|
|
+ // 判断销售工时ID不为空并且有小程序类型
|
|
|
if(companyId != null && content.getMiniType() != null){
|
|
if(companyId != null && content.getMiniType() != null){
|
|
|
- List<CompanyMiniapp> list = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().eq("company_id", 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();
|
|
|
}
|
|
}
|
|
|
|
|
+ // 获取配置文件里面的项目名称
|
|
|
String signProjectName = SpringUtils.getProperty("cloud_host.company_name");
|
|
String signProjectName = SpringUtils.getProperty("cloud_host.company_name");
|
|
|
- //区分新老用户,新用户发送备用小程序,老用户发送主小程序
|
|
|
|
|
- if(projectNames.contains(signProjectName)){
|
|
|
|
|
|
|
+ //区分新老用户,新用户发送备用小程序,老用户发送主小程序,TODO 需要使用的项目在参数里面加上
|
|
|
|
|
+ if(PROJECT_NAMES.contains(signProjectName)){
|
|
|
log.info("ID:{}, qwUserId:{},externalId:{},进入区分发小程序逻辑", vo.getId(), vo.getQwUserId(), vo.getExId());
|
|
log.info("ID:{}, qwUserId:{},externalId:{},进入区分发小程序逻辑", vo.getId(), vo.getQwUserId(), vo.getExId());
|
|
|
|
|
+ // 判断消息是否是群聊,不是群聊再进去,TODO 当权无法判断群聊是否可以发送对应的小程序
|
|
|
if(!vo.isRoom()){
|
|
if(!vo.isRoom()){
|
|
|
log.info("qwUserId:{},externalId:{},不是群聊", vo.getQwUserId(), vo.getExId());
|
|
log.info("qwUserId:{},externalId:{},不是群聊", vo.getQwUserId(), vo.getExId());
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 获取当前外部联系人
|
|
|
QwExternalContact qwExternalContact = qwExternalContactMapper.selectOne(new LambdaQueryWrapper<QwExternalContact>().eq(QwExternalContact::getQwUserId,vo.getQwUserId()).eq(QwExternalContact::getExternalUserId,vo.getExId()).last(" limit 1"));
|
|
QwExternalContact qwExternalContact = qwExternalContactMapper.selectOne(new LambdaQueryWrapper<QwExternalContact>().eq(QwExternalContact::getQwUserId,vo.getQwUserId()).eq(QwExternalContact::getExternalUserId,vo.getExId()).last(" limit 1"));
|
|
|
|
|
+ // 当前外部联系是否绑定用户数据,如果数据为空则是没看过小程序的新用户,不用去判断小程序,跳过判断
|
|
|
if(qwExternalContact.getFsUserId() != null){
|
|
if(qwExternalContact.getFsUserId() != null){
|
|
|
|
|
+ // 根据用户绑定信息去查询用户信息
|
|
|
FsUser fsUser = fsUserMapper.selectFsUserByUserId(qwExternalContact.getFsUserId());
|
|
FsUser fsUser = fsUserMapper.selectFsUserByUserId(qwExternalContact.getFsUserId());
|
|
|
- LocalDateTime createTime = DateUtil.dateToLocalDateTime(fsUser.getCreateTime());
|
|
|
|
|
- log.info("ID:{}, qwUserId:{},externalId:{},已绑定小程序,判断时间:{}", vo.getId(), vo.getQwUserId(), vo.getExId(), createTime);
|
|
|
|
|
- LocalDateTime lastTime = LocalDateTime.of(2025, 11, 23, 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);
|
|
|
|
|
|
|
+ // 判断用户是否有看过其他的小程序多个
|
|
|
|
|
+ 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{
|
|
}else{
|
|
|
log.info("ID:{}, qwUserId:{},externalId:{},未绑定小程序用户", vo.getId(), vo.getQwUserId(), vo.getExId());
|
|
log.info("ID:{}, qwUserId:{},externalId:{},未绑定小程序用户", vo.getId(), vo.getQwUserId(), vo.getExId());
|
|
@@ -213,21 +243,6 @@ public class IpadSendServer {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void sendTxtAtMsg(BaseVo vo) {
|
|
|
|
|
- WxSendTextAtMsgTwoDTO dto = new WxSendTextAtMsgTwoDTO();
|
|
|
|
|
- List<WxSendTextAtMsgTwoDTO.Contentva> contentvaList = new ArrayList<>();
|
|
|
|
|
- WxSendTextAtMsgTwoDTO.Contentva contentva = new WxSendTextAtMsgTwoDTO.Contentva();
|
|
|
|
|
- contentva.setMsgtype(5);
|
|
|
|
|
- contentva.setVid(0);
|
|
|
|
|
- contentvaList.add(contentva);
|
|
|
|
|
- dto.setContentva(contentvaList);
|
|
|
|
|
- dto.setBase(vo);
|
|
|
|
|
- dto.setUuid(vo.getUuid());
|
|
|
|
|
- dto.setSend_userid(ipadSendUtils.userIds(vo));
|
|
|
|
|
- dto.setIsRoom(true);
|
|
|
|
|
- ipadSendUtils.sendTxtAtMsgVo(dto, vo.getServerId());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public void sendVoice(BaseVo vo, QwSopCourseFinishTempSetting.Setting content) {
|
|
public void sendVoice(BaseVo vo, QwSopCourseFinishTempSetting.Setting content) {
|
|
|
if (StringUtils.isEmpty(content.getVoiceUrl()) || StringUtils.isEmpty(content.getVoiceDuration())) {
|
|
if (StringUtils.isEmpty(content.getVoiceUrl()) || StringUtils.isEmpty(content.getVoiceDuration())) {
|
|
|
log.debug("语音未生成无法发送,转文字发送:{}", vo);
|
|
log.debug("语音未生成无法发送,转文字发送:{}", vo);
|
|
@@ -367,8 +382,8 @@ public class IpadSendServer {
|
|
|
String.valueOf(qwUser.getId()),
|
|
String.valueOf(qwUser.getId()),
|
|
|
qwSopLogs.getExternalId()
|
|
qwSopLogs.getExternalId()
|
|
|
);
|
|
);
|
|
|
- log.info("ID:{}-看课记录参数:videoID:{}, qwUserID:{}, extID:{}", qwSopLogs.getId(), setting.getVideoId().longValue(), qwUser.getId(), qwSopLogs.getExternalId());
|
|
|
|
|
- log.info("ID:{}-看课记录:{}", qwSopLogs.getId(), watchLog);
|
|
|
|
|
|
|
+ log.debug("ID:{}-看课记录参数:videoID:{}, qwUserID:{}, extID:{}", qwSopLogs.getId(), setting.getVideoId().longValue(), qwUser.getId(), qwSopLogs.getExternalId());
|
|
|
|
|
+ log.debug("ID:{}-看课记录:{}", qwSopLogs.getId(), watchLog);
|
|
|
String logId = qwSopLogs.getId();
|
|
String logId = qwSopLogs.getId();
|
|
|
if (watchLog != null) {
|
|
if (watchLog != null) {
|
|
|
//新逻辑
|
|
//新逻辑
|
|
@@ -395,9 +410,9 @@ public class IpadSendServer {
|
|
|
vo.setUuid(qwUser.getUid());
|
|
vo.setUuid(qwUser.getUid());
|
|
|
vo.setExId(qwSopLogs.getExternalUserId());
|
|
vo.setExId(qwSopLogs.getExternalUserId());
|
|
|
vo.setServerId(qwUser.getServerId());
|
|
vo.setServerId(qwUser.getServerId());
|
|
|
- vo.setQwUserId(qwUser.getId());
|
|
|
|
|
vo.setCorpCode(parentVo.getCorpCode());
|
|
vo.setCorpCode(parentVo.getCorpCode());
|
|
|
vo.setCorpId(parentVo.getCorpId());
|
|
vo.setCorpId(parentVo.getCorpId());
|
|
|
|
|
+ vo.setQwUserId(qwUser.getId());
|
|
|
try {
|
|
try {
|
|
|
content.setSendStatus(1);
|
|
content.setSendStatus(1);
|
|
|
switch (content.getContentType()) {
|
|
switch (content.getContentType()) {
|
|
@@ -433,17 +448,13 @@ public class IpadSendServer {
|
|
|
// 语音
|
|
// 语音
|
|
|
sendWxVideo(vo, content);
|
|
sendWxVideo(vo, content);
|
|
|
break;
|
|
break;
|
|
|
- case "99":
|
|
|
|
|
- // 群发
|
|
|
|
|
- sendTxtAtMsg(vo);
|
|
|
|
|
- break;
|
|
|
|
|
default:
|
|
default:
|
|
|
// 未知类型,记录警告
|
|
// 未知类型,记录警告
|
|
|
log.error("SOP_LOG_ID:{}错误的发送类型: {}", qwSopLogs.getId(), content.getContentType());
|
|
log.error("SOP_LOG_ID:{}错误的发送类型: {}", qwSopLogs.getId(), content.getContentType());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} 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.setSendStatus(2);
|
|
|
content.setSendRemarks("发送失败:" + e.getMessage());
|
|
content.setSendRemarks("发送失败:" + e.getMessage());
|
|
|
}
|
|
}
|