Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

周箭河 5 gadi atpakaļ
vecāks
revīzija
860a67ff2e

+ 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 - 0
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/dto/StudentExamListDto.java

@@ -1,6 +1,7 @@
 package com.keao.edu.user.dto;
 
 import com.keao.edu.user.api.enums.ExamEvaluationResultEnum;
+import com.keao.edu.user.enums.ExamStatusEnum;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.math.BigDecimal;
@@ -18,6 +19,9 @@ public class StudentExamListDto{
     @ApiModelProperty(value = "考级项目编号")
     private Long examinationBasicId;
 
+    @ApiModelProperty(value = "考级项目状态")
+    private ExamStatusEnum examStatus;
+
     @ApiModelProperty(value = "准考证号")
     private String cardNo;
 
@@ -105,6 +109,14 @@ public class StudentExamListDto{
         this.examinationBasicId = examinationBasicId;
     }
 
+    public ExamStatusEnum getExamStatus() {
+        return examStatus;
+    }
+
+    public void setExamStatus(ExamStatusEnum examStatus) {
+        this.examStatus = examStatus;
+    }
+
     public String getSubjectName() {
         return subjectName;
     }

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

@@ -7,13 +7,17 @@ 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.dao.SysUserDao;
 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;
@@ -22,6 +26,7 @@ import com.keao.edu.user.service.ExamRoomStudentRelationService;
 import com.keao.edu.util.collection.MapUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.HashMap;
@@ -36,9 +41,13 @@ public class ExamReviewServiceImpl extends BaseServiceImpl<Long, ExamReview> imp
 	@Autowired
 	private ExamReviewDao examReviewDao;
 	@Autowired
+	private ExamRoomDao examRoomDao;
+	@Autowired
 	private SysUserFeignService sysUserFeignService;
 	@Autowired
 	private ExamRoomStudentRelationService examRoomStudentRelationService;
+	@Autowired
+	private SysUserDao sysUserDao;
 
 	@Override
 	public BaseDAO<Long, ExamReview> getDAO() {
@@ -101,9 +110,10 @@ public class ExamReviewServiceImpl extends BaseServiceImpl<Long, ExamReview> imp
 	}
 
 	@Override
-	@Transactional(rollbackFor = Exception.class)
+	@Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
 	public void add(ExamReview examReview) {
 		SysUser sysUser = sysUserFeignService.queryUserInfo();
+		sysUserDao.lockUser(sysUser.getId());
 		Long examRegistrationId = examReview.getExamRegistrationId();
 		ExamReview byRegistrationId = examReviewDao.findByRegistrationId(examRegistrationId,sysUser.getId());
 		if(byRegistrationId != null){
@@ -113,11 +123,22 @@ public class ExamReviewServiceImpl extends BaseServiceImpl<Long, ExamReview> imp
 		if(examRoomStudentRelation.getSignInTime() == null){
 			throw new BizException("评审失败:学员未考试");
 		}
+		ExamRoom examRoom = examRoomDao.get(examRoomStudentRelation.getExamRoomId());
+		if(examRoom.getMainTeacherUserId().equals(sysUser.getId())){
+			examReview.setTeacherType(ExamRoomTeaherTypeEnum.MAIN);
+		}else {
+			examReview.setTeacherType(ExamRoomTeaherTypeEnum.ASSISTANT);
+		}
 		examReview.setExaminationBasicId(examRoomStudentRelation.getExaminationBasicId());
 		examReview.setTeacherId(sysUser.getId());
 		examReview.setStudentId(examRoomStudentRelation.getStudentId());
 		examReview.setExamRoomId(examRoomStudentRelation.getExamRoomId());
 		examReview.setTenantId(examRoomStudentRelation.getTenantId());
+		if(sysUser.getId().equals(examRoom.getMainTeacherUserId())){
+			examReview.setTeacherType(ExamRoomTeaherTypeEnum.MAIN);
+		}else{
+			examReview.setTeacherType(ExamRoomTeaherTypeEnum.ASSISTANT);
+		}
 		examReviewDao.insert(examReview);
 	}
 

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

@@ -239,6 +239,9 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			if(!DateUtils.isSameDay(er.getExamStartTime(), er.getExamEndTime())){
 				throw new BizException("暂不支持跨天");
 			}
+			if(examinationBasic.getEnrollEndTime().compareTo(er.getExamStartTime())>0){
+				throw new BizException("考试时间不可在报名结束时间之前");
+			}
 			examRooms.add(er);
 		}
 		checkRoomTeachers(examRooms);
@@ -250,9 +253,6 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			examinationBasic.setActualExamStartTime(null);
 			examinationBasic.setActualExamEndTime(null);
 		}else{
-			if(examinationBasic.getEnrollEndTime().compareTo(examRoomExamTime.getExamStartTime())>0){
-				throw new BizException("考试时间不可在报名结束时间之前");
-			}
 			examinationBasic.setActualExamStartTime(DateUtils.truncate(examRoomExamTime.getExamStartTime(), Calendar.DAY_OF_MONTH));
 			examinationBasic.setActualExamEndTime(DateUtils.ceiling(examRoomExamTime.getExamEndTime(), Calendar.DAY_OF_MONTH));
 		}
