| 
					
					
						
							
						
					
					
				 | 
				@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSONArray; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.alibaba.fastjson.JSONObject; | 
				 | 
				 | 
				import com.alibaba.fastjson.JSONObject; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.dao.ActivityDAO; | 
				 | 
				 | 
				import com.votesystem.ssl.dao.ActivityDAO; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.dao.CandidateDAO; | 
				 | 
				 | 
				import com.votesystem.ssl.dao.CandidateDAO; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				import com.votesystem.ssl.dao.UserDAO; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.dao.VoteRecordDAO; | 
				 | 
				 | 
				import com.votesystem.ssl.dao.VoteRecordDAO; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.pojo.Activity; | 
				 | 
				 | 
				import com.votesystem.ssl.pojo.Activity; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.pojo.Candidate; | 
				 | 
				 | 
				import com.votesystem.ssl.pojo.Candidate; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				import com.votesystem.ssl.pojo.User; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.pojo.VoteRecord; | 
				 | 
				 | 
				import com.votesystem.ssl.pojo.VoteRecord; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.utils.Constants; | 
				 | 
				 | 
				import com.votesystem.ssl.utils.Constants; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.utils.RedisUtils; | 
				 | 
				 | 
				import com.votesystem.ssl.utils.RedisUtils; | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -20,10 +22,9 @@ import com.votesystem.ssl.service.IVoteRecordService; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.utils.IdWorker; | 
				 | 
				 | 
				import com.votesystem.ssl.utils.IdWorker; | 
			
		
		
	
		
			
				 | 
				 | 
				import com.votesystem.ssl.utils.TextUtils; | 
				 | 
				 | 
				import com.votesystem.ssl.utils.TextUtils; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				import javax.servlet.http.HttpServletRequest; | 
			
		
		
	
		
			
				 | 
				 | 
				import javax.transaction.Transactional; | 
				 | 
				 | 
				import javax.transaction.Transactional; | 
			
		
		
	
		
			
				 | 
				 | 
				import java.util.Date; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				import java.util.List; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				import java.util.Map; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				import java.util.*; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				@Slf4j | 
				 | 
				 | 
				@Slf4j | 
			
		
		
	
		
			
				 | 
				 | 
				@Service | 
				 | 
				 | 
				@Service | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -50,13 +51,49 @@ public class VoteRecordServiceImpl implements IVoteRecordService { | 
			
		
		
	
		
			
				 | 
				 | 
				    @Autowired | 
				 | 
				 | 
				    @Autowired | 
			
		
		
	
		
			
				 | 
				 | 
				    RedisUtils redisUtils; | 
				 | 
				 | 
				    RedisUtils redisUtils; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    @Autowired | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    UserDAO userDAO; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    private boolean isInIpRestrictAddress(VoteRecord voteRecord,String ipAddress,long time){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        Map<String,Object> aidMap = (Map<String, Object>) redisUtils.get(ipAddress); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//        Map<String,Object> ipMap = (Map<String, Object>) redisUtils.get(ipAddress);
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        if (aidMap == null){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            aidMap = new HashMap<>(); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//        User user = userDAO.findOneById(voteRecord.getUid()); //获取用户
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        if (aidMap.containsKey(voteRecord.getAid())){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            return true; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } else { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            aidMap.put(voteRecord.getAid(),ipAddress); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            redisUtils.set(ipAddress,aidMap,time); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        return false; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    private boolean isInIpRestrictAddress(String aid,String ipAddress,long time){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        Map<String,Object> aidMap = (Map<String, Object>) redisUtils.get(ipAddress); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//        Map<String,Object> ipMap = (Map<String, Object>) redisUtils.get(ipAddress);
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        if (aidMap == null){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            aidMap = new HashMap<>(); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//        User user = userDAO.findOneById(voteRecord.getUid()); //获取用户
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        if (aidMap.containsKey(aid)){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            return true; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } else { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            aidMap.put(aid,ipAddress); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            redisUtils.set(ipAddress,aidMap,time); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        return false; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				    /** | 
				 | 
				 | 
				    /** | 
			
		
		
	
		
			
				 | 
				 | 
				     * 单选 | 
				 | 
				 | 
				     * 单选 | 
			
		
		
	
		
			
				 | 
				 | 
				     * @param voteRecord | 
				 | 
				 | 
				     * @param voteRecord | 
			
		
		
	
		
			
				 | 
				 | 
				     * @return | 
				 | 
				 | 
				     * @return | 
			
		
		
	
		
			
				 | 
				 | 
				     */ | 
				 | 
				 | 
				     */ | 
			
		
		
	
		
			
				 | 
				 | 
				    @Override | 
				 | 
				 | 
				    @Override | 
			
		
		
	
		
			
				 | 
				 | 
				    public Result singleVote(String captcha, String captchaKey, VoteRecord voteRecord) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    public Result singleVote(String captcha, String captchaKey, VoteRecord voteRecord, HttpServletRequest request) { | 
			
		
		
	
		
			
				 | 
				 | 
				        //1.根据aid 获取活动 ===》 根据活动获取类型
 | 
				 | 
				 | 
				        //1.根据aid 获取活动 ===》 根据活动获取类型
 | 
			
		
		
	
		
			
				 | 
				 | 
				        Activity activity = activityDAO.findOneById(voteRecord.getAid());//获取活动
 | 
				 | 
				 | 
				        Activity activity = activityDAO.findOneById(voteRecord.getAid());//获取活动
 | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -83,6 +120,15 @@ public class VoteRecordServiceImpl implements IVoteRecordService { | 
			
		
		
	
		
			
				 | 
				 | 
				                redisUtils.del(Constants.User.KEY_CAPTCHA_CONTENT + captchaKey); | 
				 | 
				 | 
				                redisUtils.del(Constants.User.KEY_CAPTCHA_CONTENT + captchaKey); | 
			
		
		
	
		
			
				 | 
				 | 
				            } | 
				 | 
				 | 
				            } | 
			
		
		
	
		
			
				 | 
				 | 
				        } | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        // ip验证
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        if(activity.isIpRestrict()||true){ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            if(isInIpRestrictAddress( | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				                    voteRecord.getAid(), | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				                    request.getRemoteAddr(), | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				                    24*60*60)) { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				                return ResultFactory.buildFailResult("该IP已投过票"); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				        //4.如果是非周期性投票
 | 
				 | 
				 | 
				        //4.如果是非周期性投票
 | 
			
		
		
	
		
			
				 | 
				 | 
				        if(typeMap.get("cycleType").equals("false")){ | 
				 | 
				 | 
				        if(typeMap.get("cycleType").equals("false")){ | 
			
		
		
	
		
			
				 | 
				 | 
				            int userTotalVotes = voteRecordDAO.countByAidAndUid(activity.getId(),voteRecord.getUid()); | 
				 | 
				 | 
				            int userTotalVotes = voteRecordDAO.countByAidAndUid(activity.getId(),voteRecord.getUid()); | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -126,7 +172,7 @@ public class VoteRecordServiceImpl implements IVoteRecordService { | 
			
		
		
	
		
			
				 | 
				 | 
				    } | 
				 | 
				 | 
				    } | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				    @Override | 
				 | 
				 | 
				    @Override | 
			
		
		
	
		
			
				 | 
				 | 
				    public Result multipleVote(String captcha,String captchaKey,JSONObject voteData) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				    public Result multipleVote(String captcha,String captchaKey,JSONObject voteData ,HttpServletRequest request) { | 
			
		
		
	
		
			
				 | 
				 | 
				        log.info("voteData ==== > ",voteData); | 
				 | 
				 | 
				        log.info("voteData ==== > ",voteData); | 
			
		
		
	
		
			
				 | 
				 | 
				        JSONObject jsonObject = voteData.getJSONObject("voteData"); | 
				 | 
				 | 
				        JSONObject jsonObject = voteData.getJSONObject("voteData"); | 
			
		
		
	
		
			
				 | 
				 | 
				        //根据活动id 获取活动
 | 
				 | 
				 | 
				        //根据活动id 获取活动
 | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -157,6 +203,15 @@ public class VoteRecordServiceImpl implements IVoteRecordService { | 
			
		
		
	
		
			
				 | 
				 | 
				                redisUtils.del(Constants.User.KEY_CAPTCHA_CONTENT + captchaKey); | 
				 | 
				 | 
				                redisUtils.del(Constants.User.KEY_CAPTCHA_CONTENT + captchaKey); | 
			
		
		
	
		
			
				 | 
				 | 
				            } | 
				 | 
				 | 
				            } | 
			
		
		
	
		
			
				 | 
				 | 
				        } | 
				 | 
				 | 
				        } | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//         ip验证
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//        if(activity.isIpRestrict()){
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//            if(isInIpRestrictAddress(
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//                    aid,
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//                    request.getRemoteAddr(),
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//                    24*60*60)) {
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//                return ResultFactory.buildFailResult("该IP已投过票");
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//            }
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				//        }
 | 
			
		
		
	
		
			
				 | 
				 | 
				        //判断是否是周期性投票
 | 
				 | 
				 | 
				        //判断是否是周期性投票
 | 
			
		
		
	
		
			
				 | 
				 | 
				        //1.非周期性投票
 | 
				 | 
				 | 
				        //1.非周期性投票
 | 
			
		
		
	
		
			
				 | 
				 | 
				        if(typeMap.get("cycleType").equals("false")){ | 
				 | 
				 | 
				        if(typeMap.get("cycleType").equals("false")){ | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
					
				 | 
				
  |