Commit b8ca7a5c by 陈健智

事件其他方法接入

parent eb7f9e2e
...@@ -12,6 +12,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult; ...@@ -12,6 +12,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.dto.*; import com.zhiwei.brandkbs2.pojo.dto.*;
import com.zhiwei.brandkbs2.service.*; import com.zhiwei.brandkbs2.service.*;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.event.pojo.dto.BrandkbsEventSearchDTO;
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.apache.commons.lang3.time.DateUtils;
...@@ -203,6 +204,18 @@ public class AppSearchController extends BaseController { ...@@ -203,6 +204,18 @@ public class AppSearchController extends BaseController {
return ResponseResult.success(eventService.getEventList(eventSearchDTO)); return ResponseResult.success(eventService.getEventList(eventSearchDTO));
} }
@ApiOperation("搜索-前台事件库-搜索条件-新")
@GetMapping("/event/criteria/{brandId}")
public ResponseResult getEventSearchCriteriaMiddleware(@PathVariable String brandId){
return ResponseResult.success(eventService.getEventListCriteria(brandId));
}
@ApiOperation("搜索-前台事件库-品牌事件库-新")
@PostMapping("/event/newList")
public ResponseResult getEventListMiddleware(@RequestBody BrandkbsEventSearchDTO dto){
return ResponseResult.success(eventService.getEventListMiddleware(dto));
}
@ApiOperation("搜索-查竞品") @ApiOperation("搜索-查竞品")
@PostMapping("/contend/list") @PostMapping("/contend/list")
public ResponseResult getContendSearchList(@RequestBody MarkSearchDTO markSearchDTO) { public ResponseResult getContendSearchList(@RequestBody MarkSearchDTO markSearchDTO) {
......
...@@ -54,6 +54,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -54,6 +54,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
} }
@Override @Override
@Deprecated
public List<String> getEvents(ChannelIndex channelIndex) { public List<String> getEvents(ChannelIndex channelIndex) {
// 添加渠道唯一标识 // 添加渠道唯一标识
Criteria criteria = addChannelIndex(channelIndex); Criteria criteria = addChannelIndex(channelIndex);
...@@ -68,18 +69,21 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -68,18 +69,21 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
} }
@Override @Override
@Deprecated
public Map<Long, List<Event>> getEventDay(ChannelIndex channelIndex, Long startTime, Long endTime) { public Map<Long, List<Event>> getEventDay(ChannelIndex channelIndex, Long startTime, Long endTime) {
// return getEventTimePattern(channelIndex, startTime, endTime, 8 + 2); // return getEventTimePattern(channelIndex, startTime, endTime, 8 + 2);
return getEventTimePatternNew(channelIndex, startTime, endTime, false); return getEventTimePatternNew(channelIndex, startTime, endTime, false);
} }
@Override @Override
@Deprecated
public Map<Long, List<Event>> getEventMonth(ChannelIndex channelIndex, Long startTime, Long endTime) { public Map<Long, List<Event>> getEventMonth(ChannelIndex channelIndex, Long startTime, Long endTime) {
// return getEventTimePattern(channelIndex, startTime, endTime, 6 + 1); // return getEventTimePattern(channelIndex, startTime, endTime, 6 + 1);
return getEventTimePatternNew(channelIndex, startTime, endTime, true); return getEventTimePatternNew(channelIndex, startTime, endTime, true);
} }
@Override @Override
@Deprecated
public long getEventCount(ChannelIndex channelIndex, List<String> eventEmotions, String emotion) { public long getEventCount(ChannelIndex channelIndex, List<String> eventEmotions, String emotion) {
long res = 0; long res = 0;
Criteria criteria = Criteria.where("channelFid").is(channelIndex.getFid()); Criteria criteria = Criteria.where("channelFid").is(channelIndex.getFid());
...@@ -98,11 +102,13 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -98,11 +102,13 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
} }
@Override @Override
@Deprecated
public long getEventCountByProjectIdAndContendId(Long startTime, Long endTime, String emotion, String projectId, String contendId) { public long getEventCountByProjectIdAndContendId(Long startTime, Long endTime, String emotion, String projectId, String contendId) {
return mongoTemplate.count(Query.query(eventCountCriteria(startTime, endTime, emotion, projectId, contendId)), COLLECTION_NAME); return mongoTemplate.count(Query.query(eventCountCriteria(startTime, endTime, emotion, projectId, contendId)), COLLECTION_NAME);
} }
@Override @Override
@Deprecated
public List<Event> getEventsByProjectIdAndContendId(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit) { public List<Event> getEventsByProjectIdAndContendId(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit) {
Query query = new Query(); Query query = new Query();
Criteria criteria = eventCountCriteria(startTime, endTime, emotion, projectId, contendId); Criteria criteria = eventCountCriteria(startTime, endTime, emotion, projectId, contendId);
...@@ -114,6 +120,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -114,6 +120,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
} }
@Override @Override
@Deprecated
public List<Event> getEventsByProjectIdAndContendId(Long startTime, Long endTime, List<String> emotions, String projectId, String contendId, int limit) { public List<Event> getEventsByProjectIdAndContendId(Long startTime, Long endTime, List<String> emotions, String projectId, String contendId, int limit) {
Query query = new Query(); Query query = new Query();
Criteria criteria = eventCountCriteria(startTime, endTime, emotions, projectId, contendId); Criteria criteria = eventCountCriteria(startTime, endTime, emotions, projectId, contendId);
...@@ -125,6 +132,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -125,6 +132,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
} }
@Override @Override
@Deprecated
public List<Event> getEventsByTotalChannelVolumeTop(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit) { public List<Event> getEventsByTotalChannelVolumeTop(Long startTime, Long endTime, String emotion, String projectId, String contendId, int limit) {
Query query = new Query(); Query query = new Query();
Criteria criteria = eventCountCriteria(startTime, endTime, emotion, projectId, contendId); Criteria criteria = eventCountCriteria(startTime, endTime, emotion, projectId, contendId);
...@@ -135,6 +143,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -135,6 +143,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
return mongoTemplate.find(query, clazz, COLLECTION_NAME); return mongoTemplate.find(query, clazz, COLLECTION_NAME);
} }
@Deprecated
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);
...@@ -257,6 +266,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -257,6 +266,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
return res; return res;
} }
@Deprecated
private Map<Long, List<Event>> getEventTimePatternNew(ChannelIndex channelIndex, Long startTime, Long endTime, boolean month) { private Map<Long, List<Event>> getEventTimePatternNew(ChannelIndex channelIndex, Long startTime, Long endTime, boolean month) {
Map<Long, List<Event>> res = new HashMap<>(); Map<Long, List<Event>> res = new HashMap<>();
String pattern; String pattern;
......
...@@ -58,11 +58,13 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve ...@@ -58,11 +58,13 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve
} }
@Override @Override
@Deprecated
public long getEventArticleCount(Event event) { public long getEventArticleCount(Event event) {
return count(Query.query(Criteria.where("eventId").is(event.getId())), event.getCollectionName()); return count(Query.query(Criteria.where("eventId").is(event.getId())), event.getCollectionName());
} }
@Override @Override
@Deprecated
public long getEventArticleWithChannelCount(Event event, ChannelIndex channelIndex) { public long getEventArticleWithChannelCount(Event event, ChannelIndex channelIndex) {
return count(Query.query(Criteria.where("eventId").is(event.getId()).and("source").is(channelIndex.getSource()).and("realSource").is(channelIndex.getRealSource()).and("platform").is(channelIndex.getPlatform())), event.getCollectionName()); return count(Query.query(Criteria.where("eventId").is(event.getId()).and("source").is(channelIndex.getSource()).and("realSource").is(channelIndex.getRealSource()).and("platform").is(channelIndex.getPlatform())), event.getCollectionName());
} }
...@@ -73,6 +75,7 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve ...@@ -73,6 +75,7 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve
} }
@Override @Override
@Deprecated
public List<EventData> findEventDataListByTime(String eventId, Date startTime, Date endTime, String collectionName) { public List<EventData> findEventDataListByTime(String eventId, Date startTime, Date endTime, String collectionName) {
Query query = Query.query(Criteria.where("eventId").is(eventId)); Query query = Query.query(Criteria.where("eventId").is(eventId));
query.addCriteria(Criteria.where("time").gte(startTime).lt(endTime)); query.addCriteria(Criteria.where("time").gte(startTime).lt(endTime));
...@@ -80,12 +83,14 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve ...@@ -80,12 +83,14 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve
} }
@Override @Override
@Deprecated
public long findEventDataCount(String eventId, String collectionName) { public long findEventDataCount(String eventId, String collectionName) {
Query query = Query.query(Criteria.where("eventId").is(eventId)); Query query = Query.query(Criteria.where("eventId").is(eventId));
return mongoTemplate.count(query, EventData.class, collectionName); return mongoTemplate.count(query, EventData.class, collectionName);
} }
@Override @Override
@Deprecated
public Set<String> findEventIdsByChannelFid(String channelFid, long startTime, long endTime) { public Set<String> findEventIdsByChannelFid(String channelFid, long startTime, long endTime) {
Set<String> res = new HashSet<>(); Set<String> res = new HashSet<>();
Criteria criteria = Criteria.where("channelFid").is(channelFid).and("eventMapper.startTime").gte(startTime).lt(endTime); Criteria criteria = Criteria.where("channelFid").is(channelFid).and("eventMapper.startTime").gte(startTime).lt(endTime);
......
...@@ -2,7 +2,8 @@ package com.zhiwei.brandkbs2.pojo.dto; ...@@ -2,7 +2,8 @@ package com.zhiwei.brandkbs2.pojo.dto;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.zhiwei.brandkbs2.enmus.EventTagEnum; import com.zhiwei.brandkbs2.enmus.EventTagEnum;
import com.zhiwei.brandkbs2.pojo.Event; import com.zhiwei.middleware.event.pojo.entity.Event;
import com.zhiwei.middleware.event.pojo.entity.EventTagBasicInfo;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
...@@ -39,10 +40,15 @@ public class ExportAppChannelEventDTO { ...@@ -39,10 +40,15 @@ public class ExportAppChannelEventDTO {
ExportAppChannelEventDTO dto = new ExportAppChannelEventDTO(); ExportAppChannelEventDTO dto = new ExportAppChannelEventDTO();
dto.setStartTime(new Date(event.getStartTime())); dto.setStartTime(new Date(event.getStartTime()));
dto.setEndTime(new Date(event.getEndTime())); dto.setEndTime(new Date(event.getEndTime()));
dto.setTitle(event.getTitle()); dto.setTitle(event.getName());
dto.setEmotion(event.getEmotion()); dto.setEmotion(event.getEmotionEventTag().getName());
dto.setInfluence(event.getInfluence()); dto.setInfluence(event.getInfluence());
dto.setEventType(event.getEventTag().getString(EventTagEnum.EVENT_TYPE.getName())); dto.setEventType(null);
for (EventTagBasicInfo eventTag : event.getEventTags()) {
if (eventTag.getGroupName().equals(EventTagEnum.EVENT_TYPE.getName())){
dto.setEventType(eventTag.getName());
}
}
return dto; return dto;
} }
} }
package com.zhiwei.brandkbs2.pojo.external; package com.zhiwei.brandkbs2.pojo.external;
import com.zhiwei.brandkbs2.pojo.Event; import com.zhiwei.middleware.event.pojo.entity.Event;
import com.zhiwei.middleware.event.pojo.entity.EventTagBasicInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
...@@ -65,14 +66,16 @@ public class BrandkbsHotEventWarn { ...@@ -65,14 +66,16 @@ public class BrandkbsHotEventWarn {
public static HotEvent createFromEvent(String type, Event event) { public static HotEvent createFromEvent(String type, Event event) {
HotEvent hotEvent = new HotEvent(); HotEvent hotEvent = new HotEvent();
hotEvent.setType(type); hotEvent.setType(type);
hotEvent.setTitle(event.getTitle()); hotEvent.setTitle(event.getName());
hotEvent.setEmotion(event.getEmotion()); hotEvent.setEmotion(event.getEmotionEventTag().getName());
hotEvent.setTotalChannelVolume(event.getTotalChannelVolume()); hotEvent.setTotalChannelVolume(event.getTotalChannelVolume());
hotEvent.setTotalDisseminationVolume(event.getTotalDisseminationVolume()); hotEvent.setTotalDisseminationVolume(event.getTotalDisseminationVolume());
hotEvent.setStartTime(event.getStartTime()); hotEvent.setStartTime(event.getStartTime());
hotEvent.setInfluence(event.getInfluence()); hotEvent.setInfluence(event.getInfluence());
List<String> tagList = // List<String> tagList = event.getEventTag().entrySet().stream().filter(entry -> !"情感倾向".equals(entry.getKey()))
event.getEventTag().entrySet().stream().filter(entry -> !"情感倾向".equals(entry.getKey())).map(entry -> String.valueOf(entry.getValue())).collect(Collectors.toList()); // .map(entry -> String.valueOf(entry.getValue())).collect(Collectors.toList());
List<String> tagList = event.getEventTags().stream().filter(eventTagBasicInfo -> !"情感倾向".equals(eventTagBasicInfo.getGroupName()))
.map(EventTagBasicInfo::getName).collect(Collectors.toList());
hotEvent.setTagList(tagList); hotEvent.setTagList(tagList);
return hotEvent; return hotEvent;
} }
......
...@@ -32,6 +32,9 @@ import com.zhiwei.brandkbs2.service.ProjectService; ...@@ -32,6 +32,9 @@ import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.MongoUtil; import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.RedisUtil; import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.event.core.EventClient;
import com.zhiwei.middleware.event.pojo.entity.Event;
import com.zhiwei.middleware.event.pojo.entity.EventTagBasicInfo;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
...@@ -52,6 +55,7 @@ import org.elasticsearch.search.sort.SortBuilders; ...@@ -52,6 +55,7 @@ import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.joda.time.Period; import org.joda.time.Period;
import org.joda.time.PeriodType; import org.joda.time.PeriodType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
...@@ -115,6 +119,9 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -115,6 +119,9 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "esSearchExecutor") @Resource(name = "esSearchExecutor")
ThreadPoolTaskExecutor esSearchExecutor; ThreadPoolTaskExecutor esSearchExecutor;
@Autowired
private EventClient eventClient;
@Override @Override
public PageVO<JSONObject> findChannelList(int page, int size, String contendId, String emotion, String platform, public PageVO<JSONObject> findChannelList(int page, int size, String contendId, String emotion, String platform,
Boolean show, String keyword, String sorter) { Boolean show, String keyword, String sorter) {
...@@ -229,26 +236,28 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -229,26 +236,28 @@ public class ChannelServiceImpl implements ChannelService {
@Override @Override
public PageVO<JSONObject> findEventList(int page, int size, String channelId) { public PageVO<JSONObject> findEventList(int page, int size, String channelId) {
Channel channel = channelDao.findOneById(channelId); Channel channel = channelDao.findOneById(channelId);
List<String> eventIds = eventDao.getEvents(channel.getChannelIndex()); List<String> eventIds = eventClient.getEvents(channel.getChannelIndex().getFid());
Query query = Query.query(Criteria.where("_id").in(eventIds)); long total = eventClient.countInEventIds(eventIds);
long total = eventDao.count(query); // mongoUtil.start(page, size, query);
mongoUtil.start(page, size, query); List<com.zhiwei.middleware.event.pojo.entity.Event> list = eventClient.findListInEventIds(eventIds, page, size);
List<Event> list = eventDao.findList(query); List<JSONObject> resList = new ArrayList<>();
List<JSONObject> resList = list.stream().map(event -> { if (CollectionUtils.isNotEmpty(list)) {
resList = list.stream().map(event -> {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("id", event.getId()); json.put("id", event.getId());
json.put("title", event.getTitle()); json.put("title", event.getName());
json.put("startTime", event.getStartTime()); json.put("startTime", event.getStartTime());
json.put("emotion", event.getEmotion()); json.put("emotion", event.getEmotionEventTag().getName());
Query query1 = new Query(); // Query query1 = new Query();
query1.addCriteria(Criteria.where("eventId").is(event.getId())); // query1.addCriteria(Criteria.where("eventId").is(event.getId()));
json.put("total", eventDataDao.count(query1, event.getCollectionName())); json.put("total", eventClient.countEventDataByEventId(event));
query1.addCriteria(channelDao.addChannelIndex(channel.getChannelIndex())); // query1.addCriteria(channelDao.addChannelIndex(channel.getChannelIndex()));
json.put("channelTotal", eventDataDao.count(query1, event.getCollectionName())); // query1.addCriteria(Criteria.where("eventBrandkbsChannels.channelFid").is(channel.getChannelIndex().getFid()));
json.put("channelTotal", eventClient.countEventDataByEventIdAndFid(event, channel.getChannelIndex().getFid()));
return json; return json;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
MongoUtil.PageHelper<JSONObject> pageHelper = mongoUtil.pageHelper(total, resList); }
return PageVO.createPageVo(pageHelper, resList); return PageVO.createPageVo(total, page, size, resList);
} }
@Override @Override
...@@ -327,24 +336,30 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -327,24 +336,30 @@ public class ChannelServiceImpl implements ChannelService {
public List<ExportAdminChannelEventDTO> findDownloadChannelEventList(String channelId) { public List<ExportAdminChannelEventDTO> findDownloadChannelEventList(String channelId) {
List<ExportAdminChannelEventDTO> resList = new ArrayList<>(); List<ExportAdminChannelEventDTO> resList = new ArrayList<>();
Channel channel = channelDao.findOneById(channelId); Channel channel = channelDao.findOneById(channelId);
List<String> eventIds = eventDao.getEvents(channel.getChannelIndex()); List<String> eventIds = eventClient.getEvents(channel.getChannelIndex().getFid());
if (CollectionUtils.isEmpty(eventIds)) { if (CollectionUtils.isEmpty(eventIds)) {
return resList; return resList;
} }
List<Event> events = eventDao.findList(Query.query(Criteria.where("_id").in(eventIds))); List<com.zhiwei.middleware.event.pojo.entity.Event> events = eventClient.findListInEventIds(eventIds);
return events.stream().map(event -> { return events.stream().map(event -> {
ExportAdminChannelEventDTO dto = Tools.convertMap(event, ExportAdminChannelEventDTO.class); ExportAdminChannelEventDTO dto = Tools.convertMap(event, ExportAdminChannelEventDTO.class);
dto.setTitle(event.getName());
// 首发信息 // 首发信息
EventData firstData = eventDataDao.findFirstData(event.getId(), event.getCollectionName()); com.zhiwei.middleware.event.pojo.entity.EventData firstData = event.getOriginArticle();
if (null != firstData) { if (null != firstData) {
dto.setFirstPlatform(firstData.getPlatform()); dto.setFirstPlatform(firstData.getPlatform());
dto.setFirstRealSource(firstData.getRealSource()); dto.setFirstRealSource(firstData.getRealSource());
dto.setFirstSource(firstData.getSource()); dto.setFirstSource(firstData.getSource());
} }
dto.setEventArticleCount(eventDataDao.getEventArticleCount(event)); dto.setEventArticleCount(eventClient.getEventArticleCount(event));
dto.setChannelArticleCount( ChannelIndex channelIndex = Tools.convertMap(channel, ChannelIndex.class);
eventDataDao.getEventArticleWithChannelCount(event, Tools.convertMap(channel, ChannelIndex.class))); dto.setChannelArticleCount(eventClient.getEventArticleWithChannelCount(event, channelIndex.getSource(), channelIndex.getRealSource(), channelIndex.getPlatform()));
dto.setEventType(event.getEventTag().getString(EventTagEnum.EVENT_TYPE.getName())); dto.setEventType(null);
for (EventTagBasicInfo eventTag : event.getEventTags()) {
if (eventTag.getGroupName().equals(EventTagEnum.EVENT_TYPE.getName())){
dto.setEventType(eventTag.getName());
}
}
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
...@@ -661,8 +676,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -661,8 +676,7 @@ public class ChannelServiceImpl implements ChannelService {
} }
// 根据品牌分类 // 根据品牌分类
List<String> contendList = Arrays.asList(contends.split(",")); List<String> contendList = Arrays.asList(contends.split(","));
Map<String, List<ChannelIndex.Article>> contendMap = getSourceContendMap(channelId, contendList, startTime, Map<String, List<ChannelIndex.Article>> contendMap = getSourceContendMap(channelId, contendList, startTime, endTime);
endTime);
Channel channel = channelDao.findOneById(channelId); Channel channel = channelDao.findOneById(channelId);
long articleTotal = 0; long articleTotal = 0;
long eventTotal = 0; long eventTotal = 0;
...@@ -768,13 +782,13 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -768,13 +782,13 @@ public class ChannelServiceImpl implements ChannelService {
return dayResult; return dayResult;
} }
private JSONObject getDayResultWithEvent(List<Event> list, int page, int pageSize, Long time) { private JSONObject getDayResultWithEvent(List<com.zhiwei.middleware.event.pojo.entity.Event> list, int page, int pageSize, Long time) {
JSONObject dayResult = new JSONObject(); JSONObject dayResult = new JSONObject();
List<JSONObject> collect = list.stream().skip((long) (page - 1) * pageSize).limit(pageSize).map(event -> { List<JSONObject> collect = list.stream().skip((long) (page - 1) * pageSize).limit(pageSize).map(event -> {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("id", event.getId()); json.put("id", event.getId());
json.put("emotion", event.getEmotion()); json.put("emotion", event.getEmotionEventTag().getName());
json.put("title", event.getTitle()); json.put("title", event.getName());
json.put("influence", event.getInfluence()); json.put("influence", event.getInfluence());
return json; return json;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
...@@ -805,8 +819,8 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -805,8 +819,8 @@ public class ChannelServiceImpl implements ChannelService {
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
List<JSONObject> dayList = new ArrayList<>(); List<JSONObject> dayList = new ArrayList<>();
Channel channel = channelDao.findOneById(channelId); Channel channel = channelDao.findOneById(channelId);
Map<Long, List<Event>> eventDay = eventDao.getEventDay(new ChannelIndex(channel, contendId), startTime, Map<Long, List<com.zhiwei.middleware.event.pojo.entity.Event>> eventDay =
endTime); eventClient.getEventDay(new ChannelIndex(channel, contendId).getFid(), startTime, endTime);
eventDay = Tools.sortTimeKeyMap(eventDay, true); eventDay = Tools.sortTimeKeyMap(eventDay, true);
eventDay.forEach((time, list) -> dayList.add(getDayResultWithEvent(list, page, pageSize, time))); eventDay.forEach((time, list) -> dayList.add(getDayResultWithEvent(list, page, pageSize, time)));
res.put("list", dayList); res.put("list", dayList);
...@@ -818,8 +832,8 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -818,8 +832,8 @@ public class ChannelServiceImpl implements ChannelService {
String contendId) { String contendId) {
List<ExportAppChannelEventDTO> res = new ArrayList<>(); List<ExportAppChannelEventDTO> res = new ArrayList<>();
Channel channel = channelDao.findOneById(channelId); Channel channel = channelDao.findOneById(channelId);
Map<Long, List<Event>> eventDay = eventDao.getEventDay(new ChannelIndex(channel, contendId), startTime, Map<Long, List<com.zhiwei.middleware.event.pojo.entity.Event>> eventDay =
endTime); eventClient.getEventDay(new ChannelIndex(channel, contendId).getFid(), startTime, endTime);
Tools.sortTimeKeyMap(eventDay, true).values().forEach(events -> { Tools.sortTimeKeyMap(eventDay, true).values().forEach(events -> {
events.forEach(event -> { events.forEach(event -> {
res.add(ExportAppChannelEventDTO.createFromEvent(event)); res.add(ExportAppChannelEventDTO.createFromEvent(event));
...@@ -849,10 +863,10 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -849,10 +863,10 @@ public class ChannelServiceImpl implements ChannelService {
// 是否友好渠道 // 是否友好渠道
boolean isPositive = false; boolean isPositive = false;
boolean isNegative = false; boolean isNegative = false;
long specNegativeCount = eventDao.getEventCount(new ChannelIndex(channel), long specNegativeCount = eventClient.getEventCount(new ChannelIndex(channel).getFid(),
Arrays.asList(EmotionEnum.POSITIVE.getName(), EmotionEnum.NEUTRAL.getName()), Arrays.asList(EmotionEnum.POSITIVE.getName(), EmotionEnum.NEUTRAL.getName()),
EmotionEnum.NEGATIVE.getName()); EmotionEnum.NEGATIVE.getName());
long specPositiveCount = eventDao.getEventCount(new ChannelIndex(channel), long specPositiveCount = eventClient.getEventCount(new ChannelIndex(channel).getFid(),
Collections.singletonList(EmotionEnum.NEGATIVE.getName()), EmotionEnum.POSITIVE.getName()); Collections.singletonList(EmotionEnum.NEGATIVE.getName()), EmotionEnum.POSITIVE.getName());
// 特殊情况:若皆有发布过反常稿件 // 特殊情况:若皆有发布过反常稿件
if (specNegativeCount > 0 && specPositiveCount > 0) { if (specNegativeCount > 0 && specPositiveCount > 0) {
...@@ -1114,7 +1128,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1114,7 +1128,7 @@ public class ChannelServiceImpl implements ChannelService {
} }
channel.setEmotionIndex(index); channel.setEmotionIndex(index);
channel.setEmotion(emotion); channel.setEmotion(emotion);
channel.setEventCount(eventDao.getEvents(new ChannelIndex(channel)).size()); channel.setEventCount(eventClient.getEvents(new ChannelIndex(channel).getFid()).size());
} }
/** /**
...@@ -1138,7 +1152,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1138,7 +1152,7 @@ public class ChannelServiceImpl implements ChannelService {
// 正面-负面得分 // 正面-负面得分
double negativeScore = this.getNegativeScore(value); double negativeScore = this.getNegativeScore(value);
// 正面事件 // 正面事件
value = eventDao.getEventCount(new ChannelIndex(channel), value = eventClient.getEventCount(new ChannelIndex(channel).getFid(),
Collections.singletonList(EmotionEnum.POSITIVE.getName()), null); Collections.singletonList(EmotionEnum.POSITIVE.getName()), null);
// 正面事件得分 // 正面事件得分
double positiveEventScore = this.getPositiveEventScore(value); double positiveEventScore = this.getPositiveEventScore(value);
...@@ -1315,7 +1329,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1315,7 +1329,7 @@ public class ChannelServiceImpl implements ChannelService {
// 负面稿件数得分 // 负面稿件数得分
double negativeArticlesScore = this.getNegativeArticlesScore(value); double negativeArticlesScore = this.getNegativeArticlesScore(value);
// 参与负面事件 // 参与负面事件
value = eventDao.getEventCount(channel, Collections.singletonList(EmotionEnum.NEGATIVE.getName()), null); value = eventClient.getEventCount(channel.getFid(), Collections.singletonList(EmotionEnum.NEGATIVE.getName()), null);
// 参与负面事件得分 // 参与负面事件得分
double negativeEventScore = this.getNegativeEventScore(value); double negativeEventScore = this.getNegativeEventScore(value);
// 特殊稿件 // 特殊稿件
...@@ -1436,8 +1450,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1436,8 +1450,7 @@ public class ChannelServiceImpl implements ChannelService {
} }
private double inEventCountMonthAverage(Channel channel, String eventEmotion) { private double inEventCountMonthAverage(Channel channel, String eventEmotion) {
long eventCount = eventDao.getEventCount(new ChannelIndex(channel), Collections.singletonList(eventEmotion), long eventCount = eventClient.getEventCount(new ChannelIndex(channel).getFid(), Collections.singletonList(eventEmotion), null);
null);
Period periodDays = new Period(channel.getCTime(), System.currentTimeMillis(), PeriodType.months()); Period periodDays = new Period(channel.getCTime(), System.currentTimeMillis(), PeriodType.months());
return (double) eventCount / periodDays.getMonths(); return (double) eventCount / periodDays.getMonths();
} }
...@@ -1497,22 +1510,22 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1497,22 +1510,22 @@ public class ChannelServiceImpl implements ChannelService {
private Pair<Long, JSONObject> getEventCount(Long startTime, Long endTime, Channel channel, String contendId) { private Pair<Long, JSONObject> getEventCount(Long startTime, Long endTime, Channel channel, String contendId) {
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
Map<Long, List<Event>> eventCount; Map<Long, List<com.zhiwei.middleware.event.pojo.entity.Event>> eventCount;
if (endTime - startTime > Constant.ONE_MONTH) { if (endTime - startTime > Constant.ONE_MONTH) {
eventCount = eventDao.getEventMonth(new ChannelIndex(channel, contendId), startTime, endTime); eventCount = eventClient.getEventMonth(new ChannelIndex(channel, contendId).getFid(), startTime, endTime);
} else { } else {
eventCount = eventDao.getEventDay(new ChannelIndex(channel, contendId), startTime, endTime); eventCount = eventClient.getEventDay(new ChannelIndex(channel, contendId).getFid(), startTime, endTime);
} }
// 事件部分 // 事件部分
long positiveEventCount = 0; long positiveEventCount = 0;
long negativeEventCount = 0; long negativeEventCount = 0;
long totalEvent = 0; long totalEvent = 0;
// 统计参与事件 // 统计参与事件
for (List<Event> events : eventCount.values()) { for (List<com.zhiwei.middleware.event.pojo.entity.Event> events : eventCount.values()) {
for (Event event : events) { for (com.zhiwei.middleware.event.pojo.entity.Event event : events) {
if (EmotionEnum.NEGATIVE.getName().equals(event.getEmotion())) { if (EmotionEnum.NEGATIVE.getName().equals(event.getEmotionEventTag().getName())) {
negativeEventCount++; negativeEventCount++;
} else if (EmotionEnum.POSITIVE.getName().equals(event.getEmotion())) { } else if (EmotionEnum.POSITIVE.getName().equals(event.getEmotionEventTag().getName())) {
positiveEventCount++; positiveEventCount++;
} }
totalEvent++; totalEvent++;
...@@ -1536,13 +1549,12 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1536,13 +1549,12 @@ public class ChannelServiceImpl implements ChannelService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
private List<JSONObject> spreadingTendEvent(Long startTime, Long endTime, Channel channel, String contendId, private List<JSONObject> spreadingTendEvent(Long startTime, Long endTime, Channel channel, String contendId, String timePattern) {
String timePattern) {
Map<Long, List<Event>> eventCount = completeTimes(startTime, endTime, timePattern); Map<Long, List<Event>> eventCount = completeTimes(startTime, endTime, timePattern);
if (Constant.MONTH_PATTERN.equals(timePattern)) { if (Constant.MONTH_PATTERN.equals(timePattern)) {
eventCount.putAll(eventDao.getEventMonth(new ChannelIndex(channel, contendId), startTime, endTime)); eventCount.putAll(eventClient.getEventMonth(new ChannelIndex(channel, contendId).getFid(), startTime, endTime));
} else { } else {
eventCount.putAll(eventDao.getEventDay(new ChannelIndex(channel, contendId), startTime, endTime)); eventCount.putAll(eventClient.getEventDay(new ChannelIndex(channel, contendId).getFid(), startTime, endTime));
} }
return eventCount.entrySet().stream().sorted(Comparator.comparingLong(Map.Entry::getKey)).map(e -> { return eventCount.entrySet().stream().sorted(Comparator.comparingLong(Map.Entry::getKey)).map(e -> {
JSONObject spreadJson = new JSONObject(); JSONObject spreadJson = new JSONObject();
......
...@@ -19,12 +19,14 @@ import com.zhiwei.brandkbs2.service.MarkDataService; ...@@ -19,12 +19,14 @@ import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.service.ProjectService; import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.RedisUtil; import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.event.core.EventClient;
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.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.Period; import org.joda.time.Period;
import org.joda.time.PeriodType; import org.joda.time.PeriodType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -61,6 +63,9 @@ public class IndexServiceImpl implements IndexService { ...@@ -61,6 +63,9 @@ public class IndexServiceImpl implements IndexService {
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private EventClient eventClient;
@Override @Override
public JSONObject getYuqingAmount(Long startTime, Long endTime, boolean cache) { public JSONObject getYuqingAmount(Long startTime, Long endTime, boolean cache) {
if (null == startTime || null == endTime) { if (null == startTime || null == endTime) {
...@@ -184,11 +189,10 @@ public class IndexServiceImpl implements IndexService { ...@@ -184,11 +189,10 @@ public class IndexServiceImpl implements IndexService {
Long oldStartTime = startTime - (endTime - startTime); Long oldStartTime = startTime - (endTime - startTime);
int selectMonths = new Period(startTime, endTime, PeriodType.months()).getMonths(); int selectMonths = new Period(startTime, endTime, PeriodType.months()).getMonths();
selectMonths = 0 == selectMonths ? 1 : selectMonths; selectMonths = 0 == selectMonths ? 1 : selectMonths;
long total = eventDao.getEventCountByProjectIdAndContendId(null, null, EmotionEnum.ALL.getName(), projectId, contendId); // 调用事件中间件时,主品牌id使用项目id
long eventTotal = eventDao.getEventCountByProjectIdAndContendId long total = eventClient.getEventCountByProjectIdAndContendId(null, null, EmotionEnum.ALL.getName(), projectId, projectId);
(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId); long eventTotal = eventClient.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, projectId);
long oldEventTotal = eventDao.getEventCountByProjectIdAndContendId long oldEventTotal = eventClient.getEventCountByProjectIdAndContendId(oldStartTime, endTime, EmotionEnum.ALL.getName(), projectId, projectId);
(oldStartTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId);
jsonObject.put("eventTotal", eventTotal); jsonObject.put("eventTotal", eventTotal);
jsonObject.put("avgEventTotal", total * selectMonths / (totalMonths + 1)); jsonObject.put("avgEventTotal", total * selectMonths / (totalMonths + 1));
jsonObject.put("compare", oldEventTotal == 0 ? 0d : (eventTotal - oldEventTotal) / (double) oldEventTotal); jsonObject.put("compare", oldEventTotal == 0 ? 0d : (eventTotal - oldEventTotal) / (double) oldEventTotal);
...@@ -418,12 +422,14 @@ public class IndexServiceImpl implements IndexService { ...@@ -418,12 +422,14 @@ public class IndexServiceImpl implements IndexService {
*/ */
private JSONObject getTopEvent(Long startTime, Long endTime, String projectId, String contendId) { private JSONObject getTopEvent(Long startTime, Long endTime, String projectId, String contendId) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
List<Event> eventList = eventDao.getEventsByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId, 1); contendId = Objects.equals(contendId, Constant.PRIMARY_CONTEND_ID) ? projectId : contendId;
List<com.zhiwei.middleware.event.pojo.entity.Event> eventList =
eventClient.getEventsByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId, 1);
if (CollectionUtils.isNotEmpty(eventList)) { if (CollectionUtils.isNotEmpty(eventList)) {
Event event = eventList.get(0); com.zhiwei.middleware.event.pojo.entity.Event event = eventList.get(0);
long articleCount = eventDataDao.getEventArticleCount(event); long articleCount = eventClient.getEventArticleCount(event);
result.put("id", event.getId()); result.put("id", event.getId());
result.put("title", event.getTitle()); result.put("title", event.getName());
result.put("influence", event.getInfluence()); result.put("influence", event.getInfluence());
result.put("articleCount", articleCount); result.put("articleCount", articleCount);
} }
...@@ -535,7 +541,8 @@ public class IndexServiceImpl implements IndexService { ...@@ -535,7 +541,8 @@ public class IndexServiceImpl implements IndexService {
result.put("normalCount", normalCount); result.put("normalCount", normalCount);
result.put("time", startTime); result.put("time", startTime);
//统计时间段总事件数 //统计时间段总事件数
long eventCount = eventDao.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, "0"); // 调用事件中间件时,主品牌id使用项目id
long eventCount = eventClient.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, projectId);
result.put("eventCount", eventCount); result.put("eventCount", eventCount);
lineList.add(result); lineList.add(result);
} }
...@@ -556,10 +563,11 @@ public class IndexServiceImpl implements IndexService { ...@@ -556,10 +563,11 @@ public class IndexServiceImpl implements IndexService {
Long startTime = map.get("startTime"); Long startTime = map.get("startTime");
Long endTime = map.get("endTime"); Long endTime = map.get("endTime");
//统计时间段总事件数 //统计时间段总事件数
long totalEventCount = eventDao.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, contendId); // 调用事件中间件时,主品牌id使用项目id
long posEventCount = eventDao.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, contendId); long totalEventCount = eventClient.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.ALL.getName(), projectId, projectId);
long neuEventCount = eventDao.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.NEUTRAL.getName(), projectId, contendId); long posEventCount = eventClient.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, projectId);
long negEventCount = eventDao.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, contendId); long neuEventCount = eventClient.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.NEUTRAL.getName(), projectId, projectId);
long negEventCount = eventClient.getEventCountByProjectIdAndContendId(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, projectId);
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("totalCount", totalEventCount); result.put("totalCount", totalEventCount);
result.put("posCount", posEventCount); result.put("posCount", posEventCount);
......
...@@ -18,6 +18,9 @@ import com.zhiwei.brandkbs2.service.ProjectService; ...@@ -18,6 +18,9 @@ import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.service.ProjectWarnService; import com.zhiwei.brandkbs2.service.ProjectWarnService;
import com.zhiwei.brandkbs2.util.RedisUtil; import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.event.core.EventClient;
import com.zhiwei.middleware.event.pojo.entity.Event;
import com.zhiwei.middleware.event.pojo.entity.EventTagBasicInfo;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
...@@ -78,6 +81,9 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -78,6 +81,9 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
@Resource(name = "redisUtil") @Resource(name = "redisUtil")
RedisUtil redisUtil; RedisUtil redisUtil;
@Autowired
private EventClient eventClient;
private static final Map<String, String> TYPE_SEARCH = new HashMap<>(); private static final Map<String, String> TYPE_SEARCH = new HashMap<>();
static { static {
...@@ -297,7 +303,7 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -297,7 +303,7 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
return new BrandkbsWarnTemplate(firstCount, key1, key2, key3, key4, new BrandkbsYuQingWarn(collect)); return new BrandkbsWarnTemplate(firstCount, key1, key2, key3, key4, new BrandkbsYuQingWarn(collect));
} }
private BrandkbsWarnTemplate brandkbsWarnTemplate4HotEvent(BrandkbsHotEventConfig config, Map<String, List<Event>> eventMap, long start, long end, AbstractProject project) { private BrandkbsWarnTemplate brandkbsWarnTemplate4HotEvent(BrandkbsHotEventConfig config, Map<String, List<com.zhiwei.middleware.event.pojo.entity.Event>> eventMap, long start, long end, AbstractProject project) {
int firstCount = eventMap.values().stream().mapToInt(List::size).sum(); int firstCount = eventMap.values().stream().mapToInt(List::size).sum();
if (firstCount == 0) { if (firstCount == 0) {
return null; return null;
...@@ -313,17 +319,17 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -313,17 +319,17 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
final int limit = 2; final int limit = 2;
int count = limit; int count = limit;
out: out:
for (List<Event> value : eventMap.values()) { for (List<com.zhiwei.middleware.event.pojo.entity.Event> value : eventMap.values()) {
for (Event event : value) { for (Event event : value) {
if (--count == 0) { if (--count == 0) {
if (firstCount <= limit) { if (firstCount <= limit) {
keyBuilder4.append(event.getTitle()); keyBuilder4.append(event.getName());
} else { } else {
keyBuilder4.append(event.getTitle()).append("\r\n"); keyBuilder4.append(event.getName()).append("\r\n");
} }
break out; break out;
} else { } else {
keyBuilder4.append(event.getTitle()).append("\r\n"); keyBuilder4.append(event.getName()).append("\r\n");
} }
} }
} }
...@@ -332,7 +338,8 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -332,7 +338,8 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
} else { } else {
key4 = keyBuilder4.toString(); key4 = keyBuilder4.toString();
} }
Map<String, List<BrandkbsHotEventWarn.HotEvent>> collect = eventMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(event -> BrandkbsHotEventWarn.HotEvent.createFromEvent(entry.getKey(), event)).collect(Collectors.toList()))); Map<String, List<BrandkbsHotEventWarn.HotEvent>> collect = eventMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue()
.stream().map(event -> BrandkbsHotEventWarn.HotEvent.createFromEvent(entry.getKey(), event)).collect(Collectors.toList())));
// List<BrandkbsHotEventWarn.HotEvent> collect = eventMap.entrySet().stream().map(entry -> entry.getValue().stream(). // List<BrandkbsHotEventWarn.HotEvent> collect = eventMap.entrySet().stream().map(entry -> entry.getValue().stream().
// map(event -> BrandkbsHotEventWarn.HotEvent.createFromEvent(entry.getKey(), event)).collect(Collectors.toList())). // map(event -> BrandkbsHotEventWarn.HotEvent.createFromEvent(entry.getKey(), event)).collect(Collectors.toList())).
// collect(Collectors.toList()).stream().flatMap(List::stream).collect(Collectors.toList()); // collect(Collectors.toList()).stream().flatMap(List::stream).collect(Collectors.toList());
...@@ -718,30 +725,39 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -718,30 +725,39 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
long start = end - Constant.ONE_DAY * 7; long start = end - Constant.ONE_DAY * 7;
try { try {
log.info("获取热点事件预警开始,project:{}", project.getProjectName()); log.info("获取热点事件预警开始,project:{}", project.getProjectName());
Map<String, List<Event>> eventMap = new LinkedHashMap<>(); Map<String, List<com.zhiwei.middleware.event.pojo.entity.Event>> eventMap = new LinkedHashMap<>();
if (CollectionUtils.isNotEmpty(config.getOwnEvent())) { if (CollectionUtils.isNotEmpty(config.getOwnEvent())) {
List<Event> ownEvents = eventDao.getEventsByProjectIdAndContendId(start, end, config.getOwnEvent(), projectId, "0", config.getEventTop()); // 调用事件中间件时,使用项目id作为主品牌id
List<com.zhiwei.middleware.event.pojo.entity.Event> ownEvents =
eventClient.getEventsByProjectIdAndContendId(start, end, config.getOwnEvent(), projectId, projectId, config.getEventTop());
eventMap.put("品牌动态", ownEvents); eventMap.put("品牌动态", ownEvents);
} }
if (CollectionUtils.isNotEmpty(config.getContendsEvent())) { if (CollectionUtils.isNotEmpty(config.getContendsEvent())) {
List<Event> contentEvents = new ArrayList<>(); List<com.zhiwei.middleware.event.pojo.entity.Event> contentEvents = new ArrayList<>();
for (String contendId : config.getContendsEvent()) { for (String contendId : config.getContendsEvent()) {
contentEvents.addAll(eventDao.getEventsByProjectIdAndContendId(start, end, config.getOwnEvent(), projectId, contendId, config.getEventTop())); contendId = Objects.equals(Constant.PRIMARY_CONTEND_ID, contendId) ? projectId : contendId;
contentEvents.addAll(eventClient.getEventsByProjectIdAndContendId(start, end, config.getOwnEvent(), projectId, contendId, config.getEventTop()));
} }
eventMap.put("友商动态", contentEvents); eventMap.put("友商动态", contentEvents);
} }
if (CollectionUtils.isNotEmpty(config.getZhiWeiEvent())) { if (CollectionUtils.isNotEmpty(config.getZhiWeiEvent())) {
List<Event> externalEvents = new ArrayList<>(); List<com.zhiwei.middleware.event.pojo.entity.Event> externalEvents = new ArrayList<>();
ResponseEntity<String> forEntity = restTemplate.getForEntity(getExternalFilterNewUrl, String.class, config.getZhiWeiEvent().toArray(), start, end); ResponseEntity<String> forEntity = restTemplate.getForEntity(getExternalFilterNewUrl, String.class, config.getZhiWeiEvent().toArray(), start, end);
JSONObject jsonObject = JSON.parseObject(forEntity.getBody()); JSONObject jsonObject = JSON.parseObject(forEntity.getBody());
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("events"); JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("events");
for (int i = 0; i < config.getEventTop(); i++) { for (int i = 0; i < config.getEventTop(); i++) {
JSONObject zhiweiEvent = jsonArray.getJSONObject(i); JSONObject zhiweiEvent = jsonArray.getJSONObject(i);
Event event = new Event(); com.zhiwei.middleware.event.pojo.entity.Event event = new com.zhiwei.middleware.event.pojo.entity.Event();
event.setTitle(zhiweiEvent.getString("eventname")); event.setName(zhiweiEvent.getString("eventname"));
JSONObject eventTag = new JSONObject(); // JSONObject eventTag = new JSONObject();
eventTag.put("事件类型", zhiweiEvent.getString("type")); // eventTag.put("事件类型", zhiweiEvent.getString("type"));
event.setEventTag(eventTag); // event.setEventTag(eventTag);
EventTagBasicInfo eventTagBasicInfo = new EventTagBasicInfo();
eventTagBasicInfo.setGroupName("事件类型");
eventTagBasicInfo.setName(zhiweiEvent.getString("type"));
List<EventTagBasicInfo> infos = new ArrayList<>(1);
infos.add(eventTagBasicInfo);
event.setEventTags(infos);
event.setTotalDisseminationVolume(zhiweiEvent.getLong("allCount")); event.setTotalDisseminationVolume(zhiweiEvent.getLong("allCount"));
event.setStartTime(zhiweiEvent.getLong("startTime")); event.setStartTime(zhiweiEvent.getLong("startTime"));
event.setInfluence(zhiweiEvent.getDouble("index")); event.setInfluence(zhiweiEvent.getDouble("index"));
......
...@@ -28,6 +28,8 @@ import com.zhiwei.brandkbs2.service.ReportService; ...@@ -28,6 +28,8 @@ import com.zhiwei.brandkbs2.service.ReportService;
import com.zhiwei.brandkbs2.util.MongoUtil; import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.RedisUtil; import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.event.core.EventClient;
import com.zhiwei.middleware.event.pojo.entity.BrandkbsBasicInfo;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
...@@ -86,6 +88,9 @@ public class ReportServiceImpl implements ReportService { ...@@ -86,6 +88,9 @@ public class ReportServiceImpl implements ReportService {
@Autowired @Autowired
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
@Autowired
private EventClient eventClient;
@Override @Override
public Map<String, ReportSettingsDTO> getReportSettings() { public Map<String, ReportSettingsDTO> getReportSettings() {
Map<String, ReportSettingsDTO> res = new HashMap<>(); Map<String, ReportSettingsDTO> res = new HashMap<>();
...@@ -348,7 +353,9 @@ public class ReportServiceImpl implements ReportService { ...@@ -348,7 +353,9 @@ public class ReportServiceImpl implements ReportService {
result.put("curPosTotal", curPositiveTotal); result.put("curPosTotal", curPositiveTotal);
result.put("curPosPro", curTotal == 0 ? 0 : curPositiveTotal * 1.0 / curTotal); result.put("curPosPro", curTotal == 0 ? 0 : curPositiveTotal * 1.0 / curTotal);
//正面事件传播量top //正面事件传播量top
List<Event> topPosEventList = eventDao.getEventsByTotalChannelVolumeTop(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, contendId, 3); // 调用事件中间件时,主品牌id使用项目id
List<com.zhiwei.middleware.event.pojo.entity.Event> topPosEventList =
eventClient.getEventsByTotalChannelVolumeTop(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, projectId, 3);
if (CollectionUtils.isEmpty(topPosEventList)) { if (CollectionUtils.isEmpty(topPosEventList)) {
List<Map.Entry<String, Integer>> topPosArticleList = markDataService.getMarkTopTitle(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, linkedGroupId, contendId, 3); List<Map.Entry<String, Integer>> topPosArticleList = markDataService.getMarkTopTitle(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, linkedGroupId, contendId, 3);
result.put("topPosSummary", this.getTopArticlesMsg(startTime, endTime, projectId, linkedGroupId, contendId, topPosArticleList)); result.put("topPosSummary", this.getTopArticlesMsg(startTime, endTime, projectId, linkedGroupId, contendId, topPosArticleList));
...@@ -364,7 +371,9 @@ public class ReportServiceImpl implements ReportService { ...@@ -364,7 +371,9 @@ public class ReportServiceImpl implements ReportService {
result.put("curNeuTotal", curNeutralTotal); result.put("curNeuTotal", curNeutralTotal);
result.put("curNeuPro", curTotal == 0 ? 0 : curNeutralTotal * 1.0 / curTotal); result.put("curNeuPro", curTotal == 0 ? 0 : curNeutralTotal * 1.0 / curTotal);
//中性事件传播量top //中性事件传播量top
List<Event> topNeuEventList = eventDao.getEventsByTotalChannelVolumeTop(startTime, endTime, EmotionEnum.NEUTRAL.getName(), projectId, contendId, 4); // 调用事件中间件时,主品牌id使用项目id
List<com.zhiwei.middleware.event.pojo.entity.Event> topNeuEventList =
eventClient.getEventsByTotalChannelVolumeTop(startTime, endTime, EmotionEnum.NEUTRAL.getName(), projectId, projectId, 4);
if (CollectionUtils.isEmpty(topNeuEventList)) { if (CollectionUtils.isEmpty(topNeuEventList)) {
List<Map.Entry<String, Integer>> topNeuArticleList = markDataService.getMarkTopTitle(startTime, endTime, EmotionEnum.NEUTRAL.getName(), projectId, linkedGroupId, contendId, 4); List<Map.Entry<String, Integer>> topNeuArticleList = markDataService.getMarkTopTitle(startTime, endTime, EmotionEnum.NEUTRAL.getName(), projectId, linkedGroupId, contendId, 4);
result.put("topNeuSummary", this.getTopArticlesMsg(startTime, endTime, projectId, linkedGroupId, contendId, topNeuArticleList)); result.put("topNeuSummary", this.getTopArticlesMsg(startTime, endTime, projectId, linkedGroupId, contendId, topNeuArticleList));
...@@ -380,7 +389,9 @@ public class ReportServiceImpl implements ReportService { ...@@ -380,7 +389,9 @@ public class ReportServiceImpl implements ReportService {
result.put("curNegTotal", curNegativeTotal); result.put("curNegTotal", curNegativeTotal);
result.put("curNegPro", curTotal == 0 ? 0 : curNegativeTotal * 1.0 / curTotal); result.put("curNegPro", curTotal == 0 ? 0 : curNegativeTotal * 1.0 / curTotal);
//中性事件传播量top //中性事件传播量top
List<Event> topNegEventList = eventDao.getEventsByTotalChannelVolumeTop(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, contendId, 4); // 调用事件中间件时,主品牌id使用项目id
List<com.zhiwei.middleware.event.pojo.entity.Event> topNegEventList =
eventClient.getEventsByTotalChannelVolumeTop(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, projectId, 4);
if (CollectionUtils.isEmpty(topNegEventList)) { if (CollectionUtils.isEmpty(topNegEventList)) {
List<Map.Entry<String, Integer>> topNegArticleList = markDataService.getMarkTopTitle(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, linkedGroupId, contendId, 4); List<Map.Entry<String, Integer>> topNegArticleList = markDataService.getMarkTopTitle(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, linkedGroupId, contendId, 4);
result.put("topNegSummary", this.getTopArticlesMsg(startTime, endTime, projectId, linkedGroupId, contendId, topNegArticleList)); result.put("topNegSummary", this.getTopArticlesMsg(startTime, endTime, projectId, linkedGroupId, contendId, topNegArticleList));
...@@ -457,17 +468,24 @@ public class ReportServiceImpl implements ReportService { ...@@ -457,17 +468,24 @@ public class ReportServiceImpl implements ReportService {
return emotions.stream().map(emotion -> { return emotions.stream().map(emotion -> {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("name", Objects.equals(emotion, EmotionEnum.POSITIVE.getName()) ? "正面事件" : Objects.equals(emotion, EmotionEnum.NEGATIVE.getName()) ? "负面事件" : "中性事件"); result.put("name", Objects.equals(emotion, EmotionEnum.POSITIVE.getName()) ? "正面事件" : Objects.equals(emotion, EmotionEnum.NEGATIVE.getName()) ? "负面事件" : "中性事件");
List<Event> topEventList = eventDao.getEventsByTotalChannelVolumeTop(startTime, endTime, emotion, projectId, contendId, 10); // 调用事件中间件时,主品牌id使用项目id
List<com.zhiwei.middleware.event.pojo.entity.Event> topEventList =
eventClient.getEventsByTotalChannelVolumeTop(startTime, endTime, emotion, projectId, projectId, 10);
result.put("events", topEventList.stream().map(event -> { result.put("events", topEventList.stream().map(event -> {
JSONObject topEvent = new JSONObject(); JSONObject topEvent = new JSONObject();
boolean hasAnalyze = Objects.equals(event.getContendId(), Constant.PRIMARY_CONTEND_ID); boolean hasAnalyze = false;
for (BrandkbsBasicInfo brandkbsInfo : event.getBrandkbsInfos()) {
if (brandkbsInfo.getBrandkbsProjectId().equals(projectId) && brandkbsInfo.getBrandkbsBrandId().equals(projectId)){
hasAnalyze = true;
}
}
topEvent.put("id", event.getId()); topEvent.put("id", event.getId());
String title = event.getTitle(); String title = event.getName();
topEvent.put("title", title.length() <= 30 ? title : title.substring(0, 30) + "..."); topEvent.put("title", title.length() <= 30 ? title : title.substring(0, 30) + "...");
topEvent.put("influence", event.getInfluence()); topEvent.put("influence", event.getInfluence());
topEvent.put("articleCount", event.getTotalDisseminationVolume()); topEvent.put("articleCount", event.getTotalDisseminationVolume());
//查询首发稿件 // 首发稿件
EventData firstData = eventDataDao.findFirstData(event.getId(), event.getCollectionName()); com.zhiwei.middleware.event.pojo.entity.EventData firstData = event.getOriginArticle();
topEvent.put("firstSource", Objects.isNull(firstData) ? "" : firstData.getSource()); topEvent.put("firstSource", Objects.isNull(firstData) ? "" : firstData.getSource());
topEvent.put("hasAnalyze", hasAnalyze); topEvent.put("hasAnalyze", hasAnalyze);
return topEvent; return topEvent;
...@@ -516,12 +534,18 @@ public class ReportServiceImpl implements ReportService { ...@@ -516,12 +534,18 @@ public class ReportServiceImpl implements ReportService {
* @param topEventList top事件集合 * @param topEventList top事件集合
* @return top事件信息 * @return top事件信息
*/ */
private List<JSONObject> getTopEventMsg(List<Event> topEventList) { private List<JSONObject> getTopEventMsg(List<com.zhiwei.middleware.event.pojo.entity.Event> topEventList) {
String projectId = UserThreadLocal.getProjectId();
return topEventList.stream().map(event -> { return topEventList.stream().map(event -> {
boolean hasAnalyze = Objects.equals(event.getContendId(), Constant.PRIMARY_CONTEND_ID); boolean hasAnalyze = false;
for (BrandkbsBasicInfo brandkbsInfo : event.getBrandkbsInfos()) {
if (brandkbsInfo.getBrandkbsProjectId().equals(projectId) && brandkbsInfo.getBrandkbsBrandId().equals(projectId)){
hasAnalyze = true;
}
}
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("id", event.getId()); jsonObject.put("id", event.getId());
String title = event.getTitle(); String title = event.getName();
jsonObject.put("title", title.length() <= 30 ? title : title.substring(0, 30) + "..."); jsonObject.put("title", title.length() <= 30 ? title : title.substring(0, 30) + "...");
jsonObject.put("hasAnalyze", hasAnalyze); jsonObject.put("hasAnalyze", hasAnalyze);
return jsonObject; return jsonObject;
......
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