@@ -332,6 +332,10 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			throw new BizException("暂不支持跨天");
 		}
 
+		if(examinationBasic.getEnrollEndTime().compareTo(examRoom.getExamStartTime())>0){
+			throw new BizException("考试时间不可在报名结束时间之前");
+		}
+
 		List<ExamRoom> examRooms=new ArrayList<>(Arrays.asList(examRoom));
 		checkRoomTeachers(examRooms);
 
@@ -342,9 +346,6 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			examinationBasic.setActualExamStartTime(null);
 			examinationBasic.setActualExamEndTime(null);
 		}else{
-            if(examinationBasic.getEnrollEndTime().compareTo(examRoomExamTime.getExamStartTime())>0){
-                throw new BizException("考试时间不可在报名结束时间之前");
-            }
 			examinationBasic.setActualExamStartTime(DateUtils.truncate(examRoomExamTime.getExamStartTime(), Calendar.DAY_OF_MONTH));
 			examinationBasic.setActualExamEndTime(DateUtils.ceiling(examRoomExamTime.getExamEndTime(), Calendar.DAY_OF_MONTH));
 		}
@@ -375,7 +376,7 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 		ExamRoom examRoom = examRoomDao.get(examRoomIds.get(0));
 
 		if(examRoom.getExamPlanPushFlag()==1){
-			throw new BizException("无法删除");
+			throw new BizException("已发送考试安排,无法删除");
 		}
 
 		ExaminationBasic examinationBasic = examinationBasicDao.get(examRoom.getExaminationBasicId().longValue());
@@ -831,7 +832,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());

+ 93 - 7
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamRoomStudentRelationServiceImpl.java

@@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.keao.edu.auth.api.client.SysUserFeignService;
 import com.keao.edu.auth.api.entity.SysUser;
 import com.keao.edu.common.dal.BaseDAO;
+import com.keao.edu.common.entity.SysConfig;
 import com.keao.edu.common.enums.MessageTypeEnum;
 import com.keao.edu.common.exception.BizException;
 import com.keao.edu.common.page.PageInfo;
+import com.keao.edu.common.service.IdGeneratorService;
 import com.keao.edu.common.service.SysMessageService;
 import com.keao.edu.common.service.impl.BaseServiceImpl;
 import com.keao.edu.common.tenant.TenantContextHolder;
@@ -15,6 +17,7 @@ import com.keao.edu.im.api.entity.MemberChangedMessage;
 import com.keao.edu.im.api.entity.PublishMessageDto;
 import com.keao.edu.im.api.entity.ReqUserData;
 import com.keao.edu.thirdparty.message.provider.JiguangPushPlugin;
