zyp 5 hari lalu
induk
melakukan
422ec1e076

+ 120 - 95
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -658,105 +658,126 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
     }
     private R handleRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
         //查询客户列表
-        List<QwExternalContact> contacts = qwExternalContactMapper.selectQwExternalContactListVOByfsUserId(user.getUserId());
-        log.info("查出来的企微客户数量:"+contacts.size());
-        if (!contacts.isEmpty()){
-            //找出对应销售匹配的客户
-            QwExternalContact matchedContact = contacts.stream()
-                    .filter(contact -> contact.getQwUserId().equals(Long.parseLong(param.getQwUserId())))
-                    .findFirst()
-                    .orElse(null);
-
-            if (matchedContact!=null){
-                log.info("匹配到的第一个企微用户:"+matchedContact.getUserId());
-                log.info("企微id:"+matchedContact.getId());
-                log.info("用户:"+param.getVideoId());
-                log.info("企微用户:"+param.getQwUserId());
-                param.setQwExternalId(matchedContact.getId());
-                FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(matchedContact.getId(), param.getVideoId(),param.getQwUserId());
-                if (log==null){
-                    createWatchLog(param);
-                }
-                return R.error(567,"群聊通用链接").put("qwExternalId", matchedContact.getId());
-            }
-        }
+//        List<QwExternalContact> contacts = qwExternalContactMapper.selectQwExternalContactListVOByfsUserId(user.getUserId());
+//        log.info("查出来的企微客户数量:"+contacts.size());
+//        if (!contacts.isEmpty()){
+//            //找出对应销售匹配的客户
+//            QwExternalContact matchedContact = contacts.stream()
+//                    .filter(contact -> contact.getQwUserId().equals(Long.parseLong(param.getQwUserId())))
+//                    .findFirst()
+//                    .orElse(null);
+//
+//            if (matchedContact!=null){
+//                log.info("匹配到的第一个企微用户:"+matchedContact.getUserId());
+//                log.info("企微id:"+matchedContact.getId());
+//                log.info("用户:"+param.getVideoId());
+//                log.info("企微用户:"+param.getQwUserId());
+//                param.setQwExternalId(matchedContact.getId());
+//                FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(matchedContact.getId(), param.getVideoId(),param.getQwUserId());
+//                if (log==null){
+//                    createWatchLog(param);
+//                }
+//                return R.error(567,"群聊通用链接").put("qwExternalId", matchedContact.getId());
+//            }
+//        }
 
         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>";
 
-        return addCustomerService(param.getQwUserId(),msg);
+        FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
 
