|
|
@ -1,11 +1,20 @@ |
|
|
|
package com.ccsens.mt.service; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.ccsens.mt.bean.dto.TopicDto; |
|
|
|
import com.ccsens.mt.bean.po.MtGroup; |
|
|
|
import com.ccsens.mt.bean.po.MtGroupTopic; |
|
|
|
import com.ccsens.mt.bean.po.MtTopic; |
|
|
|
import com.ccsens.mt.bean.vo.TopicVo; |
|
|
|
import com.ccsens.mt.persist.dao.TopicDao; |
|
|
|
import com.ccsens.mt.persist.dao.GroupDao; |
|
|
|
import com.ccsens.mt.persist.dao.GroupTopicDao; |
|
|
|
import com.ccsens.mt.persist.dao.TopicDao; |
|
|
|
import com.ccsens.mt.util.Constant; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.RedisUtil; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
@ -21,11 +30,14 @@ public class TopicService implements ITopicService{ |
|
|
|
|
|
|
|
@Resource |
|
|
|
private TopicDao topicDao; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private RedisUtil redisUtil; |
|
|
|
@Resource |
|
|
|
private GroupDao groupDao; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
@Resource |
|
|
|
private GroupTopicDao groupTopicDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public TopicVo.TopicInfo getTopicByLink(TopicDto.GetTopic getTopic) { |
|
|
@ -35,12 +47,46 @@ public class TopicService implements ITopicService{ |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TopicVo.GroupInfo> queryGroupByProject(TopicDto.GetGroup getGroup) { |
|
|
|
return null; |
|
|
|
log.info("查询分组:{}",getGroup.toString()); |
|
|
|
return topicDao.queryGroupByProject(getGroup.getProjectId(),getGroup.getLinkType(),getGroup.getType()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveAnswers(TopicDto.SaveAnswers saveAnswers) { |
|
|
|
|
|
|
|
log.info("主持人提交分数:{}",saveAnswers.toString()); |
|
|
|
//查询题目
|
|
|
|
MtTopic topic = topicDao.selectByPrimaryKey(saveAnswers.getTopicId()); |
|
|
|
if(ObjectUtil.isNull(topic)){ |
|
|
|
throw new BaseException(CodeEnum.NOT_TOPIC); |
|
|
|
} |
|
|
|
//循环遍历提交的分组
|
|
|
|
if(CollectionUtil.isNotEmpty(saveAnswers.getAnswersGroupList())){ |
|
|
|
saveAnswers.getAnswersGroupList().forEach(saveAnswersGroup ->{ |
|
|
|
MtGroup group = groupDao.selectByPrimaryKey(saveAnswersGroup.getGroupId()); |
|
|
|
if(ObjectUtil.isNull(group)){ |
|
|
|
throw new BaseException(CodeEnum.NOT_GROUP); |
|
|
|
} |
|
|
|
//添加分组答题的信息
|
|
|
|
MtGroupTopic groupTopic = new MtGroupTopic(); |
|
|
|
groupTopic.setId(snowflake.nextId()); |
|
|
|
groupTopic.setTopicId(saveAnswers.getTopicId()); |
|
|
|
groupTopic.setGroupId(saveAnswersGroup.getGroupId()); |
|
|
|
groupTopic.setAnswers(saveAnswersGroup.getAnswers()); |
|
|
|
int score = 0; |
|
|
|
if("T".equalsIgnoreCase(saveAnswersGroup.getAnswers())){ |
|
|
|
score = topic.getScore(); |
|
|
|
}else { |
|
|
|
if(topic.getScoreRule() == 1){ |
|
|
|
score = -topic.getScore(); |
|
|
|
} |
|
|
|
} |
|
|
|
groupTopic.setScore(score); |
|
|
|
groupTopicDao.insertSelective(groupTopic); |
|
|
|
//修改分组的分数
|
|
|
|
group.setScore(group.getScore() + score); |
|
|
|
groupDao.updateByPrimaryKeySelective(group); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|