Commit 2dca5346 by shenjunjie

Merge branch 'feature' into 'dev'

Feature

See merge request !17
parents 9a3a494a 9277c5d1
...@@ -72,4 +72,13 @@ public class GlobalPojo { ...@@ -72,4 +72,13 @@ public class GlobalPojo {
return null; return null;
} }
public static String getPlatformNameById(String platformId) {
for (MessagePlatform platform : PLATFORMS) {
if (platform.getId().equals(platformId)) {
return platform.getName();
}
}
return null;
}
} }
...@@ -28,6 +28,13 @@ public class RedisKeyPrefix { ...@@ -28,6 +28,13 @@ public class RedisKeyPrefix {
public static final String AGGREE_RESULT_CACHE = "BRANDKBS:AGGREE_CACHE:"; public static final String AGGREE_RESULT_CACHE = "BRANDKBS:AGGREE_CACHE:";
/** /**
* 自定义事件相关缓存
*/
public static final String CUSTOM_EVENT_LIST = "BRANDKBS:CUSTOM_EVENT:LIST:";
public static final String CUSTOM_EVENT_ANALYZE_SHARE = "BRANDKBS:CUSTOM_EVENT:SHARE";
public static final String CUSTOM_EVENT_ANALYZE = "BRANDKBS:CUSTOM_EVENT:ANALYZE:";
/**
* 热点相关缓存KEY * 热点相关缓存KEY
*/ */
public static final String HOT_RANKLIST = "brandkbs:hot:rankList:"; public static final String HOT_RANKLIST = "brandkbs:hot:rankList:";
......
...@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*; ...@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @ClassName: AppChannelController * @ClassName: AppChannelController
...@@ -109,7 +108,7 @@ public class AppChannelController extends BaseController { ...@@ -109,7 +108,7 @@ public class AppChannelController extends BaseController {
@ApiOperation("渠道库-收藏渠道列表") @ApiOperation("渠道库-收藏渠道列表")
@ApiImplicitParams(@ApiImplicitParam(name = "contendId", value = "品牌ID", paramType = "query", dataType = "string")) @ApiImplicitParams(@ApiImplicitParam(name = "contendId", value = "品牌ID", paramType = "query", dataType = "string"))
@GetMapping("/list/collect}") @GetMapping("/list/collect")
public ResponseResult getCollectList(@RequestParam(value = "contendId", required = false, defaultValue = "0") String contendId) { public ResponseResult getCollectList(@RequestParam(value = "contendId", required = false, defaultValue = "0") String contendId) {
return ResponseResult.success(channelService.getCollectList(contendId)); return ResponseResult.success(channelService.getCollectList(contendId));
} }
...@@ -132,7 +131,7 @@ public class AppChannelController extends BaseController { ...@@ -132,7 +131,7 @@ public class AppChannelController extends BaseController {
@GetMapping("/spreadingTend") @GetMapping("/spreadingTend")
public ResponseResult getSpreadingTend(@RequestParam("channelId") String channelId, public ResponseResult getSpreadingTend(@RequestParam("channelId") String channelId,
@RequestParam(value = "type", defaultValue = "文章") String type, @RequestParam(value = "type", defaultValue = "文章") String type,
@RequestParam(value = "contends", required = false) Set<String> contends, @RequestParam(value = "contends", required = false) String contends,
@RequestParam(value = "startTime", required = false) Long startTime, @RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime) { @RequestParam(value = "endTime", required = false) Long endTime) {
return ResponseResult.success(channelService.getSpreadingTend(channelId, type, contends, startTime, endTime)); return ResponseResult.success(channelService.getSpreadingTend(channelId, type, contends, startTime, endTime));
...@@ -147,7 +146,7 @@ public class AppChannelController extends BaseController { ...@@ -147,7 +146,7 @@ public class AppChannelController extends BaseController {
}) })
@GetMapping("/spreadingTend/summary") @GetMapping("/spreadingTend/summary")
public ResponseResult getSpreadingTendSummary(@RequestParam("channelId") String channelId, public ResponseResult getSpreadingTendSummary(@RequestParam("channelId") String channelId,
@RequestParam(value = "contends", required = false) Set<String> contends, @RequestParam(value = "contends", required = false) String contends,
@RequestParam(value = "startTime", required = false) Long startTime, @RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime) { @RequestParam(value = "endTime", required = false) Long endTime) {
return ResponseResult.success(channelService.getSpreadingTendSummary(channelId, contends, startTime, endTime)); return ResponseResult.success(channelService.getSpreadingTendSummary(channelId, contends, startTime, endTime));
...@@ -157,6 +156,7 @@ public class AppChannelController extends BaseController { ...@@ -157,6 +156,7 @@ public class AppChannelController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query", dataType = "long"), @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query", dataType = "long"), @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "dayLimit", value = "限制有效数据天数", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "页码大小", defaultValue = "10", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "pageSize", value = "页码大小", defaultValue = "10", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "channelId", value = "渠道ID", required = true, paramType = "query", dataType = "int"), @ApiImplicitParam(name = "channelId", value = "渠道ID", required = true, paramType = "query", dataType = "int"),
...@@ -165,11 +165,12 @@ public class AppChannelController extends BaseController { ...@@ -165,11 +165,12 @@ public class AppChannelController extends BaseController {
@GetMapping("/articles") @GetMapping("/articles")
public ResponseResult getArticles(@RequestParam(value = "startTime") Long startTime, public ResponseResult getArticles(@RequestParam(value = "startTime") Long startTime,
@RequestParam(value = "endTime") Long endTime, @RequestParam(value = "endTime") Long endTime,
@RequestParam(value = "dayLimit", required = false) Integer dayLimit,
@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
@RequestParam("channelId") String channelId, @RequestParam("channelId") String channelId,
@RequestParam(value = "contendId", defaultValue = "0") String contendId) { @RequestParam(value = "contendId", defaultValue = "0") String contendId) {
return ResponseResult.success(channelService.getArticlesByTime(startTime, endTime, page, pageSize, channelId, contendId)); return ResponseResult.success(channelService.getArticlesByTime(startTime, endTime, dayLimit, page, pageSize, channelId, contendId));
} }
@ApiOperation("渠道库-下载文章列表") @ApiOperation("渠道库-下载文章列表")
......
package com.zhiwei.brandkbs2.controller.app;
import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.dto.CustomEventDTO;
import com.zhiwei.brandkbs2.service.CustomEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author sjj
* @ClassName AppCrisisController
* @Description 前台自定义事件展示接口
* @date 2022-07-19 10:20
*/
@RestController
@RequestMapping("/app/customEvent")
@Api(tags = "前台自定义事件展示接口", description = "提供前台自定义事件模块信息展示及操作")
@Auth(role = RoleEnum.CUSTOMER)
public class AppCustomEventController {
@Resource
private CustomEventService customEventService;
@ApiOperation("事件库-我的事件列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query", dataType = "Long")
})
@GetMapping("/rankList")
public ResponseResult getCustomEventRankList(@RequestParam(value = "startTime") Long startTime,
@RequestParam(value = "endTime") Long endTime) {
return ResponseResult.success(customEventService.getCustomEventRankList(startTime, endTime));
}
@ApiOperation("事件库-保存事件")
@PostMapping()
public ResponseResult saveCustomEvent(@RequestBody CustomEventDTO customEventDTO) {
customEventService.saveCustomEvent(customEventDTO);
return ResponseResult.success();
}
@ApiOperation("事件库-修改自定义事件")
@PatchMapping()
public ResponseResult updateCustomEvent(@RequestBody CustomEventDTO customEventDTO) {
customEventService.updateCustomEvent(customEventDTO);
return ResponseResult.success();
}
@ApiOperation("事件库-自定义事件列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "页码大小", defaultValue = "10", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "keyword", value = "关键词", paramType = "query", dataType = "string")
})
@GetMapping("/list")
public ResponseResult getCustomEventList(@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "size", defaultValue = "10") int pageSize,
@RequestParam(value = "keyword", defaultValue = "") String keyword) {
return ResponseResult.success(customEventService.getCustomEventList(page, pageSize, keyword));
}
@ApiOperation("事件库-删除自定义事件信息")
@ApiImplicitParam(name = "id", value = "自定义事件ID", required = true, paramType = "path", dataType = "string")
@DeleteMapping("/{id}")
public ResponseResult deleteCustomEventById(@PathVariable String id) {
customEventService.deleteCustomEventById(id);
return ResponseResult.success();
}
@ApiOperation("事件库-更新自定义事件数据")
@ApiImplicitParam(name = "id", value = "自定义事件ID", required = true, paramType = "path", dataType = "string")
@PatchMapping("/{id}")
public ResponseResult analyzeCustomEvent(@PathVariable String id) {
customEventService.analyzeCustomEvent(id);
return ResponseResult.success();
}
@ApiOperation("事件库-获取自定义事件分享id")
@ApiImplicitParam(name = "id", value = "自定义事件ID", required = true, paramType = "path", dataType = "string")
@GetMapping("/share/{id}")
public ResponseResult getCustomEventAnalyzeShareId(@PathVariable String id) {
return ResponseResult.success(customEventService.getCustomEventAnalyzeShareId(id));
}
@ApiOperation("获取自定义事件分析结果")
@ApiImplicitParam(name = "id", value = "自定义事件ID", required = true, paramType = "path", dataType = "string")
@GetMapping("/analyze/{id}")
public ResponseResult getCustomEventAnalyze(@PathVariable String id) {
return ResponseResult.success(customEventService.getCustomEventAnalyze(id, true));
}
}
...@@ -7,10 +7,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult; ...@@ -7,10 +7,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult;
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.ApiOperation; import io.swagger.annotations.ApiOperation;
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;
/** /**
* @Description: 前台事件库 * @Description: 前台事件库
...@@ -47,5 +44,35 @@ public class AppEventController extends BaseController { ...@@ -47,5 +44,35 @@ public class AppEventController extends BaseController {
return ResponseResult.success(eventService.getEventList(linkedGroupId, emotion, startTime, endTime, page, pageSize, sorter)); return ResponseResult.success(eventService.getEventList(linkedGroupId, emotion, startTime, endTime, page, pageSize, sorter));
} }
@ApiOperation("前台事件库-事件详情-基础信息")
@GetMapping("/info/base/{id}")
public ResponseResult getEventBaseInfo(@PathVariable String id) {
return ResponseResult.success(eventService.getEventBaseInfo(id));
}
@ApiOperation("前台事件库-事件详情-传播趋势图")
@GetMapping("/info/dissemination-trends/{id}")
public ResponseResult getEventDisseminationTrends(@PathVariable String id, @RequestParam(value = "type", defaultValue = "小时") String type) {
return ResponseResult.success(eventService.getEventDisseminationTrends(id, type));
}
@ApiOperation("前台事件库-事件详情-渠道发声")
@GetMapping("/info/channel-voices/{id}")
public ResponseResult getEventChannelVoices(@PathVariable String id,
@RequestParam(value = "type", defaultValue = "重要渠道") String type,
@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "pageSize", defaultValue = "50") int pageSize,
@RequestParam(value = "sorter", required = false) String sorter) {
return ResponseResult.success(eventService.getEventChannelVoices(id, type, page, pageSize, sorter));
}
@ApiOperation("前台事件库-事件详情-热门文章分析")
@GetMapping("/info/top-articles-analysis/{id}")
public ResponseResult getEventTopArticlesAnalysis(@PathVariable String id,
@RequestParam(value = "type", defaultValue = "按时间") String type,
@RequestParam(value = "emotion", defaultValue = "全部") String emotion,
@RequestParam(value = "aggTitle", required = false) String aggTitle) {
return ResponseResult.success(eventService.getEventTopArticlesAnalysis(id, type, emotion, aggTitle));
}
} }
...@@ -6,10 +6,9 @@ import com.zhiwei.brandkbs2.auth.Auth; ...@@ -6,10 +6,9 @@ import com.zhiwei.brandkbs2.auth.Auth;
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.controller.BaseController; import com.zhiwei.brandkbs2.controller.BaseController;
import com.zhiwei.brandkbs2.enmus.EmotionEnum;
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.vo.ProjectVO; import com.zhiwei.brandkbs2.pojo.BaseMap;
import com.zhiwei.brandkbs2.service.MarkDataService; 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;
...@@ -26,7 +25,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -26,7 +25,6 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -144,23 +142,19 @@ public class AppHotController extends BaseController { ...@@ -144,23 +142,19 @@ public class AppHotController extends BaseController {
Date startDate = DateUtils.addHours(endDate, -24); Date startDate = DateUtils.addHours(endDate, -24);
List<Map.Entry<String, Integer>> markTopTitleList = List<Map.Entry<String, Integer>> markTopTitleList =
markDataService.getMarkTopTitle(startDate.getTime(), endDate.getTime(), null, projectId, linkedGroupId, size); markDataService.getMarkTopTitle(startDate.getTime(), endDate.getTime(), null, projectId, linkedGroupId,"0", size);
List<JSONObject> resultList = markTopTitleList.stream().map(map -> { List<JSONObject> resultList = markTopTitleList.stream().map(map -> {
JSONObject article = null;
try {
article = markDataService.getFirstArticle(startDate.getTime(), endDate.getTime(), map.getKey(), projectId, linkedGroupId);
} catch (IOException e) {
throw new RuntimeException(e);
}
JSONObject resultJsonObject = new JSONObject(); JSONObject resultJsonObject = new JSONObject();
resultJsonObject.put("title", map.getKey()); resultJsonObject.put("title", map.getKey());
if (Objects.nonNull(article)) {
resultJsonObject.put("content", article.get("content"));
resultJsonObject.put("url", article.get("url"));
resultJsonObject.put("realSource", article.get("realSource"));
}
resultJsonObject.put("num", map.getValue()); resultJsonObject.put("num", map.getValue());
try {
BaseMap firstArticle = markDataService.getFirstArticle(startDate.getTime(), endDate.getTime(), map.getKey(), projectId, linkedGroupId);
resultJsonObject.put("content", firstArticle.getContent());
resultJsonObject.put("url", firstArticle.getUrl());
resultJsonObject.put("realSource", firstArticle.getRealSource());
} catch (IOException ignored) {
}
return resultJsonObject; return resultJsonObject;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return ResponseResult.success(resultList); return ResponseResult.success(resultList);
......
...@@ -4,8 +4,10 @@ import com.zhiwei.brandkbs2.auth.Auth; ...@@ -4,8 +4,10 @@ import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.controller.BaseController; import com.zhiwei.brandkbs2.controller.BaseController;
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.service.CustomEventService;
import com.zhiwei.brandkbs2.service.MarkFlowService; import com.zhiwei.brandkbs2.service.MarkFlowService;
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.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -20,22 +22,33 @@ import javax.annotation.Resource; ...@@ -20,22 +22,33 @@ import javax.annotation.Resource;
@RestController @RestController
@RequestMapping("/app/global") @RequestMapping("/app/global")
@Api(tags = "全局通用接口", description = "提供全局通用相关") @Api(tags = "全局通用接口", description = "提供全局通用相关")
@Auth(role = RoleEnum.CUSTOMER)
public class GlobalController extends BaseController { public class GlobalController extends BaseController {
@Resource(name = "markFlowServiceImpl") @Resource(name = "markFlowServiceImpl")
MarkFlowService markFlowService; MarkFlowService markFlowService;
@Resource
CustomEventService customEventService;
@ApiOperation("内部快照-组装页面") @ApiOperation("内部快照-组装页面")
@Auth(role = RoleEnum.CUSTOMER)
@PostMapping("/shotPage") @PostMapping("/shotPage")
public ResponseResult setShotPage(@RequestBody String markFlowEntity) { public ResponseResult setShotPage(@RequestBody String markFlowEntity) {
return ResponseResult.success(markFlowService.setShotPage(markFlowEntity)); return ResponseResult.success(markFlowService.setShotPage(markFlowEntity));
} }
@ApiOperation("内部快照-获取页面") @ApiOperation("内部快照-获取页面")
@Auth(role = RoleEnum.CUSTOMER)
@GetMapping("/shotPage/{id}") @GetMapping("/shotPage/{id}")
public ResponseResult getShotPage(@PathVariable(name = "id") String id) { public ResponseResult getShotPage(@PathVariable(name = "id") String id) {
return ResponseResult.success(markFlowService.getShotPageFromCache(id)); return ResponseResult.success(markFlowService.getShotPageFromCache(id));
} }
@ApiOperation("分享自定义事件分析展示")
@ApiImplicitParam(name = "share", value = "自定义事件分享id", required = true, paramType = "path", dataType = "string")
@GetMapping("/customEvent/analyze/{share}")
public ResponseResult getShareCustomEventAnalyze(@PathVariable String share) {
return ResponseResult.success(customEventService.getShareCustomEventAnalyze(share));
}
} }
...@@ -56,6 +56,13 @@ public interface BaseMongoDao<T extends AbstractBaseMongo> { ...@@ -56,6 +56,13 @@ public interface BaseMongoDao<T extends AbstractBaseMongo> {
/** /**
* 通过id删除数据 * 通过id删除数据
* *
* @param query 查询条件
*/
void deleteOneByQuery(Query query, String... collectionNames);
/**
* 通过id删除数据
*
* @param id 数据库唯一id * @param id 数据库唯一id
*/ */
void deleteOneByIdWithQuery(String id, Query query, String... collectionNames); void deleteOneByIdWithQuery(String id, Query query, String... collectionNames);
......
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.CustomEvent;
/**
* @ClassName: CustomEventDao
* @Description CustomEventDao
* @author: sjj
* @date: 2022-08-04 14:00
*/
public interface CustomEventDao extends BaseMongoDao<CustomEvent>{
}
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.CustomEventData;
/**
* @ClassName: CustomEventDataDao
* @Description CustomEventDataDao
* @author: sjj
* @date: 2022-08-04 16:07
*/
public interface CustomEventDataDao extends BaseMongoDao<CustomEventData>{
CustomEventData queryUnique(CustomEventData customEventData);
}
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend;
import org.springframework.data.mongodb.core.query.Query;
/**
* @Description:EventDisseminationTrendDao
* @Author: shentao
* @Date: 2022/8/3 16:21
*/
public interface EventDisseminationTrendDao extends BaseMongoDao<EventDisseminationTrend>{
/**
* 按条件获取单个
* @param query
* @return
*/
EventDisseminationTrend findOne(Query query);
}
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.EventTopArticlesAnalysis;
/**
* @Description:EventTopArticlesAnalysisDao
* @Author: shentao
* @Date: 2022/8/3 16:23
*/
public interface EventTopArticlesAnalysisDao extends BaseMongoDao<EventTopArticlesAnalysis>{
}
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.MediaType;
/**
* @ClassName: MediaTypeDao
* @Description MediaTypeDao
* @author: sjj
* @date: 2022-08-05 09:49
*/
public interface MediaTypeDao extends BaseMongoDao<MediaType>{
MediaType queryUnique(String source,String platform,String projectId);
}
...@@ -15,16 +15,16 @@ import org.springframework.stereotype.Service; ...@@ -15,16 +15,16 @@ import org.springframework.stereotype.Service;
*/ */
@Service("aggreeResultDaoImpl") @Service("aggreeResultDaoImpl")
public class AggreeResultDaoImpl extends BaseMongoDaoImpl<AggreeResult> implements AggreeResultDao { public class AggreeResultDaoImpl extends BaseMongoDaoImpl<AggreeResult> implements AggreeResultDao {
private static final String COLLECTION_PREFIX = "brandkbs_aggree_result"; private static final String COLLECTION_NAME = "brandkbs_aggree_result";
public AggreeResultDaoImpl() { public AggreeResultDaoImpl() {
super(COLLECTION_PREFIX); super(COLLECTION_NAME);
} }
@Override @Override
public long deleteExpire(long expireTime) { public long deleteExpire(long expireTime) {
Query query = Query.query(Criteria.where("cTime").lt(expireTime)); Query query = Query.query(Criteria.where("cTime").lt(expireTime));
DeleteResult remove = mongoTemplate.remove(query, COLLECTION_PREFIX); DeleteResult remove = mongoTemplate.remove(query, COLLECTION_NAME);
return remove.getDeletedCount(); return remove.getDeletedCount();
} }
} }
...@@ -77,6 +77,11 @@ public class BaseMongoDaoImpl<T extends AbstractBaseMongo> implements BaseMongoD ...@@ -77,6 +77,11 @@ public class BaseMongoDaoImpl<T extends AbstractBaseMongo> implements BaseMongoD
} }
@Override @Override
public void deleteOneByQuery(Query query, String... collectionNames) {
mongoTemplate.remove(query, getCollections(collectionNames)[0]);
}
@Override
public void deleteOneByIdWithQuery(String id, Query query, String... collectionNames) { public void deleteOneByIdWithQuery(String id, Query query, String... collectionNames) {
mongoTemplate.remove(query.addCriteria(Criteria.where(ID).is(id)), getCollections(collectionNames)[0]); mongoTemplate.remove(query.addCriteria(Criteria.where(ID).is(id)), getCollections(collectionNames)[0]);
} }
......
...@@ -15,16 +15,16 @@ import org.springframework.stereotype.Component; ...@@ -15,16 +15,16 @@ import org.springframework.stereotype.Component;
*/ */
@Component("brandkbsTaskDao") @Component("brandkbsTaskDao")
public class BrandkbsTaskDaoImpl extends BaseMongoDaoImpl<BrandkbsTask> implements BrandkbsTaskDao { public class BrandkbsTaskDaoImpl extends BaseMongoDaoImpl<BrandkbsTask> implements BrandkbsTaskDao {
private static final String COLLECTION_PREFIX = "brandkbs_task"; private static final String COLLECTION_NAME = "brandkbs_task";
public BrandkbsTaskDaoImpl() { public BrandkbsTaskDaoImpl() {
super(COLLECTION_PREFIX); super(COLLECTION_NAME);
} }
@Override @Override
public BrandkbsTask findTaskByTaskNameAndVersion(String taskName, int version) { public BrandkbsTask findTaskByTaskNameAndVersion(String taskName, int version) {
Query query = Query.query(Criteria.where("taskName").is(taskName).and("version").is(version)); Query query = Query.query(Criteria.where("taskName").is(taskName).and("version").is(version));
return mongoTemplate.findOne(query, clazz, COLLECTION_PREFIX); return mongoTemplate.findOne(query, clazz, COLLECTION_NAME);
} }
@Override @Override
...@@ -32,6 +32,6 @@ public class BrandkbsTaskDaoImpl extends BaseMongoDaoImpl<BrandkbsTask> implemen ...@@ -32,6 +32,6 @@ public class BrandkbsTaskDaoImpl extends BaseMongoDaoImpl<BrandkbsTask> implemen
int version = task.getVersion(); int version = task.getVersion();
Query query = Query query =
Query.query(Criteria.where("_id").is(task.getId()).and("version").is(version).and("executableTime").is(task.getExecutableTime())); Query.query(Criteria.where("_id").is(task.getId()).and("version").is(version).and("executableTime").is(task.getExecutableTime()));
return mongoTemplate.updateFirst(query, Update.update("version", ++version), COLLECTION_PREFIX).getModifiedCount(); return mongoTemplate.updateFirst(query, Update.update("version", ++version), COLLECTION_NAME).getModifiedCount();
} }
} }
...@@ -25,18 +25,18 @@ import java.util.concurrent.CompletableFuture; ...@@ -25,18 +25,18 @@ import java.util.concurrent.CompletableFuture;
public class ChannelDaoImpl extends BaseMongoDaoImpl<Channel> implements ChannelDao { public class ChannelDaoImpl extends BaseMongoDaoImpl<Channel> implements ChannelDao {
private static final Logger log = LogManager.getLogger(ChannelDaoImpl.class); private static final Logger log = LogManager.getLogger(ChannelDaoImpl.class);
private static final String COLLECTION_PREFIX = "brandkbs_channel"; private static final String COLLECTION_NAME = "brandkbs_channel";
private final ThreadPoolTaskExecutor executor; private final ThreadPoolTaskExecutor executor;
public ChannelDaoImpl(@Qualifier("mongoQueryExecutor") ThreadPoolTaskExecutor executor) { public ChannelDaoImpl(@Qualifier("mongoQueryExecutor") ThreadPoolTaskExecutor executor) {
super(COLLECTION_PREFIX); super(COLLECTION_NAME);
this.executor = executor; this.executor = executor;
} }
@Override @Override
public Channel queryUnique(String channelFid) { public Channel queryUnique(String channelFid) {
Query query = Query.query(Criteria.where("fid").is(channelFid)); Query query = Query.query(Criteria.where("fid").is(channelFid));
return mongoTemplate.findOne(query, clazz, COLLECTION_PREFIX); return mongoTemplate.findOne(query, clazz, COLLECTION_NAME);
} }
@Override @Override
......
...@@ -12,10 +12,10 @@ import org.springframework.stereotype.Component; ...@@ -12,10 +12,10 @@ import org.springframework.stereotype.Component;
*/ */
@Component("channelTagDao") @Component("channelTagDao")
public class ChannelTagDaoImpl extends BaseMongoDaoImpl<ChannelTag> implements ChannelTagDao { public class ChannelTagDaoImpl extends BaseMongoDaoImpl<ChannelTag> implements ChannelTagDao {
private static final String COLLECTION_PREFIX = "brandkbs_channel_tag"; private static final String COLLECTION_NAME = "brandkbs_channel_tag";
public ChannelTagDaoImpl() { public ChannelTagDaoImpl() {
super(COLLECTION_PREFIX); super(COLLECTION_NAME);
} }
@Override @Override
......
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.CustomEventDao;
import com.zhiwei.brandkbs2.pojo.CustomEvent;
import org.springframework.stereotype.Component;
/**
* @ClassName: CustomEventDaoImpl
* @Description CustomEventDaoImpl
* @author: sjj
* @date: 2022-08-04 14:01
*/
@Component
public class CustomEventDaoImpl extends BaseMongoDaoImpl<CustomEvent> implements CustomEventDao {
private static final String COLLECTION_NAME = "brandkbs_custom_event";
public CustomEventDaoImpl() {
super(COLLECTION_NAME);
}
}
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.CustomEventDataDao;
import com.zhiwei.brandkbs2.pojo.CustomEventData;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* @ClassName: CustomEventDataDaoImpl
* @Description CustomEventDataDaoImpl
* @author: sjj
* @date: 2022-08-04 16:08
*/
@Component
public class CustomEventDataDaoImpl extends BaseMongoDaoImpl<CustomEventData> implements CustomEventDataDao {
private static final String COLLECTION_NAME = "brandkbs_custom_event_data";
public CustomEventDataDaoImpl() {
super(COLLECTION_NAME);
}
@Override
public CustomEventData queryUnique(CustomEventData customEventData) {
Objects.requireNonNull(customEventData.getCustomEventId());
Objects.requireNonNull(customEventData.getMarkDataId());
Objects.requireNonNull(customEventData.getProjectId());
Criteria criteria = Criteria.where("customEventId").is(customEventData.getCustomEventId());
criteria.and("markDataId").is(customEventData.getMarkDataId());
criteria.and("projectId").is(customEventData.getProjectId());
return mongoTemplate.findOne(Query.query(criteria), clazz, COLLECTION_NAME);
}
}
...@@ -69,6 +69,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao { ...@@ -69,6 +69,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
private Map<Long, List<Event>> getEventTimePattern(ChannelIndex channelIndex, Long startTime, Long endTime, int nrOfChars) { private Map<Long, List<Event>> getEventTimePattern(ChannelIndex channelIndex, Long startTime, Long endTime, int nrOfChars) {
// 添加渠道唯一标识 // 添加渠道唯一标识
Criteria criteria = addChannelIndex(channelIndex); Criteria criteria = addChannelIndex(channelIndex);
criteria.and("startTime").gte(startTime).lt(endTime);
// 分组 // 分组
Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria),
// 截取前8位,按日分组 // 截取前8位,按日分组
......
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.EventDisseminationTrendDao;
import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.EventDisseminationTrend;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
/**
* @Description:
* @Author: shentao
* @Date: 2022/8/4 16:53
*/
@Component("eventDisseminationTrendDao")
public class EventDisseminationTrendDaoImpl extends BaseMongoDaoImpl<EventDisseminationTrend> implements EventDisseminationTrendDao {
private static final String COLLECTION_NAME = "brandkbs_event_dissemination_trend";
public EventDisseminationTrendDaoImpl() {
super(COLLECTION_NAME);
}
@Override
public EventDisseminationTrend findOne(Query query) {
return mongoTemplate.findOne(query, EventDisseminationTrend.class);
}
}
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.EventTopArticlesAnalysisDao;
import com.zhiwei.brandkbs2.pojo.EventTopArticlesAnalysis;
import org.springframework.stereotype.Component;
/**
* @Description:
* @Author: shentao
* @Date: 2022/8/3 16:23
*/
@Component("eventTopArticlesAnalysisDao")
public class EventTopArticlesAnalysisDaoImpl extends BaseMongoDaoImpl<EventTopArticlesAnalysis> implements EventTopArticlesAnalysisDao {
private static final String COLLECTION_NAME = "brandkbs_event_top_articles_analysis";
public EventTopArticlesAnalysisDaoImpl() {
super(COLLECTION_NAME);
}
}
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.MediaTypeDao;
import com.zhiwei.brandkbs2.pojo.MediaType;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
/**
* @ClassName: MediaTypeDaoImpl
* @Description MediaTypeDaoImpl
* @author: sjj
* @date: 2022-08-05 09:50
*/
@Component
public class MediaTypeDaoImpl extends BaseMongoDaoImpl<MediaType> implements MediaTypeDao {
private static final String COLLECTION_NAME = "brandkbs_media_type";
public MediaTypeDaoImpl() {
super(COLLECTION_NAME);
}
@Override
public MediaType queryUnique(String source, String platform, String projectId) {
Query query = new Query();
query.addCriteria(Criteria.where("channel").is(source).and("platform").is(platform).and("projectId").is(projectId));
return mongoTemplate.findOne(query, clazz, COLLECTION_NAME);
}
}
...@@ -3,7 +3,6 @@ package com.zhiwei.brandkbs2.es; ...@@ -3,7 +3,6 @@ package com.zhiwei.brandkbs2.es;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.common.GenericAttribute; import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.pojo.ChannelIndex; import com.zhiwei.brandkbs2.pojo.ChannelIndex;
import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -23,7 +22,6 @@ import org.elasticsearch.common.unit.TimeValue; ...@@ -23,7 +22,6 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregationBuilder;
...@@ -53,7 +51,6 @@ public class EsClientDao { ...@@ -53,7 +51,6 @@ public class EsClientDao {
protected static final FastDateFormat DF = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); protected static final FastDateFormat DF = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
private static final String[] CHANNEL_RECORD_FETCH_SOURCE = new String[]{"id", "c5", "foreign", "real_source", "source", "mtime", "time", private static final String[] CHANNEL_RECORD_FETCH_SOURCE = new String[]{"id", "c5", "foreign", "real_source", "source", "mtime", "time",
"brandkbs_cache_maps", "brandkbs_mark_cache_maps"}; "brandkbs_cache_maps", "brandkbs_mark_cache_maps"};
private static final String[] EVENT_FETCH_SOURCE = new String[]{"ind_full_text", "c5", "real_source", "source", "mtime", "time", "url", "mtag"};
private static final Long ONE_HOUR = 60 * 60 * 1000L; private static final Long ONE_HOUR = 60 * 60 * 1000L;
// 滚动查询超时时间 // 滚动查询超时时间
...@@ -74,12 +71,12 @@ public class EsClientDao { ...@@ -74,12 +71,12 @@ public class EsClientDao {
public JSONObject searchById(String queryId) throws IOException { public JSONObject searchById(String queryId) throws IOException {
return searchByIds(Collections.singleton(queryId)).get(queryId); return searchByIds(Collections.singleton(queryId)).get(queryId);
} }
public Map<String, JSONObject> searchByIds(Collection<String> queryIds) throws IOException { public Map<String, JSONObject> searchByIds(Collection<String> queryIds) throws IOException {
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
QueryBuilder queryBuilder = QueryBuilders.idsQuery().addIds(queryIds.toArray(new String[0])); QueryBuilder queryBuilder = QueryBuilders.idsQuery().addIds(queryIds.toArray(new String[0]));
sourceBuilder.query(queryBuilder).size(queryIds.size()); sourceBuilder.query(queryBuilder).size(queryIds.size());
SearchResponse searchResponse = getEsClient().search(new SearchRequest(getIndexes()).source(sourceBuilder), RequestOptions.DEFAULT); SearchResponse searchResponse = retryTemplate.execute(context -> getEsClient().search(new SearchRequest(getIndexes()).source(sourceBuilder), RequestOptions.DEFAULT));
return Arrays.stream(searchResponse.getHits().getHits()).collect(Collectors.toMap(SearchHit::getId, hit -> new JSONObject(hit.getSourceAsMap()))); return Arrays.stream(searchResponse.getHits().getHits()).collect(Collectors.toMap(SearchHit::getId, hit -> new JSONObject(hit.getSourceAsMap())));
} }
...@@ -106,32 +103,24 @@ public class EsClientDao { ...@@ -106,32 +103,24 @@ public class EsClientDao {
return res; return res;
} }
/**
* 搜索符合事件数据
*
* @param event
* @return
*/
public List<Map<String, Object>> searchMarkDataByEvent(Event event) {
try {
RangeQueryBuilder timeBuilder = QueryBuilders.rangeQuery("time").gte(event.getStartTime());
if (event.isEndStatus()) {
timeBuilder.lt(event.getEndTime());
}
return searchScroll(timeBuilder, 2000, EVENT_FETCH_SOURCE);
} catch (IOException e) {
log.error("searchByEvent-", e);
}
return Collections.emptyList();
}
// public Object searchMarkData(MarkSearchDTO markSearchDTO) {
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// // 添加排序字段
// addSort(searchSourceBuilder, markSearchDTO.getSorter());
// //
// return null; // /**
// * 搜索符合事件数据
// *
// * @param event
// * @return
// */
// public List<JSONObject> searchMarkDataByEvent(Event event) {
// try {
// RangeQueryBuilder timeBuilder = QueryBuilders.rangeQuery("time").gte(event.getStartTime());
// if (event.isEndStatus()) {
// timeBuilder.lt(event.getEndTime());
// }
// return searchScroll(timeBuilder, 2000, EVENT_FETCH_SOURCE);
// } catch (IOException e) {
// log.error("searchByEvent-", e);
// }
// return Collections.emptyList();
// } // }
/** /**
...@@ -140,8 +129,8 @@ public class EsClientDao { ...@@ -140,8 +129,8 @@ public class EsClientDao {
* @param searchSourceBuilder 搜索source * @param searchSourceBuilder 搜索source
* @throws IOException * @throws IOException
*/ */
private List<Map<String, Object>> searchScroll(SearchSourceBuilder searchSourceBuilder) throws IOException { private List<JSONObject> searchScroll(SearchSourceBuilder searchSourceBuilder) throws IOException {
List<Map<String, Object>> res = new ArrayList<>(); List<JSONObject> res = new ArrayList<>();
SearchResponse searchResponse = getEsClient().search(new SearchRequest(getIndexes()).source(searchSourceBuilder).scroll(TIME_VALUE), RequestOptions.DEFAULT); SearchResponse searchResponse = getEsClient().search(new SearchRequest(getIndexes()).source(searchSourceBuilder).scroll(TIME_VALUE), RequestOptions.DEFAULT);
while (true) { while (true) {
if (0 == searchResponse.getHits().getHits().length) { if (0 == searchResponse.getHits().getHits().length) {
...@@ -150,7 +139,7 @@ public class EsClientDao { ...@@ -150,7 +139,7 @@ public class EsClientDao {
getEsClient().clearScroll(clearScrollRequest, RequestOptions.DEFAULT); getEsClient().clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
break; break;
} }
res.addAll(Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getSourceAsMap).collect(Collectors.toList())); res.addAll(Arrays.stream(searchResponse.getHits().getHits()).map(hit -> new JSONObject(hit.getSourceAsMap())).collect(Collectors.toList()));
SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId()); SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId());
scrollRequest.scroll(TIME_VALUE); scrollRequest.scroll(TIME_VALUE);
searchResponse = getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); searchResponse = getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT);
...@@ -166,7 +155,7 @@ public class EsClientDao { ...@@ -166,7 +155,7 @@ public class EsClientDao {
* @param fetchSource 包含的属性阈 * @param fetchSource 包含的属性阈
* @throws IOException * @throws IOException
*/ */
private List<Map<String, Object>> searchScroll(QueryBuilder queryBuilder, int size, String[] fetchSource) throws IOException { public List<JSONObject> searchScroll(QueryBuilder queryBuilder, int size, String[] fetchSource) throws IOException {
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(queryBuilder).size(size).fetchSource(fetchSource, null); sourceBuilder.query(queryBuilder).size(size).fetchSource(fetchSource, null);
return retryTemplate.execute(context -> searchScroll(sourceBuilder)); return retryTemplate.execute(context -> searchScroll(sourceBuilder));
...@@ -176,7 +165,7 @@ public class EsClientDao { ...@@ -176,7 +165,7 @@ public class EsClientDao {
Map<ChannelIndex, ChannelIndex.Record> res = new HashMap<>(); Map<ChannelIndex, ChannelIndex.Record> res = new HashMap<>();
try { try {
QueryBuilder queryBuilder = QueryBuilders.rangeQuery("mtime").gte(startTime).lt(endTime); QueryBuilder queryBuilder = QueryBuilders.rangeQuery("mtime").gte(startTime).lt(endTime);
List<Map<String, Object>> results = searchScroll(queryBuilder, 10000, CHANNEL_RECORD_FETCH_SOURCE); List<JSONObject> results = searchScroll(queryBuilder, 10000, CHANNEL_RECORD_FETCH_SOURCE);
for (Map<String, Object> result : results) { for (Map<String, Object> result : results) {
for (ChannelIndex channelIndex : ChannelIndex.createChannelIndexes(result)) { for (ChannelIndex channelIndex : ChannelIndex.createChannelIndexes(result)) {
res.compute(channelIndex, (k, v) -> { res.compute(channelIndex, (k, v) -> {
...@@ -271,6 +260,10 @@ public class EsClientDao { ...@@ -271,6 +260,10 @@ public class EsClientDao {
return response.getCount(); return response.getCount();
} }
public Long count(QueryBuilder postFilter) throws IOException {
return count(getIndexes(), postFilter, null);
}
public static SearchHelper createSearchHelper() { public static SearchHelper createSearchHelper() {
return new SearchHelper(); return new SearchHelper();
} }
...@@ -314,7 +307,7 @@ public class EsClientDao { ...@@ -314,7 +307,7 @@ public class EsClientDao {
} }
if (null == size) { if (null == size) {
searchSourceBuilder.size(10000); searchSourceBuilder.size(10000);
} else if (size > 0) { } else if (size >= 0) {
searchSourceBuilder.size(size); searchSourceBuilder.size(size);
} }
if (!Objects.isNull(highlighter)) { if (!Objects.isNull(highlighter)) {
......
...@@ -78,7 +78,7 @@ public class EsQueryTools { ...@@ -78,7 +78,7 @@ public class EsQueryTools {
public static BoolQueryBuilder assembleTagQuery(List<String> tagIds) { public static BoolQueryBuilder assembleTagQuery(List<String> tagIds) {
BoolQueryBuilder tagQuery = QueryBuilders.boolQuery(); BoolQueryBuilder tagQuery = QueryBuilders.boolQuery();
tagIds.forEach(e -> { tagIds.forEach(e -> {
tagQuery.should(QueryBuilders.termQuery("mark_cache_maps.unique_id.keyword", e)); tagQuery.should(QueryBuilders.termQuery("brandkbs_mark_cache_maps.unique_id.keyword", e));
}); });
return tagQuery; return tagQuery;
} }
...@@ -92,7 +92,7 @@ public class EsQueryTools { ...@@ -92,7 +92,7 @@ public class EsQueryTools {
public static BoolQueryBuilder assembleMediaTypeQuery(List<String> mediaTypes) { public static BoolQueryBuilder assembleMediaTypeQuery(List<String> mediaTypes) {
BoolQueryBuilder tagQuery = QueryBuilders.boolQuery(); BoolQueryBuilder tagQuery = QueryBuilders.boolQuery();
mediaTypes.forEach(e -> { mediaTypes.forEach(e -> {
tagQuery.should(QueryBuilders.termQuery("mark_cache_maps.channel_type.keyword", e)); tagQuery.should(QueryBuilders.termQuery("brandkbs_mark_cache_maps.channel_type.keyword", e));
}); });
return tagQuery; return tagQuery;
} }
...@@ -124,7 +124,7 @@ public class EsQueryTools { ...@@ -124,7 +124,7 @@ public class EsQueryTools {
public static void assembleContendsQuery(BoolQueryBuilder query, Collection<String> contends) { public static void assembleContendsQuery(BoolQueryBuilder query, Collection<String> contends) {
BoolQueryBuilder contendQuery = QueryBuilders.boolQuery(); BoolQueryBuilder contendQuery = QueryBuilders.boolQuery();
// 主品牌一定参与 // 主品牌一定参与
contendQuery.should(QueryBuilders.termQuery("contend_id.keyword", "0")); // contendQuery.should(QueryBuilders.termQuery("contend_id.keyword", "0"));
if (null == contends) { if (null == contends) {
return; return;
} }
......
...@@ -24,7 +24,7 @@ public class AggreeResult extends AbstractBaseMongo { ...@@ -24,7 +24,7 @@ public class AggreeResult extends AbstractBaseMongo {
/** /**
* 需要移除的属性 * 需要移除的属性
*/ */
private static final List<String> EXCLUDE_FIELD = Arrays.asList("mark_cache_maps", "brandkbs_cache_maps"); private static final List<String> EXCLUDE_FIELD = Arrays.asList("brandkbs_mark_cache_maps", "brandkbs_cache_maps");
/** /**
* 任务id * 任务id
......
package com.zhiwei.brandkbs2.pojo; package com.zhiwei.brandkbs2.pojo;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.base.category.ClassD; import com.zhiwei.base.category.ClassD;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -66,6 +67,8 @@ public class BaseMap { ...@@ -66,6 +67,8 @@ public class BaseMap {
*/ */
private String emotion; private String emotion;
private JSONObject sourceJson;
public String getTitleNullOptionalContent() { public String getTitleNullOptionalContent() {
if (null != title) { if (null != title) {
return title; return title;
......
...@@ -165,7 +165,7 @@ public class ChannelIndex extends AbstractBaseMongo { ...@@ -165,7 +165,7 @@ public class ChannelIndex extends AbstractBaseMongo {
public static List<Article> sortArticles(List<Article> articles) { public static List<Article> sortArticles(List<Article> articles) {
articles.sort(Comparator.comparingLong(ChannelIndex.Article::getTime)); articles.sort((x, y) -> Long.compare(y.getTime(), x.getTime()));
return articles; return articles;
} }
......
package com.zhiwei.brandkbs2.pojo;
import com.zhiwei.brandkbs2.pojo.dto.CustomEventDTO;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author lxj
* @version 1.0
* @description 自定义事件信息实体类
* @date 2020/10/19 17:48
*/
@Setter
@Getter
public class CustomEvent extends AbstractBaseMongo {
/**
* 标题
*/
private String title;
/**
* 开始时间
*/
private Long startTime;
/**
* 结束时间
*/
private Long endTime;
/**
* 更新时间
*/
private Long updateTime;
/**
* 关键字
*/
private List<String> keywords;
/**
* 事件状态
*/
private Boolean status;
/**
* 项目ID
*/
private String projectId;
/**
* 关联项目组ID
*/
private String linkedGroupId;
/**
* 将自定义事件传输对象转换为自定义事件对象
*
* @param customEventDTO 自定义事件传输对象
* @return 自定义事件对象
*/
public static CustomEvent creatFromCustomEventDTO(CustomEventDTO customEventDTO) {
CustomEvent customEvent = new CustomEvent();
customEvent.setTitle(customEventDTO.getTitle());
customEvent.setStartTime(customEventDTO.getStartTime());
customEvent.setEndTime(customEventDTO.getEndTime());
customEvent.setKeywords(customEventDTO.getKeywords());
return customEvent;
}
}
package com.zhiwei.brandkbs2.pojo;
import lombok.Getter;
import lombok.Setter;
/**
* @author lxj
* @version 1.0
* @description 自定义事件信息实体类
* @date 2020/10/19 17:48
*/
@Setter
@Getter
public class CustomEventData extends AbstractBaseMongo {
/**
* 事件ID
*/
private String customEventId;
/**
* 标识数据ID
*/
private String markDataId;
/**
* 渠道ID
*/
// private String channelId;
/**
* 项目ID
*/
private String projectId;
}
...@@ -71,6 +71,10 @@ public class Event extends AbstractBaseMongo { ...@@ -71,6 +71,10 @@ public class Event extends AbstractBaseMongo {
*/ */
private String linkedGroupId; private String linkedGroupId;
/** /**
* 品牌ID
*/
private String contendId;
/**
* 是否是舆情事件 * 是否是舆情事件
*/ */
private String yqEventId; private String yqEventId;
...@@ -82,6 +86,22 @@ public class Event extends AbstractBaseMongo { ...@@ -82,6 +86,22 @@ public class Event extends AbstractBaseMongo {
* 参与渠道数 * 参与渠道数
*/ */
private Long totalChannelVolume; private Long totalChannelVolume;
/**
* 负面稿件数
*/
private Long negativeArticleVolume;
/**
* 正负中稿件比例
*/
private JSONObject articleEmotionProportions;
/**
* 平台稿件比例
*/
private JSONObject articlePlatformProportions;
/**
* 热门文章分析,传播方向:
*/
private String eventTopArticlesAnalysisDetail;
public static Event createFromYqEventDTO(YqEventDTO yqEventDTO, String collectionName, String projectId, String linkedGroupId) { public static Event createFromYqEventDTO(YqEventDTO yqEventDTO, String collectionName, String projectId, String linkedGroupId) {
Event event = new Event(); Event event = new Event();
......
...@@ -60,6 +60,10 @@ public class EventData extends AbstractBaseMongo { ...@@ -60,6 +60,10 @@ public class EventData extends AbstractBaseMongo {
*/ */
private String linkedGroupId; private String linkedGroupId;
/** /**
* 品牌ID
*/
private String contendId;
/**
* 情感倾向 * 情感倾向
*/ */
private String emotion; private String emotion;
...@@ -79,6 +83,10 @@ public class EventData extends AbstractBaseMongo { ...@@ -79,6 +83,10 @@ public class EventData extends AbstractBaseMongo {
* 原创/转发(微博平台) * 原创/转发(微博平台)
*/ */
private boolean isForward; private boolean isForward;
/**
* 来源标签(重要渠道)
*/
private String sourceTag;
public static EventData createFromEsMap(Map<String, Object> map, Event event) { public static EventData createFromEsMap(Map<String, Object> map, Event event) {
EventData data = new EventData(); EventData data = new EventData();
...@@ -86,6 +94,7 @@ public class EventData extends AbstractBaseMongo { ...@@ -86,6 +94,7 @@ public class EventData extends AbstractBaseMongo {
BaseMap baseMap = Tools.getBaseFromEsMap(map); BaseMap baseMap = Tools.getBaseFromEsMap(map);
data.setEventId(event.getId()); data.setEventId(event.getId());
data.setProjectId(event.getProjectId()); data.setProjectId(event.getProjectId());
data.setContendId(event.getContendId());
data.setLinkedGroupId(event.getLinkedGroupId()); data.setLinkedGroupId(event.getLinkedGroupId());
data.setPlatform(baseMap.getPlatform()); data.setPlatform(baseMap.getPlatform());
data.setRealSource(baseMap.getRealSource()); data.setRealSource(baseMap.getRealSource());
......
package com.zhiwei.brandkbs2.pojo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
import java.util.Map;
/**
* @Description: 事件传播趋势
* @Author: shentao
* @Date: 2022/8/3 14:33
*/
@Getter
@Setter
@Document(collection = "brandkbs_event_dissemination_trend")
public class EventDisseminationTrend extends AbstractBaseMongo{
/**
* 负面稿件传播
*/
private List<Map<String,Object>> negativeSpread;
/**
* 总稿件传播
*/
private List<Map<String,Object>> totalSpread;
/**
* 类型 按小时、按天
*/
private String type;
/**
* 关联事件id
*/
private String eventId;
}
package com.zhiwei.brandkbs2.pojo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @Description: 事件热门文章分析
* @Author: shentao
* @Date: 2022/8/3 16:01
*/
@Getter
@Setter
@Document(collection = "brandkbs_event_top_articles_analysis")
public class EventTopArticlesAnalysis extends AbstractBaseMongo{
/**
* 聚合标题
*/
private String aggTitle;
/**
* 聚合标题
*/
private String emotion;
/**
* 聚合数
*/
private String count;
/**
* 发布时间
*/
private Long time;
/**
* 发布时间点(天级) 查询用
*/
private String timePoint;
/**
* type 按时间、按数量
*/
private String type;
/**
* 关联事件id
*/
private String eventId;
}
package com.zhiwei.brandkbs2.pojo;
import lombok.Getter;
import lombok.Setter;
/**
* @author lxj
* @version 1.0
* @description 媒体类型实体类
* @date 2019/9/5 14:35
*/
@Getter
@Setter
public class MediaType extends AbstractBaseMongo{
/**
* 渠道
*/
private String channel;
/**
* 平台
*/
private String platform;
/**
* 类别
*/
private String type;
/**
* 项目ID
*/
private String projectId;
}
package com.zhiwei.brandkbs2.pojo.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.util.List;
/**
* @author lxj
* @version 1.0
* @description 自定义事件传输类
* @date 2020/10/19 14:06
*/
@Data
@ToString
@ApiModel("自定义事件传输类")
public class CustomEventDTO {
/**
* 自定义事件ID
*/
@ApiModelProperty("自定义事件ID")
private String id;
/**
* 标题
*/
@ApiModelProperty("标题")
private String title;
/**
* 开始时间
*/
@ApiModelProperty("开始时间")
private Long startTime;
/**
* 结束时间
*/
@ApiModelProperty("结束时间")
private Long endTime;
/**
* 关键词
*/
@ApiModelProperty(value = "关键词")
private List<String> keywords;
}
\ No newline at end of file
package com.zhiwei.brandkbs2.pojo.vo; package com.zhiwei.brandkbs2.pojo.vo;
import com.alibaba.fastjson.JSONObject;
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 io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -7,8 +8,6 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -7,8 +8,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
import java.util.Date;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -66,6 +65,21 @@ public class EventListInfoVO { ...@@ -66,6 +65,21 @@ public class EventListInfoVO {
*/ */
@ApiModelProperty("事件首发稿件") @ApiModelProperty("事件首发稿件")
private EventData firstEventData; private EventData firstEventData;
/**
* 负面稿件数
*/
@ApiModelProperty("负面稿件数")
private Long negativeArticleVolume;
/**
* 正负中稿件比例
*/
@ApiModelProperty("正负中稿件比例")
private JSONObject articleEmotionProportions;
/**
* 平台稿件比例
*/
@ApiModelProperty("平台稿件比例")
private JSONObject articlePlatformProportions;
public EventListInfoVO(Event event) { public EventListInfoVO(Event event) {
this.id = event.getId(); this.id = event.getId();
...@@ -78,5 +92,8 @@ public class EventListInfoVO { ...@@ -78,5 +92,8 @@ public class EventListInfoVO {
this.eventTag = event.getEventTag().entrySet().stream() this.eventTag = event.getEventTag().entrySet().stream()
.map(entry-> String.valueOf(entry.getValue())) .map(entry-> String.valueOf(entry.getValue()))
.collect(Collectors.joining("|")); .collect(Collectors.joining("|"));
this.negativeArticleVolume = event.getNegativeArticleVolume();
this.articleEmotionProportions = event.getArticleEmotionProportions();
this.articlePlatformProportions = event.getArticlePlatformProportions();
} }
} }
package com.zhiwei.brandkbs2.pojo.vo;
import com.zhiwei.brandkbs2.pojo.EventTopArticlesAnalysis;
import lombok.Data;
import lombok.ToString;
/**
* @Description:
* @Author: shentao
* @Date: 2022/8/4 17:56
*/
@Data
@ToString
public class EventTopArticlesAnalysisVO {
/**
* 聚合标题
*/
private String aggTitle;
/**
* 聚合标题
*/
private String emotion;
/**
* 聚合数
*/
private String count;
/**
* 发布时间
*/
private Long time;
/**
* 发布时间点(天级) 查询用
*/
private String timePoint;
/**
* type 按时间、按数量
*/
private String type;
/**
* 关联事件id
*/
private String eventId;
/**
* 选中高亮
*/
private Boolean highLight;
public EventTopArticlesAnalysisVO(EventTopArticlesAnalysis eventTopArticlesAnalysis, boolean highLight) {
this.aggTitle = eventTopArticlesAnalysis.getAggTitle();
this.emotion = eventTopArticlesAnalysis.getEmotion();
this.count = eventTopArticlesAnalysis.getCount();
this.time = eventTopArticlesAnalysis.getTime();
this.timePoint = eventTopArticlesAnalysis.getTimePoint();
this.type = eventTopArticlesAnalysis.getType();
this.eventId = eventTopArticlesAnalysis.getEventId();
this.highLight = highLight;
}
}
...@@ -10,7 +10,6 @@ import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO; ...@@ -10,7 +10,6 @@ import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @ClassName: ChannelService * @ClassName: ChannelService
...@@ -183,7 +182,7 @@ public interface ChannelService { ...@@ -183,7 +182,7 @@ public interface ChannelService {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 渠道动向 * @return 渠道动向
*/ */
JSONObject getSpreadingTend(String channelId, String type, Set<String> contends, Long startTime, Long endTime); JSONObject getSpreadingTend(String channelId, String type, String contends, Long startTime, Long endTime);
/** /**
* 获取渠道动向-摘要 * 获取渠道动向-摘要
...@@ -194,7 +193,7 @@ public interface ChannelService { ...@@ -194,7 +193,7 @@ public interface ChannelService {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 渠道动向-摘要 * @return 渠道动向-摘要
*/ */
JSONObject getSpreadingTendSummary(String channelId, Set<String> contends, Long startTime, Long endTime); JSONObject getSpreadingTendSummary(String channelId, String contends, Long startTime, Long endTime);
/** /**
...@@ -208,18 +207,16 @@ public interface ChannelService { ...@@ -208,18 +207,16 @@ public interface ChannelService {
* @param contendId 竞品ID * @param contendId 竞品ID
* @return 稿件信息 * @return 稿件信息
*/ */
JSONObject getArticlesByTime(Long startTime, Long endTime, int page, int pageSize, String channelId, String contendId); JSONObject getArticlesByTime(Long startTime, Long endTime, Integer dayLimit, int page, int pageSize, String channelId, String contendId);
/** /**
* 下载时间段稿件信息 * 下载时间段稿件信息
* *
* @param startTime 开始时间时间戳 * @param startTime 开始时间时间戳
* @param endTime 结束时间 * @param endTime 结束时间
* @param page 页码
* @param pageSize 页码大小
* @param channelId 渠道ID * @param channelId 渠道ID
* @param contendId 竞品ID * @param contendId 竞品ID
* @return 稿件信息 * @return 稿件信息
*/ */
List<ExportAppChannelArticleDTO> downloadArticlesByTime(Long startTime, Long endTime,String channelId, String contendId); List<ExportAppChannelArticleDTO> downloadArticlesByTime(Long startTime, Long endTime, String channelId, String contendId);
} }
package com.zhiwei.brandkbs2.service;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.pojo.dto.CustomEventDTO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import java.util.List;
/**
* @ClassName: CustomEventService
* @Description 自定义事件服务抽象类
* @author: sjj
* @date: 2022-08-04 11:19
*/
public interface CustomEventService {
/**
* 获取稿件榜单数据
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 稿件榜单数据
*/
List<JSONObject> getCustomEventRankList(Long startTime, Long endTime);
/**
* 保存自定义事件
*
* @param customEventDTO 自定义事件传输类
*/
void saveCustomEvent(CustomEventDTO customEventDTO);
/**
* 更新自定义事件
*
* @param customEventDTO 自定义事件传输类
*/
void updateCustomEvent(CustomEventDTO customEventDTO);
/**
* 分页获取自定义事件列表
*
* @param page 页码
* @param pageSize 页码大小
* @param keyword 关键词
* @return 自定义事件列表
*/
PageVO<JSONObject> getCustomEventList(int page, int pageSize, String keyword);
/**
* 删除自定义事件
*
* @param id 自定义事件ID
*/
void deleteCustomEventById(String id);
/**
* 自定义事件数据更新
*
* @param id 自定义事件ID
*/
void analyzeCustomEvent(String id);
/**
* 获取分享自定义事件分析唯一标识
*
* @param id 自定义事件ID
* @return 分享自定义事件分析唯一标识
*/
JSONObject getCustomEventAnalyzeShareId(String id);
/**
* 获取自定义事件分析结果
*
* @param id 自定义事件ID
* @return 自定义事件分析结果
*/
JSONObject getCustomEventAnalyze(String id, boolean cache);
/**
* 获取自定义事件分析结果
*
* @param share 分享自定义事件分析唯一标识
* @return 自定义事件分析结果
*/
JSONObject getShareCustomEventAnalyze(String share);
}
...@@ -20,9 +20,9 @@ public interface EventDataService { ...@@ -20,9 +20,9 @@ public interface EventDataService {
/** /**
* 删除事件数据 * 删除事件数据
* *
* @param id 数据id * @param id 数据id
* @param eventId 事件id * @param eventId 事件id
*/ */
String deleteOneByIdAndEventId(String id,String eventId); String deleteOneByIdAndEventId(String id, String eventId);
} }
...@@ -5,16 +5,16 @@ import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDTO; ...@@ -5,16 +5,16 @@ 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.dto.EventDataDTO; import com.zhiwei.brandkbs2.pojo.dto.EventDataDTO;
import com.zhiwei.brandkbs2.pojo.dto.YqEventDTO; import com.zhiwei.brandkbs2.pojo.dto.YqEventDTO;
import com.zhiwei.brandkbs2.pojo.vo.EventListInfoVO; import com.zhiwei.brandkbs2.pojo.vo.*;
import com.zhiwei.brandkbs2.pojo.vo.EventVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.pojo.vo.YqEventSearchVO;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @ClassName: EventService * @ClassName: EventService
...@@ -220,5 +220,52 @@ public interface EventService { ...@@ -220,5 +220,52 @@ public interface EventService {
*/ */
JSONObject getEventsSearchCriteria(); JSONObject getEventsSearchCriteria();
/**
* 获取品牌事件列表信息
* @param linkedGroupId
* @param emotion
* @param startTime
* @param endTime
* @param page
* @param pageSize
* @param sorter
* @return
*/
PageVO<EventListInfoVO> getEventList(String linkedGroupId, String emotion, Long startTime, Long endTime, int page, int pageSize, String sorter); PageVO<EventListInfoVO> getEventList(String linkedGroupId, String emotion, Long startTime, Long endTime, int page, int pageSize, String sorter);
/**
* 事件详情-基础静态信息
* @param eventId
* @return
*/
EventListInfoVO getEventBaseInfo(String eventId);
/**
* 事件详情-传播趋势图
* @param eventId
* @param type
* @return
*/
EventDisseminationTrend getEventDisseminationTrends(String eventId, String type);
/**
* 事件详情-渠道发声
* @param eventId
* @param type
* @param page
* @param pageSize
* @param sorter
* @return
*/
PageVO<EventData> getEventChannelVoices(String eventId, String type, int page, int pageSize, String sorter);
/**
* 事件详情-热门文章分析
* @param id
* @param type
* @param emotion
* @param aggTitle
* @return
*/
JSONObject getEventTopArticlesAnalysis(String id, String type, String emotion, String aggTitle);
} }
package com.zhiwei.brandkbs2.service; package com.zhiwei.brandkbs2.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.pojo.EventData; import com.zhiwei.brandkbs2.pojo.BaseMap;
import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.MarkFlowEntity; import com.zhiwei.brandkbs2.pojo.MarkFlowEntity;
import com.zhiwei.brandkbs2.pojo.dto.ExportAppYuqingDTO; import com.zhiwei.brandkbs2.pojo.dto.ExportAppYuqingDTO;
import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
...@@ -30,17 +31,18 @@ public interface MarkDataService { ...@@ -30,17 +31,18 @@ public interface MarkDataService {
* @param markSearchDTO 标注数据搜索传输类 * @param markSearchDTO 标注数据搜索传输类
* @return 返回结果 * @return 返回结果
*/ */
Pair<String,List<ExportAppYuqingDTO>> downloadYuqingMarkList(MarkSearchDTO markSearchDTO); Pair<String, List<ExportAppYuqingDTO>> downloadYuqingMarkList(MarkSearchDTO markSearchDTO);
/** /**
* 生成聚合列表并返回id * 生成聚合列表并返回id
* *
* @return 聚合id * @return 聚合id
*/ */
String generateYuqingMarkAggreeList(Long startTime,Long endTime); String generateYuqingMarkAggreeList(Long startTime, Long endTime);
/** /**
* 获取聚合进度结果 * 获取聚合进度结果
*
* @param id 聚合id * @param id 聚合id
* @return 进度值 * @return 进度值
*/ */
...@@ -95,7 +97,7 @@ public interface MarkDataService { ...@@ -95,7 +97,7 @@ public interface MarkDataService {
* @param cache 是否启用缓存 * @param cache 是否启用缓存
* @return 获取舆情标注数据舆情渠道分布 * @return 获取舆情标注数据舆情渠道分布
*/ */
List<JSONObject> getMarkChannelProportion(Long startTime, Long endTime, boolean cache); JSONObject getMarkChannelProportion(Long startTime, Long endTime, boolean cache);
/** /**
* 获取舆情标注数据舆情平台分布 * 获取舆情标注数据舆情平台分布
...@@ -126,10 +128,12 @@ public interface MarkDataService { ...@@ -126,10 +128,12 @@ public interface MarkDataService {
* @param size 分页大小 * @param size 分页大小
* @return 最热标题 * @return 最热标题
*/ */
List<Map.Entry<String, Integer>> getMarkTopTitle(Long startTime, Long endTime, String emotion, String projectId, String linkedGroupId, int size) throws IOException; List<Map.Entry<String, Integer>> getMarkTopTitle(Long startTime, Long endTime, String emotion, String projectId, String linkedGroupId,
String contendId, int size) throws IOException;
/** /**
* 根据聚合标题和时间获取首发稿件 * 根据聚合标题和时间获取首发稿件
*
* @param startTime 开始时间 * @param startTime 开始时间
* @param endTime 结束时间 * @param endTime 结束时间
* @param aggTitle 聚合标题 * @param aggTitle 聚合标题
...@@ -137,5 +141,26 @@ public interface MarkDataService { ...@@ -137,5 +141,26 @@ public interface MarkDataService {
* @param linkedGroupId 关联组id * @param linkedGroupId 关联组id
* @return 首发稿件 * @return 首发稿件
*/ */
JSONObject getFirstArticle(Long startTime, Long endTime, String aggTitle, String projectId, String linkedGroupId) throws IOException; BaseMap getFirstArticle(Long startTime, Long endTime, String aggTitle, String projectId, String linkedGroupId) throws IOException;
/**
* 搜索标注数据通过事件
*
* @param event
* @return
*/
List<JSONObject> searchMarkDataByEvent(Event event);
/**
* 搜索标注数据
*
* @param projectId
* @param contendId
* @param startTime
* @param endTime
* @param fetchSource
* @return
*/
List<JSONObject> searchMarkDataByTime(String projectId, String linkedGroupId, String contendId, Long startTime, Long endTime, String... fetchSource);
} }
...@@ -2,10 +2,10 @@ package com.zhiwei.brandkbs2.service.impl; ...@@ -2,10 +2,10 @@ package com.zhiwei.brandkbs2.service.impl;
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.es.EsClientDao;
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.service.EventDataService; import com.zhiwei.brandkbs2.service.EventDataService;
import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -34,8 +34,8 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -34,8 +34,8 @@ public class EventDataServiceImpl implements EventDataService {
@Resource(name = "eventDataDao") @Resource(name = "eventDataDao")
private EventDataDao eventDataDao; private EventDataDao eventDataDao;
@Resource(name = "esClientDao") @Resource(name = "markDataServiceImpl")
private EsClientDao esClientDao; private MarkDataService markDataService;
@Resource(name = "eventServiceImpl") @Resource(name = "eventServiceImpl")
private EventServiceImpl eventServiceImpl; private EventServiceImpl eventServiceImpl;
...@@ -54,7 +54,8 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -54,7 +54,8 @@ public class EventDataServiceImpl implements EventDataService {
return; return;
} }
//查询可能符合该事件时间段内的所有数据 //查询可能符合该事件时间段内的所有数据
List<EventData> eventDataList = esClientDao.searchMarkDataByEvent(event).stream().map(map -> EventData.createFromEsMap(map, event)).collect(Collectors.toList()); List<EventData> eventDataList =
markDataService.searchMarkDataByEvent(event).stream().map(map -> EventData.createFromEsMap(map, event)).collect(Collectors.toList());
log.info("analysisEvent-eventId:{},查询可能符合该事件时间段内的所有数据:{}条", event.getId(), eventDataList.size()); log.info("analysisEvent-eventId:{},查询可能符合该事件时间段内的所有数据:{}条", event.getId(), eventDataList.size());
//更新事件稿件信息 //更新事件稿件信息
this.updateEventData(event, eventDataList); this.updateEventData(event, eventDataList);
......
...@@ -7,6 +7,8 @@ import com.zhiwei.brandkbs2.auth.UserThreadLocal; ...@@ -7,6 +7,8 @@ import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.RedisKeyPrefix; import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
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.easyexcel.EasyExcelUtil; import com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil;
import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO; import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportEventDTO;
...@@ -22,6 +24,8 @@ import com.zhiwei.brandkbs2.listener.ApplicationProjectListener; ...@@ -22,6 +24,8 @@ import com.zhiwei.brandkbs2.listener.ApplicationProjectListener;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
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.dto.EventDataDTO; import com.zhiwei.brandkbs2.pojo.dto.EventDataDTO;
import com.zhiwei.brandkbs2.pojo.dto.YqEventDTO; import com.zhiwei.brandkbs2.pojo.dto.YqEventDTO;
import com.zhiwei.brandkbs2.pojo.vo.*; import com.zhiwei.brandkbs2.pojo.vo.*;
...@@ -81,6 +85,12 @@ public class EventServiceImpl implements EventService { ...@@ -81,6 +85,12 @@ public class EventServiceImpl implements EventService {
@Resource(name = "eventDataDao") @Resource(name = "eventDataDao")
private EventDataDao eventDataDao; private EventDataDao eventDataDao;
@Resource(name = "eventDisseminationTrendDao")
private EventDisseminationTrendDao eventDisseminationTrendDao;
@Resource(name = "eventTopArticlesAnalysisDao")
private EventTopArticlesAnalysisDao eventTopArticlesAnalysisDao;
@Resource(name = "eventDataServiceImpl") @Resource(name = "eventDataServiceImpl")
private EventDataService eventDataService; private EventDataService eventDataService;
...@@ -546,6 +556,82 @@ public class EventServiceImpl implements EventService { ...@@ -546,6 +556,82 @@ public class EventServiceImpl implements EventService {
return pageVo; return pageVo;
} }
@Override
public EventListInfoVO getEventBaseInfo(String eventId) {
Event event = getEventById(eventId);
// vo封装
EventListInfoVO vo = new EventListInfoVO(event);
// 放入首发稿件
vo.setFirstEventData(eventDataDao.findFirstData(event.getId(), event.getCollectionName()));
return vo;
}
@Override
public EventDisseminationTrend getEventDisseminationTrends(String eventId, String type) {
Query query = new Query(Criteria.where("eventId").is(eventId).and("type").is(type));
return eventDisseminationTrendDao.findOne(query);
}
@Override
public PageVO<EventData> getEventChannelVoices(String eventId, String type, int page, int pageSize, String sorter) {
Event event = getEventById(eventId);
Query query = Query.query(Criteria.where("eventId").is(eventId));
if (Objects.equals("重要渠道", type)) {
query.addCriteria(Criteria.where("sourceTag").ne(null));
}
// 排序
JSONObject sortJson = JSONObject.parseObject(sorter);
sortJson.entrySet().forEach(sortEntry -> {
String sort = String.valueOf(sortEntry.getValue()).replace("end", "");
String sortField = sortEntry.getKey();
if (Sort.Direction.ASC.name().equalsIgnoreCase(sort)) {
query.with(Sort.by(Sort.Direction.ASC, sortField));
} else {
query.with(Sort.by(Sort.Direction.DESC, sortField));
}
});
// 总数
long total = eventDataDao.count(query, event.getCollectionName());
int start = pageSize * (page - 1);
query.limit(pageSize).skip(start);
// 数据
List<EventData> eventDataList = eventDataDao.findList(query, event.getCollectionName());
PageVO<EventData> pageVo = PageVO.createPageVo(total, page, pageSize, eventDataList);
return pageVo;
}
@Override
public JSONObject getEventTopArticlesAnalysis(String eventId, String type, String emotion, String aggTitle) {
JSONObject res = new JSONObject();
// 传播方向
Event event = getEventById(eventId);
res.put("detail", event.getEventTopArticlesAnalysisDetail());
// 分析结果
res.put("type", type);
Query query = new Query(Criteria.where("eventId").is(eventId).and("type").is(type));
if (!Objects.equals("全部", emotion)) {
query.addCriteria(Criteria.where("emotion").is(emotion));
}
List<EventTopArticlesAnalysis> eventTopArticlesAnalyses = eventTopArticlesAnalysisDao.findList(query);
switch (type) {
case "按时间":
Map<String, List<EventTopArticlesAnalysisVO>> collect = eventTopArticlesAnalyses.stream()
.map(eventTopArticlesAnalysis -> {
boolean highLight = Objects.equals(aggTitle, eventTopArticlesAnalysis.getAggTitle());
return new EventTopArticlesAnalysisVO(eventTopArticlesAnalysis, highLight);
}).collect(Collectors.groupingBy(EventTopArticlesAnalysisVO::getTimePoint));
res.put("dataDay", collect);
res.put("dataAmount", null);
return res;
case "按数量":
res.put("dataDay", null);
res.put("dataAmount", eventTopArticlesAnalyses);
return res;
default:
throw new IllegalStateException("Unexpected value: " + type);
}
}
/** /**
* 获取时间筛选条件 * 获取时间筛选条件
* *
......
package com.zhiwei.brandkbs2.util; package com.zhiwei.brandkbs2.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import lombok.Data; import lombok.Data;
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;
...@@ -38,6 +39,10 @@ public class MongoUtil { ...@@ -38,6 +39,10 @@ public class MongoUtil {
return new PageHelper<>(this.pageNum, this.pageSize, total, list); return new PageHelper<>(this.pageNum, this.pageSize, total, list);
} }
public PageVO<JSONObject> pageVO(long total, List<JSONObject> list) {
return PageVO.createPageVo(pageHelper(total, list), list);
}
@Data @Data
public static class PageHelper<T> { public static class PageHelper<T> {
private final Integer pageNum; private final Integer pageNum;
......
...@@ -19,6 +19,10 @@ public class RedisUtil { ...@@ -19,6 +19,10 @@ public class RedisUtil {
@Autowired @Autowired
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
public static String getCustomEventListKey(String projectId, Long startTimeStr, Long endTimeStr) {
return RedisKeyPrefix.CUSTOM_EVENT_LIST + Tools.concat(projectId, startTimeStr, endTimeStr);
}
public static String getShotPageKey(String id, String projectId) { public static String getShotPageKey(String id, String projectId) {
return RedisKeyPrefix.REDIS_SYSTEM_COPY + "SHOT_PAGE:" + projectId + "-" + id; return RedisKeyPrefix.REDIS_SYSTEM_COPY + "SHOT_PAGE:" + projectId + "-" + id;
} }
...@@ -35,6 +39,10 @@ public class RedisUtil { ...@@ -35,6 +39,10 @@ public class RedisUtil {
stringRedisTemplate.opsForValue().set(key, value, 1, TimeUnit.DAYS); stringRedisTemplate.opsForValue().set(key, value, 1, TimeUnit.DAYS);
} }
public void set(String key, String value) {
stringRedisTemplate.opsForValue().set(key, value);
}
public String get(String key) { public String get(String key) {
return stringRedisTemplate.opsForValue().get(key); return stringRedisTemplate.opsForValue().get(key);
} }
......
...@@ -313,9 +313,12 @@ public class Tools { ...@@ -313,9 +313,12 @@ public class Tools {
return res; return res;
} }
public static BaseMap getBaseFromEsMap(Map<String, Object> map) { public static BaseMap getBaseFromEsMap(Map<String, Object> map, boolean cacheSource) {
// 设置source,forward,time // 设置source,forward,time
BaseMap res = Tools.convertMap(map, BaseMap.class); BaseMap res = Tools.convertMap(map, BaseMap.class);
if (cacheSource) {
res.setSourceJson(new JSONObject(map));
}
res.setTypeB(ClassCodec.decodeClassD((int) map.get(GenericAttribute.ES_C5)).typeB()); res.setTypeB(ClassCodec.decodeClassD((int) map.get(GenericAttribute.ES_C5)).typeB());
// 统一设置属性:realSource,platform,emotion // 统一设置属性:realSource,platform,emotion
res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE))); res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE)));
...@@ -356,6 +359,10 @@ public class Tools { ...@@ -356,6 +359,10 @@ public class Tools {
return res; return res;
} }
public static BaseMap getBaseFromEsMap(Map<String, Object> map) {
return getBaseFromEsMap(map, false);
}
public static String getPlatform(Map<String, Object> map) { public static String getPlatform(Map<String, Object> map) {
Integer c5 = Integer.parseInt(String.valueOf(map.get(GenericAttribute.ES_C5))); Integer c5 = Integer.parseInt(String.valueOf(map.get(GenericAttribute.ES_C5)));
Integer foreign = Integer.parseInt(String.valueOf(map.get(GenericAttribute.ES_FOREIGN))); Integer foreign = Integer.parseInt(String.valueOf(map.get(GenericAttribute.ES_FOREIGN)));
...@@ -642,7 +649,7 @@ public class Tools { ...@@ -642,7 +649,7 @@ public class Tools {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 按日分割的map集合 * @return 按日分割的map集合
*/ */
public static List<Long> parseToDays(Long startTime, Long endTime) { public static List<Long> parseToDayList(Long startTime, Long endTime) {
Date start = new Date(startTime); Date start = new Date(startTime);
Date end = new Date(endTime); Date end = new Date(endTime);
start = Tools.truncDate(start, Constant.DAY_PATTERN); start = Tools.truncDate(start, Constant.DAY_PATTERN);
...@@ -656,7 +663,102 @@ public class Tools { ...@@ -656,7 +663,102 @@ public class Tools {
for (int i = 0; i <= days; i++) { for (int i = 0; i <= days; i++) {
resList.add(DateUtils.addDays(start, i).getTime()); resList.add(DateUtils.addDays(start, i).getTime());
} }
Collections.reverse(resList);
return resList; return resList;
} }
/**
* 解析时间转换成按日的集合
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 按日分割的map集合
*/
public static List<Map<String, String>> parseToDays(Long startTime, Long endTime) {
FastDateFormat df = DAY_FORMAT;
Date start = Tools.truncDate(new Date(startTime), Constant.DAY_PATTERN);
Date end = Tools.truncDate(new Date(endTime), Constant.DAY_PATTERN);
Period periodDays = new Period(start.getTime(), end.getTime(), PeriodType.days());
int days = periodDays.getDays();
if (days < 0) {
return Collections.emptyList();
}
List<Map<String, String>> dayList = new ArrayList<>(days);
for (int i = 0; i <= days; i++) {
Map<String, String> dayMap = new HashMap<>(4);
//开始时间
dayMap.put("startTime", df.format(DateUtils.addDays(start, i)));
//结束时间
dayMap.put("endTime", df.format(DateUtils.addDays(start, i + 1)));
dayList.add(dayMap);
}
return dayList;
}
/**
* 解析时间转换成按小时的集合
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 按小时分割的map集合
*/
public static List<Map<String, String>> parseToHours(Long startTime, Long endTime) {
FastDateFormat df = HOUR_FORMAT;
Date start = Tools.truncDate(new Date(startTime), Constant.HOUR_PATTERN);
Date end = Tools.truncDate(new Date(endTime), Constant.HOUR_PATTERN);
Period periodHour = new Period(start.getTime(), end.getTime(), PeriodType.hours());
int hours = periodHour.getHours();
if (hours < 0) {
return Collections.emptyList();
}
List<Map<String, String>> hourList = new ArrayList<>(hours);
for (int i = 0; i <= hours; i++) {
Map<String, String> hourMap = new HashMap<>(4);
//开始时间
hourMap.put("startTime", df.format(DateUtils.addHours(start, i)));
//结束时间
hourMap.put("endTime", df.format(DateUtils.addHours(start, i + 1)));
hourList.add(hourMap);
}
return hourList;
}
/**
* 是否包含关键字
*
* @param keywords 关键词数据
* @param content 文本内容
* @return 是否包含关键字
*/
public static boolean isContains(List<String> keywords, String content) {
boolean contains = true;
content = content.toLowerCase();
for (String value : keywords) {
//按空格分割必须全部命中
String[] keys = value.split(" ");
for (String key : keys) {
if (!content.contains(key.toLowerCase())) {
//一个不命中,直接结束当前循环
contains = false;
break;
}
}
if (contains) {
//已经满足条件,视为有效数据,结束循环
break;
}
}
return contains;
}
public static Map<String, Object> getBrandkbsHitMap(Map<String, Object> esMap, String hitKey) {
List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) esMap.get("brandkbs_cache_maps");
for (Map<String, Object> cacheMap : cacheMaps) {
if (hitKey.equals(cacheMap.get("key"))) {
return cacheMap;
}
}
return Collections.emptyMap();
}
} }
\ No newline at end of file
...@@ -80,6 +80,8 @@ XIN公益大会|引光行动 ...@@ -80,6 +80,8 @@ XIN公益大会|引光行动
阿里投资 阿里投资
唐家三少 唐家三少
梭子蟹 梭子蟹
美团
抖音
......
...@@ -1259,4 +1259,5 @@ com ...@@ -1259,4 +1259,5 @@ com
呵呵 呵呵
凤行 凤行
\ No newline at end of file %
\ No newline at end of file
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