|
@@ -1,24 +1,5 @@
|
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.cache.annotation.CacheEvict;
|
|
|
-import org.springframework.cache.annotation.CachePut;
|
|
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
@@ -35,6 +16,18 @@ import com.qmth.themis.business.service.TEExamPaperService;
|
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
+import org.springframework.cache.annotation.CachePut;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: 考试试卷 服务实现类
|
|
@@ -45,20 +38,20 @@ import com.qmth.themis.common.exception.BusinessException;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExamPaper> implements TEExamPaperService {
|
|
|
-
|
|
|
- private final static long objectiveAnswerCacheTimeOutHours=48L;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private TEExamService examService;
|
|
|
-
|
|
|
+
|
|
|
+ private final static long objectiveAnswerCacheTimeOutHours = 48L;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TEExamService examService;
|
|
|
+
|
|
|
@Resource
|
|
|
OssUtil ossUtil;
|
|
|
|
|
|
@Resource
|
|
|
TEExamPaperMapper teExamPaperMapper;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
- TEExamActivityMapper examActivityMapper;
|
|
|
+ TEExamActivityMapper examActivityMapper;
|
|
|
|
|
|
@Override
|
|
|
public TEExamPaper findByExamIdAndCourseCodeAndPaperCode(Long examId, String courseCode, String paperCode) {
|
|
@@ -149,20 +142,20 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
|
|
|
ret.setPaperViewPath(ep.getPaperViewPath());
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public void reloadObjectiveAnswerCacheBean(Long paperId,Long timeOutHours) {
|
|
|
+ public void reloadObjectiveAnswerCacheBean(Long paperId, Long timeOutHours) {
|
|
|
ExamPaperCacheBean ep = getExamPaperCacheBean(paperId);
|
|
|
if (ep == null) {
|
|
|
- return ;
|
|
|
+ return;
|
|
|
}
|
|
|
- Long examId=ep.getExamId();
|
|
|
+ Long examId = ep.getExamId();
|
|
|
if (StringUtils.isBlank(ep.getAnswerPath())) {//没有答案文件
|
|
|
- return ;
|
|
|
+ return;
|
|
|
}
|
|
|
try {
|
|
|
String answerjson = new String(ossUtil.download(false, ep.getAnswerPath()), StandardCharsets.UTF_8);
|
|
|
- Map<String, ObjectiveAnswerCacheBean> map=buildObjectiveAnswerCache(answerjson);
|
|
|
+ Map<String, ObjectiveAnswerCacheBean> map = buildObjectiveAnswerCache(answerjson);
|
|
|
ObjectiveAnswerCacheUtil.saveObjectiveAnswerCache(examId, paperId, map);
|
|
|
ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, timeOutHours);
|
|
|
} catch (Exception e) {
|
|
@@ -177,17 +170,17 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
|
|
|
if (ep == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- Long examId=ep.getExamId();
|
|
|
+ Long examId = ep.getExamId();
|
|
|
if (StringUtils.isBlank(ep.getAnswerPath())) {//没有答案文件
|
|
|
return null;
|
|
|
}
|
|
|
- Map<String, ObjectiveAnswerCacheBean> map=ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paperId);
|
|
|
- if(map!=null) {
|
|
|
- return map;
|
|
|
+ Map<String, ObjectiveAnswerCacheBean> map = ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paperId);
|
|
|
+ if (map != null) {
|
|
|
+ return map;
|
|
|
}
|
|
|
try {
|
|
|
String answerjson = new String(ossUtil.download(false, ep.getAnswerPath()), StandardCharsets.UTF_8);
|
|
|
- map=buildObjectiveAnswerCache(answerjson);
|
|
|
+ map = buildObjectiveAnswerCache(answerjson);
|
|
|
ObjectiveAnswerCacheUtil.saveObjectiveAnswerCache(examId, paperId, map);
|
|
|
ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, objectiveAnswerCacheTimeOutHours);
|
|
|
return map;
|
|
@@ -196,7 +189,7 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Map<String, ObjectiveAnswerCacheBean> buildObjectiveAnswerCache(String answerStr) {
|
|
|
Map<String, ObjectiveAnswerCacheBean> map = new HashMap<String, ObjectiveAnswerCacheBean>();
|
|
|
JSONObject answerJson = JSONObject.parseObject(answerStr);
|
|
@@ -265,60 +258,64 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
|
|
|
teExamPaperMapper.updateWeight(id, map.get(id));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**获取缓存过期时间,不满足条件的返回-1.条件:场次最小startTime在当天的,或者当前时间在场次最小startTime和最大finishTime之间的。
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取缓存过期时间,不满足条件的返回-1.条件:场次最小startTime在当天的,或者当前时间在场次最小startTime和最大finishTime之间的。
|
|
|
+ *
|
|
|
* @param examId
|
|
|
* @return
|
|
|
*/
|
|
|
private Long getObjectiveAnswerCacheTimeOut(Long examId) {
|
|
|
- Long objectiveAnswerCacheTimeOut=-1L;
|
|
|
- List<Map<String, Long>> list=examActivityMapper.findMinStartTimeAndMaxFinshTimeByExamId(examId);
|
|
|
- if(list!=null&&list.size()>0) {
|
|
|
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- Date now=new Date();
|
|
|
- Long startTime=list.get(0).get("startTime");
|
|
|
- Long finishTime=list.get(0).get("finishTime");
|
|
|
- Date start=new Date(startTime);
|
|
|
- if(sdf.format(now).equals(sdf.format(start))||(now.getTime()>=startTime&&now.getTime()<=finishTime)) {
|
|
|
- objectiveAnswerCacheTimeOut=(finishTime-now.getTime())/(1000*60*60)+24;
|
|
|
- }
|
|
|
- }
|
|
|
- return objectiveAnswerCacheTimeOut;
|
|
|
+ Long objectiveAnswerCacheTimeOut = -1L;
|
|
|
+ List<Map<String, Long>> list = examActivityMapper.findMinStartTimeAndMaxFinshTimeByExamId(examId);
|
|
|
+ if (list != null && list.size() > 0 && Objects.nonNull(list.get(0))) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date now = new Date();
|
|
|
+ Long startTime = list.get(0).get("startTime");
|
|
|
+ Long finishTime = list.get(0).get("finishTime");
|
|
|
+ Date start = new Date(startTime);
|
|
|
+ if (sdf.format(now).equals(sdf.format(start)) || (now.getTime() >= startTime && now.getTime() <= finishTime)) {
|
|
|
+ objectiveAnswerCacheTimeOut = (finishTime - now.getTime()) / (1000 * 60 * 60) + 24;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objectiveAnswerCacheTimeOut;
|
|
|
}
|
|
|
-
|
|
|
- /**处理考试批次下的客观题答案缓存
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理考试批次下的客观题答案缓存
|
|
|
+ *
|
|
|
* @param examId
|
|
|
*/
|
|
|
@Override
|
|
|
public void disposeObjectiveAnswer(Long examId) {
|
|
|
- Long objectiveAnswerCacheTimeOut=getObjectiveAnswerCacheTimeOut(examId);
|
|
|
- if(objectiveAnswerCacheTimeOut>0) {
|
|
|
- List<TEExamPaper> list=teExamPaperMapper.findByExamId(examId);
|
|
|
- if(list!=null&&list.size()>0) {
|
|
|
- for(TEExamPaper paper:list) {
|
|
|
- if(ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paper.getId())==null) {
|
|
|
- reloadObjectiveAnswerCacheBean(paper.getId(), objectiveAnswerCacheTimeOut);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Long count=ObjectiveAnswerCacheUtil.getHashCacheSize(examId);
|
|
|
- if(count!=null&&count>0) {
|
|
|
- ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, objectiveAnswerCacheTimeOut);
|
|
|
- }
|
|
|
- }
|
|
|
+ Long objectiveAnswerCacheTimeOut = getObjectiveAnswerCacheTimeOut(examId);
|
|
|
+ if (objectiveAnswerCacheTimeOut > 0) {
|
|
|
+ List<TEExamPaper> list = teExamPaperMapper.findByExamId(examId);
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ for (TEExamPaper paper : list) {
|
|
|
+ if (ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paper.getId()) == null) {
|
|
|
+ reloadObjectiveAnswerCacheBean(paper.getId(), objectiveAnswerCacheTimeOut);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long count = ObjectiveAnswerCacheUtil.getHashCacheSize(examId);
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, objectiveAnswerCacheTimeOut);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- *导入试卷时处理缓存
|
|
|
+ * 导入试卷时处理缓存
|
|
|
*/
|
|
|
@Override
|
|
|
- public void disposePaperCacheOnPaperImport(Long examId,List<Long> paperIds) {
|
|
|
+ public void disposePaperCacheOnPaperImport(Long examId, List<Long> paperIds) {
|
|
|
TEExamPaperService examPaperService = SpringContextHolder.getBean(TEExamPaperService.class);
|
|
|
for (Long id : paperIds) {
|
|
|
examPaperService.deleteExamPaperCacheBean(id);
|
|
|
- Long objectiveAnswerCacheTimeOut=getObjectiveAnswerCacheTimeOut(examId);
|
|
|
- if(objectiveAnswerCacheTimeOut>0) {
|
|
|
- examPaperService.reloadObjectiveAnswerCacheBean(id,objectiveAnswerCacheTimeOut);
|
|
|
+ Long objectiveAnswerCacheTimeOut = getObjectiveAnswerCacheTimeOut(examId);
|
|
|
+ if (objectiveAnswerCacheTimeOut > 0) {
|
|
|
+ examPaperService.reloadObjectiveAnswerCacheBean(id, objectiveAnswerCacheTimeOut);
|
|
|
}
|
|
|
examPaperService.deletePaperStructCacheBean(id);
|
|
|
}
|