+import com.keao.edu.thirdparty.message.provider.YimeiSmsPlugin;
 import com.keao.edu.user.api.entity.ExamRoom;
 import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
 import com.keao.edu.user.api.enums.ExamModeEnum;
@@ -25,10 +28,7 @@ import com.keao.edu.user.dto.RoomStudentListDto;
 import com.keao.edu.user.dto.StuRecordDetailDto;
 import com.keao.edu.user.entity.*;
 import com.keao.edu.user.page.ExamRoomStudentRelationQueryInfo;
-import com.keao.edu.user.service.ExamCertificationService;
-import com.keao.edu.user.service.ExamRoomStudentRelationService;
-import com.keao.edu.user.service.ExamTeacherSalaryService;
-import com.keao.edu.user.service.OrganizationService;
+import com.keao.edu.user.service.*;
 import com.keao.edu.util.collection.MapUtil;
 import com.keao.edu.util.date.DateUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -72,6 +72,10 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 	private ExamOrganizationRelationDao examOrganizationRelationDao;
 	@Autowired
 	private SysMessageService sysMessageService;
+	@Autowired
+	private IdGeneratorService idGeneratorService;
+	@Autowired
+	private SysConfigService sysConfigService;
 
 	@Override
 	public BaseDAO<Long, ExamRoomStudentRelation> getDAO() {
@@ -96,8 +100,8 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 		if(Objects.isNull(examRoom)){
 			throw new BizException("教室不存在");
 		}
-
-		if(examRoom.getExamPlanPushFlag()==1){
+		Date now=new Date();
+		if(now.compareTo(examRoom.getExamStartTime())>0||DateUtil.isSameDay(now, examRoom.getExamStartTime())){
 			throw new BizException("无法添加学员");
 		}
 
@@ -129,6 +133,8 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 		}
 
 		List<ExamRoomStudentRelation> examRoomStudentRelations=new ArrayList<>();
+		List<ExamCertification> examCertifications=new ArrayList<>();
+		List<StudentExamResult> studentExamResults=new ArrayList<>();
 		for (String registId : registIds) {
 			if(existRegistIds.contains(Long.valueOf(registId))){
 				continue;
@@ -148,6 +154,33 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 			e.setStudentId(examRegistration.getStudentId());
 			e.setTenantId(TenantContextHolder.getTenantId());
 			examRoomStudentRelations.add(e);
+
+			if(examRoom.getExamPlanPushFlag()==1){
+				ExamCertification ec=new ExamCertification();
+				ec.setExamRegistrationId(examRegistration.getId().longValue());
+				ec.setExaminationBasicId(examRegistration.getExaminationBasicId());
+				ec.setStudentId(examRegistration.getStudentId());
+				ec.setCardNo(String.valueOf(idGeneratorService.generatorId()));
+				ec.setSubjectId(examRegistration.getSubjectId());
+				ec.setLevel(examRegistration.getLevel());
+				ec.setExamStartTime(examRoom.getExamStartTime());
+				ec.setExamEndTime(examRoom.getExamEndTime());
+				if(ExamModeEnum.OFFLINE.equals(examRoom.getExamMode())){
+					ec.setExamAddress(examLocation.getName());
+				}
+				ec.setTenantId(TenantContextHolder.getTenantId());
+				examCertifications.add(ec);
+
+				StudentExamResult ser = new StudentExamResult();
+				ser.setExamRegistrationId(examRegistration.getId().longValue());
+				ser.setExaminationBasicId(examRegistration.getExaminationBasicId());
+				ser.setStudentId(examRegistration.getStudentId());
+				ser.setIsFinishedExam(3);
+				ser.setConfirmStatus(0);
+				ser.setTenantId(TenantContextHolder.getTenantId());
+				ser.setExamRoomId(examRoom.getId());
+				studentExamResults.add(ser);
+			}
 		}
 		if(!CollectionUtils.isEmpty(examRoomStudentRelations)){
 			examRoomStudentRelationDao.batchInsert(examRoomStudentRelations);
@@ -155,6 +188,55 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 			examRoom.setExamRoomStudentNum(examRoomStudentRelationDao.countStudentsWithRoom(examRoom.getId()));
 			examRoomDao.update(examRoom);
 		}
+		if(!CollectionUtils.isEmpty(examCertifications)){
+			examCertificationService.batchInsert(examCertifications);
+		}
+		if(!CollectionUtils.isEmpty(studentExamResults)){
+			studentExamResultDao.batchInsert(studentExamResults);
+			ExaminationBasic exam = examinationBasicDao.get(examRoom.getExaminationBasicId());
+			SysConfig baseH5UrlConfig = sysConfigService.findByParamName(SysConfigService.BASE_H5_URL);
+			String baseH5Url = "";
+			if(Objects.nonNull(baseH5UrlConfig)){
+				baseH5Url = baseH5UrlConfig.getParanValue();
+			}
+
+			Map<Integer, String> idPhoneMap = this.getMap("sys_user", "id_", "phone_", new ArrayList(studentIds), Integer.class, String.class);
+
+			String baseUrl = "2?examRegistrationId=";
+			String downloadUrl = baseH5Url + "/#/downLoad?memo=2&examRegistrationId=";
+			for (ExamRoomStudentRelation examRoomStudentRelation : examRoomStudentRelations) {
+				MessageTypeEnum pushMessageType = MessageTypeEnum.EXAM_ROOM_CONFIRM_ONLINE_STUDENT_PUSH;
+				MessageTypeEnum smsMessageType = MessageTypeEnum.EXAM_ROOM_CONFIRM_ONLINE_STUDENT_SMS;
+
+				Map<Integer, String> receiverMap = new HashMap<>(1);
+				receiverMap.put(examRoomStudentRelation.getStudentId(), examRoomStudentRelation.getStudentId().toString());
+
+				Map<Integer, String> phoneMap = new HashMap<>(1);
+				phoneMap.put(examRoomStudentRelation.getStudentId(), idPhoneMap.get(examRoomStudentRelation.getStudentId()));
+
+				String examName = exam.getName();
+
+				String examDayStr = DateUtil.dateToString(examRoom.getExamStartTime(), "MM月dd日");
+				StringBuffer examTimeStr = new StringBuffer();
+				examTimeStr.append(DateUtil.dateToString(examRoom.getExamStartTime(), "HH时mm分"));
+				examTimeStr.append("-");
+				examTimeStr.append(DateUtil.dateToString(examRoom.getExamEndTime(), "HH时mm分"));
+
+				String locationName = "网络考场";
+				if(ExamModeEnum.OFFLINE.equals(examRoom.getExamMode())){
+					pushMessageType = MessageTypeEnum.EXAM_ROOM_CONFIRM_OFFLINE_STUDENT_PUSH;
+					smsMessageType = MessageTypeEnum.EXAM_ROOM_CONFIRM_OFFLINE_STUDENT_SMS;
+					locationName=examLocation.getName();
+				}
+				String url = baseUrl + examRoomStudentRelation.getExamRegistrationId();
+				sysMessageService.batchSendMessage(pushMessageType,
+						receiverMap, null, 0, url, JiguangPushPlugin.PLUGIN_NAME,
+						examName, examDayStr, examTimeStr, locationName);
+				sysMessageService.batchSendMessage(smsMessageType,
+						phoneMap, null, 0, null, YimeiSmsPlugin.PLUGIN_NAME,
+						examName, examDayStr, examTimeStr, locationName, downloadUrl + examRoomStudentRelation.getExamRegistrationId());
+			}
+		}
 	}
 
 	@Override
@@ -275,6 +357,9 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 		if(StringUtils.isBlank(registIdsStr)){
 			return;
 		}
+		List<Long> registIds = Arrays.asList(registIdsStr.split(",")).stream().map(e -> Long.valueOf(e)).collect(Collectors.toList());
+		examRoomStudentRelationDao.deleteStudentsFromExamRoom(examRoomId, registIds);
+		studentExamResultDao.deleteWithRegists(registIds);
 		examRoom.setExamRoomStudentNum(examRoomStudentRelationDao.countStudentsWithRoom(examRoom.getId()));
 		examRoomDao.update(examRoom);
 		examTeacherSalaryService.teacherSalarySettlementWithExam(examRoom.getExaminationBasicId());
@@ -482,7 +567,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 +579,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);
 		}

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

