浏览代码

Merge remote-tracking branch 'origin/master_saas' into master_saas

zouxuan 2 年之前
父节点
当前提交
ec827bb408

+ 1 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/core/filter/UsernameAuthenticationFilter.java

@@ -78,7 +78,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
 				clientId = "SYSTEM";
 			}
 			if (!userInfo.getSysUser().getUserType().contains(clientId)) {
-				throw new LockedException("用户不存在,请联系教务老师");
+				throw new LockedException("用户不存在,请联系乐团主管");
 			}
 		}
 		

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

@@ -173,5 +173,12 @@ public interface ImLiveBroadcastRoomService extends IService<ImLiveBroadcastRoom
      * @param whetherMicStatus 连麦状态
      */
     void userWhetherMic(String roomUid, Long userId, Integer whetherMicStatus);
+
+    /**
+     * 同步直播间点赞数
+     *
+     * @param roomUid 直播间uid
+     */
+    int syncLikeCount(String roomUid);
 }
 

+ 64 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -754,9 +754,9 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 
         //获取直播点赞
         int like = 0;
+        like = syncLikeCount(roomUid);
         RBucket<Object> likeCache = redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, roomUid));
         if (likeCache.isExists()) {
-            like = (int) likeCache.get();
             //删除房间点赞数据
             likeCache.delete();
         }
@@ -1180,6 +1180,8 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         //主讲人退出房间关闭录像
         closeLive(speakerInfo);
 
+        syncLikeCount(roomUid);
+
         //主讲人退出房间
         speakerInfo.setExitRoomTime(now);
         log.info("opsRoom>>>> exit speakerCache {}", JSONObject.toJSONString(speakerInfo));
@@ -1707,6 +1709,12 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
             //生成主讲人信息到缓存
             SysUser sysUser = getSysUser(room.getSpeakerId());
 
+            // 判断直播间时间
+            Date endTime = DateUtil.addMinutes(new Date(), PRE_LIVE_TIME_MINUTE);
+
+            if (room.getLiveStartTime().compareTo(endTime)> 0) {
+                throw new BizException("直播间时间未到");
+            }
 
             //记录用户当前房间uid
             RLock lock = redissonClient.getLock(SPEAKER_ROOM_ING_INFO_LOCK.replace(USER_ID, room.getSpeakerId().toString()));
@@ -1966,6 +1974,9 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         if (Objects.isNull(like)) {
             like = 0;
         }
+
+        like = syncLikeCount(roomVo.getRoomUid());
+
         roomVo.setLikeNum((int) like);
         //累计总用户数量
         // roomVo.setTotalLookNum(getNum.apply(this::getTotalUserCache, roomVo.getRoomUid()));
@@ -2460,6 +2471,58 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         liveBroadcastRoomMemberDao.userWhetherMic(roomUid, userId, whetherMicStatus);
     }
 
