Joburgess 5 år sedan
förälder
incheckning
76b9882e49

+ 5 - 1
edu-common/src/main/java/com/keao/edu/common/enums/MessageTypeEnum.java

@@ -11,7 +11,11 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     EXAM_REGIST_EXPIRE_SMS("EXAM_REGIST_EXPIRE_SMS", "报名截至"),
     REGIST_PASS_PUSH("REGIST_PASS_PUSH", "报名审核通过"),
     REGIST_REJECT_PUSH("REGIST_REJECT_PUSH", "报名审核未通过"),
-    REGIST_REJECT_SMS("REGIST_REJECT_SMS", "报名审核未通过");
+    REGIST_REJECT_SMS("REGIST_REJECT_SMS", "报名审核未通过"),
+    EXAM_ROOM_CONFIRM_ONLINE_STUDENT_PUSH("EXAM_ROOM_CONFIRM_ONLINE_STUDENT_PUSH", "考场已确认"),
+    EXAM_ROOM_CONFIRM_ONLINE_STUDENT_SMS("EXAM_ROOM_CONFIRM_ONLINE_STUDENT_SMS", "考场已确认"),
+    EXAM_ROOM_CONFIRM_OFFLINE_STUDENT_PUSH("EXAM_ROOM_CONFIRM_OFFLINE_STUDENT_PUSH", "考场已确认"),
+    EXAM_ROOM_CONFIRM_OFFLINE_STUDENT_SMS("EXAM_ROOM_CONFIRM_OFFLINE_STUDENT_SMS", "考场已确认");
 
     MessageTypeEnum(String code, String msg) {
         this.code = code;

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

@@ -9,7 +9,7 @@ import java.util.Date;
 /**
  * 对应数据库表(exam_room_student_relation):
  */
-public class ExamRoomStudentRelation {
+public class ExamRoomStudentRelation extends  ExamRoom{
 
 	private Long id;
 

+ 11 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/ExamRoomStudentRelationDao.java

@@ -57,6 +57,17 @@ public interface ExamRoomStudentRelationDao extends BaseDAO<Long, ExamRoomStuden
     int deleteWithExamRooms(@Param("examRoomIds") List<Long> examRoomIds);
 
     /**
+     * @describe 获取考级项目下指定分部未发送考试安排的学员
+     * @author Joburgess
+     * @date 2020.07.22
+     * @param examId:
+     * @param organIds:
+     * @return java.util.List<com.keao.edu.user.api.entity.ExamRoomStudentRelation>
+     */
+    List<ExamRoomStudentRelation> getNoSendExamPlanRooms(@Param("examId") Long examId,
+                                                               @Param("organIds") List<Integer> organIds);
+
+    /**
      * 获取教室学员关联
      * @param basicId
      * @param roomId

+ 50 - 2
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamRoomServiceImpl.java

@@ -15,6 +15,7 @@ import com.keao.edu.common.service.impl.BaseServiceImpl;
 import com.keao.edu.common.tenant.TenantContextHolder;
 import com.keao.edu.im.api.client.ImFeignService;
 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;
@@ -74,6 +75,8 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 	private SysUserFeignService sysUserFeignService;
 	@Autowired
 	private SysMessageService sysMessageService;
+	@Autowired
+	private ExamRoomStudentRelationDao examRoomStudentRelationDao;
 
 	@Override
 	public BaseDAO<Long, ExamRoom> getDAO() {
@@ -315,14 +318,59 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public void sendExamPlan(Integer organId, Integer examId, Integer operatorId) {
-		List<Integer> nextLevelOrganIds = organizationService.getNextLevelOrganIds(organId, true);
-		int withoutExamRoomStudentNum = examRegistrationDao.countWithoutExamRoomStudentNum(nextLevelOrganIds, examId);
+		int withoutExamRoomStudentNum = examRegistrationDao.countWithoutExamRoomStudentNum(null, examId);
 		if(withoutExamRoomStudentNum>0){
 			throw new BizException("存在未安排教室的学员");
 		}
 		examLifecycleLogDao.insert(new ExamLifecycleLog(examId, "确认考试安排", operatorId));
+		List<ExamRoomStudentRelation> examRoomStudentWithOrgans = examRoomStudentRelationDao.getNoSendExamPlanRooms(examId.longValue(), null);
+
+		Set<Long> examIds = examRoomStudentWithOrgans.stream().map(ExamRoomStudentRelation::getExaminationBasicId).collect(Collectors.toSet());
+		Map<Integer, String> idExamNameMap = this.getMap("examination_basic", "id_", "name_", new ArrayList(examIds), Integer.class, String.class);
+
+		Set<Integer> locationIds = examRoomStudentWithOrgans.stream().filter(e -> Objects.nonNull(e.getExamLocationId())).map(ExamRoomStudentRelation::getExamLocationId).collect(Collectors.toSet());
+		Map<Integer, String> idLocationMap = this.getMap("exam_location", "id_", "name_", new ArrayList(locationIds), Integer.class, String.class);
+
+		Set<Integer> AllStudentIds = examRoomStudentWithOrgans.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
+		Map<Integer, String> idPhoneMap = this.getMap("sys_user", "id_", "phone_", new ArrayList(AllStudentIds), Integer.class, String.class);
 
+		Map<Long, List<ExamRoomStudentRelation>> examRoomStudentMap = examRoomStudentWithOrgans.stream().collect(Collectors.groupingBy(ExamRoomStudentRelation::getExamRoomId));
+		for (Map.Entry<Long, List<ExamRoomStudentRelation>> examRoomStudentEntry : examRoomStudentMap.entrySet()) {
+			List<ExamRoomStudentRelation> students = examRoomStudentEntry.getValue();
+			Set<Integer> studentIds = students.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
+			if(CollectionUtils.isEmpty(studentIds)){
+				continue;
+			}
+			ExamRoom examRoom=students.get(0);
+			Map<Integer, String> receiverMap = studentIds.stream().collect(Collectors.toMap(e->e, e->e.toString()));
+			Map<Integer, String> phoneMap = idPhoneMap.entrySet().stream().filter(e->studentIds.contains(e.getKey())).collect(Collectors.toMap(e->e.getKey(), e->e.getValue()));
+
+			MessageTypeEnum pushMessageType = MessageTypeEnum.EXAM_ROOM_CONFIRM_ONLINE_STUDENT_PUSH;
+			MessageTypeEnum smsMessageType = MessageTypeEnum.EXAM_ROOM_CONFIRM_ONLINE_STUDENT_SMS;
+
+			String examName = idExamNameMap.get(examRoom.getExaminationBasicId());
+
+			String examDayStr = DateUtil.dateToString(examRoom.getExamStartTime(), "MM月dd日");
+			StringBuffer examTimeStr = new StringBuffer();
+			examTimeStr.append(DateUtil.dateToString(examRoom.getExamStartTime(), "MM月dd日"));
+			examTimeStr.append("-");
+			examTimeStr.append(DateUtil.dateToString(examRoom.getExamEndTime(), "MM月dd日"));
+
+			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=idLocationMap.get(examRoom.getExamLocationId());
+			}
+			sysMessageService.batchSendMessage(pushMessageType,
+					receiverMap, null, 0, null, JiguangPushPlugin.PLUGIN_NAME,
+					examName, examDayStr, examTimeStr, locationName);
+			sysMessageService.batchSendMessage(smsMessageType,
+					phoneMap, null, 0, null, YimeiSmsPlugin.PLUGIN_NAME,
+					examName, examDayStr, examTimeStr, locationName);
+		}
 	}
 
 	@Override

+ 17 - 1
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamRoomStudentRelationMapper.xml

@@ -6,7 +6,7 @@
 -->
 <mapper namespace="com.keao.edu.user.dao.ExamRoomStudentRelationDao">
 	
-	<resultMap type="com.keao.edu.user.api.entity.ExamRoomStudentRelation" id="ExamRoomStudentRelation">
+	<resultMap type="com.keao.edu.user.api.entity.ExamRoomStudentRelation" id="ExamRoomStudentRelation" extends="com.keao.edu.user.dao.ExamRoomDao.ExamRoom">
 		<result column="id_" property="id" />
 		<result column="examination_basic_id_" property="examinationBasicId" />
 		<result column="exam_registration_id_" property="examRegistrationId" />
@@ -241,4 +241,20 @@
     <select id="getStudentIds" resultType="java.lang.String">
 		SELECT GROUP_CONCAT(DISTINCT student_id_) FROM exam_room_student_relation WHERE exam_room_id_ = #{examRoomId}
 	</select>
+
+    <select id="getNoSendExamPlanRooms" resultMap="ExamRoomStudentRelation">
+		SELECT
+			*
+		FROM
+			exam_room_student_relation ersr
+			LEFT JOIN exam_room er ON ersr.exam_room_id_ = er.id_
+		WHERE er.exam_plan_push_flag_=0
+			AND ersr.examination_basic_id_ = #{examId}
+			<if test="organIds!=null">
+				AND er.organ_id_ IN
+				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
+					#{organId}
+				</foreach>
+			</if>
+	</select>
 </mapper>