|
|
@@ -1,6 +1,8 @@
|
|
|
package com.finikes.oc.vote.service;
|
|
|
|
|
|
+import com.finikes.oc.base.entity.Passport;
|
|
|
import com.finikes.oc.vote.LockService;
|
|
|
+import com.finikes.oc.vote.PassportHelper;
|
|
|
import com.finikes.oc.vote.dao.ChoiceDao;
|
|
|
import com.finikes.oc.vote.dao.OptionDao;
|
|
|
import com.finikes.oc.vote.dao.VoteActivityDao;
|
|
|
@@ -220,11 +222,14 @@ public class VoteServiceImpl implements VoteService {
|
|
|
|
|
|
@Override
|
|
|
public void madeChoice(ChoiceDto dto) {
|
|
|
- int voterId = 0;
|
|
|
+ Passport passport = PassportHelper.currentPassport();
|
|
|
+ if (passport == null) {
|
|
|
+ throw new BusinessException("获取登录状态异常");
|
|
|
+ }
|
|
|
// TODO 需要方法获取登录用户信息
|
|
|
|
|
|
// TODO 这里需要锁住 用户ID 防止单个用户的并发调用, 锁住用户具有的房产主键已达到一房一票的需求.
|
|
|
- String resourceId = "vote:" + voterId;
|
|
|
+ String resourceId = "vote:" + passport.getId();
|
|
|
String ownerId = UUID.randomUUID().toString();
|
|
|
boolean locked = lockService.lock(resourceId, ownerId, 60, TimeUnit.SECONDS);
|
|
|
if (!locked) {
|
|
|
@@ -260,7 +265,7 @@ public class VoteServiceImpl implements VoteService {
|
|
|
// TODO 检查此登录人员的房产下的绑定人员是否参与过此抽奖.
|
|
|
|
|
|
Choice choice = new Choice();
|
|
|
- choice.setAssigneeId(voterId);
|
|
|
+ choice.setAssigneeId(passport.getId());
|
|
|
choice.setOptionId(dto.getOptionId());
|
|
|
choice.setProxy(false);
|
|
|
choice.setChooseTime(now);
|
|
|
@@ -270,4 +275,56 @@ public class VoteServiceImpl implements VoteService {
|
|
|
lockService.unlock(resourceId, ownerId);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void madeChoiceDelegation(ChoiceDelegationDto dto) {
|
|
|
+ Passport passport = PassportHelper.currentPassport();
|
|
|
+ if (passport == null) {
|
|
|
+ throw new BusinessException("获取登录状态异常");
|
|
|
+ }
|
|
|
+ String resourceId = "vote:" + passport.getId();
|
|
|
+ String ownerId = UUID.randomUUID().toString();
|
|
|
+ boolean locked = lockService.lock(resourceId, ownerId, 60, TimeUnit.SECONDS);
|
|
|
+ if (!locked) {
|
|
|
+ throw new BusinessException("请稍后再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+
|
|
|
+ Option option = optionDao.selectByPrimaryKey(dto.getOptionId());
|
|
|
+ if (option == null) {
|
|
|
+ throw new BusinessException("参与的投票不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Vote vote = voteDao.selectByPrimaryKey(option.getVoteId());
|
|
|
+ if (vote == null) {
|
|
|
+ throw new BusinessException("参与的投票不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ VoteActivity activity = voteActivityDao.selectByPrimaryKey(vote.getActivityId());
|
|
|
+ if (activity == null) {
|
|
|
+ throw new BusinessException("参与的投票不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (now < activity.getStartTime()) {
|
|
|
+ throw new BusinessException("投票日期未到");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (now > activity.getEndTime()) {
|
|
|
+ throw new BusinessException("投票日期已过");
|
|
|
+ }
|
|
|
+
|
|
|
+ Choice choice = new Choice();
|
|
|
+ choice.setAssigneeId(dto.getPrincipalId());
|
|
|
+ choice.setOptionId(dto.getOptionId());
|
|
|
+ choice.setAssigneeId(passport.getId());
|
|
|
+ choice.setProxy(true);
|
|
|
+ choice.setChooseTime(now);
|
|
|
+
|
|
|
+ choiceDao.insert(choice);
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(resourceId, ownerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|