Browse Source

抢答

master
zhizhi wu 5 years ago
parent
commit
d0b8392f9f
  1. 3
      mt/src/main/java/com/ccsens/mt/bean/vo/TopicVo.java
  2. 26
      mt/src/main/java/com/ccsens/mt/service/TopicService.java

3
mt/src/main/java/com/ccsens/mt/bean/vo/TopicVo.java

@ -42,7 +42,8 @@ public class TopicVo {
@ApiModelProperty("最大题号")
private Integer max ;
}
@Data
@ApiModel("答题记录")
public static class Answer{
@ApiModelProperty("分组ID")
private Long groupId;

26
mt/src/main/java/com/ccsens/mt/service/TopicService.java

@ -83,6 +83,19 @@ public class TopicService implements ITopicService{
if(ObjectUtil.isNull(group)){
throw new BaseException(CodeEnum.NOT_GROUP);
}
//查找该组这道题之前的提交记录,有则删除重新添加
int groupTopicScore = 0;
MtGroupTopicExample groupTopicExample = new MtGroupTopicExample();
groupTopicExample.createCriteria().andTopicIdEqualTo(saveAnswers.getTopicId())
.andGroupIdEqualTo(saveAnswersGroup.getGroupId());
List<MtGroupTopic> mtGroupTopicList = groupTopicDao.selectByExample(groupTopicExample);
if(CollectionUtil.isNotEmpty(mtGroupTopicList)){
for(MtGroupTopic groupTopic:mtGroupTopicList){
groupTopicScore += groupTopic.getScore();
groupTopic.setRecStatus((byte) 2);
groupTopicDao.updateByPrimaryKeySelective(groupTopic);
}
}
//添加分组答题的信息
MtGroupTopic groupTopic = new MtGroupTopic();
groupTopic.setId(snowflake.nextId());
@ -100,7 +113,7 @@ public class TopicService implements ITopicService{
groupTopic.setScore(score);
groupTopicDao.insertSelective(groupTopic);
//修改分组的分数
group.setScore(group.getScore() + score);
group.setScore(group.getScore() + score - groupTopicScore);
groupDao.updateByPrimaryKeySelective(group);
});
}
@ -171,14 +184,19 @@ public class TopicService implements ITopicService{
return;
}
//储存数据库
long count = topicDao.countVote(group.getProjectId(), (long)(int)o);
long l = topicDao.countVote(group.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);
MtResponder mtResponder = new MtResponder();
mtResponder.setId(snowflake.nextId());
mtResponder.setGroupId(group.getGroupId());
mtResponder.setTopicId((long)o);
mtResponder.setTopicId((long)(int)o);
mtResponderMapper.insertSelective(mtResponder);
}
}
@ -189,7 +207,7 @@ public class TopicService implements ITopicService{
Object o = redisUtil.get(topic.getProjectId() + Constant.Redis.RESPONDER + topic.getTopicId());
log.info("缓存:{}", o);
if (o!=null) {
MtGroup mtGroup = mtGroupMapper.selectByPrimaryKey((Long) o);
MtGroup mtGroup = mtGroupMapper.selectByPrimaryKey((long)(int)o);
if (mtGroup == null) {
throw new BaseException(CodeEnum.PARAM_ERROR);
}

Loading…
Cancel
Save