Browse Source

Merge branch 'master' of http://git.dayaedu.com/yonge/edu-saas

zouxuan 5 years ago
parent
commit
34372d5362

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

@@ -12,7 +12,15 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     REGIST_PASS_PUSH("REGIST_PASS_PUSH", "报名审核通过"),
     REGIST_REJECT_PUSH("REGIST_REJECT_PUSH", "报名审核未通过"),
     REGIST_REJECT_SMS("REGIST_REJECT_SMS", "报名审核未通过"),
-    ACTION_EXAM_SIGN_PUSH("ACTION_EXAM_SIGN_PUSH", "开考签到提醒");
+    ACTION_EXAM_SIGN_PUSH("ACTION_EXAM_SIGN_PUSH", "开考签到提醒"),
+    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", "考场已确认"),
+    EXAM_ROOM_CONFIRM_TEACHER_SMS("EXAM_ROOM_CONFIRM_TEACHER_SMS", "考场已确认"),
+    BEFORE_EXAM_TEACHER_REMIND_SMS("BEFORE_EXAM_TEACHER_REMIND_SMS","明日考试安排"),
+    BEFORE_EXAM_STUDENT_REMIND_PUSH("BEFORE_EXAM_STUDENT_REMIND_PUSH","明日考试安排"),
+    BEFORE_EXAM_STUDENT_REMIND_SMS("BEFORE_EXAM_STUDENT_REMIND_SMS","明日考试安排");
 
     MessageTypeEnum(String code, String msg) {
         this.code = code;

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

@@ -54,7 +54,7 @@ public class ExamRoom {
 
 	private Integer openFlag;
 
-	private YesOrNoEnum examPlanPushFlag;
+	private Integer examPlanPushFlag;
 
 	private Integer examRoomStudentNum;
 
@@ -69,6 +69,14 @@ public class ExamRoom {
 	/**  */
 	private String tenantId;
 
+	public ExamRoom() {
+	}
+
+	public ExamRoom(Long id, Integer examPlanPushFlag) {
+		this.id = id;
+		this.examPlanPushFlag = examPlanPushFlag;
+	}
+
 	public Integer getOpenFlag() {
 		return openFlag;
 	}
@@ -214,11 +222,11 @@ public class ExamRoom {
 		this.examEndTime = examEndTime;
 	}
 
-	public YesOrNoEnum getExamPlanPushFlag() {
+	public Integer getExamPlanPushFlag() {
 		return examPlanPushFlag;
 	}
 
-	public void setExamPlanPushFlag(YesOrNoEnum examPlanPushFlag) {
+	public void setExamPlanPushFlag(Integer examPlanPushFlag) {
 		this.examPlanPushFlag = examPlanPushFlag;
 	}
 

+ 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;
 

+ 2 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/ExamRoomDao.java

@@ -13,6 +13,8 @@ public interface ExamRoomDao extends BaseDAO<Long, ExamRoom> {
 
     int batchInsert(@Param("examRooms") List<ExamRoom> examRooms);
 
+    int batchUpdate(@Param("examRooms") List<ExamRoom> examRooms);
+
     /**
      * COUNT教师考试列表
      * @param params

+ 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

+ 8 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/ExamRoomService.java

@@ -63,6 +63,14 @@ public interface ExamRoomService extends BaseService<Long, ExamRoom> {
     void sendExamPlan(Integer organId, Integer examId, Integer operatorId);
 
     /**
+     * @describe 明日考试提醒
+     * @author Joburgess
+     * @date 2020.07.22
+     * @return void
+     */
+    void tomorrowExamPlanRemind();
+
+    /**
      * @describe 获取考场统计信息
      * @author Joburgess
      * @date 2020.06.30

+ 1 - 1
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamOrganizationRelationServiceImpl.java

@@ -309,7 +309,7 @@ public class ExamOrganizationRelationServiceImpl extends BaseServiceImpl<Long, E
 
 		StringBuffer expectRegistTime = new StringBuffer(DateUtil.dateToString(examinationBasic.getEnrollStartTime(), "yyyy年MM月dd日 HH时mm分"));
 		expectRegistTime.append("-");
-		expectRegistTime.append(DateUtil.dateToString(examinationBasic.getEnrollStartTime(), "yyyy年MM月dd日 HH时mm分"));
+		expectRegistTime.append(DateUtil.dateToString(examinationBasic.getEnrollEndTime(), "yyyy年MM月dd日 HH时mm分"));
 
 		TenantInfo tenantInfo = tenantInfoDao.getWithOrgan(examinationBasic.getOrganId());
 		if(Objects.isNull(tenantInfo)){

+ 101 - 5
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamRoomServiceImpl.java

@@ -7,7 +7,6 @@ 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.enums.MessageTypeEnum;
-import com.keao.edu.common.enums.YesOrNoEnum;
 import com.keao.edu.common.exception.BizException;
 import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.service.SysMessageService;
@@ -15,6 +14,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;
@@ -33,7 +33,6 @@ import com.keao.edu.user.service.OrganizationService;
 import com.keao.edu.util.collection.MapUtil;
 import com.keao.edu.util.date.DateUtil;
 import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -75,6 +74,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() {
@@ -163,7 +164,7 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 		}
 
 		examRoom.setTenantId(TenantContextHolder.getTenantId());
-		examRoom.setExamPlanPushFlag(YesOrNoEnum.NO);
+		examRoom.setExamPlanPushFlag(0);
 		examRoom.setExamRoomStudentNum(0);
 		if(StringUtils.isBlank(examRoom.getExamTimeJson())){
 			examRoomDao.insert(examRoom);
@@ -316,13 +317,108 @@ 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);
+		if(Objects.isNull(examId)){
+			throw new BizException("请指定考级项目");
+		}
+		ExaminationBasic exam = examinationBasicDao.get(examId.longValue());
+		if(Objects.isNull(exam)){
+			throw new BizException("考级项目不存在");
+		}
+
+		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<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));
+
+		Map<Integer, List<ExamRoom>> teacherExamRoomsMap = new HashMap<>();
+
+		List<ExamRoom> needUpdateExamRooms = new ArrayList<>();
+
+		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);
+			examRoom.setId(students.get(0).getExamRoomId());
+
+			needUpdateExamRooms.add(new ExamRoom(examRoom.getId(), 1));
+
+			if(!teacherExamRoomsMap.containsKey(examRoom.getMainTeacherUserId())){
+				teacherExamRoomsMap.put(examRoom.getMainTeacherUserId(), new ArrayList<>());
+			}
+			teacherExamRoomsMap.get(examRoom.getMainTeacherUserId()).add(examRoom);
+			if(StringUtils.isNotBlank(examRoom.getAssistantTeacherUserIdList())){
+				Set<Integer> ateacherIds = Arrays.stream(examRoom.getAssistantTeacherUserIdList().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toSet());
+				for (Integer ateacherId : ateacherIds) {
+					if(!teacherExamRoomsMap.containsKey(ateacherId)){
+						teacherExamRoomsMap.put(ateacherId, new ArrayList<>());
+					}
+					teacherExamRoomsMap.get(ateacherId).add(examRoom);
+				}
+			}
+
+			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 = exam.getName();
+
+			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);
+		}
+
+		Map<Integer, String> idTeacherPhoneMap = this.getMap("sys_user", "id_", "real_name_", new ArrayList(teacherExamRoomsMap.keySet()), Integer.class, String.class);
+		for (Map.Entry<Integer, List<ExamRoom>> teacherRoomEntry : teacherExamRoomsMap.entrySet()) {
+			String teacherPhone = idTeacherPhoneMap.get(teacherRoomEntry.getKey());
+			Date examStartTime = teacherRoomEntry.getValue().stream().min(Comparator.comparing(ExamRoom::getExamStartTime)).get().getExamStartTime();
+			String examStartTimeStr = DateUtil.dateToString(examStartTime, "MM月dd日 HH时mm分");
+			int examRoomNum = teacherRoomEntry.getValue().size();
+			Map<Integer, String> phoneMap = new HashMap<>();
+			phoneMap.put(teacherRoomEntry.getKey(), teacherPhone);
+			sysMessageService.batchSendMessage(MessageTypeEnum.EXAM_ROOM_CONFIRM_TEACHER_SMS,
+												phoneMap, null, 0, null, YimeiSmsPlugin.PLUGIN_NAME,
+												exam.getName(), examStartTimeStr, examRoomNum);
+		}
+
+		if(!CollectionUtils.isEmpty(needUpdateExamRooms)){
+			examRoomDao.batchUpdate(needUpdateExamRooms);
+		}
+	}
+
+	@Override
+	public void tomorrowExamPlanRemind() {
 
 	}
 

+ 64 - 5
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamRoomMapper.xml

@@ -22,7 +22,7 @@
 		<result column="del_flag_" property="delFlag" />
 		<result column="organ_id_" property="organId"/>
 		<result column="open_flag_" property="openFlag"/>
-		<result column="exam_plan_push_flag_" property="examPlanPushFlag" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler"/>
+		<result column="exam_plan_push_flag_" property="examPlanPushFlag"/>
 		<result column="exam_room_student_num_" property="examRoomStudentNum"/>
 		<result column="create_time_" property="createTime" />
 		<result column="update_time_" property="updateTime" />
@@ -47,7 +47,7 @@
 		exam_room_student_num_,create_time_,update_time_,tenant_id_)
 		VALUES(#{id},#{examinationBasicId},#{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examLocationId},
 		#{subjectIdList},#{subjectNameList},#{mainTeacherUserId},#{mainTeacherName},#{assistantTeacherUserIdList},#{assistantTeacherUserNameList},
-		#{examStartTime},#{examEndTime},#{delFlag},#{organId},#{examPlanPushFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
+		#{examStartTime},#{examEndTime},#{delFlag},#{organId},#{examPlanPushFlag},
 		#{examRoomStudentNum},NOW(),NOW(),#{tenantId})
 	</insert>
 
@@ -61,7 +61,7 @@
 			(#{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,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
+			#{examRoom.examStartTime},#{examRoom.examEndTime},#{examRoom.delFlag},#{examRoom.organId},#{examRoom.examPlanPushFlag},
 			#{examRoom.examRoomStudentNum},NOW(),NOW(),#{examRoom.tenantId})
 		</foreach>
 	</insert>
@@ -114,7 +114,7 @@
 				organ_id_ = #{organId},
 			</if>
 			<if test="examPlanPushFlag != null">
-				exam_plan_push_flag_ = #{examPlanPushFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
+				exam_plan_push_flag_ = #{examPlanPushFlag},
 			</if>
 			<if test="examRoomStudentNum!=null">
 				exam_room_student_num_=#{examRoomStudentNum},
@@ -123,6 +123,65 @@
 		</set> WHERE id_ = #{id}
 	</update>
 
+	<!-- 根据主键查询一条记录 -->
+	<update id="batchUpdate" parameterType="com.keao.edu.user.api.entity.ExamRoom">
+		<foreach collection="examRooms" item="er" separator=";">
+			UPDATE exam_room
+			<set>
+				<if test="er.delFlag != null">
+					del_flag_ = #{er.delFlag},
+				</if>
+				<if test="er.openFlag != null">
+					open_flag_ = #{er.openFlag},
+				</if>
+				<if test="er.examinationBasicId != null">
+					examination_basic_id_ = #{er.examinationBasicId},
+				</if>
+				<if test="er.examStartTime != null">
+					exam_start_time_ = #{er.examStartTime},
+				</if>
+				<if test="er.examEndTime != null">
+					exam_end_time_ = #{er.examEndTime},
+				</if>
+				<if test="er.subjectIdList != null">
+					subject_id_list_ = #{er.subjectIdList},
+				</if>
+				<if test="er.subjectNameList != null">
+					subject_name_list_ = #{er.subjectNameList},
+				</if>
+				<if test="er.tenantId != null and er.tenantId != 0">
+					tenant_id_ = #{er.tenantId},
+				</if>
+				<if test="er.examMode != null">
+					exam_mode_ = #{er.examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
+				</if>
+				exam_location_id_ = #{er.examLocationId},
+				<if test="er.mainTeacherUserId != null">
+					main_teacher_user_id_ = #{er.mainTeacherUserId},
+				</if>
+				<if test="er.mainTeacherName != null">
+					main_teacher_user_name_ = #{er.mainTeacherName},
+				</if>
+				<if test="er.assistantTeacherUserIdList != null">
+					assistant_teacher_user_id_list_ = #{er.assistantTeacherUserIdList},
+				</if>
+				<if test="er.assistantTeacherUserNameList != null">
+					assistant_teacher_user_name_list_ = #{er.assistantTeacherUserNameList},
+				</if>
+				<if test="er.organId != null">
+					organ_id_ = #{er.organId},
+				</if>
+				<if test="er.examPlanPushFlag != null">
+					exam_plan_push_flag_ = #{er.examPlanPushFlag},
+				</if>
+				<if test="er.examRoomStudentNum!=null">
+					exam_room_student_num_=#{er.examRoomStudentNum},
+				</if>
+				update_time_ = NOW()
+			</set> WHERE id_ = #{er.id}
+		</foreach>
+	</update>
+
 	<update id="updateSL" parameterType="com.keao.edu.user.api.entity.ExamRoom">
 		UPDATE exam_room
 		<set>
@@ -167,7 +226,7 @@
 				organ_id_ = #{organId},
 			</if>
 			<if test="examPlanPushFlag != null">
-				exam_plan_push_flag_ = #{examPlanPushFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
+				exam_plan_push_flag_ = #{examPlanPushFlag},
 			</if>
 			<if test="examRoomStudentNum!=null">
 				exam_room_student_num_=#{examRoomStudentNum},

+ 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" />
@@ -249,4 +249,20 @@
 		WHERE exam_room_id_ = #{examRoomId}
 		GROUP BY student_id_
 	</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>