Commit 9277c5d1 by shenjunjie

2022/8/9 13:56

parent 973ce022
...@@ -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:";
......
...@@ -108,7 +108,7 @@ public class AppChannelController extends BaseController { ...@@ -108,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));
} }
...@@ -156,6 +156,7 @@ public class AppChannelController extends BaseController { ...@@ -156,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"),
...@@ -164,11 +165,12 @@ public class AppChannelController extends BaseController { ...@@ -164,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));
}
}
...@@ -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.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);
}
}
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;
}
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
...@@ -207,7 +207,7 @@ public interface ChannelService { ...@@ -207,7 +207,7 @@ 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);
/** /**
* 下载时间段稿件信息 * 下载时间段稿件信息
...@@ -218,5 +218,5 @@ public interface ChannelService { ...@@ -218,5 +218,5 @@ public interface ChannelService {
* @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);
} }
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);
......
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