zouxuan 5 年之前
父節點
當前提交
c9e0629d9e

+ 0 - 2
mec-im/src/main/java/com/ym/SealClassApplication.java

@@ -1,7 +1,6 @@
 package com.ym;
 
 import lombok.extern.slf4j.Slf4j;
-
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -9,7 +8,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.scheduling.annotation.EnableAsync;

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

@@ -10,6 +10,6 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
 public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
     @Override
     public void configure(HttpSecurity http) throws Exception {
-        http.authorizeRequests().antMatchers("/v2/api-docs","/user/register","/group/join","/group/create","/room/leave").permitAll().anyRequest().authenticated().and().csrf().disable();
+        http.authorizeRequests().antMatchers("/v2/api-docs","/user/register","/group/join","/group/create","/room/leave","/room/statusSync").permitAll().anyRequest().authenticated().and().csrf().disable();
     }
 }

+ 11 - 0
mec-im/src/main/java/com/ym/controller/RoomController.java

@@ -1,5 +1,6 @@
 package com.ym.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.ym.common.ApiException;
 import com.ym.common.BaseResponse;
 import com.ym.common.ErrorEnum;
@@ -33,6 +34,16 @@ public class RoomController{
         return new BaseResponse<>(result);
     }
 
+    @RequestMapping(value = "/statusSync", method = RequestMethod.POST)
+    public Object statusSync(@RequestBody String body) throws Exception {
+        ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
+        boolean result = false;
+        if(notify.getEvent() == 12){
+            result = roomService.statusSync(notify.getChannelId(), notify.getUserId());
+        }
+        return new BaseResponse<>(result);
+    }
+
     @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
     public Object downRole(@RequestBody ReqChangeUserRoleData data)
             throws ApiException, Exception {

+ 81 - 0
mec-im/src/main/java/com/ym/pojo/ChannelStateNotify.java

@@ -0,0 +1,81 @@
+package com.ym.pojo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ChannelStateNotify {
+
+	private String appKey;
+	private String channelId;
+	private String sessionId;
+	private int event;
+	private String userId;
+	private long timestamp;
+	private String token;
+    private String extra;
+    private List<Member> members = new ArrayList<Member>();
+	public String getAppKey() {
+		return appKey;
+	}
+	public void setAppKey(String appKey) {
+		this.appKey = appKey;
+	}
+	public String getChannelId() {
+		return channelId;
+	}
+	public void setChannelId(String channelId) {
+		this.channelId = channelId;
+	}
+	public String getSessionId() {
+		return sessionId;
+	}
+	public void setSessionId(String sessionId) {
+		this.sessionId = sessionId;
+	}
+	public int getEvent() {
+		return event;
+	}
+	public void setEvent(int event) {
+		this.event = event;
+	}
+	public String getUserId() {
+		return userId;
+	}
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+	public long getTimestamp() {
+		return timestamp;
+	}
+	public void setTimestamp(long timestamp) {
+		this.timestamp = timestamp;
+	}
+	public String getToken() {
+		return token;
+	}
+	public void setToken(String token) {
+		this.token = token;
+	}
+	public String getExtra() {
+		return extra;
+	}
+	public void setExtra(String extra) {
+		this.extra = extra;
+	}
+	public List<Member> getMembers() {
+		return members;
+	}
+	public void setMembers(List<Member> members) {
+		this.members = members;
+	}
+	
+	public Member getMemberByUserId (String userId) {
+		for (Member member : this.members) {
+			if (userId.equals(member.getUserId())) {
+				return member;
+			}
+		}
+		return null;
+	}
+	
+}

+ 21 - 0
mec-im/src/main/java/com/ym/pojo/Member.java

@@ -0,0 +1,21 @@
+package com.ym.pojo;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class Member {
+
+	private String userId;
+    private JSONObject data;
+	public String getUserId() {
+		return userId;
+	}
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+	public JSONObject getData(){
+		return data;
+	}
+	public void setData(JSONObject data){
+		this.data = data;
+	}
+}

+ 84 - 1
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -1126,7 +1126,90 @@ public class RoomServiceImpl implements RoomService {
             }
         }
     }
