|
|
@ -268,9 +268,21 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
Set<String> notExistedIds = new HashSet<String>(); |
|
|
|
notExistedIds.addAll(ids); |
|
|
|
notExistedIds.removeAll(statisiticalIds); |
|
|
|
|
|
|
|
Set<String> existedIds = new HashSet<>(); |
|
|
|
existedIds.addAll(ids); |
|
|
|
existedIds.retainAll(statisiticalIds); |
|
|
|
//更新
|
|
|
|
//TODO 对ids进行更新 - 从缓存中拿取
|
|
|
|
//对ids进行更新 - 从缓存中拿取
|
|
|
|
List<IssueVoteStatisticalDTO> listToUpdate = new ArrayList<>(); |
|
|
|
setVotableCountsAndUpdateCache(listToUpdate, |
|
|
|
existedIds.stream().flatMap(existedId -> issues.stream().filter(issue -> |
|
|
|
StringUtils.equals(issue.getId(),existedId)).map(issueDTO -> { |
|
|
|
return issueDTO; |
|
|
|
})).collect(Collectors.toSet()), |
|
|
|
votableCountMap); |
|
|
|
|
|
|
|
//TODO 批量更新listToUpdate
|
|
|
|
|
|
|
|
|
|
|
|
if (notExistedIds.size() > NumConstant.ZERO) { |
|
|
|
//新增
|
|
|
@ -325,7 +337,29 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
.collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
//TODO 批量查找collect的votableCount
|
|
|
|
//批量查找summary的votableCount
|
|
|
|
Map<String,List<IssueDTO>> gridIssueMap = |
|
|
|
issues.stream().collect(Collectors.groupingBy(IssueDTO::getGridId)); |
|
|
|
for(IssueVoteStatisticalDTO vote : summary){ |
|
|
|
for(Map.Entry<String,List<IssueDTO>> entry : gridIssueMap.entrySet()){ |
|
|
|
String k = entry.getKey(); |
|
|
|
List<IssueDTO> v = entry.getValue(); |
|
|
|
if(null == v || v.size() < NumConstant.ONE) continue; |
|
|
|
for(IssueDTO issue : v){ |
|
|
|
if(StringUtils.equals(vote.getIssueId(),issue.getId())) |
|
|
|
vote.setVotableCount( |
|
|
|
null == votableCountMap ? NumConstant.ZERO |
|
|
|
: null == votableCountMap.get(k) ? NumConstant.ZERO : votableCountMap.get(k) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for(Map.Entry<String,List<IssueDTO>> entry : gridIssueMap.entrySet()){ |
|
|
|
String k = entry.getKey(); |
|
|
|
List<IssueDTO> v = entry.getValue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//TODO 批量插入
|
|
|
|
} |
|
|
@ -347,29 +381,9 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
Map<String,List<IssueDTO>> gridIssueMap = |
|
|
|
issues.stream().collect(Collectors.groupingBy(IssueDTO::getGridId)); |
|
|
|
|
|
|
|
setVotableCountsAndUpdateCache(listToUpdate,issues,votableCountMap); |
|
|
|
|
|
|
|
for(Map.Entry<String,List<IssueDTO>> entry : gridIssueMap.entrySet()){ |
|
|
|
String k = entry.getKey(); |
|
|
|
List<IssueDTO> v = entry.getValue(); |
|
|
|
for(IssueDTO issue : v){ |
|
|
|
IssueVoteStatisticalDTO vote = new IssueVoteStatisticalDTO(); |
|
|
|
vote.setIssueId(issue.getId()); |
|
|
|
VoteRedisFormDTO cache = issueVoteDetailRedis.get(issue.getId()); |
|
|
|
if(null == cache) |
|
|
|
continue; |
|
|
|
vote.setSupportCount(cache.getSupportAmount()); |
|
|
|
vote.setOppositionCount(cache.getOppositionAmount()); |
|
|
|
vote.setVotableCount( null == votableCountMap ? |
|
|
|
NumConstant.ZERO : |
|
|
|
null == votableCountMap.get(k) ? NumConstant.ZERO : votableCountMap.get(k) |
|
|
|
); |
|
|
|
//if(cache.get)
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO listToUpdate批量更新
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -406,4 +420,40 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
return baseDao.selectByIssueId(issueId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 遍历应表决数 |
|
|
|
* @param list - List<IssueVoteStatisticalDTO> | Set<IssueDTO> | Map<String,Integer> |
|
|
|
* @return |
|
|
|
* @author wangc |
|
|
|
* @date 2020.05.22 11:55 |
|
|
|
**/ |
|
|
|
private void setVotableCountsAndUpdateCache(List<IssueVoteStatisticalDTO> list, |
|
|
|
Set<IssueDTO> issues, |
|
|
|
Map<String,Integer> votableCountMap){ |
|
|
|
Map<String,List<IssueDTO>> gridIssueMap = |
|
|
|
issues.stream().collect(Collectors.groupingBy(IssueDTO::getGridId)); |
|
|
|
for(Map.Entry<String,List<IssueDTO>> entry : gridIssueMap.entrySet()){ |
|
|
|
String k = entry.getKey(); |
|
|
|
List<IssueDTO> v = entry.getValue(); |
|
|
|
for(IssueDTO issue : v){ |
|
|
|
IssueVoteStatisticalDTO vote = new IssueVoteStatisticalDTO(); |
|
|
|
vote.setIssueId(issue.getId()); |
|
|
|
VoteRedisFormDTO cache = issueVoteDetailRedis.get(issue.getId()); |
|
|
|
if(null == cache) |
|
|
|
continue; |
|
|
|
vote.setSupportCount(cache.getSupportAmount()); |
|
|
|
vote.setOppositionCount(cache.getOppositionAmount()); |
|
|
|
vote.setVotableCount( null == votableCountMap ? |
|
|
|
NumConstant.ZERO : |
|
|
|
null == votableCountMap.get(k) ? NumConstant.ZERO : votableCountMap.get(k) |
|
|
|
); |
|
|
|
list.add(vote); |
|
|
|
if(cache.getShouldVoteCount() != vote.getVotableCount()){ |
|
|
|
issueVoteDetailRedis.hset(issue.getId(),ModuleConstants.SHOULD_VOTE_COUNT,vote.getVotableCount()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |