Browse Source

0815投票前

master
zy_Java 5 years ago
parent
commit
aa1b16fafb
  1. 10
      mt/src/main/java/com/ccsens/mt/api/VoteController.java
  2. 2
      mt/src/main/java/com/ccsens/mt/bean/vo/TopicVo.java
  3. 6
      mt/src/main/java/com/ccsens/mt/service/IVoteService.java
  4. 3
      mt/src/main/java/com/ccsens/mt/service/TopicService.java
  5. 36
      mt/src/main/java/com/ccsens/mt/service/VoteService.java
  6. 12
      mt/src/main/java/com/ccsens/mt/util/Constant.java
  7. 2
      mt/src/main/resources/application-dev.yml
  8. 4
      tall/src/main/resources/application.yml
  9. 7
      util/src/main/java/com/ccsens/util/CodeEnum.java
  10. 11
      util/src/test/java/com/ccsens/util/TestQrCord.java

10
mt/src/main/java/com/ccsens/mt/api/VoteController.java

@ -31,6 +31,16 @@ public class VoteController {
@Resource
private IVoteService voteService;
@MustLogin
@ApiOperation(value = "用户投票", notes = "")
@ApiImplicitParams({
})
@RequestMapping(value = "/start", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse startVote(@RequestBody @ApiParam @Validated QueryDto<TopicDto.Project> params) throws Exception {
log.info("开始投票:{}",params.toString());
voteService.startVote(params);
return JsonResponse.newInstance().ok();
}
@MustLogin
@ApiOperation(value = "用户投票", notes = "")

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

@ -28,6 +28,8 @@ public class TopicVo {
private int sequence;
@ApiModelProperty("题目类型")
private int topicType;
@ApiModelProperty("当前环节一共多少题")
private int totalNum;
@ApiModelProperty("有无上一个:0:无 1:有")
private Byte prev;
@ApiModelProperty("有无下一个:0:无 1:有")

6
mt/src/main/java/com/ccsens/mt/service/IVoteService.java

@ -19,4 +19,10 @@ public interface IVoteService {
* @return
*/
List<VoteVo.GroupInfo> queryVote(TopicDto.Project project);
/**
* 开始投票
* @param params
*/
void startVote(QueryDto<TopicDto.Project> params);
}

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

@ -55,7 +55,8 @@ public class TopicService implements ITopicService{
List<TopicVo.Answer> answers = topicDao.queryAnswer(getTopic.getProjectId(), topicInfo.getTopicId());
// 查询是否有最小最大序号
TopicVo.TopicSequence sequence = topicDao.getMinAndMax(getTopic.getLinkType());
//总题数
topicInfo.setTotalNum(sequence.getMax());
topicInfo.setAnswers(answers);
topicInfo.setPrev(topicInfo.getSequence() == sequence.getMin() ? (byte)0 : 1);
topicInfo.setNext(topicInfo.getSequence() == sequence.getMax() ? (byte)0 : 1);

36
mt/src/main/java/com/ccsens/mt/service/VoteService.java

@ -1,6 +1,7 @@
package com.ccsens.mt.service;
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.MtVote;
@ -9,15 +10,20 @@ import com.ccsens.mt.persist.dao.VoteDao;
import com.ccsens.mt.persist.mapper.MtGroupMapper;
import com.ccsens.mt.util.Constant;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.util.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
@ -30,6 +36,26 @@ public class VoteService implements IVoteService{
private MtGroupMapper mtGroupMapper;
@Resource
private Snowflake snowflake;
@Resource
private RedisUtil redisUtil;
@Override
public void startVote(QueryDto<TopicDto.Project> params) {
TopicDto.Project project = params.getParam();
if(ObjectUtil.isNull(project)){
throw new BaseException(CodeEnum.PARAM_ERROR);
}
redisUtil.set(project.getProjectId()+ Constant.Redis.START_VOTE,1, Constant.Redis.VOTE_TIME);
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(Constant.Redis.VOTE_START,
new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build());
executorService.schedule(new Thread(new Runnable() {
@Override
public void run() {
redisUtil.set(project.getProjectId()+ Constant.Redis.START_VOTE,Constant.Redis.VOTE_COMPLETED, Constant.Redis.VOTE_TIME);
}
}), Constant.Redis.VOTE_TIME_OUT, TimeUnit.MILLISECONDS);
}
@Override
public void saveVote(QueryDto<List<TopicDto.Group>> params) {
@ -56,7 +82,13 @@ public class VoteService implements IVoteService{
}
}
}
// 检查投票时间是否有效
Object o = redisUtil.get(projectId + Constant.Redis.START_VOTE);
if(ObjectUtil.isNull(o)){
throw new BaseException(CodeEnum.VOTE_NOT_START);
}else if((int)o == Constant.Redis.VOTE_COMPLETED){
throw new BaseException(CodeEnum.VOTE_COMPLETED);
}
// 判断是否在当前项目中已投
long count = voteDao.countUserVoteNums(params.getUserId(), projectId);
log.info("{}-{}投票数:{}", params.getUserId(), projectId, count);
@ -70,8 +102,6 @@ public class VoteService implements IVoteService{
mtVote.setUserId(params.getUserId());
voteDao.insertSelective(mtVote);
});
}
@Override

12
mt/src/main/java/com/ccsens/mt/util/Constant.java

@ -9,10 +9,20 @@ public class Constant {
public static class Redis{
// 项目正在进行中的题目 项目ID_start_question
public final static String START_QUESTION = "_start_question";
// 有效期10分钟
// 抢答有效期10分钟
public final static long TIME_OUT = 10 * 60;
// 抢答成功的队伍 项目ID_responder_题目ID
public final static String RESPONDER = "_responder_";
// 开始投票
public final static String START_VOTE = "_start_vote";
// 投票有效期3分钟
public final static long VOTE_TIME_OUT = 3 * 60 * 1000;
// 投票存在时间一天
public final static long VOTE_TIME = 24 * 60 * 60;
//投票未开始
public final static int VOTE_COMPLETED = 2;
//投票已结束
public final static int VOTE_START = 1;
}

2
mt/src/main/resources/application-dev.yml

@ -8,7 +8,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
rabbitmq:
host: api.ccsens.com
host: 81.70.54.64
password: 111111
port: 5672
username: admin

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

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

7
util/src/main/java/com/ccsens/util/CodeEnum.java

@ -133,9 +133,10 @@ public enum CodeEnum {
NOT_ROW(112,"该行不存在",true),
VOTED(113,"对不起,您已经支持过看好的队伍了",true),
NOT_TOPIC(113,"找不到该题目",true),
NOT_GROUP(113,"找不到该组信息",true),
NOT_TOPIC(114,"找不到该题目",true),
NOT_GROUP(115,"找不到该组信息",true),
VOTE_COMPLETED(116,"投票已结束",true),
VOTE_NOT_START(116,"投票未开始",true),
;

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

@ -25,9 +25,12 @@ public class TestQrCord {
*/
@Test
public void test01() throws Exception {
for (int i = 1;i < 11; i++){
String fileName = "zzz/" + DateUtil.today() + "/" + i+"组" + ".png";
String text = "https://test.tall.wiki/pt-dev/respond?groupId="+i+"&groupName="+i+"组";
// for (int i = 1;i < 11; i++){
// String fileName = "zzz/" + DateUtil.today() + "/" + i+"组" + ".png";
// String text = "https://www.tall.wiki/pt-dev/respond?groupId="+i+"&groupName="+i+"组";
String text = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7af1bf1e14facf82&redirect_uri=https://www.tall.wiki/pt-dev/vote&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
String fileName = "zzz/" + DateUtil.today() + "/投票.png";
QRCodeWriter qrCodeWriter = new QRCodeWriter();
@ -40,7 +43,7 @@ public class TestQrCord {
Path path = FileSystems.getDefault().getPath(WebConstant.UPLOAD_PATH_BASE + "/" + fileName);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
}
// }
// String text = "https://test.tall.wiki/respond?groupId=1&groupName=1组";
// String fileName = "zzz/" + DateUtil.today() + "/" + 1+"组" + ".png";
// ByteArrayOutputStream stream = QRCode.from("https://test.tall.wiki/respond?groupId=1&groupName='1组'")

Loading…
Cancel
Save