Commit 246c2461 by 陈健智

工具库-互动量更新调整

parent ea317a06
......@@ -1510,15 +1510,23 @@ public class MarkDataServiceImpl implements MarkDataService {
@Override
public ResponseResult markInteractionUpdate(MarkSearchDTO dto) {
Pair<String, List<ExportAppYuqingDTO>> pair = downloadList(dto, esSearchService::searchMarkHitsAndCount);
assert pair != null;
List<ExportAppYuqingDTO> list = pair.getRight();
List<BaseMap> list = new ArrayList<>();
dto.setProjectId(UserThreadLocal.getProjectId());
try {
SearchHits[] searchHits = esSearchService.searchMarkHitsAndCount(dto, true).getLeft();
for (SearchHits searchHit : searchHits) {
List<BaseMap> baseMaps = Arrays.stream(searchHit.getHits()).map(SearchHit::getSourceAsMap).map(Tools::getBaseFromEsMap).collect(Collectors.toList());
list.addAll(baseMaps);
}
} catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL, "es查询异常");
}
// 互动量更新剩余可用次数
int interactionBalance = projectService.getProjectById(UserThreadLocal.getProjectId()).getInteractionBalance();
if (interactionBalance - list.size() < 0){
return ResponseResult.failure("剩余可用次数不足");
}
Map<String, String> map = list.stream().collect(Collectors.toMap(ExportAppYuqingDTO::getUrl, ExportAppYuqingDTO::getPlatform, (v1, v2) -> v1));
Map<String, String> map = list.stream().collect(Collectors.toMap(BaseMap::getUrl, BaseMap::getPlatform, (v1, v2) -> v1));
// 分割map,list里每个map.size为100,目前品见最大链接限制为100,见知微tapd-wiki《互动量更新中间件使用》说明
List<Map<String, String>> mapList = Tools.splitMap(map, 100);
AtomicInteger id = new AtomicInteger(0);
......@@ -1537,7 +1545,7 @@ public class MarkDataServiceImpl implements MarkDataService {
}
}
Map<Object, JSONObject> urlMap = result.stream().collect(Collectors.toMap(jsonObject -> jsonObject.get("url"), o -> o));
List<ExportInteractionUpdateDTO> exportList = list.stream().map(ExportAppYuqingDTO::getUrl)
List<ExportInteractionUpdateDTO> exportList = list.stream().map(BaseMap::getUrl)
.map(url -> ExportInteractionUpdateDTO.createWithPlatform(String.valueOf(id.incrementAndGet()), map, urlMap, url))
.collect(Collectors.toList());
// excel输出到指定路径
......@@ -1556,10 +1564,16 @@ public class MarkDataServiceImpl implements MarkDataService {
@Override
public Long interactionUpdatePrediction(MarkSearchDTO dto) {
try {
defaultMarkSearch(dto);
dto.setPageSize(null);
Pair<SearchHits[], Map<String, Long>> hitsAndCounts = esSearchService.searchMarkHitsAndCount(dto, false);
return hitsAndCounts.getLeft()[0].getTotalHits().value;
String projectId = UserThreadLocal.getProjectId();
String contendId = Constant.PRIMARY_CONTEND_ID;
BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQuery(projectId, contendId, dto.getPoliticsLevel(), dto.getField(), dto.getRegion(), dto.getMainBodyType(), dto.getChannelEmotion());
// time
postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).gte(dto.getStartTime()).lt(dto.getEndTime()));
// platform
if (CollectionUtils.isNotEmpty(dto.getPlatforms())) {
postFilter.must(EsQueryTools.assemblePlatformQuery(Tools.getPlatformByIds(dto.getPlatforms())));
}
return esClientDao.count(postFilter);
}catch (Exception e){
ExceptionCast.cast(CommonCodeEnum.FAIL, "es查询异常");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment