|
@@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.BeanCopyUtils;
|
|
@@ -55,6 +56,7 @@ import com.fs.qw.mapper.QwUserMapper;
|
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
|
import com.fs.qwApi.Result.QwAddContactWayResult;
|
|
|
+import com.fs.qwApi.Result.QwGroupChatDetailsResult;
|
|
|
import com.fs.qwApi.param.QwAddContactWayParam;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
@@ -479,6 +481,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
Integer isRoom = param.getIsRoom();
|
|
|
|
|
|
// 处理逻辑
|
|
|
+ if(StringUtils.isNotEmpty(param.getChatId())){
|
|
|
+ return handleQwRoom(param, fsUser);
|
|
|
+ }
|
|
|
if (isRoom == null || isRoom == 0) {
|
|
|
// 当 isRoom 为 null 或 0 时走 handleExt
|
|
|
return handleExt(param,msg, oneCompanyCourse);
|
|
@@ -492,7 +497,88 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ private R handleQwRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
|
|
|
+ FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
|
|
|
+ String msg = "<div style=\"color: red;margin-bottom: 15px;font-weight: bold;\">本课程为群会员独享<br>请长按二维码</div>\n" +
|
|
|
+ "\t\t\t\t\t<div style=\"color: #999;font-size: 14px;font-weight: bold;\">添加伴学助手免费领取会员权限</div>";
|
|
|
+ QwGroupChatDetailsResult result = qwApiService.groupChatDetails(courseLink.getChatId(), param.getCorpId());
|
|
|
+ log.info("群聊参数:{},链接参数:{}, 企微返回:{}", JSON.toJSONString(param), JSON.toJSONString(courseLink), JSON.toJSONString(result));
|
|
|
+ if(result.getErrCode() != 0){
|
|
|
+ return R.error("企微接口请求失败,请联系管理员:" +result.getErrMsg());
|
|
|
+ }
|
|
|
+// List<QwGroupChatDetailsResult.Member> collect = result.getGroupChat().getMemberList().stream().filter(e -> e.getType() == 2).collect(Collectors.toList());
|
|
|
+// if(collect.isEmpty()){
|
|
|
+// return addCustomerService(param.getQwUserId(),msg);
|
|
|
+// }
|
|
|
+// Optional<QwGroupChatDetailsResult.Member> optional = collect.stream().filter(e -> e.getName().equals(fsUser.getNickName()) || e.getName().equals(param.getNickName())).findFirst();
|
|
|
+// if(!optional.isPresent()){
|
|
|
+// return addCustomerService(param.getQwUserId(),msg);
|
|
|
+// }
|
|
|
+// QwGroupChatDetailsResult.Member member = optional.get();
|
|
|
+// QwExternalContact qwExternalContact =
|
|
|
+// qwExternalContactMapper.selectOne(new QueryWrapper<QwExternalContact>()
|
|
|
+// .eq("user_id", result.getGroupChat().getOwner())
|
|
|
+// .eq("external_user_id", member.getUserId())
|
|
|
+// );
|
|
|
+ QwExternalContact qwExternalContact =
|
|
|
+ qwExternalContactMapper.selectOne(new QueryWrapper<QwExternalContact>()
|
|
|
+ .eq("user_id", result.getGroupChat().getOwner())
|
|
|
+ .eq("fs_user_id", param.getUserId())
|
|
|
+ .eq("corp_id", param.getCorpId())
|
|
|
+ .eq("status",0));
|
|
|
+ if(qwExternalContact==null){
|
|
|
+ return addCustomerService(param.getQwUserId(),msg);
|
|
|
+ }
|
|
|
+ log.info("外部联系人数据:{}", qwExternalContact);
|
|
|
+ if(result.getGroupChat().getMemberList().stream().noneMatch(e -> e.getUserId().equals(qwExternalContact.getExternalUserId()))){
|
|
|
+ return addCustomerService(param.getQwUserId(),msg);
|
|
|
+ }
|
|
|
+ Long qwExternalId = qwExternalContact.getId();
|
|
|
+// addCompanyCompanyFsUser(param);
|
|
|
+ FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(qwExternalId, param.getVideoId(),param.getQwUserId());
|
|
|
+ if (log==null ){
|
|
|
+ return addCustomerService(param.getQwUserId(),msg);
|
|
|
+ }
|
|
|
+ //判断外部联系人有没有绑定userId
|
|
|
+ if (qwExternalContact.getFsUserId()!=null){
|
|
|
+ //有客户有小程序id 但 登录的小程序id和根据外部联系人id查出来的小程序id不一致
|
|
|
+ if (!qwExternalContact.getFsUserId().equals(param.getUserId())) {
|
|
|
+ return addCustomerService(param.getQwUserId(),msg);
|
|
|
+ }
|
|
|
+ List<QwExternalContact> qwExternalContacts = qwExternalContactMapper.selectQwExternalContactByMiniUserId(param.getUserId());
|
|
|
+ //匹配客户公司id
|
|
|
+ if (qwExternalContacts.stream().noneMatch(contact -> contact.getCorpId().equals(param.getCorpId()))){
|
|
|
+ return addCustomerService(param.getQwUserId(),msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ //看课记录中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 fsUser = new FsUser();
|
|
|
+ fsUser.setUserId(user.getUserId());
|
|
|
+ fsUser.setIsAddQw(1);
|
|
|
+ fsUserMapper.updateFsUser(fsUser);
|
|
|
+ //绑定上之后 更新观看记录
|
|
|
+ //看课记录中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());
|
|
|
+ }
|
|
|
private R handleRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
|
|
|
//查询客户列表
|
|
|
List<QwExternalContact> contacts = qwExternalContactMapper.selectQwExternalContactListVOByfsUserId(user.getUserId());
|