Przeglądaj źródła

直播使用sop发送

lmx 6 dni temu
rodzic
commit
4a97423f96

+ 6 - 0
fs-service/src/main/java/com/fs/live/domain/Live.java

@@ -3,14 +3,17 @@ package com.fs.live.domain;
 
 
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
+import com.fs.live.vo.LiveTagItemVO;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 直播对象 live
@@ -127,4 +130,7 @@ public class   Live extends BaseEntity {
     private Long videoFileSize;
     private Long videoDuration;
     private Integer globalVisible;
+
+    @TableField(exist = false)
+    private List<LiveTagItemVO> liveTagList;
 }

+ 6 - 0
fs-service/src/main/java/com/fs/live/mapper/LiveTagConfigMapper.java

@@ -3,6 +3,8 @@ package com.fs.live.mapper;
 import java.util.List;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.live.domain.LiveTagConfig;
+import com.fs.live.vo.LiveTagItemVO;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 直播间标签配置Mapper接口
@@ -58,4 +60,8 @@ public interface LiveTagConfigMapper extends BaseMapper<LiveTagConfig>{
      * @return 结果
      */
     int deleteLiveTagConfigByIds(Long[] ids);
+
+    int deleteByLiveId(@Param("liveId") Long liveId);
+
+    List<LiveTagItemVO> getLiveTagListByliveId(@Param("liveId") Long liveId);
 }

+ 39 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -123,6 +123,9 @@ public class LiveServiceImpl implements ILiveService
     private CompanyMapper companyMapper;
     @Autowired
     private LiveCouponMapper liveCouponMapper;
+    
+    @Autowired
+    LiveTagConfigMapper liveTagConfigMapper;
 
     private static String TOKEN_VALID_CODE = "40001";
 
@@ -147,6 +150,12 @@ public class LiveServiceImpl implements ILiveService
             byId.setVideoFileSize(liveVideo.getFileSize());
             byId.setVideoDuration(liveVideo.getDuration());
         }
+        List<LiveTagItemVO> list = liveTagConfigMapper.getLiveTagListByliveId(liveId);
+        if(null != list && !list.isEmpty()){
+            byId.setLiveTagList(list);
+        }else{
+            byId.setLiveTagList(new ArrayList<>());
+        }
 
         return byId;
     }
@@ -401,6 +410,7 @@ public class LiveServiceImpl implements ILiveService
      * @return 结果
      */
     @Override
+    @Transactional
     public int insertLive(Live live){
 
 
@@ -434,6 +444,12 @@ public class LiveServiceImpl implements ILiveService
         liveData.setFavouriteNum(0L);
         liveData.setFollowNum(0L);
         liveDataService.insertLiveData(liveData);
+
+        //处理直播间标签配置
+        if(null != live.getLiveTagList() && !live.getLiveTagList().isEmpty()){
+            insertLiveTagConfig(live.getLiveTagList(),live.getLiveId(),live.getCreateBy());
+        }
+
         return save > 0 ? 1 : 0;
     }
 
@@ -554,6 +570,7 @@ public class LiveServiceImpl implements ILiveService
      * @return 结果
      */
     @Override
