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