|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package com.msdw.tms.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
@ -409,37 +410,32 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt |
|
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(evaluationRules, evaluation); |
|
|
|
|
|
|
|
|
|
//TODO 处理时长,获取当前登录用户id,将用户剩余的时长实时计算,存在Redis中
|
|
|
|
|
//时长转成秒来计算
|
|
|
|
|
//先查询该用户有没有开始考试,既redis中有没有跟该用户id相关联的key
|
|
|
|
|
//如果没有,表示是开始测评,向redis中插入一条数据,key是前缀加用户id,value是当前时间,过期时间是测评时长加三十秒
|
|
|
|
|
//如果有,则得到value,既开始测评的时间,用当前时间和开始测评时间做差,测评时长减去该差值
|
|
|
|
|
//TODO 提交测评时删除redis中的该条数据
|
|
|
|
|
//得到总时长
|
|
|
|
|
//得到总时长,单位:分
|
|
|
|
|
Integer duration = evaluation.getDuration(); |
|
|
|
|
|
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
|
|
|
|
|
|
String key = REMAINING_TINE_KEY + userId; |
|
|
|
|
|
|
|
|
|
String startTime = ops.get(key); |
|
|
|
|
int remainingTime = duration; |
|
|
|
|
// 剩余时间,单位:秒
|
|
|
|
|
int remainingTime = duration * 60; |
|
|
|
|
if (StringUtils.isEmpty(startTime)) { |
|
|
|
|
//如果没有,表示是开始测评,向redis中插入一条数据,key是前缀加用户id,value是当前时间,过期时间是测评时长加十秒
|
|
|
|
|
ops.set(key, getSecondTimestamp(new Date()) + "", duration * 60 + 10, TimeUnit.SECONDS); |
|
|
|
|
|
|
|
|
|
ops.set(key, String.valueOf(System.currentTimeMillis()), duration * 60 + 10, TimeUnit.SECONDS); |
|
|
|
|
} else { |
|
|
|
|
int difference = getSecondTimestamp(new Date()) - Integer.valueOf(startTime); |
|
|
|
|
remainingTime = duration - difference; |
|
|
|
|
// 当前时间与开始时间得时间差,单位:毫秒
|
|
|
|
|
long difference = System.currentTimeMillis() - Long.parseLong(startTime); |
|
|
|
|
remainingTime = (duration * 60) - (new Long(difference).intValue() / 1000); |
|
|
|
|
if (remainingTime < 0) { |
|
|
|
|
ExceptionCast.cast(CommonCode.EVALUATION_TIME_INVALID); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
evaluation.setRemainingDuration(formatDateTime(remainingTime)); |
|
|
|
|
|
|
|
|
|
evaluation.setRemainingDuration(DateUtil.secondToTime(remainingTime)); |
|
|
|
|
//搜集随机抽取的试题
|
|
|
|
|
Set<QuestionsVO> set = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
//根据测评规则的类型不同
|
|
|
|
|
Integer evaluationType = evaluationRules.getEvaluationType(); |
|
|
|
|
if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机
|
|
|
|
@ -455,7 +451,6 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt |
|
|
|
|
int multipleNum = 0; |
|
|
|
|
// 判断题数量
|
|
|
|
|
int judgmentNum = 0; |
|
|
|
|
|
|
|
|
|
//判断各条目的题型是否启用
|
|
|
|
|
if (evaluationRules.getIsSingleEnable().equals(Constant.IsEnable.ENABLE.getType())) { |
|
|
|
|
singleNum = evaluationRules.getSingleNum(); |
|
|
|
@ -486,32 +481,6 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt |
|
|
|
|
return evaluation; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private int getSecondTimestamp(Date date) { |
|
|
|
|
if (null == date) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
String timestamp = String.valueOf(date.getTime() / 1000 / 60); |
|
|
|
|
return Integer.valueOf(timestamp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String formatDateTime(long mss) { |
|
|
|
|
String DateTimes; |
|
|
|
|
long hours = (mss % (60 * 24)) / (60); |
|
|
|
|
long minutes = (mss % (60)); |
|
|
|
|
//long seconds = mss % 60;
|
|
|
|
|
if (hours > 0) { |
|
|
|
|
if (hours < 10) { |
|
|
|
|
DateTimes = "0" + hours + ":" + minutes; |
|
|
|
|
} else { |
|
|
|
|
DateTimes = hours + ":" + minutes; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
DateTimes = "00:" + minutes; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return DateTimes; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void exportQuestion(HttpServletResponse response) throws Exception { |
|
|
|
|
// 请求包装类
|
|
|
|
|