-	private void updateDisplay(String roomId, String senderId, String display, Integer isIncludeSender) throws ApiException, Exception {
+
+    @Override
+    public boolean statusSync(String roomId,String userId) throws Exception {
+        List<RoomMember> byRidAndUid = roomMemberDao.findByRidAndUid(roomId, userId);
+        if(byRidAndUid.size() > 0){
+            SysUser sysUser = sysUserFeignService.queryUserById(Integer.parseInt(userId));
+            Teacher teacher = teacherDao.get(sysUser.getId());
+            if(teacher != null){
+                try {
+                    teacherAttendanceService.addTeacherAttendanceRecord(Integer.parseInt(roomId.substring(4)),sysUser.getId(), SignStatusEnum.SIGN_OUT,true);
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+            List<Room> roomList = roomDao.findByRid(roomId);
+            if (roomList.size() == 0) {
+                log.error("room : {} not exist ", roomId);
+                throw new ApiException(ErrorEnum.ERR_ROOM_NOT_EXIST);
+            }
+
+            List<RoomMember> roomMemberList = roomMemberDao.findByRidAndUid(roomId, userId);
+            if (roomMemberList.size() == 0) {
+                log.error("{} not exist in room: {}", userId, roomId);
+                throw new ApiException(ErrorEnum.ERR_USER_NOT_EXIST_IN_ROOM);
+            }
+
+            int userRole = roomMemberList.get(0).getRole();
+            log.info("leaveRoom: roomId={}, role={}", roomId, RoleEnum.getEnumByValue(userRole));
+
+            if (userRole == RoleEnum.RoleTeacher.getValue() || userRole == RoleEnum.RoleAssistant.getValue()) {
+                if (isUserDisplay(roomList.get(0), userId)) {
+                    updateDisplay(roomId, userId, "", 0);
+                    log.info("clear display cause speaker leave: roomId={}", roomId);
+                } else {
+                    log.info("don't update current display: room={}, role={}", roomList.get(0), RoleEnum.getEnumByValue(userRole));
+                }
+            } else {
+                log.info("don't update current display: room={}, userRole={}", roomList.get(0), RoleEnum.getEnumByValue(userRole));
+            }
+
+            if (roomMemberDao.countByRid(roomId) == 1) {
+                IMApiResultInfo apiResultInfo = null;
+                try {
+                    apiResultInfo = imHelper.dismiss(userId, roomId);
+                    if (apiResultInfo.getCode() == 200) {
+                        roomMemberDao.deleteUserByRidAndUid(roomId, userId);
+                        roomDao.deleteByRid(roomId);
+                        deleteWhiteboardByUser(roomId, userId);
+                        log.info("dismiss the room: {}", roomId);
+                    } else {
+                        log.error("{} exit {} room error: {}", userId, roomId, apiResultInfo.getErrorMessage());
+                        throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, apiResultInfo.getErrorMessage());
+                    }
+                } catch (Exception e) {
+                    log.error("{} exit {} room error: {}", userId, roomId, e.getMessage());
+                    throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, e.getMessage());
+                }
+            } else {
+                IMApiResultInfo apiResultInfo = null;
+                try {
+                    apiResultInfo = imHelper.quit(new String[]{userId}, roomId);
+                    if (apiResultInfo.isSuccess()) {
+                        roomMemberDao.deleteUserByRidAndUid(roomId, userId);
+                        MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, userId, userRole);
+                        msg.setUserName(sysUser.getUsername());
+                        imHelper.publishMessage(userId, roomId, msg);
+                        imHelper.quit(new String[]{userId}, roomId);
+                        log.info("quit group: roomId={}", roomId);
+                    } else {
+                        throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, apiResultInfo.getErrorMessage());
+                    }
+                } catch (Exception e) {
+                    log.error("leave room error: roomId={}, {}", roomId, e.getMessage());
+                    throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR);
+                }
+            }
+            userDao.deleteByUid(userId);
+
+            return true;
+        }
+        return true;
+    }
+
+    private void updateDisplay(String roomId, String senderId, String display, Integer isIncludeSender) throws ApiException, Exception {
         roomDao.updateDisplayByRid(roomId, display);
         DisplayMessage displayMessage = new DisplayMessage(display);
         imHelper.publishMessage(senderId, roomId, displayMessage, isIncludeSender);

+ 2 - 0
mec-im/src/main/java/com/ym/service/RoomService.java

@@ -63,4 +63,6 @@ public interface RoomService {
     public void destroyRoom(String roomId);
     public Boolean memberOnlineStatus(List<ReqMemberOnlineStatus> statusList, String nonce, String timestamp, String signature) throws ApiException, Exception;
     public void userIMOfflineKick(String userId);
+
+    boolean statusSync(String roomId,String userId) throws Exception;
 }