Browse Source

0814_v3.1

master
zy_Java 5 years ago
parent
commit
4cb69527af
  1. 3
      mt/src/main/java/com/ccsens/mt/bean/dto/TopicDto.java
  2. 2
      mt/src/main/java/com/ccsens/mt/bean/vo/TopicVo.java
  3. 17
      mt/src/main/java/com/ccsens/mt/service/TopicService.java
  4. 4
      mt/src/main/resources/application.yml
  5. 2
      mt/src/main/resources/mapper_dao/TopicDao.xml
  6. 4
      util/src/test/java/com/ccsens/util/TestQrCord.java

3
mt/src/main/java/com/ccsens/mt/bean/dto/TopicDto.java

@ -97,9 +97,6 @@ public class TopicDto {
@Data
@ApiModel("分组id")
public static class Group{
@NotNull
@ApiModelProperty("项目ID")
private Long projectId;
@NotNull
@ApiModelProperty("分组id")
private Long groupId;

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

@ -26,6 +26,8 @@ public class TopicVo {
private String answersTrue;
@ApiModelProperty("题号")
private int sequence;
@ApiModelProperty("题目类型")
private int topicType;
@ApiModelProperty("有无上一个:0:无 1:有")
private Byte prev;
@ApiModelProperty("有无下一个:0:无 1:有")

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

@ -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);
}
}

4
mt/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: dev
include: common, util-dev
active: test
include: common, util-test

2
mt/src/main/resources/mapper_dao/TopicDao.xml

@ -7,6 +7,7 @@
<result column="description" property="description"/>
<result column="answersTrue" property="answersTrue"/>
<result column="sequence" property="sequence"/>
<result column="topicType" property="topicType"/>
<collection property="options" ofType="String">
<id column="options"/>
</collection>
@ -28,6 +29,7 @@
t.description as description,
t.answers as answersTrue,
t.sequence,
t.topic_type as topicType,
if(o.`option` is null,'' , concat(o.`option` ,':' ,o.contant)) as options
FROM
t_mt_topic t LEFT JOIN t_mt_topic_option o on t.id = o.topic_id

4
util/src/test/java/com/ccsens/util/TestQrCord.java

@ -16,10 +16,10 @@ public class TestQrCord {
*
* @throws Exception
*/
// @Test
@Test
public void test01() throws Exception {
String fileName = "zzz/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
ByteArrayOutputStream stream = QRCode.from("112233").to(ImageType.BMP).withSize(1000, 1000).stream();
ByteArrayOutputStream stream = QRCode.from("https://www.tall.wiki/respond?groupId=1").to(ImageType.BMP).withSize(1000, 1000).stream();
byte[] codeByte = stream.toByteArray();
File file = new File(WebConstant.UPLOAD_PATH_BASE + "/", fileName);
if (!file.getParentFile().exists()) {

Loading…
Cancel
Save