Commit 08a6dad5 by shenjunjie

Merge branch 'feature' into 'dev'

Feature

See merge request !28
parents 2a9e8f84 590feb2f
...@@ -232,6 +232,11 @@ ...@@ -232,6 +232,11 @@
<artifactId>nlp-aggree</artifactId> <artifactId>nlp-aggree</artifactId>
<version>0.0.5-SNAPSHOT</version> <version>0.0.5-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.zhiwei.tools</groupId>
<artifactId>zhiwei-tools</artifactId>
<version>0.3.3-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -15,7 +15,8 @@ public class GenericAttribute { ...@@ -15,7 +15,8 @@ public class GenericAttribute {
* es index * es index
*/ */
public static final String ES_INDEX_PRE = "brandkbs2"; public static final String ES_INDEX_PRE = "brandkbs2";
public static final String ES_INDEX_TEST = "brandkbs2_test"; // public static final String ES_INDEX_TEST = "brandkbs2_test";
public static final String ES_INDEX_TEST = "brandkbs2_2022";
public static final String ES_CHANNEL_INDEX_TEST = "brandkbs2_channel_record_test"; public static final String ES_CHANNEL_INDEX_TEST = "brandkbs2_channel_record_test";
/** /**
* es ind_title * es ind_title
...@@ -34,7 +35,7 @@ public class GenericAttribute { ...@@ -34,7 +35,7 @@ public class GenericAttribute {
*/ */
public static final String ES_MEDIA_TYPE = "media_type"; public static final String ES_MEDIA_TYPE = "media_type";
// es platform_id // es platform_id
public static final String ES_PLATFORM_ID= "platform_id"; public static final String ES_PLATFORM_ID = "platform_id";
// es channel_influence // es channel_influence
public static final String ES_CHANNEL_INDEX = "channel_influence"; public static final String ES_CHANNEL_INDEX = "channel_influence";
/** /**
...@@ -50,33 +51,61 @@ public class GenericAttribute { ...@@ -50,33 +51,61 @@ public class GenericAttribute {
public static final String ES_CHANNEL_FID = "fid"; public static final String ES_CHANNEL_FID = "fid";
public static final String ES_CNAME = "cname"; public static final String ES_CNAME = "cname";
/** es c2 **/ /**
* es c2
**/
public static final String ES_C2 = "c2"; public static final String ES_C2 = "c2";
/** es c4 **/ /**
* es c4
**/
public static final String ES_C4 = "c4"; public static final String ES_C4 = "c4";
/** es c5 **/ /**
* es c5
**/
public static final String ES_C5 = "c5"; public static final String ES_C5 = "c5";
/** es foreign **/ /**
* es foreign
**/
public static final String ES_FOREIGN = "foreign"; public static final String ES_FOREIGN = "foreign";
/** es source **/ /**
* es source
**/
public static final String ES_SOURCE = "source"; public static final String ES_SOURCE = "source";
/** es real_source **/ /**
* es real_source
**/
public static final String ES_REAL_SOURCE = "real_source"; public static final String ES_REAL_SOURCE = "real_source";
/** es time **/ /**
* es time
**/
public static final String ES_TIME = "time"; public static final String ES_TIME = "time";
/** es ctime **/ /**
* es ctime
**/
public static final String ES_CTIME = "ctime"; public static final String ES_CTIME = "ctime";
/** es mtime **/ /**
* es mtime
**/
public static final String ES_MTIME = "mtime"; public static final String ES_MTIME = "mtime";
/** es mtag **/ /**
* es mtag
**/
public static final String ES_MTAG = "mtag"; public static final String ES_MTAG = "mtag";
/** es mgroup **/ /**
* es mgroup
**/
public static final String ES_MGROUP = "mgroup"; public static final String ES_MGROUP = "mgroup";
/** es forward **/ /**
* es forward
**/
public static final String ES_FORWARD = "forward"; public static final String ES_FORWARD = "forward";
/** es brandkbs_cache_maps **/ /**
* es brandkbs_cache_maps
**/
public static final String ES_BRANDKBS_CACHE_MAPS = "brandkbs_cache_maps"; public static final String ES_BRANDKBS_CACHE_MAPS = "brandkbs_cache_maps";
/** es mark_cache_maps **/ /**
* es mark_cache_maps
**/
public static final String ES_MARK_CACHE_MAPS = "brandkbs_mark_cache_maps"; public static final String ES_MARK_CACHE_MAPS = "brandkbs_mark_cache_maps";
public static final String ES_LINKED_GROUP_ID = "linked_group_id"; public static final String ES_LINKED_GROUP_ID = "linked_group_id";
...@@ -92,7 +121,7 @@ public class GenericAttribute { ...@@ -92,7 +121,7 @@ public class GenericAttribute {
public static final String USER_ID = "userId"; public static final String USER_ID = "userId";
public static final String ROLE_ID = "roleId"; public static final String ROLE_ID = "roleId";
public static final String PROJECT_ID = "projectId"; public static final String PROJECT_ID = "projectId";
public static final String AVATAR_URL= "avatarUrl"; public static final String AVATAR_URL = "avatarUrl";
// public enum ChannelParam{ // public enum ChannelParam{
// 负面稿件数("negativeArticles"), // 负面稿件数("negativeArticles"),
......
...@@ -55,8 +55,8 @@ public class RedisKeyPrefix { ...@@ -55,8 +55,8 @@ public class RedisKeyPrefix {
/** /**
* 热点相关缓存KEY * 热点相关缓存KEY
*/ */
public static final String HOT_RANKLIST = "brandkbs:hot:rankList:"; public static final String HOT_RANK_LIST = "BRANDKBS:HOT:RANK_LIST:";
public static final String HOT_LIST = "brandkbs:hot:list:"; public static final String HOT_LIST = "BRANDKBS:HOT:LIST:";
/** /**
* 项目简报报相关缓存KEY * 项目简报报相关缓存KEY
......
...@@ -175,4 +175,12 @@ public class AppArticleController extends BaseController { ...@@ -175,4 +175,12 @@ public class AppArticleController extends BaseController {
return ResponseResult.success(); return ResponseResult.success();
} }
@ApiOperation("舆情简报-获取报告结果")
@ApiImplicitParam(name = "id", value = "报告ID", required = true, paramType = "path", dataType = "String")
@GetMapping("/analyze/{id}")
public ResponseResult getReportAnalyze(@PathVariable String id) {
return ResponseResult.success(reportService.getPcReportAnalyze(id, true));
}
} }
...@@ -9,6 +9,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult; ...@@ -9,6 +9,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.dto.EventSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.EventSearchDTO;
import com.zhiwei.brandkbs2.service.EventService; import com.zhiwei.brandkbs2.service.EventService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -138,4 +139,18 @@ public class AppEventController extends BaseController { ...@@ -138,4 +139,18 @@ public class AppEventController extends BaseController {
JSONObject jsonObject = JSON.parseObject(responseEntity.getBody()); JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
return ResponseResult.success(jsonObject); return ResponseResult.success(jsonObject);
} }
@ApiOperation("最新事件")
@GetMapping("/getLastEventTop")
public ResponseResult getLastEventTop() {
return ResponseResult.success(eventService.getLastEventTop(null, 5));
}
@ApiOperation("关联事件")
@ApiImplicitParam(name = "keyword", value = "关键词", paramType = "query", dataType = "String")
@GetMapping("/getRelevanceEvent")
public ResponseResult getRelevanceEvent(@RequestParam(value = "keyword", required = false) String keyword) {
return ResponseResult.success(eventService.getLastEventTop(keyword, 5));
}
} }
...@@ -99,7 +99,7 @@ public class AppHotController extends BaseController { ...@@ -99,7 +99,7 @@ public class AppHotController extends BaseController {
public ResponseResult hot(){ public ResponseResult hot(){
ResponseEntity<String> responseEntity = restTemplate.getForEntity(longTimeInListSearchUrl, String.class,"weibo"); ResponseEntity<String> responseEntity = restTemplate.getForEntity(longTimeInListSearchUrl, String.class,"weibo");
JSONObject jsonObject = JSON.parseObject(responseEntity.getBody()); JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
String redisKey = RedisKeyPrefix.HOT_RANKLIST; String redisKey = RedisKeyPrefix.HOT_RANK_LIST;
String result = redisUtil.get(redisKey); String result = redisUtil.get(redisKey);
//当舆论场崩溃时从缓存里获取 //当舆论场崩溃时从缓存里获取
if(jsonObject.getBoolean("state")){ if(jsonObject.getBoolean("state")){
......
...@@ -4,19 +4,25 @@ package com.zhiwei.brandkbs2.controller.app; ...@@ -4,19 +4,25 @@ package com.zhiwei.brandkbs2.controller.app;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.auth.Auth; import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.enmus.RoleEnum; import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO;
import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.util.Tools;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.Period;
import org.joda.time.PeriodType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -42,6 +48,9 @@ public class AppSearchController { ...@@ -42,6 +48,9 @@ public class AppSearchController {
@Value("${ef.search.url}") @Value("${ef.search.url}")
private String getEfSearchUrl; private String getEfSearchUrl;
@Resource(name = "markDataServiceImpl")
MarkDataService markDataService;
@ApiOperation("搜索-查热点") @ApiOperation("搜索-查热点")
@GetMapping("/hot/list") @GetMapping("/hot/list")
public ResponseResult searchHotList(@RequestParam(value = "pageSize",defaultValue ="10") Integer limit, public ResponseResult searchHotList(@RequestParam(value = "pageSize",defaultValue ="10") Integer limit,
...@@ -76,4 +85,18 @@ public class AppSearchController { ...@@ -76,4 +85,18 @@ public class AppSearchController {
JSONObject result = JSON.parseObject(responseEntity.getBody()); JSONObject result = JSON.parseObject(responseEntity.getBody());
return ResponseResult.success(result); return ResponseResult.success(result);
} }
@ApiOperation("搜索-全网搜")
@GetMapping("/searchWhole")
public ResponseResult searchWholeNetwork(@RequestBody SearchFilterDTO dto){
long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime();
if (time > dto.getStartTime()){
return ResponseResult.failure("仅能搜索近3个月内信息");
}
Period periodDay = new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days());
if (periodDay.getDays() > 30) {
return ResponseResult.failure("时间跨度不能超过30天");
}
return ResponseResult.success(markDataService.searchWholeNetwork(dto));
}
} }
...@@ -156,9 +156,4 @@ public interface BaseMongoDao<T extends AbstractBaseMongo> { ...@@ -156,9 +156,4 @@ public interface BaseMongoDao<T extends AbstractBaseMongo> {
return criteria; return criteria;
} }
@FunctionalInterface
interface VoidSetFunction {
<T> void set(T t);
}
} }
...@@ -94,4 +94,7 @@ public interface EventDao extends BaseMongoDao<Event> { ...@@ -94,4 +94,7 @@ public interface EventDao extends BaseMongoDao<Event> {
*/ */
List<Event> getEventsByProjectIdAndContendId(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit); List<Event> getEventsByProjectIdAndContendId(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit);
List<Event> getEventsByTotalChannelVolumeTop(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit);
} }
...@@ -105,6 +105,17 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -105,6 +105,17 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
return mongoTemplate.find(query, clazz, COLLECTION_NAME); return mongoTemplate.find(query, clazz, COLLECTION_NAME);
} }
@Override
public List<Event> getEventsByTotalChannelVolumeTop(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit) {
Query query = new Query();
Criteria criteria = eventCountCriteria(startTime, endTime, emotion, projectId, contendId);
query.addCriteria(criteria);
query.limit(limit);
// 按影响力排序
addSort(query, "{\"negativeArticleVolume\":\"descend\"}");
return mongoTemplate.find(query, clazz, COLLECTION_NAME);
}
private Criteria eventCountCriteria(Long startTime, Long endTime, String emotion, String projectId, String contendId) { private Criteria eventCountCriteria(Long startTime, Long endTime, String emotion, String projectId, String contendId) {
Criteria criteria = Criteria.where("projectId").is(projectId); Criteria criteria = Criteria.where("projectId").is(projectId);
criteria.and("contendId").is(contendId); criteria.and("contendId").is(contendId);
......
package com.zhiwei.brandkbs2.dao.impl; package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.EventDisseminationTrendDao; import com.zhiwei.brandkbs2.dao.EventDisseminationTrendDao;
import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend; import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -21,6 +20,6 @@ public class EventDisseminationTrendDaoImpl extends BaseMongoDaoImpl<EventDissem ...@@ -21,6 +20,6 @@ public class EventDisseminationTrendDaoImpl extends BaseMongoDaoImpl<EventDissem
@Override @Override
public EventDisseminationTrend findOne(Query query) { public EventDisseminationTrend findOne(Query query) {
return mongoTemplate.findOne(query, EventDisseminationTrend.class); return mongoTemplate.findOne(query, EventDisseminationTrend.class, COLLECTION_NAME);
} }
} }
...@@ -4,12 +4,19 @@ import com.zhiwei.brandkbs2.common.GenericAttribute; ...@@ -4,12 +4,19 @@ import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo; import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.pushlog.tools.Tools; import com.zhiwei.pushlog.tools.Tools;
import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform; import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.NestedQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import java.util.*; import java.util.*;
import static com.zhiwei.brandkbs2.common.GenericAttribute.ES_BRANDKBS_CACHE_MAPS;
import static com.zhiwei.brandkbs2.util.Tools.concat;
/** /**
* @ClassName: EsQueryTool * @ClassName: EsQueryTool
* @Description es语句辅助类 * @Description es语句辅助类
...@@ -83,27 +90,51 @@ public class EsQueryTools { ...@@ -83,27 +90,51 @@ public class EsQueryTools {
return tagQuery; return tagQuery;
} }
/** public static BoolQueryBuilder assembleCacheMapsQuery(String projectId, String linkedGroupId, String contendId) {
* 媒体类型请求匹配 return assembleCacheMapsQuery(projectId, linkedGroupId, contendId, null);
* }
* @param mediaTypes
* @return public static BoolQueryBuilder assembleCacheMapsQuery(String projectId, String linkedGroupId, String contendId, List<String> mediaTypes) {
*/ BoolQueryBuilder nestedBoolQueryBuilder = QueryBuilders.boolQuery();
public static BoolQueryBuilder assembleMediaTypeQuery(List<String> mediaTypes) { // must key
BoolQueryBuilder tagQuery = QueryBuilders.boolQuery(); nestedBoolQueryBuilder.must(cacheMapsNestedQuery(QueryBuilders.termQuery("brandkbs_cache_maps.key.keyword", concat(projectId, linkedGroupId, contendId))));
// mediaType
if (CollectionUtils.isNotEmpty(mediaTypes)) {
BoolQueryBuilder mediaTypeQueryBuilder = QueryBuilders.boolQuery();
mediaTypes.forEach(e -> { mediaTypes.forEach(e -> {
tagQuery.should(QueryBuilders.termQuery("brandkbs_cache_maps.channel_type.keyword", e)); mediaTypeQueryBuilder.should(cacheMapsNestedQuery(QueryBuilders.termQuery("brandkbs_cache_maps.channel_type.keyword", e)));
}); });
return tagQuery; nestedBoolQueryBuilder.must(mediaTypeQueryBuilder);
}
return nestedBoolQueryBuilder;
} }
public static NestedQueryBuilder cacheMapsNestedQuery(QueryBuilder query) {
return new NestedQueryBuilder(ES_BRANDKBS_CACHE_MAPS, query, ScoreMode.None);
}
// /**
// * 媒体类型请求匹配
// *
// * @param mediaTypes
// * @return
// */
// public static BoolQueryBuilder assembleMediaTypeQuery(List<String> mediaTypes) {
// BoolQueryBuilder tagQuery = QueryBuilders.boolQuery();
// mediaTypes.forEach(e -> {
// // TODO 1
// tagQuery.should(QueryBuilders.termQuery("brandkbs_cache_maps.channel_type.keyword", e));
// });
// return tagQuery;
// }
public static BoolQueryBuilder assembleSourceQuery(String sourceKeyword) { public static BoolQueryBuilder assembleSourceQuery(String sourceKeyword) {
BoolQueryBuilder channelBoolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder channelBoolQueryBuilder = QueryBuilders.boolQuery();
String[] keys = sourceKeyword.trim().split("\\|"); String[] keys = sourceKeyword.trim().split("\\|");
for (String key : keys) { for (String key : keys) {
String channelRegex = getAllRegex(key); String channelRegex = getAllRegex(key);
BoolQueryBuilder keyQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder keyQueryBuilder = QueryBuilders.boolQuery();
keyQueryBuilder.must(QueryBuilders.regexpQuery("source.keyword", ".*" + channelRegex + ".*")); keyQueryBuilder.must(QueryBuilders.regexpQuery("source", ".*" + channelRegex + ".*"));
channelBoolQueryBuilder.should(keyQueryBuilder); channelBoolQueryBuilder.should(keyQueryBuilder);
} }
return channelBoolQueryBuilder; return channelBoolQueryBuilder;
......
package com.zhiwei.brandkbs2.pojo; package com.zhiwei.brandkbs2.pojo;
import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.util.Tools;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -15,15 +19,15 @@ import java.util.Map; ...@@ -15,15 +19,15 @@ import java.util.Map;
@Getter @Getter
@Setter @Setter
@Document(collection = "brandkbs_event_dissemination_trend") @Document(collection = "brandkbs_event_dissemination_trend")
public class EventDisseminationTrend extends AbstractBaseMongo{ public class EventDisseminationTrend extends AbstractBaseMongo {
/** /**
* 负面稿件传播 * 负面稿件传播
*/ */
private List<Map<String,Object>> negativeSpread; private List<Map<String, Object>> negativeSpread;
/** /**
* 总稿件传播 * 总稿件传播
*/ */
private List<Map<String,Object>> totalSpread; private List<Map<String, Object>> totalSpread;
/** /**
* 类型 按小时、按天 * 类型 按小时、按天
*/ */
...@@ -32,4 +36,61 @@ public class EventDisseminationTrend extends AbstractBaseMongo{ ...@@ -32,4 +36,61 @@ public class EventDisseminationTrend extends AbstractBaseMongo{
* 关联事件id * 关联事件id
*/ */
private String eventId; private String eventId;
public static EventDisseminationTrend createFromType(List<EventData> list, Long startTime, Long endTime, String type, String eventId) {
EventDisseminationTrend eventDisseminationTrend = new EventDisseminationTrend();
eventDisseminationTrend.setEventId(eventId);
eventDisseminationTrend.setType(type);
switch (type) {
case "小时": {
setSpreadAll(list, Tools.parseToHours(startTime, endTime), eventDisseminationTrend);
break;
}
case "天": {
setSpreadAll(list, Tools.parseToDays(startTime, endTime), eventDisseminationTrend);
break;
}
}
return eventDisseminationTrend;
}
private static void setSpreadAll(List<EventData> list, List<Map<String, Long>> rangeTimeList, EventDisseminationTrend trend) {
long start;
long end;
long negCount = 0;
long count = 0;
int index = 0;
List<Map<String, Object>> negativeSpread = new ArrayList<>();
List<Map<String, Object>> totalSpread = new ArrayList<>();
for (EventData eventData : list) {
Map<String, Long> map = rangeTimeList.get(index);
start = map.get("startTime");
end = map.get("endTime");
if (eventData.getTime() >= start && eventData.getTime() < end) {
// 数据统计
count++;
if (EmotionEnum.NEGATIVE.getName().equals(eventData.getEmotion())) {
negCount++;
}
} else {
// 总统计
Map<String, Object> element = new HashMap<>();
element.put("time", start);
element.put("sum", count);
negativeSpread.add(element);
// 负面统计
Map<String, Object> negElement = new HashMap<>();
negElement.put("time", start);
negElement.put("sum", negCount);
totalSpread.add(negElement);
// 推进节点并重置计量值
count = 0;
negCount = 0;
index++;
}
}
trend.setTotalSpread(totalSpread);
trend.setNegativeSpread(negativeSpread);
}
} }
...@@ -18,6 +18,11 @@ public class EventTopArticlesAnalysis extends AbstractBaseMongo { ...@@ -18,6 +18,11 @@ public class EventTopArticlesAnalysis extends AbstractBaseMongo {
* 聚合标题 * 聚合标题
*/ */
private String aggTitle; private String aggTitle;
/**
* 首条标题
*/
private String url;
/** /**
* 聚合情感 * 聚合情感
*/ */
...@@ -49,6 +54,7 @@ public class EventTopArticlesAnalysis extends AbstractBaseMongo { ...@@ -49,6 +54,7 @@ public class EventTopArticlesAnalysis extends AbstractBaseMongo {
eventTopArticlesAnalysis.setEmotion(templateData.getEmotion()); eventTopArticlesAnalysis.setEmotion(templateData.getEmotion());
eventTopArticlesAnalysis.setCount(count); eventTopArticlesAnalysis.setCount(count);
eventTopArticlesAnalysis.setTime(templateData.getTime()); eventTopArticlesAnalysis.setTime(templateData.getTime());
eventTopArticlesAnalysis.setUrl(templateData.getUrl());
eventTopArticlesAnalysis.setTimePoint(timePoint); eventTopArticlesAnalysis.setTimePoint(timePoint);
eventTopArticlesAnalysis.setType("按时间"); eventTopArticlesAnalysis.setType("按时间");
eventTopArticlesAnalysis.setEventId(eventId); eventTopArticlesAnalysis.setEventId(eventId);
...@@ -61,6 +67,7 @@ public class EventTopArticlesAnalysis extends AbstractBaseMongo { ...@@ -61,6 +67,7 @@ public class EventTopArticlesAnalysis extends AbstractBaseMongo {
eventTopArticlesAnalysis.setEmotion(templateData.getEmotion()); eventTopArticlesAnalysis.setEmotion(templateData.getEmotion());
eventTopArticlesAnalysis.setCount(count); eventTopArticlesAnalysis.setCount(count);
eventTopArticlesAnalysis.setTime(templateData.getTime()); eventTopArticlesAnalysis.setTime(templateData.getTime());
eventTopArticlesAnalysis.setUrl(templateData.getUrl());
eventTopArticlesAnalysis.setType("按数量"); eventTopArticlesAnalysis.setType("按数量");
eventTopArticlesAnalysis.setEventId(eventId); eventTopArticlesAnalysis.setEventId(eventId);
return eventTopArticlesAnalysis; return eventTopArticlesAnalysis;
......
package com.zhiwei.brandkbs2.pojo.dto; package com.zhiwei.brandkbs2.pojo.dto;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.*;
@Data @Data
@ApiModel("全网搜搜索传输类") @ApiModel("全网搜搜索传输类")
...@@ -44,7 +45,7 @@ public class SearchFilterDTO { ...@@ -44,7 +45,7 @@ public class SearchFilterDTO {
* 关键字 * 关键字
*/ */
@ApiModelProperty(value = "关键字") @ApiModelProperty(value = "关键字")
private String keyword; private String search;
/** /**
* 平台 * 平台
...@@ -53,13 +54,15 @@ public class SearchFilterDTO { ...@@ -53,13 +54,15 @@ public class SearchFilterDTO {
private List<String> platforms; private List<String> platforms;
/** /**
* 平台(真正用于搜索的) * 平台(查商业数据库用)
*/ */
@ApiModelProperty(value = "平台(查商业数据库用)")
private String platformsStr; private String platformsStr;
/** /**
* 数据类型 1:原创, 2:转发, 7:评论 * 数据类型 1:原创, 2:转发, 7:评论 (查商业数据库用)
*/ */
@ApiModelProperty(value = "数据类型(查商业数据库用)")
private String filterForward = "1,2"; private String filterForward = "1,2";
/** /**
...@@ -69,13 +72,27 @@ public class SearchFilterDTO { ...@@ -69,13 +72,27 @@ public class SearchFilterDTO {
private String sorter; private String sorter;
/** /**
* 排序字段(真正用于搜索的) * 排序字段(查商业数据库用)
*/ */
@ApiModelProperty(value = "排序字段(查商业数据库用)")
private String sortOf; private String sortOf;
/** /**
* 匹配域名 默认标题+内容 * 来源
*/ */
@ApiModelProperty(value = "来源")
private String source;
/**
* 过滤关键字
*/
@ApiModelProperty(value = "过滤关键字")
private String filterWords;
/**
* 匹配域名 默认标题+内容(查商业数据库用)
*/
@ApiModelProperty(value = "匹配域名(查商业数据库用)")
private String matchFields = null; private String matchFields = null;
/** /**
...@@ -84,4 +101,48 @@ public class SearchFilterDTO { ...@@ -84,4 +101,48 @@ public class SearchFilterDTO {
@ApiModelProperty(value = "查询类型") @ApiModelProperty(value = "查询类型")
private String matchType; private String matchType;
/**
* 重要渠道,{father:"区域",son:"北京"},{father:"全部"}
*/
@ApiModelProperty(value = "重要渠道")
private Map<String, String> sensitiveChannels;
/**
* 粉丝数
*/
@ApiModelProperty(value = "粉丝数")
private String fans;
/**
* 过滤类型 标题/全文
*/
@ApiModelProperty(value = "过滤类型 标题/全文")
private String filterType;
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>();
map.put("timeType","time");
map.put("pt", getPt());
map.put("matchType", matchType);
map.put("search", search);
map.put("startTime", startTime);
map.put("endTime", endTime);
map.put("source", source);
map.put("sort", Objects.nonNull(sorter) ? sorter : "DESC");
map.put("page", page);
map.put("pageSize", pageSize);
map.put("notWords", filterWords);
map.put("sensitiveChannels", sensitiveChannels);
map.put("fans", fans);
map.put("filterType", filterType);
return map;
}
public List<String> getPt() {
return Objects.nonNull(platforms) ? this.platforms : Collections.emptyList();
}
public String getMatchType() {
return Objects.nonNull(this.matchType) ? this.matchType : "标题";
}
} }
...@@ -5,6 +5,7 @@ import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDTO; ...@@ -5,6 +5,7 @@ import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDataDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDataDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDTO; import com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDTO;
import com.zhiwei.brandkbs2.pojo.Event; import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.EventData;
import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend; import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend;
import com.zhiwei.brandkbs2.pojo.dto.EventDataDTO; import com.zhiwei.brandkbs2.pojo.dto.EventDataDTO;
import com.zhiwei.brandkbs2.pojo.dto.EventSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.EventSearchDTO;
...@@ -218,12 +219,14 @@ public interface EventService { ...@@ -218,12 +219,14 @@ public interface EventService {
/** /**
* 获取品牌事件搜索条件 * 获取品牌事件搜索条件
*
* @return * @return
*/ */
JSONObject getEventsSearchCriteria(); JSONObject getEventsSearchCriteria();
/** /**
* 获取品牌事件列表信息 * 获取品牌事件列表信息
*
* @param eventSearchDTO 事件搜索类 * @param eventSearchDTO 事件搜索类
* @return * @return
*/ */
...@@ -231,6 +234,7 @@ public interface EventService { ...@@ -231,6 +234,7 @@ public interface EventService {
/** /**
* 事件详情-基础静态信息 * 事件详情-基础静态信息
*
* @param eventId * @param eventId
* @return * @return
*/ */
...@@ -238,6 +242,7 @@ public interface EventService { ...@@ -238,6 +242,7 @@ public interface EventService {
/** /**
* 事件详情-传播趋势图 * 事件详情-传播趋势图
*
* @param eventId * @param eventId
* @param type * @param type
* @return * @return
...@@ -246,6 +251,7 @@ public interface EventService { ...@@ -246,6 +251,7 @@ public interface EventService {
/** /**
* 事件详情-渠道发声 * 事件详情-渠道发声
*
* @param eventId * @param eventId
* @param type * @param type
* @param page * @param page
...@@ -253,10 +259,11 @@ public interface EventService { ...@@ -253,10 +259,11 @@ public interface EventService {
* @param sorter * @param sorter
* @return * @return
*/ */
List<JSONObject> getEventChannelVoices(String eventId, String type, int page, int pageSize, String sorter); PageVO<JSONObject> getEventChannelVoices(String eventId, String type, int page, int pageSize, String sorter);
/** /**
* 事件详情-热门文章分析 * 事件详情-热门文章分析
*
* @param id * @param id
* @param type * @param type
* @param emotion * @param emotion
...@@ -264,4 +271,12 @@ public interface EventService { ...@@ -264,4 +271,12 @@ public interface EventService {
* @return * @return
*/ */
JSONObject getEventTopArticlesAnalysis(String id, String type, String emotion, String aggTitle); JSONObject getEventTopArticlesAnalysis(String id, String type, String emotion, String aggTitle);
/**
* 获得最新的事件
*
* @return
*/
List<JSONObject> getLastEventTop(String keyword,int limit);
} }
...@@ -62,4 +62,14 @@ public interface IndexService { ...@@ -62,4 +62,14 @@ public interface IndexService {
*/ */
JSONObject getSpreadingTend(Long startTime, Long endTime, boolean cache); JSONObject getSpreadingTend(Long startTime, Long endTime, boolean cache);
/**
* 获取主品牌传播趋势
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param cache 是否优先读取缓存
* @return 主品牌传播趋势
*/
JSONObject getSpreadingTend(Long startTime, Long endTime, String projectId, String contendId, boolean cache);
} }
...@@ -40,7 +40,6 @@ import org.springframework.stereotype.Service; ...@@ -40,7 +40,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -134,7 +133,7 @@ public class CustomEventServiceImpl implements CustomEventService { ...@@ -134,7 +133,7 @@ public class CustomEventServiceImpl implements CustomEventService {
if (Objects.isNull(customEvent)) { if (Objects.isNull(customEvent)) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("自定义事件数据异常")); ExceptionCast.cast(CommonCodeEnum.FAIL.message("自定义事件数据异常"));
} }
if (!customEvent.getStatus()) { if (Boolean.FALSE.equals(customEvent.getStatus())) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("该事件数据更新中,无法修改该事件信息!")); ExceptionCast.cast(CommonCodeEnum.FAIL.message("该事件数据更新中,无法修改该事件信息!"));
} }
// 修改自定义事件及清空历史数据 // 修改自定义事件及清空历史数据
...@@ -180,7 +179,7 @@ public class CustomEventServiceImpl implements CustomEventService { ...@@ -180,7 +179,7 @@ public class CustomEventServiceImpl implements CustomEventService {
if (Objects.isNull(customEvent)) { if (Objects.isNull(customEvent)) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("自定义事件数据异常")); ExceptionCast.cast(CommonCodeEnum.FAIL.message("自定义事件数据异常"));
} }
if (!customEvent.getStatus()) { if (Boolean.FALSE.equals(customEvent.getStatus())) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("该事件数据更新中!")); ExceptionCast.cast(CommonCodeEnum.FAIL.message("该事件数据更新中!"));
} }
customEvent.setStatus(false); customEvent.setStatus(false);
...@@ -210,7 +209,7 @@ public class CustomEventServiceImpl implements CustomEventService { ...@@ -210,7 +209,7 @@ public class CustomEventServiceImpl implements CustomEventService {
try { try {
return getCustomEventAnalyzeInner(id, cache); return getCustomEventAnalyzeInner(id, cache);
} catch (Exception e) { } catch (Exception e) {
log.info("自定义事件:{} 数据更新异常", id, e); log.info("自定义事件:{} 获取异常", id, e);
} }
return new JSONObject(); return new JSONObject();
} }
...@@ -231,9 +230,6 @@ public class CustomEventServiceImpl implements CustomEventService { ...@@ -231,9 +230,6 @@ public class CustomEventServiceImpl implements CustomEventService {
} }
String redisKey = RedisKeyPrefix.CUSTOM_EVENT_ANALYZE + id; String redisKey = RedisKeyPrefix.CUSTOM_EVENT_ANALYZE + id;
if (cache) { if (cache) {
if (Boolean.FALSE.equals(customEvent.getStatus())) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("该事件数据更新中,请勿重复更新!"));
}
String resultStr = redisUtil.get(redisKey); String resultStr = redisUtil.get(redisKey);
if (StringUtils.isNotEmpty(resultStr)) { if (StringUtils.isNotEmpty(resultStr)) {
return JSON.parseObject(resultStr); return JSON.parseObject(resultStr);
...@@ -510,7 +506,7 @@ public class CustomEventServiceImpl implements CustomEventService { ...@@ -510,7 +506,7 @@ public class CustomEventServiceImpl implements CustomEventService {
// 获得首发标题 // 获得首发标题
List<BaseMap> list = entry.getValue().stream().sorted(Comparator.comparingLong(BaseMap::getTime)).limit(1).collect(Collectors.toList()); List<BaseMap> list = entry.getValue().stream().sorted(Comparator.comparingLong(BaseMap::getTime)).limit(1).collect(Collectors.toList());
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("title", list.get(0).getTitle()); result.put("title", list.get(0).getTitleNullOptionalContent());
result.put("url", list.get(0).getUrl()); result.put("url", list.get(0).getUrl());
result.put("num", entry.getValue().size()); result.put("num", entry.getValue().size());
res.add(result); res.add(result);
......
...@@ -5,10 +5,12 @@ import com.google.common.collect.Lists; ...@@ -5,10 +5,12 @@ import com.google.common.collect.Lists;
import com.zhiwei.brandkbs2.config.Constant; import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.EventDao; import com.zhiwei.brandkbs2.dao.EventDao;
import com.zhiwei.brandkbs2.dao.EventDataDao; import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.dao.EventDisseminationTrendDao;
import com.zhiwei.brandkbs2.dao.EventTopArticlesAnalysisDao; import com.zhiwei.brandkbs2.dao.EventTopArticlesAnalysisDao;
import com.zhiwei.brandkbs2.enmus.EmotionEnum; import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.pojo.Event; import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.EventData; import com.zhiwei.brandkbs2.pojo.EventData;
import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend;
import com.zhiwei.brandkbs2.pojo.EventTopArticlesAnalysis; import com.zhiwei.brandkbs2.pojo.EventTopArticlesAnalysis;
import com.zhiwei.brandkbs2.service.EventDataService; import com.zhiwei.brandkbs2.service.EventDataService;
import com.zhiwei.brandkbs2.service.MarkDataService; import com.zhiwei.brandkbs2.service.MarkDataService;
...@@ -17,9 +19,13 @@ import org.apache.logging.log4j.LogManager; ...@@ -17,9 +19,13 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.joda.time.Period; import org.joda.time.Period;
import org.joda.time.PeriodType; import org.joda.time.PeriodType;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
...@@ -50,6 +56,9 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -50,6 +56,9 @@ public class EventDataServiceImpl implements EventDataService {
@Resource(name = "eventTopArticlesAnalysisDao") @Resource(name = "eventTopArticlesAnalysisDao")
private EventTopArticlesAnalysisDao eventTopArticlesAnalysisDao; private EventTopArticlesAnalysisDao eventTopArticlesAnalysisDao;
@Resource(name = "eventDisseminationTrendDao")
private EventDisseminationTrendDao eventDisseminationTrendDao;
private static final String TOP_DETAIL_TEMPLATE = "Top媒体传播方向:全局Top8的文章中,{0}报道方向占比最高,为{1}%,{2}报道方向占比{3}%。Top报道方向中,《{4}》相似文章数最多,总文章数为{5}篇。"; private static final String TOP_DETAIL_TEMPLATE = "Top媒体传播方向:全局Top8的文章中,{0}报道方向占比最高,为{1}%,{2}报道方向占比{3}%。Top报道方向中,《{4}》相似文章数最多,总文章数为{5}篇。";
@Override @Override
...@@ -104,6 +113,7 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -104,6 +113,7 @@ public class EventDataServiceImpl implements EventDataService {
// 删除历史数据 // 删除历史数据
eventDataDao.deleteByEventId(event.getId(), event.getCollectionName()); eventDataDao.deleteByEventId(event.getId(), event.getCollectionName());
eventTopArticlesAnalysisDao.deleteByEventId(event.getId()); eventTopArticlesAnalysisDao.deleteByEventId(event.getId());
eventDisseminationTrendDao.deleteOneByQuery(Query.query(Criteria.where("eventId").is(event.getId())));
} }
private void setEventStaticState(Event event, List<EventData> eventDataList) { private void setEventStaticState(Event event, List<EventData> eventDataList) {
...@@ -142,12 +152,25 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -142,12 +152,25 @@ public class EventDataServiceImpl implements EventDataService {
JSONObject articlePlatformProportions = new JSONObject(); JSONObject articlePlatformProportions = new JSONObject();
platformIdCounts.forEach((platform, count) -> articlePlatformProportions.put(platform, getProportion(count.get(), totalDisseminationVolume))); platformIdCounts.forEach((platform, count) -> articlePlatformProportions.put(platform, getProportion(count.get(), totalDisseminationVolume)));
// 热门文章分析描述 // 热门文章分析描述
String eventTopArticlesAnalysisDetail = MessageFormat.format(TOP_DETAIL_TEMPLATE, topArticlesAnalysis(eventDataList, event)); String eventTopArticlesAnalysisDetail = MessageFormat.format(TOP_DETAIL_TEMPLATE, topArticlesAnalysis(eventDataList, event).toArray());
event.setStaticState(totalDisseminationVolume, totalChannelVolumes.size(), negativeArticleVolume, articleEmotionProportions, event.setStaticState(totalDisseminationVolume, totalChannelVolumes.size(), negativeArticleVolume, articleEmotionProportions,
articlePlatformProportions, eventTopArticlesAnalysisDetail); articlePlatformProportions, eventTopArticlesAnalysisDetail);
// 传播分析
eventDisseminationTrend(eventDataList, event);
eventDao.updateOne(event); eventDao.updateOne(event);
} }
private void eventDisseminationTrend(List<EventData> eventDataList, Event event) {
// 按时间排序
eventDataList = eventDataList.stream().sorted(Comparator.comparingLong(EventData::getTime)).collect(Collectors.toList());
Long startTime = event.getStartTime();
Long endTime = null == event.getEndTime() ? System.currentTimeMillis() : event.getEndTime();
EventDisseminationTrend hourTrend = EventDisseminationTrend.createFromType(eventDataList, startTime, endTime, "小时", event.getId());
EventDisseminationTrend dayTrend = EventDisseminationTrend.createFromType(eventDataList, startTime, endTime, "天", event.getId());
eventDisseminationTrendDao.insertOne(hourTrend);
eventDisseminationTrendDao.insertOne(dayTrend);
}
private List<String> topArticlesAnalysis(List<EventData> eventDataList, Event event) { private List<String> topArticlesAnalysis(List<EventData> eventDataList, Event event) {
// 标题前8数据 // 标题前8数据
List<Map.Entry<String, List<EventData>>> top8Titles = List<Map.Entry<String, List<EventData>>> top8Titles =
...@@ -199,7 +222,7 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -199,7 +222,7 @@ public class EventDataServiceImpl implements EventDataService {
long sum = emotionMap.values().stream().mapToLong(AtomicLong::get).sum(); long sum = emotionMap.values().stream().mapToLong(AtomicLong::get).sum();
emotionMap.entrySet().stream().sorted((x, y) -> Long.compare(y.getValue().get(), x.getValue().get())).limit(2).forEach(entry -> { emotionMap.entrySet().stream().sorted((x, y) -> Long.compare(y.getValue().get(), x.getValue().get())).limit(2).forEach(entry -> {
details.add(entry.getKey()); details.add(entry.getKey());
details.add(String.valueOf((entry.getValue().get()) / sum)); details.add(new BigDecimal((double) (entry.getValue().get() * 100) / sum).setScale(2, RoundingMode.UP).toString());
}); });
details.add(top8Titles.get(0).getKey()); details.add(top8Titles.get(0).getKey());
details.add(String.valueOf(top8Titles.get(0).getValue().size())); details.add(String.valueOf(top8Titles.get(0).getValue().size()));
......
...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.zhiwei.brandkbs2.auth.UserThreadLocal; import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.RedisKeyPrefix; import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.EventDao; import com.zhiwei.brandkbs2.dao.EventDao;
import com.zhiwei.brandkbs2.dao.EventDataDao; import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.dao.EventDisseminationTrendDao; import com.zhiwei.brandkbs2.dao.EventDisseminationTrendDao;
...@@ -538,6 +539,8 @@ public class EventServiceImpl implements EventService { ...@@ -538,6 +539,8 @@ public class EventServiceImpl implements EventService {
if (Objects.nonNull(eventSearchDTO.getStartTime()) && Objects.nonNull(eventSearchDTO.getEndTime())) { if (Objects.nonNull(eventSearchDTO.getStartTime()) && Objects.nonNull(eventSearchDTO.getEndTime())) {
query.addCriteria(Criteria.where("startTime").gte(eventSearchDTO.getStartTime()).lt(eventSearchDTO.getEndTime())); query.addCriteria(Criteria.where("startTime").gte(eventSearchDTO.getStartTime()).lt(eventSearchDTO.getEndTime()));
} }
// 关键词
eventDao.addKeywordFuzz(query, eventSearchDTO.getKeyword(), "title");
// 传播量 // 传播量
if (Objects.nonNull(eventSearchDTO.getTotalDisseminationVolumes())) { if (Objects.nonNull(eventSearchDTO.getTotalDisseminationVolumes())) {
Long[] totalDisseminationVolumes = eventSearchDTO.getTotalDisseminationVolumes(); Long[] totalDisseminationVolumes = eventSearchDTO.getTotalDisseminationVolumes();
...@@ -568,8 +571,7 @@ public class EventServiceImpl implements EventService { ...@@ -568,8 +571,7 @@ public class EventServiceImpl implements EventService {
sortMap.get(event.getId()).setFirstEventData(r); sortMap.get(event.getId()).setFirstEventData(r);
return null; return null;
})).toArray(CompletableFuture[]::new)).join(); })).toArray(CompletableFuture[]::new)).join();
return PageVO.createPageVo(total, eventSearchDTO.getPage(), eventSearchDTO.getPageSize(), return PageVO.createPageVo(total, eventSearchDTO.getPage(), eventSearchDTO.getPageSize(), eventList.stream().map(event -> sortMap.get(event.getId())).collect(Collectors.toList()));
eventList.stream().map(event -> sortMap.get(event.getId())).collect(Collectors.toList()));
} }
@Override @Override
...@@ -589,31 +591,30 @@ public class EventServiceImpl implements EventService { ...@@ -589,31 +591,30 @@ public class EventServiceImpl implements EventService {
} }
@Override @Override
public List<JSONObject> getEventChannelVoices(String eventId, String type, int page, int pageSize, String sorter) { public PageVO<JSONObject> getEventChannelVoices(String eventId, String type, int page, int pageSize, String sorter) {
Event event = getEventById(eventId); Event event = getEventById(eventId);
Query query = Query.query(Criteria.where("eventId").is(eventId)); Query query = Query.query(Criteria.where("eventId").is(eventId));
if (Objects.equals("重要渠道", type)) { if (Objects.equals("重要渠道", type)) {
query.addCriteria(Criteria.where("mediaType").in(IMPORTANT_CHANNEL_LIST)); query.addCriteria(Criteria.where("mediaType").in(IMPORTANT_CHANNEL_LIST));
} }
mongoUtil.start(page, pageSize, query); // 总量
// 总数
long total = eventDataDao.count(query, event.getCollectionName()); long total = eventDataDao.count(query, event.getCollectionName());
mongoUtil.start(page, pageSize, query);
// 排序 // 排序
eventDataDao.addSort(query, sorter); eventDataDao.addSort(query, sorter);
// 数据 // 数据
List<EventData> eventDataList = eventDataDao.findList(query, event.getCollectionName()); List<EventData> eventDataList = eventDataDao.findList(query, event.getCollectionName());
// 分组排序 List<JSONObject> collect = eventDataList.stream().map(data -> {
Map<String, List<EventData>> groupMap = new HashMap<>();
for (EventData eventData : eventDataList) {
groupMap.putIfAbsent(eventData.getMediaType(), new ArrayList<>());
groupMap.get(eventData.getMediaType()).add(eventData);
}
return groupMap.entrySet().stream().map(entry -> {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("type", entry.getKey()); json.put("title", data.getTitle());
json.put("list", entry.getValue()); json.put("url", data.getUrl());
json.put("time", data.getTime());
json.put("source", data.getSource());
json.put("emotion", data.getEmotion());
json.put("mediaType", data.getMediaType());
return json; return json;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return PageVO.createPageVo(total, page, pageSize, collect);
} }
@Override @Override
...@@ -632,10 +633,10 @@ public class EventServiceImpl implements EventService { ...@@ -632,10 +633,10 @@ public class EventServiceImpl implements EventService {
switch (type) { switch (type) {
case "按时间": case "按时间":
Map<String, List<EventTopArticlesAnalysisVO>> collect = eventTopArticlesAnalyses.stream().map(eventTopArticlesAnalysis -> { Map<String, List<EventTopArticlesAnalysisVO>> collect = eventTopArticlesAnalyses.stream().map(eventTopArticlesAnalysis -> {
boolean highLight = Objects.equals(aggTitle, eventTopArticlesAnalysis.getAggTitle()); boolean highLight = null == aggTitle || Objects.equals(aggTitle, eventTopArticlesAnalysis.getAggTitle());
return new EventTopArticlesAnalysisVO(eventTopArticlesAnalysis, highLight); return new EventTopArticlesAnalysisVO(eventTopArticlesAnalysis, highLight);
}).collect(Collectors.groupingBy(EventTopArticlesAnalysisVO::getTimePoint)); }).collect(Collectors.groupingBy(EventTopArticlesAnalysisVO::getTimePoint));
res.put("dataDay", collect); res.put("dataDay", Tools.sortTimeKeyMap(collect, Constant.SPEC_DAY_FORMAT, false));
res.put("dataAmount", null); res.put("dataAmount", null);
return res; return res;
case "按数量": case "按数量":
...@@ -647,6 +648,21 @@ public class EventServiceImpl implements EventService { ...@@ -647,6 +648,21 @@ public class EventServiceImpl implements EventService {
} }
} }
@Override
public List<JSONObject> getLastEventTop(String keyword, int limit) {
Query query = Query.query(Criteria.where("projectId").is(UserThreadLocal.getProjectId()));
eventDao.addKeywordFuzz(query, keyword, "title");
eventDao.addSort(query, "{\"startTime\":\"descend\"}");
query.limit(limit);
return eventDao.findList(query).stream().map(event -> {
JSONObject result = new JSONObject();
result.put("id", event.getId());
result.put("title", event.getTitle());
result.put("total", event.getTotalDisseminationVolume());
return result;
}).sorted((o1, o2) -> Long.compare((long) o2.get("total"), (long) o1.get("total"))).collect(Collectors.toList());
}
/** /**
* 获取时间筛选条件 * 获取时间筛选条件
* *
......
...@@ -99,7 +99,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -99,7 +99,7 @@ public class IndexServiceImpl implements IndexService {
jsonObject.put("compare", lastRangeCount == 0 ? 0d : (rangeCount - lastRangeCount) / (double) lastRangeCount); jsonObject.put("compare", lastRangeCount == 0 ? 0d : (rangeCount - lastRangeCount) / (double) lastRangeCount);
List<Map<String, Long>> dayList = Tools.parseToDaysWithBase(startTime, endTime); List<Map<String, Long>> dayList = Tools.parseToDaysWithBase(startTime, endTime);
jsonObject.put("spread", this.getArticleSpreadWithBrand(projectId, Constant.PRIMARY_CONTEND_ID, dayList)); jsonObject.put("spread", this.getArticleSpreadWithBrand(projectId, Constant.PRIMARY_CONTEND_ID, dayList));
redisUtil.set(redisKey, JSON.toJSONString(jsonObject)); redisUtil.setExpire(redisKey, JSON.toJSONString(jsonObject));
} catch (Exception e) { } catch (Exception e) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("getYuqingAmount异常"), e); ExceptionCast.cast(CommonCodeEnum.FAIL.message("getYuqingAmount异常"), e);
} }
...@@ -156,7 +156,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -156,7 +156,7 @@ public class IndexServiceImpl implements IndexService {
jsonObject.put("compare", oldPosPro == 0 ? 0d : (posPro - oldPosPro) / oldPosPro); jsonObject.put("compare", oldPosPro == 0 ? 0d : (posPro - oldPosPro) / oldPosPro);
double avgPosPro = totalNormalCount == 0 ? 0d : totalPositiveCount / (double) totalNormalCount; double avgPosPro = totalNormalCount == 0 ? 0d : totalPositiveCount / (double) totalNormalCount;
jsonObject.put("avgPosPro", avgPosPro); jsonObject.put("avgPosPro", avgPosPro);
redisUtil.set(redisKey, JSON.toJSONString(jsonObject)); redisUtil.setExpire(redisKey, JSON.toJSONString(jsonObject));
} catch (IOException e) { } catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("es查询异常"), e); ExceptionCast.cast(CommonCodeEnum.FAIL.message("es查询异常"), e);
} }
...@@ -212,7 +212,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -212,7 +212,7 @@ public class IndexServiceImpl implements IndexService {
} }
} }
jsonObject.put("spread", lineList); jsonObject.put("spread", lineList);
redisUtil.set(redisKey, JSONObject.toJSONString(jsonObject)); redisUtil.setExpire(redisKey, JSONObject.toJSONString(jsonObject));
} catch (Exception e) { } catch (Exception e) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("getEventAmount异常"), e); ExceptionCast.cast(CommonCodeEnum.FAIL.message("getEventAmount异常"), e);
} }
...@@ -237,7 +237,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -237,7 +237,7 @@ public class IndexServiceImpl implements IndexService {
try { try {
long normalCount = markDataService.getYuqingMarkCount(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId); long normalCount = markDataService.getYuqingMarkCount(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId);
List<JSONObject> platforms = getPlatformProportionWithPlatform(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId, normalCount); List<JSONObject> platforms = getPlatformProportionWithPlatform(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId, normalCount);
redisUtil.set(redisKey, JSON.toJSONString(platforms)); redisUtil.setExpire(redisKey, JSON.toJSONString(platforms));
return platforms; return platforms;
} catch (IOException e) { } catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("es查询异常"), e); ExceptionCast.cast(CommonCodeEnum.FAIL.message("es查询异常"), e);
...@@ -247,6 +247,11 @@ public class IndexServiceImpl implements IndexService { ...@@ -247,6 +247,11 @@ public class IndexServiceImpl implements IndexService {
@Override @Override
public JSONObject getSpreadingTend(Long startTime, Long endTime, boolean cache) { public JSONObject getSpreadingTend(Long startTime, Long endTime, boolean cache) {
return getSpreadingTend(startTime, endTime, UserThreadLocal.getProjectId(), "0", cache);
}
@Override
public JSONObject getSpreadingTend(Long startTime, Long endTime, String projectId, String contendId, boolean cache) {
boolean flag = true; boolean flag = true;
if (null == startTime || null == endTime) { if (null == startTime || null == endTime) {
Long[] timeRangeMonth = commonService.getTimeRangeMonth(); Long[] timeRangeMonth = commonService.getTimeRangeMonth();
...@@ -254,9 +259,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -254,9 +259,7 @@ public class IndexServiceImpl implements IndexService {
endTime = timeRangeMonth[1]; endTime = timeRangeMonth[1];
flag = false; flag = false;
} }
String projectId = UserThreadLocal.getProjectId();
String linkedGroupId = projectService.getProjectById(projectId).getBrandLinkedGroupId(); String linkedGroupId = projectService.getProjectById(projectId).getBrandLinkedGroupId();
String contendId = "0";
String redisKey = RedisUtil.getIndexSpread(projectId, startTime, endTime); String redisKey = RedisUtil.getIndexSpread(projectId, startTime, endTime);
String resultStr; String resultStr;
// 返回缓存 // 返回缓存
...@@ -287,7 +290,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -287,7 +290,7 @@ public class IndexServiceImpl implements IndexService {
summary.put("topEvent", this.getTopEvent(startTime, endTime, projectId, contendId)); summary.put("topEvent", this.getTopEvent(startTime, endTime, projectId, contendId));
summary.put("topSource", this.getTopSource(startTime, endTime, projectId, linkedGroupId, contendId)); summary.put("topSource", this.getTopSource(startTime, endTime, projectId, linkedGroupId, contendId));
resJson.put("summary", summary); resJson.put("summary", summary);
redisUtil.set(redisKey, JSON.toJSONString(resJson)); redisUtil.setExpire(redisKey, JSON.toJSONString(resJson));
} catch (IOException e) { } catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("es查询异常"), e); ExceptionCast.cast(CommonCodeEnum.FAIL.message("es查询异常"), e);
} }
...@@ -305,7 +308,7 @@ public class IndexServiceImpl implements IndexService { ...@@ -305,7 +308,7 @@ public class IndexServiceImpl implements IndexService {
} catch (IOException ignored) { } catch (IOException ignored) {
count = -1; count = -1;
} }
result.put("platform", platformId); result.put("platform", GlobalPojo.getPlatformNameById(platformId));
result.put("num", count); result.put("num", count);
result.put("proportion", normalCount == 0 ? 0d : count / (double) normalCount); result.put("proportion", normalCount == 0 ? 0d : count / (double) normalCount);
resultList.add(result); resultList.add(result);
......
...@@ -37,6 +37,7 @@ import java.nio.ByteBuffer; ...@@ -37,6 +37,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel; import java.nio.channels.WritableByteChannel;
import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -446,6 +447,17 @@ public class Tools { ...@@ -446,6 +447,17 @@ public class Tools {
/** /**
* 日期取整,去掉时分秒 * 日期取整,去掉时分秒
* *
* @param time
* @param pattern
* @return
*/
public static Long truncDate(Long time, String pattern) {
return truncDate(new Date(time), pattern).getTime();
}
/**
* 日期取整,去掉时分秒
*
* @param date * @param date
* @return Date * @return Date
* @Title: truncDate * @Title: truncDate
...@@ -782,7 +794,6 @@ public class Tools { ...@@ -782,7 +794,6 @@ public class Tools {
* @return 按小时分割的map集合 * @return 按小时分割的map集合
*/ */
public static List<Map<String, Long>> parseToHours(Long startTime, Long endTime) { public static List<Map<String, Long>> parseToHours(Long startTime, Long endTime) {
FastDateFormat df = HOUR_FORMAT;
Date start = Tools.truncDate(new Date(startTime), Constant.HOUR_PATTERN); Date start = Tools.truncDate(new Date(startTime), Constant.HOUR_PATTERN);
Date end = Tools.truncDate(new Date(endTime), Constant.HOUR_PATTERN); Date end = Tools.truncDate(new Date(endTime), Constant.HOUR_PATTERN);
Period periodHour = new Period(start.getTime(), end.getTime(), PeriodType.hours()); Period periodHour = new Period(start.getTime(), end.getTime(), PeriodType.hours());
...@@ -805,8 +816,8 @@ public class Tools { ...@@ -805,8 +816,8 @@ public class Tools {
/** /**
* 解析时间转换成按月基数时间的集合 * 解析时间转换成按月基数时间的集合
* *
* @param startTime 开始时间 * @param startLong 开始时间
* @param endTime 结束时间 * @param endLong 结束时间
* @return 按月基数分割时间的集合 * @return 按月基数分割时间的集合
*/ */
public static List<Map<String, Long>> parseToDaysWithBase(Long startLong, Long endLong) { public static List<Map<String, Long>> parseToDaysWithBase(Long startLong, Long endLong) {
...@@ -842,6 +853,7 @@ public class Tools { ...@@ -842,6 +853,7 @@ public class Tools {
*/ */
public static boolean isContains(List<String> keywords, String content) { public static boolean isContains(List<String> keywords, String content) {
boolean contains = true; boolean contains = true;
if (null != keywords) {
content = content.toLowerCase(); content = content.toLowerCase();
// 按空格分割必须全部命中 // 按空格分割必须全部命中
for (String keyword : keywords) { for (String keyword : keywords) {
...@@ -852,11 +864,12 @@ public class Tools { ...@@ -852,11 +864,12 @@ public class Tools {
} }
} }
} }
}
return contains; return contains;
} }
public static JSONObject getBrandkbsHitMap(Map<String, Object> esMap, String hitKey) { public static JSONObject getBrandkbsHitMap(Map<String, Object> esMap, String hitKey) {
List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) esMap.get("brandkbs_cache_maps"); List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) esMap.get(GenericAttribute.ES_BRANDKBS_CACHE_MAPS);
for (Map<String, Object> cacheMap : cacheMaps) { for (Map<String, Object> cacheMap : cacheMaps) {
if (hitKey.equals(cacheMap.get("key"))) { if (hitKey.equals(cacheMap.get("key"))) {
return new JSONObject(cacheMap); return new JSONObject(cacheMap);
...@@ -865,6 +878,26 @@ public class Tools { ...@@ -865,6 +878,26 @@ public class Tools {
return new JSONObject(); return new JSONObject();
} }
public static <T> Map<String, T> sortTimeKeyMap(Map<String, T> map, FastDateFormat timePattern, boolean isDesc) {
Map<String, T> res = new LinkedHashMap<>();
List<Map.Entry<String, T>> sortKey = map.entrySet().stream().sorted((x, y) -> {
try {
long xTime = timePattern.parse(x.getKey()).getTime();
long yTime = timePattern.parse(y.getKey()).getTime();
if (isDesc) {
return Long.compare(yTime, xTime);
}
return Long.compare(xTime, yTime);
} catch (ParseException e) {
return 0;
}
}).collect(Collectors.toList());
for (Map.Entry<String, T> longTEntry : sortKey) {
res.put(longTEntry.getKey(), longTEntry.getValue());
}
return res;
}
public static <T> Map<Long, T> sortTimeKeyMap(Map<Long, T> map, boolean isDesc) { public static <T> Map<Long, T> sortTimeKeyMap(Map<Long, T> map, boolean isDesc) {
Map<Long, T> res = new LinkedHashMap<>(); Map<Long, T> res = new LinkedHashMap<>();
List<Map.Entry<Long, T>> sortKey = map.entrySet().stream().sorted((x, y) -> { List<Map.Entry<Long, T>> sortKey = map.entrySet().stream().sorted((x, y) -> {
......
...@@ -76,3 +76,7 @@ ef.searchCriteria.url=https://ef.zhiweidata.com/index/getSearchKey.do ...@@ -76,3 +76,7 @@ ef.searchCriteria.url=https://ef.zhiweidata.com/index/getSearchKey.do
ef.filterNew.url=https://ef.zhiweidata.com/filterNew.do?firstType={1}&start={2}&end={3}&page={4} ef.filterNew.url=https://ef.zhiweidata.com/filterNew.do?firstType={1}&start={2}&end={3}&page={4}
ef.captcha.url=https://ef.zhiweidata.com/captchaApi/getNewCaptcha.do.do?type=test ef.captcha.url=https://ef.zhiweidata.com/captchaApi/getNewCaptcha.do.do?type=test
ef.checkCaptcha.url=https://ef.zhiweidata.com/captchaApi/checkeCaptcha.do.do?id={1}&captcha={2}&type=test ef.checkCaptcha.url=https://ef.zhiweidata.com/captchaApi/checkeCaptcha.do.do?id={1}&captcha={2}&type=test
#\u5168\u7F51\u641C\u5916\u90E8\u63A5\u53E3
istarshine.addIStarShineKSData.url=https://istarshine-service.zhiweidata.com/istarshine/ks/addIStarShineKSData
istarshine.getIStarShineKSInfoData.url=https://istarshine-service.zhiweidata.com/istarshine/ks/getIStarShineKSInfoData?taskId={1}&appId=6183571e0d710000f6003a12
whole.search.url=https://yuqing.zhiweidata.com/qbjcbackPhoenix/interface/middleware/search/yuqing
\ No newline at end of file
spring.profiles.active=pro spring.profiles.active=local
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