zouxuan před 5 roky
rodič
revize
0c76d8f534

+ 12 - 12
edu-im/edu-im-server/src/main/java/com/keao/edu/im/controller/RoomController.java

@@ -89,21 +89,21 @@ public class RoomController{
     public Object statusSync(@RequestBody String body) throws Exception {
         ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
         log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
+        String extra = notify.getExtra();
 //        boolean result = false;
-        if(notify.getEvent() == 12 || notify.getEvent() == 3){
-//            result = roomService.statusSync(notify.getChannelId(), notify.getUserId());
+        if(notify.getEvent() == 1){
+            /*if(StringUtils.isEmpty(extra)){
+                roomService.configRecord(notify.getChannelId(),notify.getUserId());
+            }else {
+                roomService.startRecord(notify.getChannelId(),notify.getUserId());
+            }*/
+        }else if(notify.getEvent() == 2){
+
+        }else if(notify.getEvent() == 3){
+
         }else if(notify.getEvent() == 11){
-            roomService.startRecord(notify.getChannelId(),notify.getUserId());
-//            Teacher teacher = teacherDao.get(Integer.parseInt(notify.getUserId()));
-//            Long roomId = Long.parseLong(notify.getChannelId().substring(1));
-//            CourseSchedule courseSchedule = courseScheduleDao.get(roomId);
-//            if(teacher != null && teacher.getId().equals(courseSchedule.getActualTeacherId())){
-//                roomService.joinRoom(teacher.getRealName(),roomId.toString(),false,false);
-//            }else {
-//                roomService.joinRoom(teacher.getUsername(),roomId.toString(),false,false);
-//            }
+
         }
-        roomService.onChannelNotify(notify);
         return new BaseResponse<>();
     }
 

+ 108 - 17
edu-im/edu-im-server/src/main/java/com/keao/edu/im/mec/im/IMHelper.java

@@ -1,12 +1,14 @@
 package com.keao.edu.im.mec.im;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.keao.edu.common.exception.BizException;
 import com.keao.edu.im.api.entity.BaseMessage;
 import com.keao.edu.im.http.HttpHelper;
 import com.keao.edu.im.pojo.IMApiResultInfo;
 import com.keao.edu.im.pojo.IMTokenInfo;
+import com.keao.edu.im.pojo.RoomMember;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,8 +16,10 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
+import javax.validation.constraints.Size;
 import java.net.HttpURLConnection;
 import java.net.URLEncoder;
+import java.util.List;
 
 /**
  * Created by weiqinxiao on 2019/2/28.
@@ -227,15 +231,14 @@ public class IMHelper {
 
     /**
      * 开始录制
-     * @param hostUserId
+     * @param roomId
+     * @param registrationId
+     * @param roomMembers
      * @return
      * @throws Exception
      */
     @Async
-    public IMApiResultInfo startRecord(String hostUserId, String roomId,Long registrationId) throws Exception {
-        if (hostUserId == null) {
-            throw new IllegalArgumentException("Paramer 'hostUserId' is required");
-        }
+    public IMApiResultInfo startRecord(String roomId, Long registrationId, List<RoomMember> roomMembers) throws Exception {
         if (roomId == null) {
             throw new IllegalArgumentException("Paramer 'roomId' is required");
         }
@@ -244,13 +247,43 @@ public class IMHelper {
         jsonObject.put("videoFormat","mp4");
         jsonObject.put("audioFormat","mp3");
         jsonObject.put("videoResolution","640x480");
-        jsonObject.put("mixLayout",2);
+        jsonObject.put("mixLayout",1);
         jsonObject.put("sliceMin",30);
-        jsonObject.put("hostUserId",hostUserId);
+        jsonObject.put("renderMode",1);
+        jsonObject.put("hostUserId","");
+        jsonObject.put("hostStreamId","");
+
         JSONObject json = new JSONObject();
+        JSONArray jsonArray = new JSONArray();
+        boolean isMaster = true;
+        for (int i = 0; i < roomMembers.size(); i++) {
+            RoomMember roomMember = roomMembers.get(i);
+            JSONObject jsonObject1 = new JSONObject();
+            jsonObject1.put("userId",roomMember.getUid());
+            jsonObject1.put("streamId",roomMember.getUid());
+            if((roomMember.getRole() == 3 && isMaster) || (i == roomMembers.size() - 1 && isMaster)){
+                jsonObject1.put("x",0);
+                jsonObject1.put("y",0);
+                jsonObject1.put("width",0.5);
+                jsonObject1.put("height",0.5);
+                isMaster = false;
+            }else {
+                jsonObject1.put("x",0.5);
+                jsonObject1.put("y",0.5);
+                jsonObject1.put("width",0.5);
+                jsonObject1.put("height",0.5);
+            }
+            jsonArray.add(jsonObject1);
+        }
+        JSONObject jsonObject1 = new JSONObject();
+        jsonObject1.put("video",jsonArray);
+        jsonObject.put("input",jsonObject1);
+
+
         json.put("sessionId",roomQuery(roomId));
         json.put("config",jsonObject);
 
+
         String body = json.toJSONString();
 
         Thread.sleep(1000l);
@@ -264,30 +297,88 @@ public class IMHelper {
     }
 
     /**
-     * 结束录制
-     * @param hostUserId
+     * 更改录制布局
+     * @param roomId
+     * @param registrationId
+     * @param roomMembers
      * @return
      * @throws Exception
      */
-    public IMApiResultInfo stopRecord(String hostUserId, String roomId) throws Exception {
-        if (hostUserId == null) {
-            throw new IllegalArgumentException("Paramer 'userId' is required");
+    @Async
+    public IMApiResultInfo configRecord(String roomId, Long registrationId, List<RoomMember> roomMembers) throws Exception {
+        if (roomId == null) {
+            throw new IllegalArgumentException("Paramer 'roomId' is required");
         }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("mixLayout",1);
+        jsonObject.put("renderMode",1);
+        jsonObject.put("hostUserId","");
+        jsonObject.put("hostStreamId","");
+        JSONObject json = new JSONObject();
+        json.put("sessionId",roomQuery(roomId));
+        json.put("config",jsonObject);
+        JSONArray jsonArray = new JSONArray();
+        boolean isMaster = true;
+        for (int i = 0; i < roomMembers.size(); i++) {
+            RoomMember roomMember = roomMembers.get(i);
+            JSONObject jsonObject1 = new JSONObject();
+            jsonObject1.put("userId",roomMember.getUid());
+            jsonObject1.put("streamId",roomMember.getUid());
+            if((roomMember.getRole() == 3 && isMaster) || (i == roomMembers.size() - 1 && isMaster)){
+                jsonObject1.put("x",0);
+                jsonObject1.put("y",0);
+                jsonObject1.put("width",0.5);
+                jsonObject1.put("height",0.5);
+                isMaster = false;
+            }else {
+                jsonObject1.put("x",0.5);
+                jsonObject1.put("y",0.5);
+                jsonObject1.put("width",0.5);
+                jsonObject1.put("height",0.5);
+            }
+            jsonArray.add(jsonObject1);
+        }
+        JSONObject jsonObject1 = new JSONObject();
+        jsonObject1.put("video",jsonArray);
+        json.put("input",jsonObject1);
 
-        if (hostUserId == null) {
-            throw new IllegalArgumentException("Paramer 'groupId' is required");
+        String body = json.toJSONString();
+
+        Thread.sleep(1000l);
+        HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/config.json", "application/json",roomId);
+        httpHelper.setBodyParameter(body, conn);
+        IMApiResultInfo resultInfo = JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
+        if(resultInfo.getResultCode() == 10000){
+            redisTemplate.opsForValue().set(resultInfo.getRecordId(),registrationId.toString());
         }
-        JSONObject jsonObject = new JSONObject();
+        return resultInfo;
+    }
+
+    /**
+     * 结束录制
+     * @param roomId
+     * @return
+     * @throws Exception
+     */
+    public IMApiResultInfo stopRecord(String roomId) throws Exception {
+        if (roomId == null) {
+            throw new IllegalArgumentException("Paramer 'roomId' is required");
+        }
+
+//        if (hostUserId == null) {
+//            throw new IllegalArgumentException("Paramer 'groupId' is required");
+//        }
+        /*JSONObject jsonObject = new JSONObject();
         jsonObject.put("mode",3);
         jsonObject.put("videoFormat","mp4");
         jsonObject.put("audioFormat","mp3");
         jsonObject.put("videoResolution","640x480");
         jsonObject.put("mixLayout",2);
         jsonObject.put("sliceMin",30);
-        jsonObject.put("hostUserId",hostUserId);
+        jsonObject.put("hostUserId",hostUserId);*/
         JSONObject json = new JSONObject();
         json.put("sessionId",roomQuery(roomId));
-        json.put("config",jsonObject);
+//        json.put("config",jsonObject);
 
         String body = json.toJSONString();
 

+ 14 - 12
edu-im/edu-im-server/src/main/java/com/keao/edu/im/service/Impl/RoomServiceImpl.java

@@ -84,6 +84,11 @@ public class RoomServiceImpl implements RoomService {
     }
 
     @Override
+    public void configRecord(String roomId,String userId) throws Exception {
+//        imHelper.configRecord(roomId,userId);
+    }
+
+    @Override
     public void startRecord(String roomId,String userId) throws Exception {
 
         /*ExamRoom examRoom = eduUserFeignService.getExamRoom(Integer.parseInt(roomId));
@@ -105,8 +110,8 @@ public class RoomServiceImpl implements RoomService {
 
     @Override
     public void stopRecord(String roomId) throws Exception {
-        SysUser sysUser = sysUserFeignService.queryUserInfo();
-        imHelper.stopRecord(sysUser.getId().toString(),roomId);
+//        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        imHelper.stopRecord(roomId);
     }
 
     @Override
@@ -352,7 +357,8 @@ public class RoomServiceImpl implements RoomService {
             roomResult.setRegistrationId(registrationId);
         }
         roomResult.setExamFlag(examRoom.getExamFlag());
-        roomResult.setMembers(roomMemberDao.findByRid(roomId));
+        List<RoomMember> roomMembers = roomMemberDao.findByRid(roomId);
+        roomResult.setMembers(roomMembers);
 //        List<Whiteboard> whiteboardList = whiteboardDao.findByRid(roomId);
 //        roomResult.setWhiteboards(whiteboardList);
         log.info("join success: roomId = {}, userId = {}, userName={}, role = {}", roomId, userId, roleEnum);
@@ -362,10 +368,11 @@ public class RoomServiceImpl implements RoomService {
             }
             this.publishMessage(eduUserFeignService.getPublishMessage(registrationId));
             eduUserFeignService.upsetStudentAttendance(registrationId,0);
-            imHelper.startRecord(userId, roomId, registrationId);
+//            imHelper.startRecord(roomId, registrationId,roomMembers);
 //            eduUserFeignService.updateSessionId(registrationId,imApiResultInfo.getSessionId());
         }else {
             eduUserFeignService.upsetTeacherAttendance(examRoom.getId(),sysUser.getId(),0);
+//            imHelper.configRecord(roomId, registrationId,roomMembers);
         }
         return baseResponse;
     }
@@ -482,7 +489,7 @@ public class RoomServiceImpl implements RoomService {
 //        this.publishMessage(eduUserFeignService.getPublishMessage(registrationId));
         if(registrationId != null){
             eduUserFeignService.upsetStudentAttendance(registrationId,1);
-            imHelper.stopRecord(userId,roomId);
+//            imHelper.stopRecord(roomId);
         }else {
             eduUserFeignService.upsetTeacherAttendance(Long.parseLong(roomId),Integer.parseInt(userId),1);
         }
@@ -685,7 +692,7 @@ public class RoomServiceImpl implements RoomService {
                 if("3".equals(e.getRid())){
                     try {
                         eduUserFeignService.upsetStudentAttendance(e.getExamRegistrationId(),1);
-                        imHelper.stopRecord(e.getUid(),e.getRid());
+                        imHelper.stopRecord(e.getRid());
                     } catch (Exception e1) {
                         e1.printStackTrace();
                     }
@@ -723,7 +730,7 @@ public class RoomServiceImpl implements RoomService {
             if("recorded".equals(data.getType())){
                 msg.setRoomId("recorded" + roomId);
             }*/
-            imHelper.stopRecord(userId,roomId);
+            imHelper.stopRecord(roomId);
             IMApiResultInfo apiResultInfo = imHelper.publishMessage(userId, roomId, msg, 1);
             if (!apiResultInfo.isSuccess()) {
                 throw new ApiException(ErrorEnum.ERR_MESSAGE_ERROR);
@@ -1560,11 +1567,6 @@ public class RoomServiceImpl implements RoomService {
     }
 
     @Override
-    public void onChannelNotify(ChannelStateNotify notify) throws IOException {
-
-    }
-
-    @Override
     public void publishMessage(PublishMessageDto publishMessageDto) throws Exception {
         IMApiResultInfo apiResultInfo = imHelper.publishMessage(publishMessageDto.getUserId(),
                 publishMessageDto.getRoomId(),

+ 2 - 13
edu-im/edu-im-server/src/main/java/com/keao/edu/im/service/RoomService.java

@@ -19,6 +19,8 @@ public interface RoomService {
 
     void roomQuery(String roomId) throws Exception;
 
+    void configRecord(String roomId,String userId) throws Exception;
+
     void startRecord(String roomId,String userId) throws Exception;
 
     void stopRecord(String roomId) throws Exception;
@@ -83,19 +85,6 @@ public interface RoomService {
     boolean statusSync(String roomId,String userId) throws Exception;
 
     /**
-     * 发送节拍器消息
-     * @param playMidiMessageData
-     */
-//    void sendImPlayMidiMessage(PlayMidiMessageData playMidiMessageData) throws Exception;
-
-    /**
-     * 发送节拍器自定义消息
-     */
-//    void sendImPlayMidiMessage(PlayMidiMessageData playMidiMessageData);
-
-    void onChannelNotify(ChannelStateNotify notify) throws IOException;
-
-    /**
      * 发送消息
      * @param publishMessageDto
      */

+ 12 - 1
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamReviewServiceImpl.java

@@ -7,13 +7,16 @@ import com.keao.edu.common.dal.BaseDAO;
 import com.keao.edu.common.exception.BizException;
 import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.service.impl.BaseServiceImpl;
+import com.keao.edu.user.api.entity.ExamRoom;
 import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
 import com.keao.edu.user.dao.ExamReviewDao;
+import com.keao.edu.user.dao.ExamRoomDao;
 import com.keao.edu.user.dto.ExamReviewDto;
 import com.keao.edu.user.dto.ExamReviewRecordDto;
 import com.keao.edu.user.entity.ExamReview;
 import com.keao.edu.user.entity.ExaminationBasic;
 import com.keao.edu.user.entity.Subject;
+import com.keao.edu.user.enums.ExamRoomTeaherTypeEnum;
 import com.keao.edu.user.enums.YesOrNoEnum;
 import com.keao.edu.user.page.ExamReviewQueryInfo;
 import com.keao.edu.user.page.ExamReviewRecordQueryInfo;
@@ -36,6 +39,8 @@ public class ExamReviewServiceImpl extends BaseServiceImpl<Long, ExamReview> imp
 	@Autowired
 	private ExamReviewDao examReviewDao;
 	@Autowired
+	private ExamRoomDao examRoomDao;
+	@Autowired
 	private SysUserFeignService sysUserFeignService;
 	@Autowired
 	private ExamRoomStudentRelationService examRoomStudentRelationService;
@@ -102,7 +107,7 @@ public class ExamReviewServiceImpl extends BaseServiceImpl<Long, ExamReview> imp
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public void add(ExamReview examReview) {
+	public synchronized void add(ExamReview examReview) {
 		SysUser sysUser = sysUserFeignService.queryUserInfo();
 		Long examRegistrationId = examReview.getExamRegistrationId();
 		ExamReview byRegistrationId = examReviewDao.findByRegistrationId(examRegistrationId,sysUser.getId());
@@ -113,6 +118,12 @@ public class ExamReviewServiceImpl extends BaseServiceImpl<Long, ExamReview> imp
 		if(examRoomStudentRelation.getSignInTime() == null){
 			throw new BizException("评审失败:学员未考试");
 		}
+		ExamRoom examRoom = examRoomDao.get(examRoomStudentRelation.getExamRoomId());
+		if(examRoom.getMainTeacherUserId() == sysUser.getId()){
+			examReview.setTeacherType(ExamRoomTeaherTypeEnum.MAIN);
+		}else {
+			examReview.setTeacherType(ExamRoomTeaherTypeEnum.ASSISTANT);
+		}
 		examReview.setExaminationBasicId(examRoomStudentRelation.getExaminationBasicId());
 		examReview.setTeacherId(sysUser.getId());
 		examReview.setStudentId(examRoomStudentRelation.getStudentId());

+ 1 - 1
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamRoomServiceImpl.java

@@ -831,7 +831,7 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			if(StringUtils.isNotEmpty(examRoom.getAssistantTeacherUserIdList())){
 				String[] split = examRoom.getAssistantTeacherUserIdList().split(",");
 				ArrayList<String> strings = new ArrayList<>(Arrays.asList(split));
-				Map<Integer, String> map = getMap("sys_user", "id_", "real_name_", strings, Integer.class, String.class);
+				Map<Integer, String> map = getMap("sys_user", "id_", "phone_", strings, Integer.class, String.class);
 				//给助教老师发送短信提醒
 				sysMessageService.batchSendMessage(MessageTypeEnum.EXAM_ROOM_OPEN_SMS,
 						map,null,null,null,YimeiSmsPlugin.PLUGIN_NAME,examinationBasic.getName());

+ 2 - 1
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamRoomStudentRelationServiceImpl.java

@@ -482,7 +482,7 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 	private void currentStudent(Long examRoomStudentRelationId,Boolean isPush,Integer examStatus,Integer operator){
 		ExamRoomStudentRelation examRoomStudentRelation = examRoomStudentRelationDao.get(examRoomStudentRelationId);
 		//将当前学员退出教室并添加参考状态,如果考试未完成,清除签到时间,重新签到
-		imFeignService.kickRoom(new ReqUserData(examRoomStudentRelation.getExamRegistrationId(),examRoomStudentRelation.getStudentId().toString()));
+//
 		if(examStatus != null && examStatus == 0){
 			//未完成
 			examRoomStudentRelationDao.cleanSignInTime(examRoomStudentRelation.getExamRegistrationId());
@@ -494,6 +494,7 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 			ExaminationBasic examinationBasic = examinationBasicDao.get(examRoomStudentRelation.getExaminationBasicId());
 			sysMessageService.batchSendMessage(MessageTypeEnum.EXAM_ROOM_STUDENT_SIGN_IN_AGAIN_PUSH,map,null,null,null,JiguangPushPlugin.PLUGIN_NAME,examinationBasic.getName());
 		}else {
+            imFeignService.kickRoom(new ReqUserData(examRoomStudentRelation.getExamRegistrationId(),examRoomStudentRelation.getStudentId().toString()));
 			//结束考试
 			studentExamResultDao.updateFinishedExam(examRoomStudentRelation.getExamRegistrationId(),5);
 		}

+ 5 - 4
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExamReviewMapper.xml

@@ -12,7 +12,7 @@
 		<result column="exam_registration_id_" property="examRegistrationId" />
 		<result column="exam_room_id_" property="examRoomId" />
 		<result column="teacher_id_" property="teacherId" />
-		<result column="teacher_type_" property="teacherType"/>
+		<result column="teacher_type_" property="teacherType" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler"/>
 		<result column="student_id_" property="studentId" />
 		<result column="evaluation_content_" property="evaluationContent" />
 		<result column="evaluation_result_" property="evaluationResult"/>
@@ -42,7 +42,8 @@
 	<insert id="insert" parameterType="com.keao.edu.user.entity.ExamReview" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
 		INSERT INTO exam_review (id_,examination_basic_id_,exam_room_id_,teacher_id_,teacher_type_,student_id_,evaluation_content_,
 		evaluation_result_,create_time_,update_time_,tenant_id_,enable_edit_,exam_registration_id_)
-		VALUES(#{id},#{examinationBasicId},#{examRoomId},#{teacherId},#{teacherType},#{studentId},#{evaluationContent},
+		VALUES(#{id},#{examinationBasicId},#{examRoomId},#{teacherId},
+		#{teacherType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{studentId},#{evaluationContent},
 		#{evaluationResult},NOW(),NOW(),
 		#{tenantId},#{enableEdit,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examRegistrationId})
 	</insert>
@@ -64,7 +65,7 @@
 				teacher_id_ = #{teacherId},
 			</if>
 			<if test="teacherType != null">
-				teacher_type_ = #{teacherType},
+				teacher_type_ = #{teacherType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
 			</if>
 			<if test="evaluationResult != null">
 				evaluation_result_ = #{evaluationResult},
@@ -135,7 +136,7 @@
 				AND ere.status_=#{studentStatus,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler}
 			</if>
 			<if test="teacherType!=null">
-				AND er.teacher_type_=#{teacherType}
+				AND er.teacher_type_=#{teacherType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler}
 			</if>
 			<if test="examStartTime!=null and examEndTime!=null">
 				AND DATE_FORMAT( ero.exam_start_time_, '%Y-%m-%d' ) BETWEEN  DATE_FORMAT( #{examStartTime}, '%Y-%m-%d' ) AND DATE_FORMAT( #{examEndTime}, '%Y-%m-%d' )

+ 1 - 1
edu-user/edu-user-client-api/src/main/java/com/keao/edu/user/api/client/EduUserFeignService.java

@@ -73,7 +73,7 @@ public interface EduUserFeignService {
 	void updateFinishedExam(@RequestParam("examRegistrationId") Long examRegistrationId, @RequestParam("finishedExam") Integer finishedExam);
 
 	/**
-	 * 修改学员sessionId
+	 * 获取学员教室关联
 	 * @param examRegistrationId
 	 * @param sessionId
 	 */