@@ -123,12 +123,15 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
 		if(Objects.isNull(oldStudentExamResult)){
 			throw new BizException("考试结果不存在");
 		}
+		if(Objects.isNull(oldStudentExamResult.getAvgScore())){
+			throw new BizException("考试结果暂不可编辑");
+		}
 		ExaminationBasic examinationBasic = examinationBasicDao.get(oldStudentExamResult.getExaminationBasicId().longValue());
 		if(Objects.isNull(examinationBasic)){
 			throw new BizException("考级项目不存在");
 		}
 		if(ExamStatusEnum.RESULT_CONFIRM.equals(examinationBasic.getStatus())||ExamStatusEnum.CLOSE.equals(examinationBasic.getStatus())){
-			throw new BizException("考试结果不可编辑");
+			throw new BizException("考试结果已确认");
 		}
 		studentExamResultDao.update(studentExamResult);
 	}

+ 2 - 1
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExamRegistrationMapper.xml

@@ -510,6 +510,7 @@
 	<resultMap id="ExamRecordDtoMap" type="com.keao.edu.user.dto.StudentExamListDto">
 		<result property="level" column="level_"/>
 		<result property="examRegistrationId" column="exam_registration_id_"/>
+		<result property="examStatus" column="exam_status_"/>
 		<result property="examBaseName" column="exam_base_name_"/>
 		<result property="actualExamEndTime" column="actual_exam_end_time_"/>
 		<result property="actualExamStartTime" column="actual_exam_start_time_"/>