+    /**
+     * 同步直播间点赞数
+     *
+     * @param roomUid 直播间uid
+     * @return
+     */
+    @Override
+    @Transactional
+    public int syncLikeCount(String roomUid) {
+        ImLiveBroadcastRoom room = getById(roomUid);
+        if (room == null) {
+            return 0;
+        }
+        ImLiveBroadcastRoomDetailVo imLiveBroadcastRoomDetailVo = liveBroadcastRoomDataService.getDao()
+                                                                                              .queryByRoomUid(roomUid);
+        if (imLiveBroadcastRoomDetailVo == null) {
+            return 0;
+        }
+        if (room.getServiceProvider().equals(RongCloudLivePlugin.PLUGIN_NAME)) {
+            //点赞数
+            Object like = redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, roomUid)).get();
+            if (Objects.isNull(like)) {
+                like = 0;
+            }
+            return (int) like;
+        }
+        LivePluginService pluginService = livePluginContext.getPluginService(room.getServiceProvider());
+        List<TencentWrapper.ChatRoomGroupCounter> chatRoomGroupCounters = null;
+        try {
+            chatRoomGroupCounters = pluginService.chatRoomGroupCounterDataList(
+                room.getRoomUid());
+        } catch (Exception e) {
+            log.error("同步直播间点赞数失败", e);
+        }
+        if (CollectionUtils.isEmpty(chatRoomGroupCounters)) {
+            return 0;
+        }
+        Optional<TencentWrapper.ChatRoomGroupCounter> first = chatRoomGroupCounters.stream()
+                                                                                   .filter(a -> a.getKey()
+                                                                                                 .equals(
+                                                                                                     EGroupDefinedDataType.LIKES.getCode()))
+                                                                                   .findFirst();
+
+        if (first.isPresent()) {
+            int i = Integer.parseInt(first.get().getValue());
+            imLiveBroadcastRoomDetailVo.setTotalLikeNum(i);
+            updateById(room);
+            return i;
+        }
+        return 0;
+    }
+
 
     /**
      * 查询直播间所有用户信息

+ 18 - 0
mec-im/src/main/java/com/ym/config/ResourceServerConfig.java

@@ -1,13 +1,24 @@
 package com.ym.config;
 
+import com.ym.mec.common.security.BaseAccessDeniedHandler;
+import com.ym.mec.common.security.BaseAuthenticationEntryPoint;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
 import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
 
 @Configuration
 @EnableResourceServer
 public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
+
+    @Autowired
+    private BaseAccessDeniedHandler baseAccessDeniedHandler;
+
+    @Autowired
+    private BaseAuthenticationEntryPoint baseAuthenticationEntryPoint;
+
     @Override
     public void configure(HttpSecurity http) throws Exception {
         http.authorizeRequests().antMatchers("/v2/api-docs", "/user/register",
@@ -20,4 +31,11 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
                         "/liveRoom/addUserUnableSpeak","/liveRoom/removeUserUnableSpeak","/liveRoom/syncChatRoomStatus","/liveRoom/tencentImCallback")
                 .permitAll().anyRequest().authenticated().and().csrf().disable();
     }
+
+
+    @Override
+    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
+        resources.authenticationEntryPoint(baseAuthenticationEntryPoint).accessDeniedHandler(baseAccessDeniedHandler);
+    }
+
 }

+ 19 - 4
mec-im/src/main/java/com/ym/controller/UserController.java

@@ -19,7 +19,11 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
@@ -108,7 +112,9 @@ public class UserController {
             log.debug("callbackOnMemberStateChange: {}", callbackOnMemberStateChange);
             callbackOnMemberStateChange.setClientIP(clientIP);
             callbackOnMemberStateChange.setOptPlatform(optPlatform);
-            imLiveBroadcastRoomService.callbackOnMemberStateChange(callbackOnMemberStateChange);
+            if (callbackOnMemberStateChange.getGroupId().startsWith("LIVE")) {
+                imLiveBroadcastRoomService.callbackOnMemberStateChange(callbackOnMemberStateChange);
+            }
 
 
         } else if(request.getParameter("CallbackCommand").equals(ETencentImCallbackCommand.GROUP_CALLBACKAFTERMEMBEREXIT.getCommand())) {
@@ -118,7 +124,10 @@ public class UserController {
             log.debug("callbackAfterMemberExit: {}", callbackAfterMemberExit);
             callbackAfterMemberExit.setClientIP(clientIP);
             callbackAfterMemberExit.setOptPlatform(optPlatform);
-            imLiveBroadcastRoomService.callbackAfterMemberExit(callbackAfterMemberExit);
+
+            if (callbackAfterMemberExit.getGroupId().startsWith("LIVE")) {
+                imLiveBroadcastRoomService.callbackAfterMemberExit(callbackAfterMemberExit);
+            }
         }  else if(request.getParameter("CallbackCommand").equals(ETencentImCallbackCommand.GROUP_CALLBACKAFTERNEWMEMBERJOIN.getCommand())) {
             TencentData.CallbackAfterNewMemberJoin callbackAfterNewMemberJoin = TencentData.CallbackAfterNewMemberJoin.toObject(
                 body);
@@ -126,7 +135,10 @@ public class UserController {
             log.debug("CallbackAfterNewMemberJoin: {}", callbackAfterNewMemberJoin);
             callbackAfterNewMemberJoin.setClientIP(clientIP);
             callbackAfterNewMemberJoin.setOptPlatform(optPlatform);
-            imLiveBroadcastRoomService.callbackAfterNewMemberJoin(callbackAfterNewMemberJoin);
+
+            if (callbackAfterNewMemberJoin.getGroupId().startsWith("LIVE")) {
+                imLiveBroadcastRoomService.callbackAfterNewMemberJoin(callbackAfterNewMemberJoin);
+            }
         }
 
 
@@ -158,6 +170,9 @@ public class UserController {
 
             // 自动关闭录制
             imLiveBroadcastRoomService.closeLive(getRoomUid(event.getStreamId()), getSpeakerId(event.getStreamId()));
+
+            // 同步点赞数
+            imLiveBroadcastRoomService.syncLikeCount(getRoomUid(event.getStreamId()));
         }
 
         // 推流事件通知