+    @Transactional
     public int updateLive(Live live){
         Live exist = baseMapper.selectLiveByLiveId(live.getLiveId());
         if (live.getCompanyId() != null && exist.getCompanyId() != null && !Objects.equals(exist.getCompanyId(), live.getCompanyId())) {
@@ -595,9 +612,31 @@ public class LiveServiceImpl implements ILiveService
         // 清除缓存
         clearLiveCache(live.getLiveId());
 
+        //处理直播间标签配置
+        if(null != live.getLiveTagList() && !live.getLiveTagList().isEmpty()){
+            //删除当前直播间的所有
+            liveTagConfigMapper.deleteByLiveId(live.getLiveId());
+            insertLiveTagConfig(live.getLiveTagList(),live.getLiveId(),live.getCreateBy());
+        }
+        
         return result;
     }
 
+    public void insertLiveTagConfig(List<LiveTagItemVO> list,Long liveId,String createBy){
+        for (LiveTagItemVO liveTagItemVO : list) {
+            LiveTagConfig liveTagConfig = new LiveTagConfig();
+            liveTagConfig.setCompanyId(Long.valueOf(liveTagItemVO.getCompanyId()));
+            liveTagConfig.setLiveId(liveId);
+            liveTagConfig.setCorpId(liveTagItemVO.getCorpId());
+            liveTagConfig.setMarkType(Long.valueOf(liveTagItemVO.getMarkType()));
+            liveTagConfig.setQwTagId(liveTagItemVO.getQwTagId());
+            liveTagConfig.setQwTagName(liveTagItemVO.getQwTagName());
+            liveTagConfig.setCreateTime(new Date());
+            liveTagConfig.setCreateBy(createBy);
+            liveTagConfigMapper.insertLiveTagConfig(liveTagConfig);
+        }
+    }
+
     /**
      * 批量删除直播
      *

+ 48 - 2
fs-service/src/main/java/com/fs/live/service/impl/LiveWatchUserServiceImpl.java

@@ -11,6 +11,7 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.course.domain.FsCourseLink;
 import com.fs.course.service.impl.FsUserCourseVideoServiceImpl;
 import com.fs.his.domain.FsUser;
 import com.fs.his.mapper.FsUserMapper;
@@ -562,7 +563,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         if (StringUtils.isNotBlank(param.getChatId())) {
             return handleLiveChat(param,fsUser, noMemberMsg, noRegisterMsg);
         } else if (null != param.getQwExternalId()) {
-            return handleLivePerson(param, noMemberMsg, noRegisterMsg);
+            return handleLivePerson(param,fsUser, noMemberMsg, noRegisterMsg);
         } else {
             return R.error("直播参数错误");
         }
@@ -678,7 +679,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
      * @param noRegisterMsg
      * @return
      */
-    public R handleLivePerson(LiveIsAddKfParam param,String noMemberMsg,String noRegisterMsg){
+    public R handleLivePerson(LiveIsAddKfParam param,FsUser user,String noMemberMsg,String noRegisterMsg){
 
         Long qwExternalId = param.getQwExternalId();
 
@@ -687,6 +688,51 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         if (liveWatchLog==null ){
             return R.error(noMemberMsg);
         }
+        //查询是否有添加客服
+        QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(qwExternalId);
+
+        //用小程序id查询外部联系人
+        List<QwExternalContact> qwExternalContacts = qwExternalContactMapper.selectQwExternalContactByMiniUserId(param.getUserId());
+
+        //判断外部联系人有没有绑定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 (liveWatchLog.getUserId() == null || liveWatchLog.getUserId().equals(0L) || !liveWatchLog.getUserId().equals(param.getUserId())) {
+                liveWatchLog.setUserId(param.getUserId());
+            }
+
+            liveWatchLog.setUpdateTime(new Date());
+
+            liveWatchLogMapper.updateLiveWatchLog(liveWatchLog);
+            iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId, param.getUserId());
+
+        } 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
+            liveWatchLog.setUserId(param.getUserId());
+            liveWatchLog.setUpdateTime(new Date());
+            liveWatchLogMapper.updateLiveWatchLog(liveWatchLog);
+        }
+
         return R.ok();
 
     }

+ 23 - 0
fs-service/src/main/java/com/fs/live/vo/LiveTagItemVO.java

@@ -0,0 +1,23 @@
+package com.fs.live.vo;
+
+import lombok.Data;
+
+/**
+ * @author MixLiu
+ * @date 2025/12/13 下午4:43)
+ */
+@Data
+public class LiveTagItemVO {
+
+   private Long id;
+    //公司id
+   private Integer companyId;
+   //主体id
+   private String  corpId;
+   //标记类型
+   private Integer markType;
+   //标签id
+   private Long qwTagId;
+   //标签名称
+   private String qwTagName;
+}

+ 8 - 0
fs-service/src/main/resources/mapper/live/LiveTagConfigMapper.xml

@@ -108,4 +108,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <delete id="deleteByLiveId" parameterType="Long">
+        delete from live_tag_config where live_id = #{liveId}
+    </delete>
+
+    <select id="getLiveTagListByliveId" parameterType="Long" resultType="com.fs.live.vo.LiveTagItemVO">
+        select * from live_tag_config where live_id = #{liveId}
+    </select>
 </mapper>