|
|
@ -59,6 +59,9 @@ public class TopicService implements ITopicService{ |
|
|
|
topicInfo.setAnswers(answers); |
|
|
|
topicInfo.setPrev(topicInfo.getSequence() == sequence.getMin() ? (byte)0 : 1); |
|
|
|
topicInfo.setNext(topicInfo.getSequence() == sequence.getMax() ? (byte)0 : 1); |
|
|
|
if(topicInfo.getTopicType() == 2){ |
|
|
|
topicInfo.setAnswersTrue("T".equalsIgnoreCase(topicInfo.getAnswersTrue()) ? "正确" : "错误"); |
|
|
|
} |
|
|
|
return topicInfo; |
|
|
|
} |
|
|
|
|
|
|
@ -172,31 +175,37 @@ public class TopicService implements ITopicService{ |
|
|
|
//锁
|
|
|
|
synchronized (this){ |
|
|
|
log.info("抢答:{}", group); |
|
|
|
//查询分组的信息
|
|
|
|
MtGroup mtGroup = mtGroupMapper.selectByPrimaryKey(group.getGroupId()); |
|
|
|
if(ObjectUtil.isNull(mtGroup)){ |
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
|
//在redis中查找当前项目下开始抢答的题
|
|
|
|
Object o = redisUtil.get(group.getProjectId()+ Constant.Redis.START_QUESTION); |
|
|
|
Object o = redisUtil.get(mtGroup.getProjectId()+ Constant.Redis.START_QUESTION); |
|
|
|
log.info("题目缓存:{}", o); |
|
|
|
if (o == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
//在redis中查找之前有没有人抢答
|
|
|
|
Object a = redisUtil.get(group.getProjectId() + Constant.Redis.RESPONDER + o); |
|
|
|
Object a = redisUtil.get(mtGroup.getProjectId() + Constant.Redis.RESPONDER + o); |
|
|
|
if (a != null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
//储存数据库
|
|
|
|
long l = topicDao.countVote(group.getProjectId(), (int) o); |
|
|
|
long l = topicDao.countVote(mtGroup.getProjectId(), (int) o); |
|
|
|
log.info("数据库抢答数:{}", l); |
|
|
|
if (l > 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//将自己抢答的信息存进redis
|
|
|
|
redisUtil.set(group.getProjectId() + Constant.Redis.RESPONDER + o,group.getGroupId(),Constant.Redis.TIME_OUT); |
|
|
|
redisUtil.set(mtGroup.getProjectId() + Constant.Redis.RESPONDER + o,group.getGroupId(),Constant.Redis.TIME_OUT); |
|
|
|
|
|
|
|
MtResponder mtResponder = new MtResponder(); |
|
|
|
mtResponder.setId(snowflake.nextId()); |
|
|
|
mtResponder.setGroupId(group.getGroupId()); |
|
|
|
mtResponder.setTopicId((long)(int)o); |
|
|
|
mtResponder.setResponderTime(System.currentTimeMillis()); |
|
|
|
mtResponderMapper.insertSelective(mtResponder); |
|
|
|
} |
|
|
|
} |
|
|
|