-//        QwGroupChatDetailsResult result = qwApiService.groupChatDetails(courseLink.getChatId(), param.getCorpId());
-//        if(result.getErrCode() != 0){
-//            log.info("企微接口请求失败,请联系管理员:" +result.getErrMsg());
-//            return R.error("不是此群成员");
-//        }
-//        List<QwGroupChatDetailsResult.Member> collect = result.getGroupChat().getMemberList().stream().filter(e -> e.getType() == 2).collect(Collectors.toList());
-//        if(collect.isEmpty()){
-//            logger.info("群聊里面为空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId());
-//            return addCustomerService(param.getQwUserId(),msg);
-//        }
-//        Optional<QwGroupChatDetailsResult.Member> optional = collect.stream().filter(e -> e.getName().equals(user.getNickName()) || e.getName().equals(param.getNickName())).findFirst();
-//        if(!optional.isPresent()){
-//            logger.info("昵称未匹配上弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId());
-//
-//            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()));
-//        if(qwExternalContact==null){
-//            logger.info("外部联系人为空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId()+":"+member.getUserId()+param.getNickName());
-//            return addCustomerService(param.getQwUserId(),msg);
-//        }
-//        Long qwExternalId = qwExternalContact.getId();
-//        log.info("外部联系人数据:{}", qwExternalContact);
-////        addCompanyCompanyFsUser(param);
-//        FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(qwExternalId, param.getVideoId(),param.getQwUserId());
-//        if (log==null ){
-//            logger.info("看课记录为空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId()+qwExternalId+":"+param.getVideoId()+":"+param.getQwUserId());
-//            return addCustomerService(param.getQwUserId(),msg);
-//        }
-//        //判断外部联系人有没有绑定userId
-//        if (qwExternalContact.getFsUserId()!=null){
-//            //有客户有小程序id  但 登录的小程序id和根据外部联系人id查出来的小程序id不一致
-//            if (!qwExternalContact.getFsUserId().equals(param.getUserId())) {
-//                logger.info("小程序id不一致空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+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()))){
-//                logger.info("未匹配上公司空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId());
-//                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());
-//            courseWatchLogMapper.updateFsCourseWatchLog(log);
-//
-//            iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId,param.getUserId());
-//        }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);
-//        }
-//
-//        return R.error(567,"群聊通用链接").put("qwExternalId", qwExternalContact.getId());
+        if (courseLink == null || StringUtils.isEmpty(courseLink.getChatId())) {
+            return R.error("参数有误");
+        }
+        QwGroupChat qwGroupChat = qwGroupChatMapper.selectQwGroupChatByChatId(courseLink.getChatId());
+        if (qwGroupChat == null) {
+            logger.error("群聊不存在,chatId: {}", courseLink.getChatId());
+            return R.error("群聊不存在!");
+        }
+        SopUserLogsInfo sopUserLogsInfo = new SopUserLogsInfo();
+        sopUserLogsInfo.setChatId(courseLink.getChatId());
+        List<QwGroupChatUser> qwGroupChatUsers = qwGroupChatUserMapper.selectByChatId(sopUserLogsInfo);
+
+        if (qwGroupChatUsers == null || qwGroupChatUsers.isEmpty()) {
+            logger.error("群聊用户为空,chatId: {}", courseLink.getChatId());
+            return R.error("群聊用户为空!");
+        }
+        // 构建查询条件
+        QueryWrapper<QwExternalContact> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id", qwGroupChat.getOwner());
+        queryWrapper.eq("name", user.getNickName());
+        queryWrapper.eq("corp_id", param.getCorpId());
+        queryWrapper.eq("status", 0);
+
+        QwExternalContact qwExternalContact = qwExternalContactMapper.selectOne(queryWrapper);
+
+        if (qwExternalContact == null) {
+            return R.error("未查询到客户!");
+        }
+        // 检查客户是否在群中
+        boolean isInGroup = qwGroupChatUsers.stream()
+                .anyMatch(e -> e.getUserId() != null && e.getUserId().equals(qwExternalContact.getExternalUserId()));
+
+        if (!isInGroup) {
+            logger.error("客户不在群:{},里面:{}", qwGroupChat.getChatId(), qwExternalContact.getExternalUserId());
+            return R.error("客户不在群聊!");
+        }
+
+        logger.info("外部联系人数据:{}", qwExternalContact);
+        Long qwExternalId = qwExternalContact.getId();
+
+        FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(qwExternalId, param.getVideoId(),param.getQwUserId());
+        if (log==null ){
+            logger.info("看课记录为空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId()+qwExternalId+":"+param.getVideoId()+":"+param.getQwUserId());
+            return addCustomerService(param.getQwUserId(),msg);
+        }
+        //判断外部联系人有没有绑定userId
+        if (qwExternalContact.getFsUserId()!=null){
+            //有客户有小程序id  但 登录的小程序id和根据外部联系人id查出来的小程序id不一致
+            if (!qwExternalContact.getFsUserId().equals(param.getUserId())) {
+                logger.info("小程序id不一致空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+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()))){
+                logger.info("未匹配上公司空弹二维码:"+param.getCorpId()+":"+param.getQwUserId()+":"+param.getChatId()+":"+param.getUserId());
+                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());
+            courseWatchLogMapper.updateFsCourseWatchLog(log);
+
+            iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalContact.getId(),param.getUserId());
+            fsUserCompanyBindService.bindFsUser(user.getUserId(), qwExternalId, log.getLogId());
+
+        }else {
+            //没绑定fsUser直接绑定fsUser
+            QwExternalContact contact = new QwExternalContact();
+            contact.setId(qwExternalId);
+            contact.setFsUserId(param.getUserId());
+            qwExternalContactMapper.updateQwExternalContact(contact);
+            iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId,param.getUserId());
+            FsUser fsUser = new FsUser();
+            fsUser.setUserId(user.getUserId());
+            fsUser.setIsAddQw(1);
+            fsUserMapper.updateFsUser(fsUser);
+            //绑定上之后 更新观看记录
+            //看课记录中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());
+        }
+
+        return R.error(567,"群聊通用链接").put("qwExternalId", qwExternalContact.getId());
     }
 
     private void createWatchLog(FsUserCourseVideoAddKfUParam param) {
@@ -1317,6 +1338,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
             return R.error("未识别到用户信息");
         }
 
+        if (user.getStatus()==0){
+            return R.error("会员被停用,无权限,请联系客服!");
+        }
+
         FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByFsUser(param.getUserId(), param.getVideoId(), param.getCompanyUserId());
         if (log == null) {
             return R.error("无记录");
@@ -1334,7 +1359,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 
         if (log.getRewardType() != null ) {
             if (log.getRewardType() == 1){
-                FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+                FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
                 if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
                     return R.error("已领取该课程奖励,不可重复领取!");
                 }

+ 1 - 1
fs-user-app/src/main/java/com/fs/app/controller/CourseController.java

@@ -63,7 +63,7 @@ public class CourseController extends  AppBaseController{
         }
     }
 
-    @Cacheable(value = "getProductCateByPid", key = "#pid")
+//    @Cacheable(value = "getProductCateByPid", key = "#pid")
     @ApiOperation("获取子分类")
     @GetMapping("/getProductCateByPid")
     public R getProductCateByPid(@RequestParam(value="pid") Long pid){