| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -20,11 +20,15 @@ package com.epmet.redis; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import cn.hutool.core.bean.BeanUtil; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.constant.NumConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.RedisUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.ConvertUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.Result; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.constant.IssueConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dao.IssueVoteDetailDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dao.IssueVoteStatisticalDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.IssueDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.IssueVoteStatisticalDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.CommonGridIdFormDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.SelectIssueVotingDetailFormDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.VoteRedisFormDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.feign.ResiGroupFeignClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.service.IssueService; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -45,6 +49,7 @@ import java.util.Map; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.Set; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.stream.Collectors; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import static com.epmet.commons.tools.redis.RedisUtils.DEFAULT_EXPIRE; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import static com.epmet.commons.tools.redis.RedisUtils.NOT_EXPIRE; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/** | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -75,6 +80,9 @@ public class IssueVoteDetailRedis { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private IssueVoteDetailDao issueVoteDetailDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private IssueVoteStatisticalDao issueVoteStatisticalDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void delete(Object[] ids) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -103,7 +111,7 @@ public class IssueVoteDetailRedis { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String key = IssueConstant.REDIS_KEY +vote.getIssueId(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //bean to map
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Map<String, Object> map = BeanUtil.beanToMap(vote, false, true); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        redisUtils.hMSet(key, map,NOT_EXPIRE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        redisUtils.hMSet(key, map,DEFAULT_EXPIRE * 3); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public VoteRedisFormDTO get(String issueId){ | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -202,41 +210,69 @@ public class IssueVoteDetailRedis { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @Description 根据issueId去缓存取表决统计数据,如果没有去数据库查询并放入缓存 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @Description 根据issueId直接获取缓存,获取到直接返回 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     *              缓存不存在,根据issue状态做不同处理 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     *              表决中:应表决数,支持数,反对数 重新计算 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     *              关闭、转项目:直接从表决统计表中查询 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param  issueId | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @return | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @author wangc | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @date 2020.05.21 22:31 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    **/ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//    public VoteRedisFormDTO getVoteStatistical(String issueId){
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        String key = new StringBuilder(IssueConstant.REDIS_KEY).append(issueId).toString();
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        Map<String, Object> stringObjectMap = redisUtils.hGetAll(key);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        if ( null != stringObjectMap && stringObjectMap.size() > NumConstant.ZERO ){
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//            return mapToEntity(stringObjectMap, VoteRedisFormDTO.class);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        }
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        //如果缓存中没有,去表决详情中计算出实时数据,并放入缓存中
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        //无需查询issue_vote_statistical中的数据,因为不是实时数据,可能不准确,有定时任务会自动同步
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        VoteRedisFormDTO voteCache = issueVoteDetailDao.selectInfo4Cache(issueId);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//        if(StringUtils.isBlank(voteCache.getIssueId())) voteCache.setIssueId(issueId);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//            IssueDTO issue = issueService.get(issueId);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//            if(null != issue){
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                CommonGridIdFormDTO gridId = new CommonGridIdFormDTO();
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                gridId.setGridId(issue.getGridId());
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                Result<Integer> votableCount =
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                        resiGroupFeignClient.votableCount(gridId);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                if(votableCount.success() && null != votableCount.getData()){
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                    voteCache.setShouldVoteCount(votableCount.getData());
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                }else{
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                    voteCache.setShouldVoteCount(NumConstant.ZERO);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                }
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                set(voteCache);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                return voteCache;
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//            }else{
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                logger.warn(String.format(ModuleConstants.ISSUE_NOT_FOUND_EXCEPTION_TEMPLATE,issueId));
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//                return null;
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//            }
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//    }
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public VoteRedisFormDTO getVoteStatistical(String issueId){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String key = new StringBuilder(IssueConstant.REDIS_KEY).append(issueId).toString(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Map<String, Object> stringObjectMap = redisUtils.hGetAll(key); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if ( null != stringObjectMap && stringObjectMap.size() > NumConstant.ZERO ){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            return mapToEntity(stringObjectMap, VoteRedisFormDTO.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //如果缓存中没有,去表决详情中计算出实时数据,并放入缓存中
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //无需查询issue_vote_statistical中的数据,因为不是实时数据,可能不准确,有定时任务会自动同步
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        VoteRedisFormDTO voteCache = issueVoteDetailDao.selectInfo4Cache(issueId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if(StringUtils.isBlank(voteCache.getIssueId())) voteCache.setIssueId(issueId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            IssueDTO issue = issueService.get(issueId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if(null != issue){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                CommonGridIdFormDTO gridId = new CommonGridIdFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                gridId.setGridId(issue.getGridId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                Result<Integer> votableCount = | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        resiGroupFeignClient.votableCount(gridId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if(votableCount.success() && null != votableCount.getData()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    voteCache.setShouldVoteCount(votableCount.getData()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                }else{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    voteCache.setShouldVoteCount(NumConstant.ZERO); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                set(voteCache); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                return voteCache; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }else{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                logger.warn(String.format(ModuleConstants.ISSUE_NOT_FOUND_EXCEPTION_TEMPLATE,issueId)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                return null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        IssueDTO issue = issueService.get(issueId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if(null != issue){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // 如果是表决中的议题,数据现算
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            VoteRedisFormDTO voteCache = new VoteRedisFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (issue.getIssueStatus().equals(IssueConstant.ISSUE_VOTING)){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                SelectIssueVotingDetailFormDTO formDTO = new SelectIssueVotingDetailFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                formDTO.setIssueId(issueId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                formDTO.setGridId(issue.getGridId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                voteCache = issueVoteDetailService.selectIssueVotingDetail(formDTO); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // 状态是关闭,转议题的,直接从结果表查询
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                voteCache = issueVoteStatisticalDao.selectVoteDetail(issueId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            set(voteCache); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            return voteCache; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        }else{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.warn(String.format(ModuleConstants.ISSUE_NOT_FOUND_EXCEPTION_TEMPLATE,issueId)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            return null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @Description 修改缓存中某个属性 - hash | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param issueId | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |