|
|
@ -63,7 +63,6 @@ import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneOffset; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
/** |
|
|
|
* 议题表决统计表 |
|
|
@ -256,6 +255,7 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
* @date 2020.05.21 09:07 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void syncVotingCacheToDb() { |
|
|
|
IssueDTO issueParam = new IssueDTO(); |
|
|
|
issueParam.setIssueStatus(ModuleConstants.ISSUE_STATUS_VOTING); |
|
|
@ -267,14 +267,15 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
} |
|
|
|
Set<String> ids = issues.stream().map(IssueDTO::getId).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
List<String> gridIds = issues.stream().map(IssueDTO::getGridId).collect(Collectors.toList()); |
|
|
|
List<String> gridIds = issues.stream().map(IssueDTO::getGridId).distinct().collect(Collectors.toList()); |
|
|
|
CommonGridIdListFormDTO gridIdList = new CommonGridIdListFormDTO(); |
|
|
|
gridIdList.setGridIds(gridIds); |
|
|
|
Result<GridVotableCountResultDTO> votableCountResult = resiGroupFeignClient.votableCounts(gridIdList); |
|
|
|
Map<String,Integer> votableCountMap = null; |
|
|
|
Map<String,Integer> votableCountMap1 = null; |
|
|
|
if(votableCountResult.success() && null != votableCountResult.getData() && null != votableCountResult.getData().getVotableCountMap()){ |
|
|
|
votableCountMap = votableCountResult.getData().getVotableCountMap(); |
|
|
|
votableCountMap1 = votableCountResult.getData().getVotableCountMap(); |
|
|
|
} |
|
|
|
final Map<String,Integer> votableCountMap = votableCountMap1; |
|
|
|
|
|
|
|
List<IssueVoteStatisticalDTO> statisticalList = |
|
|
|
baseDao.selectListByIds(ids); |
|
|
@ -287,9 +288,8 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
notExistedIds.addAll(ids); |
|
|
|
notExistedIds.removeAll(statisiticalIds); |
|
|
|
//交集
|
|
|
|
Set<String> existedIds = new HashSet<>(); |
|
|
|
existedIds.addAll(ids); |
|
|
|
existedIds.retainAll(statisiticalIds); |
|
|
|
Set<String> existedIds = new HashSet<>(statisiticalIds); |
|
|
|
|
|
|
|
//更新
|
|
|
|
//对ids进行更新 - 从缓存中拿取
|
|
|
|
List<IssueVoteStatisticalDTO> listToUpdate = new ArrayList<>(); |
|
|
@ -302,12 +302,42 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
baseDao.updateBatchByIssueId(listToUpdate); |
|
|
|
|
|
|
|
if (notExistedIds.size() > NumConstant.ZERO) { |
|
|
|
Map<String,String> issueGridMap = issues.stream().collect(Collectors.toMap(IssueDTO::getId,IssueDTO::getGridId,(o, n) -> o)); |
|
|
|
//新增
|
|
|
|
List<IssueVoteStatisticalDTO> toInsert = new ArrayList<>(); |
|
|
|
List<IssueVoteStatisticalDTO> toInsert = new LinkedList<>(); |
|
|
|
List<VoteRedisFormDTO> voteList = issueVoteDetailDao.selectBatchVoteCount(notExistedIds); |
|
|
|
List<String> votedIssueIds = new ArrayList<>(); |
|
|
|
if(!CollectionUtils.isEmpty(voteList) && StringUtils.isNotBlank(voteList.get(NumConstant.ZERO).getIssueId())) { |
|
|
|
toInsert = voteList.stream().map(o -> { |
|
|
|
IssueVoteStatisticalDTO dto = new IssueVoteStatisticalDTO(); |
|
|
|
dto.setIssueId(o.getIssueId()); |
|
|
|
dto.setOppositionCount(o.getOppositionAmount()); |
|
|
|
dto.setSupportCount(o.getSupportAmount()); |
|
|
|
dto.setVotableCount(Optional.ofNullable(votableCountMap.get(issueGridMap.get(o.getIssueId()))).orElse(NumConstant.ZERO)); |
|
|
|
dto.setCreatedBy(ModuleConstants.CREATED_BY_SYSTEM);dto.setUpdatedBy(ModuleConstants.CREATED_BY_SYSTEM); |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
votedIssueIds = voteList.stream().map(VoteRedisFormDTO::getIssueId).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
notExistedIds.removeAll(votedIssueIds); |
|
|
|
if(!notExistedIds.isEmpty()){ |
|
|
|
List<IssueVoteStatisticalDTO> collect = notExistedIds.stream().map(issueId -> { |
|
|
|
IssueVoteStatisticalDTO dto = new IssueVoteStatisticalDTO(); |
|
|
|
dto.setIssueId(issueId); |
|
|
|
dto.setSupportCount(NumConstant.ZERO); |
|
|
|
dto.setOppositionCount(NumConstant.ZERO); |
|
|
|
dto.setVotableCount(Optional.ofNullable(votableCountMap.get(issueGridMap.get(issueId))).orElse(NumConstant.ZERO)); |
|
|
|
dto.setCreatedBy(ModuleConstants.CREATED_BY_SYSTEM);dto.setUpdatedBy(ModuleConstants.CREATED_BY_SYSTEM); |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
if(!CollectionUtils.isEmpty(collect)) toInsert.addAll(collect);} |
|
|
|
|
|
|
|
List<IssueAttitudeCountResultDTO> summaryList = issueVoteDetailDao.getVotingSummaryList(ids); |
|
|
|
/* |
|
|
|
List<IssueAttitudeCountResultDTO> summaryList = issueVoteDetailDao.getVotingSummaryList(notExistedIds); |
|
|
|
Map<String, List<IssueAttitudeCountResultDTO>> summaryMap = |
|
|
|
summaryList.stream().collect(Collectors.groupingBy(IssueAttitudeCountResultDTO::getIssueId)); |
|
|
|
|
|
|
|
for (Map.Entry<String, List<IssueAttitudeCountResultDTO>> entry : summaryMap.entrySet()) { |
|
|
|
IssueVoteStatisticalDTO obj = new IssueVoteStatisticalDTO(); |
|
|
|
obj.setCreatedBy(ModuleConstants.CREATED_BY_SYSTEM); |
|
|
@ -322,19 +352,15 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
if (StringUtils.equals(ModuleConstants.ISSUE_VOTING_ATTITUDE_SUPPORT, v.get(0).getAttitude())) { |
|
|
|
obj.setSupportCount(v.get(0).getCount()); |
|
|
|
obj.setOppositionCount(NumConstant.ZERO); |
|
|
|
} else { |
|
|
|
obj.setOppositionCount(v.get(0).getCount()); |
|
|
|
obj.setSupportCount(NumConstant.ZERO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
obj.setVotableCount(Optional.ofNullable(votableCountMap.get(issueGridMap.get(entry.getKey()))).orElse(NumConstant.ZERO)); |
|
|
|
toInsert.add(obj); |
|
|
|
} |
|
|
|
|
|
|
|
Set<String> setToInsert = toInsert.stream().map(IssueVoteStatisticalDTO::getIssueId).collect(Collectors.toSet()); |
|
|
|
*/ |
|
|
|
/* Set<String> setToInsert = toInsert.stream().map(IssueVoteStatisticalDTO::getIssueId).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
Set<String> issuesNeverVotedIds = new HashSet<String>(); |
|
|
|
issuesNeverVotedIds.addAll(ids); |
|
|
@ -372,30 +398,27 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
if(!toInsert.isEmpty()) |
|
|
|
// 批量插入
|
|
|
|
baseDao.insertBatch(summary); |
|
|
|
} |
|
|
|
baseDao.insertBatch(toInsert); |
|
|
|
} |
|
|
|
else if (ids.size() < statisiticalIds.size()) { |
|
|
|
//}
|
|
|
|
//else if (ids.size() < statisiticalIds.size()) {
|
|
|
|
//统计数大于议题数,数据出错
|
|
|
|
//找出多余数据,删除
|
|
|
|
|
|
|
|
//差集
|
|
|
|
Set<String> redundantIds = new HashSet<String>(); |
|
|
|
redundantIds.addAll(statisiticalIds); |
|
|
|
redundantIds.removeAll(ids); |
|
|
|
//Set<String> redundantIds = new HashSet<String>();
|
|
|
|
//redundantIds.addAll(statisiticalIds);
|
|
|
|
//redundantIds.removeAll(ids);
|
|
|
|
//将redundantIds的议题统计信息删除
|
|
|
|
|
|
|
|
//因为statisiticalIds是通过ids查询出,因此不会出现这种情况
|
|
|
|
} else { |
|
|
|
//数据吻合,全部更新
|
|
|
|
List<IssueVoteStatisticalDTO> listToUpdate = new ArrayList<>(); |
|
|
|
Map<String,List<IssueDTO>> gridIssueMap = |
|
|
|
issues.stream().collect(Collectors.groupingBy(IssueDTO::getGridId)); |
|
|
|
|
|
|
|
setVotableCountsAndUpdateCache(listToUpdate,issues,votableCountMap); |
|
|
|
|
|
|
|
// listToUpdate批量更新
|
|
|
@ -518,8 +541,7 @@ public class IssueVoteStatisticalServiceImpl extends BaseServiceImpl<IssueVoteSt |
|
|
|
IssueVoteStatisticalDTO vote = new IssueVoteStatisticalDTO(); |
|
|
|
vote.setIssueId(issue.getId()); |
|
|
|
VoteRedisFormDTO cache = issueVoteDetailRedis.getVoteStatistical(issue.getId()); |
|
|
|
if(null == cache) |
|
|
|
continue; |
|
|
|
if(null == cache) continue; |
|
|
|
if(StringUtils.isBlank(cache.getIssueId())) cache.setIssueId(issue.getId()); |
|
|
|
vote.setCreatedBy(ModuleConstants.CREATED_BY_SYSTEM); |
|
|
|
vote.setUpdatedBy(ModuleConstants.CREATED_BY_SYSTEM); |
|
|
|