@@ -526,7 +527,7 @@
 		<result property="cardNo" column="card_no_"/>
 	</resultMap>
 	<select id="queryExamList" resultMap="ExamRecordDtoMap">
-		SELECT er.level_,ser.exam_registration_id_,eb.name_ exam_base_name_,DATE_FORMAT(eb.actual_exam_start_time_, '%Y-%m-%d') actual_exam_start_time_,
+		SELECT er.level_,ser.exam_registration_id_,eb.status_ exam_status_,eb.name_ exam_base_name_,DATE_FORMAT(eb.actual_exam_start_time_, '%Y-%m-%d') actual_exam_start_time_,
 		DATE_FORMAT(eb.actual_exam_end_time_, '%Y-%m-%d') actual_exam_end_time_,ser.avg_score_,ec.exam_address_,ec.id_ exam_certification_id_,
 		er.examination_basic_id_,er.exam_music_theory_level_,ser.is_finished_exam_,er.theory_level_fee_,
 		ser.video_url_,ser.result_,er.subject_id_,ec.card_no_

+ 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' )

+ 11 - 4
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExamRoomMapper.xml

@@ -8,6 +8,7 @@
 	
 	<resultMap type="com.keao.edu.user.api.entity.ExamRoom" id="ExamRoom">
 		<result column="id_" property="id" />
+		<result column="name_" property="name"/>
 		<result column="examination_basic_id_" property="examinationBasicId"/>
 		<result column="exam_mode_" property="examMode" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler"/>
 		<result column="exam_location_id_" property="examLocationId" />
