Browse Source

黑名单发送进入消息

liujunchi 2 years ago
parent
commit
9a9d151a0b

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/vo/ImLiveBroadcastRoomMemberVo.java

@@ -51,6 +51,17 @@ public class ImLiveBroadcastRoomMemberVo implements java.io.Serializable {
     @ApiModelProperty(value = "连麦状态 0:未申请1:申请连麦中2:连麦中")
     private Integer whetherMicStatus;
 
+    @ApiModelProperty(value = "是否黑名单")
+    private boolean blackFlag;
+
+    public boolean isBlackFlag() {
+        return blackFlag;
+    }
+
+    public void setBlackFlag(boolean blackFlag) {
+        this.blackFlag = blackFlag;
+    }
+
     public String getAvatar() {
         return avatar;
     }

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImLiveRoomBlackService.java

@@ -61,5 +61,12 @@ public interface ImLiveRoomBlackService extends IService<ImLiveRoomBlack> {
      * @param userId     用户id
      */
     void sendBlackMsg(ImLiveBroadcastRoomVo roomVo, Integer fromUserId, Integer userId, String type);
+
+    /**
+     * 检查用户是否在房间黑名单中
+     * @param userId 用户id
+     * @param roomUid 房间uid
+     */
+    Boolean checkBlackUser(Integer userId, String roomUid);
 }
 

+ 57 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -1345,11 +1345,68 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         onlineUserInfo.fastPut(userId, JSONObject.toJSONString(userInfo));
         //向直播间发送当前在线人数消息
         this.sendOnlineUserCount(imLiveBroadcastRoomVo, userId, onlineUserInfo.size());
+
+        // 黑名单发送进入消息
+        if (imLiveRoomBlackService.checkBlackUser(userId, imLiveBroadcastRoomVo.getRoomUid())) {
+            // 发送进入消息
+            this.sendBlackJoinRoom(userId, imLiveBroadcastRoomVo);
+        }
+
+
         log.info("join sendOnlineUserCount>>>>   roomUid: {}  fromUserId:{}  count:{}", roomUid, userId, onlineUserInfo.size());
         log.info("joinRoom>>>> userInfo: {}", JSONObject.toJSONString(userInfo));
     }
 
     /**
+     * 发送黑名单进入消息
+     * @param userId 用户id
+     */
+    private void sendBlackJoinRoom(Integer userId,ImLiveBroadcastRoomVo roomVo) {
+
+        String roomUid = roomVo.getRoomUid();
+        //校验传入参数,房间uid和发送人id不能为空
+        if (!WrapperUtil.checkObj(roomUid, userId)) {
+            log.info(" sendOnlineUserCount>>>> param is null roomUid: {}  fromUserId:{} ", roomUid, userId);
+            return;
+        }
+
+        // 消息发送用户
+        LiveRoomMessage.MessageUser messageUser = null;
+        SysUser sysUser = sysUserFeignService.queryUserById(userId);
+        if (Objects.nonNull(sysUser)) {
+            // 发送用户信息
+            messageUser = LiveRoomMessage.MessageUser
+                .builder()
+                .sendUserId(sysUser.getId().toString())
+                .sendUserName(sysUser.getUsername())
+                .avatarUrl(sysUser.getAvatar())
+                .build();
+        }
+
+        LiveRoomMessage.MessageContent messageContent = LiveRoomMessage.MessageContent
+            .builder()
+            .sendUserInfo(messageUser)
+            .build();
+
+        LiveRoomMessage message = LiveRoomMessage.builder()
+                                                 .isIncludeSender(1)
+                                                 .objectName(LiveRoomMessage.ENTER)
+                                                 .fromUserId(roomVo.getSpeakerId().toString())
+                                                 .toChatRoomId(roomUid)
+                                                 .content(messageContent)
+                                                 .build();
+
+        //发送消息
+        try {
+            livePluginContext.getPluginService(roomVo.getServiceProvider()).sendChatRoomMessage(message);
+            log.info("sendBlackJoinRoom>>>> message: {}", JSONObject.toJSONString(message));
+        } catch (Exception e) {
+            log.error("sendBlackJoinRoom>>>> error {}", e.getMessage());
+            log.error("sendBlackJoinRoom>>>> sendMessage {} :", JSONObject.toJSONString(message));
+        }
+    }
+
+    /**
      * 获取直播间用户信息
      * @param userId 用户id
      * @param imLiveBroadcastRoomVo 直播间信息

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveRoomBlackServiceImpl.java

@@ -207,6 +207,20 @@ public class ImLiveRoomBlackServiceImpl extends ServiceImpl<ImLiveRoomBlackDao,
         }
     }
 
+    /**
+     * 检查用户是否在房间黑名单中
+     *
+     * @param userId  用户id
+     * @param roomUid 房间uid
+     */
+    @Override
+    public Boolean checkBlackUser(Integer userId, String roomUid) {
+        ImLiveRoomBlack imLiveRoomBlack = this.getOne(Wrappers.<ImLiveRoomBlack>lambdaQuery()
+                .eq(ImLiveRoomBlack::getRoomUid, roomUid)
+                .eq(ImLiveRoomBlack::getUserId, userId));
+        return imLiveRoomBlack != null;
+    }
+
     private SysUser getSysUser() {
         //修改机构基础信息
         return Optional.ofNullable(sysUserFeignService.queryUserInfo())

+ 4 - 2
mec-biz/src/main/resources/config/mybatis/ImLiveBroadcastRoomMemberMapper.xml

@@ -37,7 +37,8 @@
         o.name_ organName,
         GROUP_CONCAT(distinct mg.name_) musicGroupName,
         a.join_time_ as joinTime,
-        a.total_time_ as totalViewTime
+        a.total_time_ as totalViewTime,
+        if(b.user_id_ is null, 0, 1) as blackFlag
         from im_live_broadcast_room_member as a
         left join im_live_broadcast_room as i on a.room_uid_ = i.room_uid_
         left join sys_user as su on su.id_ = a.user_id_
@@ -46,7 +47,8 @@
 		LEFT JOIN music_group mg ON  mg.id_ = sr.music_group_id_
         left join subject as b on st.subject_id_list_ = b.id_
 		left join `sys_user` tu on tu.`id_` = i.`speaker_id_` 
-		LEFT JOIN `organization` o on o.`id_` = su.`organ_id_` 
+		LEFT JOIN `organization` o on o.`id_` = su.`organ_id_`
+        left join im_live_room_black b on b.room_uid_ = a.room_uid_ and b.user_id_ = a.user_id_
         where a.room_uid_ = #{param.roomUid}
         <if test="param.search != null ">
             AND (