|
@@ -498,8 +498,234 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
// 设置 Redis 记录的过期时间(例如 5 分钟)
|
|
// 设置 Redis 记录的过期时间(例如 5 分钟)
|
|
|
redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ public R isAddKf(FsUserCourseVideoAddKfUParam param) {
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("zyp \n【判断添加客服】:{}",param);
|
|
|
|
|
+ //查询用户
|
|
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
|
|
+
|
|
|
|
|
+ //用户不存在唤起重新授权
|
|
|
|
|
+ if (fsUser==null){
|
|
|
|
|
+ return R.error(401,"会员不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fsUser.getStatus()==0){
|
|
|
|
|
+ return R.error("会员被停用,无权限,请联系客服!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (param.getIsRoom()!=null&& param.getIsRoom()== 1) {
|
|
|
|
|
+ // 当 isRoom 为 1 时走 handleRoom
|
|
|
|
|
+ return handleRoom(param,fsUser);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (param.getLinkType()!=null&¶m.getLinkType()==1){
|
|
|
|
|
+ if (param.getLinkId()!=null){
|
|
|
|
|
+ // 从数据库中查找短链对应的真实链接
|
|
|
|
|
+ FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLinkId(param.getLinkId());
|
|
|
|
|
+ if (courseLink != null) {
|
|
|
|
|
+ // 获取当前时间
|
|
|
|
|
+ Date currentTime = new Date();
|
|
|
|
|
+ // 获取链接的更新时间(假设这个字段代表过期时间)
|
|
|
|
|
+ Date updateTime = courseLink.getUpdateTime();
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否过期
|
|
|
|
|
+ if (currentTime.after(updateTime)) {
|
|
|
|
|
+ // 链接已过期
|
|
|
|
|
+ return R.error("链接已过期");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.error("链接过期");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
|
|
|
|
|
+// if(StringUtils.isNotEmpty(courseLink.getUNo())){
|
|
|
|
|
+// if(!courseLink.getUNo().equals(param.getUNo())){
|
|
|
|
|
+// log.error("看课链接uNO不一致,linkUNo:{}, param-uNo:{}", courseLink.getUNo(), param.getUNo());
|
|
|
|
|
+// }else{
|
|
|
|
|
+// log.info("看课链接uNO一致,uno:{}", courseLink.getUNo());
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ //未注册提示
|
|
|
|
|
+ String noRegisterMsg = "由于您还未完成注册,请联系伴学助手完成注册即可观看!";
|
|
|
|
|
+ //非独属链接提示
|
|
|
|
|
+ String noMemberMsg = "此链接已被绑定,请联系伴学助手领取您的专属链接,专属链接请勿分享哦!";
|
|
|
|
|
+
|
|
|
|
|
+ // 群聊逻辑
|
|
|
|
|
+ if(courseLink != null && StringUtils.isNotEmpty(courseLink.getChatId())){
|
|
|
|
|
+ QwGroupChat qwGroupChat = qwGroupChatMapper.selectQwGroupChatByChatId(courseLink.getChatId());
|
|
|
|
|
+ if(qwGroupChat == null){
|
|
|
|
|
+ return R.error("群参数异常!");
|
|
|
|
|
+ }
|
|
|
|
|
+ SopUserLogsInfo sopUserLogsInfo = new SopUserLogsInfo();
|
|
|
|
|
+ sopUserLogsInfo.setChatId(courseLink.getChatId());
|
|
|
|
|
+ List<QwGroupChatUser> qwGroupChatUsers = qwGroupChatUserMapper.selectByChatId(sopUserLogsInfo);
|
|
|
|
|
+ if(qwGroupChatUsers == null || qwGroupChatUsers.isEmpty()){
|
|
|
|
|
+ return R.error("群参数异常!");
|
|
|
|
|
+ }
|
|
|
|
|
+ QwExternalContact qwExternalContact =
|
|
|
|
|
+ qwExternalContactMapper.selectOne(new QueryWrapper<QwExternalContact>()
|
|
|
|
|
+ .eq("user_id", qwGroupChat.getOwner())
|
|
|
|
|
+ .eq("fs_user_id", param.getUserId())
|
|
|
|
|
+ .eq("corp_id", param.getCorpId())
|
|
|
|
|
+ .eq("status",0));
|
|
|
|
|
+ if(qwExternalContact==null){
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(qwGroupChatUsers.stream().noneMatch(e -> e.getUserId().equals(qwExternalContact.getExternalUserId()))){
|
|
|
|
|
+ log.error("客户不在群:{},里面:{}", qwGroupChat.getChatId(), qwExternalContact.getExternalUserId());
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long qwExternalId = qwExternalContact.getId();
|
|
|
|
|
+ log.info("外部联系人数据:{}", qwExternalContact);
|
|
|
|
|
+ addCompanyCompanyFsUser(param);
|
|
|
|
|
+ FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(qwExternalId, param.getVideoId(),param.getQwUserId());
|
|
|
|
|
+ if (log==null ){
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean isDebug = false;
|
|
|
|
|
+ //判断外部联系人有没有绑定userId
|
|
|
|
|
+ if (qwExternalContact.getFsUserId()!=null && isDebug){
|
|
|
|
|
+ //有客户有小程序id 但 登录的小程序id和根据外部联系人id查出来的小程序id不一致
|
|
|
|
|
+ if (!qwExternalContact.getFsUserId().equals(param.getUserId())) {
|
|
|
|
|
+ return R.error(noMemberMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<QwExternalContact> qwExternalContacts = qwExternalContactMapper.selectQwExternalContactByMiniUserId(param.getUserId());
|
|
|
|
|
+ //匹配客户公司id
|
|
|
|
|
+ if (qwExternalContacts.stream().noneMatch(contact -> contact.getCorpId().equals(param.getCorpId()))){
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //看课记录中userId为0绑定userId
|
|
|
|
|
+ if (log.getUserId()==null||log.getUserId().equals(0L) || !log.getUserId().equals(param.getUserId())){
|
|
|
|
|
+ log.setUserId(param.getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.setUpdateTime(new Date());
|
|
|
|
|
+ fsUserCompanyBindService.bindFsUser(fsUser.getUserId(), qwExternalId, log.getLogId());
|
|
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //没绑定fsUser直接绑定fsUser
|
|
|
|
|
+ QwExternalContact contact = new QwExternalContact();
|
|
|
|
|
+ contact.setId(qwExternalId);
|
|
|
|
|
+ contact.setFsUserId(param.getUserId());
|
|
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(contact);
|
|
|
|
|
+ FsUser user = new FsUser();
|
|
|
|
|
+ user.setUserId(fsUser.getUserId());
|
|
|
|
|
+ user.setIsAddQw(1);
|
|
|
|
|
+ fsUserMapper.updateFsUser(user);
|
|
|
|
|
+ //绑定上之后 更新观看记录
|
|
|
|
|
+ //看课记录中userId为0绑定userId
|
|
|
|
|
+ log.setUserId(param.getUserId());
|
|
|
|
|
+ log.setUpdateTime(new Date());
|
|
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
|
+ }
|
|
|
|
|
+ fsUserCompanyBindService.bindFsUser(fsUser.getUserId(), qwExternalId, log.getLogId());
|
|
|
|
|
+ return R.error(567,"群聊通用链接").put("qwExternalId", qwExternalContact.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ Long qwExternalId = param.getQwExternalId();
|
|
|
|
|
+
|
|
|
|
|
+ FsCourseWatchLog log=new FsCourseWatchLog();
|
|
|
|
|
+
|
|
|
|
|
+ //如果是官方的则查真正的外部联系人id
|
|
|
|
|
+ if (param.getLinkType()!=null&¶m.getLinkType()==5) {
|
|
|
|
|
+
|
|
|
|
|
+ log = courseWatchLogMapper.selectFsCourseWatchLogByCourseSopIdAndVideoId(param.getUserId(), param.getVideoId(), param.getQwUserId());
|
|
|
|
|
+ if (log == null) {
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ qwExternalId=log.getQwExternalContactId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ log = courseWatchLogMapper.getWatchCourseVideoByExt(qwExternalId, param.getVideoId(),param.getQwUserId());
|
|
|
|
|
+ if (log==null ){
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //查询是否有添加客服
|
|
|
|
|
+ QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(qwExternalId);
|
|
|
|
|
+
|
|
|
|
|
+ //用小程序id查询外部联系人
|
|
|
|
|
+ List<QwExternalContact> qwExternalContacts = qwExternalContactMapper.selectQwExternalContactByMiniUserId(param.getUserId());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //如果查不出来客户信息,加好友
|
|
|
|
|
+ if(externalContact==null){
|
|
|
|
|
+ return R.error(noRegisterMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //2025.04.10 绑定公司码
|
|
|
|
|
+ addCompanyCompanyFsUser(param);
|
|
|
|
|
+
|
|
|
|
|
+ //判断外部联系人有没有绑定userId
|
|
|
|
|
+ if (externalContact.getFsUserId()!=null){
|
|
|
|
|
+ //有客户有小程序id 但 登录的小程序id和根据外部联系人id查出来的小程序id不一致
|
|
|
|
|
+ if (!externalContact.getFsUserId().equals(param.getUserId())) {
|
|
|
|
|
+ return R.error(noMemberMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ //匹配客户公司id
|
|
|
|
|
+ if (qwExternalContacts.stream().noneMatch(contact -> contact.getCorpId().equals(param.getCorpId()))){
|
|
|
|
|
+ return R.error(noMemberMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //看课记录中userId为0绑定userId
|
|
|
|
|
+ if (log.getUserId()==null||log.getUserId().equals(0L) || !log.getUserId().equals(param.getUserId())){
|
|
|
|
|
+ log.setUserId(param.getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.setUpdateTime(new Date());
|
|
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
|
+
|
|
|
|
|
+ iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId,param.getUserId());
|
|
|
|
|
+
|
|
|
|
|
+ fsUserCompanyBindService.bindFsUser(fsUser.getUserId(), qwExternalId, log.getLogId());
|
|
|
|
|
+ if (param.getLinkType()!=null&¶m.getLinkType()==5){
|
|
|
|
|
+ FsCourseLink fsCourseLink = fsCourseLinkMapper.selectExpireLinkByQwExternalId(param.getQwUserId(), param.getVideoId(), qwExternalId);
|
|
|
|
|
+ return R.error(566,"官方群发通用链接").put("courseLink",fsCourseLink);
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //没绑定fsUser直接绑定fsUser
|
|
|
|
|
+ QwExternalContact contact = new QwExternalContact();
|
|
|
|
|
+ contact.setId(qwExternalId);
|
|
|
|
|
+ contact.setFsUserId(param.getUserId());
|
|
|
|
|
+// adHtmlClickLogService.upload(contact.getState(), AdUploadType.REGISTERED, e -> contact.setUploadRegisterStatus(1));
|
|
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(contact);
|
|
|
|
|
+
|
|
|
|
|
+ iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId,param.getUserId());
|
|
|
|
|
+
|
|
|
|
|
+ FsUser user = new FsUser();
|
|
|
|
|
+ user.setUserId(fsUser.getUserId());
|
|
|
|
|
+ user.setIsAddQw(1);
|
|
|
|
|
+ fsUserMapper.updateFsUser(user);
|
|
|
|
|
+
|
|
|
|
|
+ //绑定上之后 更新观看记录
|
|
|
|
|
+ //看课记录中userId为0绑定userId
|
|
|
|
|
+ if (log.getUserId()==null||log.getUserId().equals(0L) || !log.getUserId().equals(param.getUserId())){
|
|
|
|
|
+ log.setUserId(param.getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.setUpdateTime(new Date());
|
|
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
|
+ fsUserCompanyBindService.bindFsUser(fsUser.getUserId(), qwExternalId, log.getLogId());
|
|
|
|
|
+ if (param.getLinkType()!=null&¶m.getLinkType()==5){
|
|
|
|
|
+ FsCourseLink fsCourseLink = fsCourseLinkMapper.selectExpireLinkByQwExternalId(param.getQwUserId(), param.getVideoId(), qwExternalId);
|
|
|
|
|
+ return R.error(566,"官方群发通用链接").put("courseLink",fsCourseLink);
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /* @Override
|
|
|
public R isAddKf(FsUserCourseVideoAddKfUParam param) {
|
|
public R isAddKf(FsUserCourseVideoAddKfUParam param) {
|
|
|
logger.info("【判断添加客服】:{}",param);
|
|
logger.info("【判断添加客服】:{}",param);
|
|
|
//查询用户
|
|
//查询用户
|
|
@@ -592,7 +818,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return R.error("参数错误!");
|
|
return R.error("参数错误!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
private R handleQwRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
|
|
private R handleQwRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
|
|
|
FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
|
|
FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
|
|
|
String msg = "<div style=\"color: red;margin-bottom: 15px;font-weight: bold;\">本课程为群会员独享<br>请长按二维码</div>\n" +
|
|
String msg = "<div style=\"color: red;margin-bottom: 15px;font-weight: bold;\">本课程为群会员独享<br>请长按二维码</div>\n" +
|