|
@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.gson.Gson;
|
|
|
-import com.qmth.themis.business.cache.bean.ExamCacheBean;
|
|
|
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
|
|
|
+import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.dto.MqDto;
|
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
|
import com.qmth.themis.business.entity.TEExamActivity;
|
|
|
import com.qmth.themis.business.entity.TMRocketMessage;
|
|
|
+import com.qmth.themis.business.enums.MqTagEnum;
|
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
|
import com.qmth.themis.business.service.TMRocketMessageService;
|
|
|
import com.qmth.themis.business.util.JacksonUtil;
|
|
@@ -17,6 +19,7 @@ import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.task.enums.QuartzTaskEnum;
|
|
|
import com.qmth.themis.task.listener.service.MqTaskLogicService;
|
|
|
import com.qmth.themis.task.quartz.ExamActivityJob;
|
|
|
+import com.qmth.themis.task.quartz.ExamStudentJob;
|
|
|
import com.qmth.themis.task.service.QuartzService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -24,7 +27,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -70,47 +72,68 @@ public class MqTaskLogicServiceImpl implements MqTaskLogicService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void execMqQuartzLogic(MqDto mqDto, String key) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
|
|
|
+ public void execMqQuartzLogic(MqDto mqDto, String key) {
|
|
|
Gson gson = new Gson();
|
|
|
Map<String, Object> tranMap = mqDto.getProperties();
|
|
|
String oper = String.valueOf(tranMap.get("oper"));
|
|
|
Object o = JacksonUtil.parseJson(tranMap.get("exam"));
|
|
|
+ String tag = mqDto.getTag();
|
|
|
TEExam teExam = JSONObject.toJavaObject(JSONObject.parseObject(String.valueOf(o)), TEExam.class);
|
|
|
mqDto.setAck(SystemConstant.STANDARD_ACK_TYPE);
|
|
|
- JSONArray jsonArray = (JSONArray) JSONArray.parse(String.valueOf(mqDto.getBody()));
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- TEExamActivity teExamActivity = JSONObject.toJavaObject((JSON) jsonArray.get(i), TEExamActivity.class);
|
|
|
- ExamCacheBean examCacheBean = teExamService.getExamCacheBean(teExamActivity.getExamId());
|
|
|
- if (Objects.equals("delete", oper)) {
|
|
|
- quartzService.deleteJob(teExamActivity.getCode(), QuartzTaskEnum.EXAM_ACTIVITY_JOB_GROUP_NAME.name());
|
|
|
- } else {
|
|
|
- if (Objects.nonNull(teExam.getEnable()) && teExam.getEnable().intValue() == 1 && Objects.nonNull(teExamActivity.getEnable()) && teExamActivity.getEnable().intValue() == 1) {
|
|
|
- Date finishTime = teExamActivity.getFinishTime();
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(finishTime);
|
|
|
-// calendar.add(Calendar.SECOND, 30);
|
|
|
- if (calendar.getTime().getTime() > System.currentTimeMillis()) {
|
|
|
- int year = calendar.get(Calendar.YEAR);//获取年份
|
|
|
- int month = calendar.get(Calendar.MONTH) + 1;//获取月份
|
|
|
- int day = calendar.get(Calendar.DATE);//获取日
|
|
|
- int hour = calendar.get(Calendar.HOUR_OF_DAY);//小时
|
|
|
- int minute = calendar.get(Calendar.MINUTE);//分
|
|
|
- int second = calendar.get(Calendar.SECOND);//秒
|
|
|
- String cron = second + " " + minute + " " + hour + " " + day + " " + month + " ? " + year;
|
|
|
- log.info("cron:{}", cron);
|
|
|
- String activityCode = teExamActivity.getCode();
|
|
|
- //执行一次性延时任务
|
|
|
- Map mapJob = new HashMap();
|
|
|
- mapJob.put("name", examCacheBean.getId() + "-" + activityCode);
|
|
|
- quartzService.deleteJob(activityCode, QuartzTaskEnum.EXAM_ACTIVITY_JOB_GROUP_NAME.name());
|
|
|
- quartzService.addJob(ExamActivityJob.class, examCacheBean.getId() + "-" + activityCode, QuartzTaskEnum.EXAM_ACTIVITY_JOB_GROUP_NAME.name(), cron, mapJob);
|
|
|
+ if (Objects.equals(tag, MqTagEnum.EXAM_ACTIVITY.name())) {
|
|
|
+ JSONArray jsonArray = (JSONArray) JSONArray.parse(String.valueOf(mqDto.getBody()));
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ TEExamActivity teExamActivity = JSONObject.toJavaObject((JSON) jsonArray.get(i), TEExamActivity.class);
|
|
|
+ if (Objects.equals("delete", oper)) {
|
|
|
+ quartzService.deleteJob(String.valueOf(teExamActivity.getId()), QuartzTaskEnum.EXAM_ACTIVITY_JOB_GROUP_NAME.name());
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(teExam.getEnable()) && teExam.getEnable().intValue() == 1 && Objects.nonNull(teExamActivity.getEnable()) && teExamActivity.getEnable().intValue() == 1) {
|
|
|
+ this.setCron(teExamActivity.getFinishTime(), String.valueOf(teExamActivity.getId()), ExamActivityJob.class, QuartzTaskEnum.EXAM_ACTIVITY_JOB_GROUP_NAME);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } else if (Objects.equals(tag, MqTagEnum.EXAM_STUDENT.name())) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(String.valueOf(mqDto.getBody()));
|
|
|
+ ExamStudentCacheBean examStudentCacheBean = JSONObject.toJavaObject(jsonObject, ExamStudentCacheBean.class);
|
|
|
+ Long recordId = Long.parseLong(String.valueOf(mqDto.getObjId()));
|
|
|
+ if (Objects.equals("delete", oper)) {
|
|
|
+ quartzService.deleteJob(examStudentCacheBean.getId() + "-" + recordId, QuartzTaskEnum.EXAM_STUDENT_JOB_GROUP_NAME.name());
|
|
|
+ } else {
|
|
|
+ this.setCron(ExamRecordCacheUtil.getExamFinalFinishTime(recordId), examStudentCacheBean.getId() + "-" + recordId, ExamStudentJob.class, QuartzTaskEnum.EXAM_STUDENT_JOB_GROUP_NAME);
|
|
|
+ }
|
|
|
}
|
|
|
TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
|
|
|
tmRocketMessage.setBody(JacksonUtil.parseJson(tmRocketMessage.getBody()));
|
|
|
tmRocketMessageService.saveOrUpdate(tmRocketMessage);
|
|
|
redisUtil.delete(key, mqDto.getId());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置quart cron
|
|
|
+ *
|
|
|
+ * @param finishTime
|
|
|
+ * @param jobId
|
|
|
+ * @param cls
|
|
|
+ * @param quartzTaskEnum
|
|
|
+ */
|
|
|
+ public void setCron(Date finishTime, String jobName, Class cls, QuartzTaskEnum quartzTaskEnum) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(finishTime);
|
|
|
+// calendar.add(Calendar.SECOND, 30);
|
|
|
+ if (calendar.getTime().getTime() > System.currentTimeMillis()) {
|
|
|
+ int year = calendar.get(Calendar.YEAR);//获取年份
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1;//获取月份
|
|
|
+ int day = calendar.get(Calendar.DATE);//获取日
|
|
|
+ int hour = calendar.get(Calendar.HOUR_OF_DAY);//小时
|
|
|
+ int minute = calendar.get(Calendar.MINUTE);//分
|
|
|
+ int second = calendar.get(Calendar.SECOND);//秒
|
|
|
+ String cron = second + " " + minute + " " + hour + " " + day + " " + month + " ? " + year;
|
|
|
+ log.info("cron:{}", cron);
|
|
|
+ //执行一次性延时任务
|
|
|
+ Map mapJob = new HashMap();
|
|
|
+ mapJob.put("name", jobName);
|
|
|
+ quartzService.deleteJob(jobName, quartzTaskEnum.name());
|
|
|
+ quartzService.addJob(cls, jobName, quartzTaskEnum.name(), cron, mapJob);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|