Joburgess 5 years ago
parent
commit
4a64352013

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

@@ -21,6 +21,7 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     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","明日考试安排"),
+    EXAM_END_REMIND("EXAM_END_REMIND", "考试结果确认通知"),
     EXAM_RESULT_CONFIRM_PUSH("EXAM_RESULT_CONFIRM_PUSH", "考试结果已确认");
 
     MessageTypeEnum(String code, String msg) {

+ 22 - 0
edu-task/src/main/java/com/keao/edu/task/jobs/ExamEndRemindTask.java

@@ -0,0 +1,22 @@
+package com.keao.edu.task.jobs;
+
+import com.keao.edu.task.core.BaseTask;
+import com.keao.edu.user.api.client.TaskRemoteService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author Joburgess
+ * @Date 2020.07.27
+ */
+@Service
+public class ExamEndRemindTask extends BaseTask {
+
+    @Autowired
+    private TaskRemoteService taskRemoteService;
+
+    @Override
+    public void execute() {
+        taskRemoteService.examEndRemind();
+    }
+}

+ 9 - 0
edu-user/edu-user-client-api/src/main/java/com/keao/edu/user/api/client/TaskRemoteService.java

@@ -30,4 +30,13 @@ public interface TaskRemoteService {
 	@GetMapping("/tomorrowExamPlanRemind")
 	void tomorrowExamPlanRemind();
 
+	/**
+	 * @describe 考级项目结束提醒,提醒确认结果
+	 * @author Joburgess
+	 * @date 2020.07.27
+	 * @return void
+	 */
+	@GetMapping("/examEndRemind")
+	void examEndRemind();
+
 }

+ 5 - 0
edu-user/edu-user-client-api/src/main/java/com/keao/edu/user/api/client/fallback/TaskRemoteServiceFallback.java

@@ -24,4 +24,9 @@ public class TaskRemoteServiceFallback implements TaskRemoteService {
 	public void tomorrowExamPlanRemind() {
 		return;
 	}
+
+	@Override
+	public void examEndRemind() {
+		return;
+	}
 }

+ 6 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/TaskController.java

@@ -41,4 +41,10 @@ public class TaskController extends BaseController {
     public void tomorrowExamPlanRemind(String day){
         examRoomService.tomorrowExamPlanRemind(day);
     }
+
+    //考级项目结束提醒,提醒确认结果
+    @GetMapping("/examEndRemind")
+    public void examEndRemind(){
+        examinationBasicService.examEndRemind();
+    }
 }

+ 9 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/ExaminationBasicDao.java

@@ -16,6 +16,15 @@ public interface ExaminationBasicDao extends BaseDAO<Long, ExaminationBasic> {
 
     ExaminationBasicDto getExaminationBasic(Integer examId);
 
+    /**
+     * @describe 获取指定日期结束的考级项目
+     * @author Joburgess
+     * @date 2020.07.27
+     * @param day:
+     * @return java.util.List<com.keao.edu.user.entity.ExaminationBasic>
+     */
+    List<ExaminationBasic> getEndExamsWithDayAndStatus(@Param("day") String day);
+
     List<ExaminationBasicDto> findExaminationBasics(Map<String, Object> params);
     int countExaminationBasics(Map<String, Object> params);
 

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

@@ -12,6 +12,8 @@ public interface TenantInfoDao extends BaseDAO<Integer, TenantInfo> {
 
     List<TenantInfoDto> queryTenants(Map<String, Object> params);
 
+    List<TenantInfo> getTenants(@Param("ids") List<Integer> ids);
+
     int countTenants(Map<String, Object> params);
 
     /**

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

@@ -29,6 +29,14 @@ public interface ExaminationBasicService extends BaseService<Long, ExaminationBa
     void updateExamStatus();
 
     /**
+     * @describe 考级项目结束提醒,提醒确认结果
+     * @author Joburgess
+     * @date 2020.07.27
+     * @return void
+     */
+    void examEndRemind();
+
+    /**
      * @describe
      * @author Joburgess
      * @date 2020.07.13

+ 15 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamRoomStudentRelationServiceImpl.java

@@ -106,6 +106,7 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 
 		List<ExamRoomStudentRelation> studentsWithExamRoom = examRoomStudentRelationDao.findStudentsWithExamRoom(examRoomId);
 		Set<Long> existRegistIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getExamRegistrationId).collect(Collectors.toSet());
+		Set<Integer> existStudentIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
 
 		String[] registIds = registIdsStr.split(",");
 
@@ -124,6 +125,9 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 			if(Objects.isNull(examRegistration)){
 				throw new BizException("学员信息错误");
 			}
+			if(existStudentIds.contains(examRegistration.getStudentId())){
+				throw new BizException("学员重复");
+			}
 
 			ExamRoomStudentRelation e=new ExamRoomStudentRelation();
 			e.setExamRegistrationId(Long.valueOf(registId));
@@ -196,6 +200,17 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 			throw new BizException("考场信息不存在");
 		}
 
+		List<ExamRoomStudentRelation> studentsWithExamRoom = examRoomStudentRelationDao.findStudentsWithExamRoom(examRoomId);
+		Set<Long> existRegistIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getExamRegistrationId).collect(Collectors.toSet());
+		Set<Integer> existStudentIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
+
+		if(existRegistIds.contains(Long.valueOf(registId))){
+			throw new BizException("学员重复");
+		}
+		if(existStudentIds.contains(examRegistration.getStudentId())){
+			throw new BizException("学员重复");
+		}
+
 		ExamOrganizationRelation examOrganizationRelation = examOrganizationRelationDao.getExamOrganizationRelation(examRoom.getExaminationBasicId(), organId);
 		if(Objects.isNull(examOrganizationRelation)||examOrganizationRelation.getIsAllowArrangeExam()==0){
 			throw new BizException("无权操作");

+ 27 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExaminationBasicServiceImpl.java

@@ -2,11 +2,13 @@ package com.keao.edu.user.service.impl;
 
 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.exception.BizException;
 import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.service.SysMessageService;
 import com.keao.edu.common.service.impl.BaseServiceImpl;
 import com.keao.edu.common.tenant.TenantContextHolder;
+import com.keao.edu.thirdparty.message.provider.YimeiSmsPlugin;
 import com.keao.edu.user.api.enums.ExamModeEnum;
 import com.keao.edu.user.dao.*;
 import com.keao.edu.user.dto.ExamRoomExamTimeDto;
@@ -28,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -58,6 +61,8 @@ public class ExaminationBasicServiceImpl extends BaseServiceImpl<Long, Examinati
     private StudentExamResultService studentExamResultService;
     @Autowired
     private ExamRoomDao examRoomDao;
+    @Autowired
+    private TenantInfoDao tenantInfoDao;
 
     @Override
     public BaseDAO<Long, ExaminationBasic> getDAO() {
@@ -157,6 +162,28 @@ public class ExaminationBasicServiceImpl extends BaseServiceImpl<Long, Examinati
     }
 
     @Override
+    public void examEndRemind() {
+        LocalDate today = LocalDate.now();
+        List<ExaminationBasic> endExams = examinationBasicDao.getEndExamsWithDayAndStatus(today.plusDays(-1).toString());
+        if(CollectionUtils.isEmpty(endExams)){
+            return;
+        }
+        Set<Integer> tenantIds = endExams.stream().map(e->Integer.valueOf(e.getTenantId())).collect(Collectors.toSet());
+        List<TenantInfo> tenants = tenantInfoDao.getTenants(new ArrayList<>(tenantIds));
+        Map<Integer, TenantInfo> idTenantMap = tenants.stream().collect(Collectors.toMap(TenantInfo::getId, e -> e));
+
+        for (ExaminationBasic endExam : endExams) {
+            TenantInfo tenantInfo = idTenantMap.get(Integer.valueOf(endExam.getTenantId()));
+            Map<Integer, String> userPhoneMap = new HashMap<>();
+            userPhoneMap.put(tenantInfo.getId(), tenantInfo.getContactPhone());
+
+            sysMessageService.batchSendMessage(MessageTypeEnum.EXAM_END_REMIND,
+                    userPhoneMap, null, 0, null, YimeiSmsPlugin.PLUGIN_NAME,
+                    tenantInfo.getName(), endExam.getName());
+        }
+    }
+
+    @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateExamBasicStatus(Long examId, ExamStatusEnum statusEnum, Integer operatorId) {
         if(Objects.isNull(examId)){

+ 5 - 0
edu-user/edu-user-server/src/main/resources/config/mybatis/ExaminationBasicMapper.xml

@@ -254,7 +254,12 @@
 			#{examId}
 		</foreach>
 	</select>
+
     <select id="lockExam" resultMap="ExaminationBasic">
 		SELECT id_,name_ FROM examination_basic WHERE id_=#{examId}
 	</select>
+
+    <select id="getEndExamsWithDayAndStatus" resultMap="ExaminationBasic">
+		SELECT * FROM examination_basic WHERE DATE_FORMAT(actual_exam_end_time_, '%Y-%m-%d') = #{day}
+	</select>
 </mapper>

+ 7 - 0
edu-user/edu-user-server/src/main/resources/config/mybatis/TenantInfoMapper.xml

@@ -129,4 +129,11 @@
 		WHERE
 			o.id_=#{organId}
 	</select>
+
+    <select id="getTenants" resultMap="TenantInfo">
+		SELECT * FROM tenant_info WHERE id_ IN
+		<foreach collection="ids" item="id" separator="," open="(" close=")">
+			#{id}
+		</foreach>
+	</select>
 </mapper>