@@ -43,24 +44,24 @@
 	
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.keao.edu.user.api.entity.ExamRoom" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-		INSERT INTO exam_room (id_,examination_basic_id_,exam_mode_,exam_location_id_,subject_id_list_,subject_name_list_,
+		INSERT INTO exam_room (id_,name_,examination_basic_id_,exam_mode_,exam_location_id_,subject_id_list_,subject_name_list_,
 		main_teacher_user_id_,main_teacher_user_name_,assistant_teacher_user_id_list_,assistant_teacher_user_name_list_,
 		exam_start_time_,exam_end_time_,del_flag_,organ_id_,exam_plan_push_flag_,
 		exam_room_student_num_,create_time_,update_time_,tenant_id_,exam_flag_)
-		VALUES(#{id},#{examinationBasicId},#{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examLocationId},
+		VALUES(#{id},#{name},#{examinationBasicId},#{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examLocationId},
 		#{subjectIdList},#{subjectNameList},#{mainTeacherUserId},#{mainTeacherName},#{assistantTeacherUserIdList},#{assistantTeacherUserNameList},
 		#{examStartTime},#{examEndTime},#{delFlag},#{organId},#{examPlanPushFlag},
 		#{examRoomStudentNum},NOW(),NOW(),#{tenantId},#{examFlag})
 	</insert>
 
 	<insert id="batchInsert" parameterType="com.keao.edu.user.api.entity.ExamRoom" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-		INSERT INTO exam_room (examination_basic_id_,exam_mode_,exam_location_id_,subject_id_list_,subject_name_list_,
+		INSERT INTO exam_room (name_,examination_basic_id_,exam_mode_,exam_location_id_,subject_id_list_,subject_name_list_,
 		main_teacher_user_id_,main_teacher_user_name_,assistant_teacher_user_id_list_,assistant_teacher_user_name_list_,
 		exam_start_time_,exam_end_time_,del_flag_,organ_id_,exam_plan_push_flag_,
 		exam_room_student_num_,create_time_,update_time_,tenant_id_)
 		VALUES
 		<foreach collection="examRooms" item="examRoom" separator=",">
-			(#{examRoom.examinationBasicId},#{examRoom.examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examRoom.examLocationId},
+			(#{examRoom.name},#{examRoom.examinationBasicId},#{examRoom.examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examRoom.examLocationId},
 			#{examRoom.subjectIdList},#{examRoom.subjectNameList},
 			#{examRoom.mainTeacherUserId},#{examRoom.mainTeacherName},#{examRoom.assistantTeacherUserIdList},#{examRoom.assistantTeacherUserNameList},
 			#{examRoom.examStartTime},#{examRoom.examEndTime},#{examRoom.delFlag},#{examRoom.organId},#{examRoom.examPlanPushFlag},
@@ -72,6 +73,9 @@
 	<update id="update" parameterType="com.keao.edu.user.api.entity.ExamRoom">
 		UPDATE exam_room
 		<set>
+			<if test="name!=null">
+				name_=#{name},
+			</if>
 			<if test="shieldUserId != null">
 				shield_user_id_ = #{shieldUserId},
 			</if>
@@ -136,6 +140,9 @@
 		<foreach collection="examRooms" item="er" separator=";">
 			UPDATE exam_room
 			<set>
+				<if test="er.name!=null">
+					name_=#{er.name},
+				</if>
 				<if test="er.delFlag != null">
 					del_flag_ = #{er.delFlag},
 				</if>

+ 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
 	 */

+ 11 - 0
edu-user/edu-user-client-api/src/main/java/com/keao/edu/user/api/entity/ExamRoom.java

@@ -13,6 +13,9 @@ public class ExamRoom{
 
 	private Long id;
 
+	@ApiModelProperty(value = "考场名称")
+	private String name;
+
 	@ApiModelProperty(value = "考级项目编号")
 	private Long examinationBasicId;
 	
@@ -115,6 +118,14 @@ public class ExamRoom{
 		return this.id;
 	}
 
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
 	public Long getExaminationBasicId() {
 		return examinationBasicId;
 	}