Commit 578a5334 by shenjunjie

Merge branch 'release' into 'master'

Release

See merge request !539
parents 69aaea95 6b329a4c
......@@ -115,6 +115,8 @@ public class RedisKeyPrefix {
public static final String YUQING_ANALYZE_HIGH_WORD = "BRANDKBS:YUQING:ANALYZE:HIGH:WORD:";
public static final String SEARCH_KEYWORD = "BRANDKBS:SEARCH:KEYWORD:";
public static String projectWarnHotTopKeyAll(String projectId, String type) {
return RedisKeyPrefix.generateRedisKey(RedisKeyPrefix.PROJECT_WARN_HOT_TOP, projectId, Tools.concat(type, "*"));
}
......
......@@ -584,6 +584,12 @@ public class AppArticleController extends BaseController {
return ResponseResult.success(markDataService.getWholeSearchArticleList(dto));
}
@ApiOperation("原发溯源-扩大追溯范围")
@PostMapping("/search-whole/origin/expand")
public ResponseResult expandOriginRange(@RequestBody MarkSearchDTO dto) {
return ResponseResult.success(markDataService.expandOriginRange(dto));
}
private boolean checkMTagIllegal(StringBuilder mtag) {
List<MarkerTag> hitTags = projectService.getProjectById(UserThreadLocal.getProjectId()).getHitTags();
if (!Tools.isEmpty(hitTags)) {
......
......@@ -315,4 +315,19 @@ public class AppChannelController extends BaseController {
}
return ResponseResult.failure("渠道申请失败");
}
@ApiOperation("重要渠道清单-清单列表")
@GetMapping("/important-channel/list")
public ResponseResult getImportantChannelList(@RequestParam(value = "type", defaultValue = "市监局") String type,
@RequestParam(value = "keyword", required = false) String keyword) {
return ResponseResult.success(channelService.getImportantChannelList(type, keyword));
}
@ApiOperation("重要渠道清单-清单列表-详情")
@GetMapping("/important-channel/list/detail")
public ResponseResult getImportantChannelListDetail(@RequestParam(value = "type") String type,
@RequestParam(value = "name") String name,
@RequestParam(value = "keyword", required = false) String keyword) {
return ResponseResult.success(channelService.getImportantChannelListDetail(type, name, keyword));
}
}
......@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.controller.app;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.aop.LogRecord;
import com.zhiwei.brandkbs2.auth.Auth;
......@@ -17,10 +18,12 @@ import com.zhiwei.brandkbs2.pojo.dto.*;
import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.service.*;
import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.event.pojo.dto.BrandkbsEventSearchDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.tuple.Pair;
......@@ -33,9 +36,11 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* @author cjz
......@@ -63,6 +68,8 @@ public class AppSearchController extends BaseController {
@Value("${ef.search.url}")
private String getEfSearchUrl;
private static final int SEARCH_KEYWORD_CACHE_MAX_SIZE = 10;
@Resource(name = "markDataServiceImpl")
MarkDataService markDataService;
......@@ -84,6 +91,9 @@ public class AppSearchController extends BaseController {
@Resource(name = "extraServiceImpl")
ExtraService extraService;
@Resource(name = "redisUtil")
RedisUtil redisUtil;
@ApiOperation("搜索-查热点")
@LogRecord(values = "keyword", description = "查热点", arguments = true, entity = false)
@GetMapping("/hot/list")
......@@ -94,6 +104,7 @@ public class AppSearchController extends BaseController {
@RequestParam(value = "sort") String sort,
@RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime) {
cacheSearchKeyword(keyword, "hot");
ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsSearchUrl, JSONObject.class, limit, page, type, keyword, sort, startTime, endTime);
JSONObject result = jsonObjectResponseEntity.getBody();
if (Objects.nonNull(result)) {
......@@ -109,6 +120,7 @@ public class AppSearchController extends BaseController {
public ResponseResult crisisSearch(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
@RequestParam("keyword") String keyword) {
cacheSearchKeyword(keyword, "crisis");
ResponseEntity<String> responseEntity = restTemplate.getForEntity(crisisSearchUrl, String.class, page, pageSize, keyword);
Object result = JSON.parseObject(responseEntity.getBody()).get("data");
return ResponseResult.success(result);
......@@ -132,6 +144,7 @@ public class AppSearchController extends BaseController {
@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", defaultValue = "20") Integer size) {
String name = keyword.trim();
cacheSearchKeyword(keyword, "event");
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getEfSearchUrl, String.class, name, page, size);
JSONObject result = JSON.parseObject(responseEntity.getBody());
return ResponseResult.success(result);
......@@ -151,6 +164,7 @@ public class AppSearchController extends BaseController {
if (StringUtils.isNotEmpty(dto.getKeyword()) && Tools.checkUniteString(dto.getKeyword())){
return ResponseResult.failure("不支持特殊符号字段查询");
}
cacheSearchKeyword(dto.getKeyword(), "whole");
// 针对商业数据库做限制
if (dto.isExternalDataSource()) {
long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime();
......@@ -220,6 +234,7 @@ public class AppSearchController extends BaseController {
if (StringUtils.isNotEmpty(markSearchDTO.getKeyword()) && Tools.checkUniteString(markSearchDTO.getKeyword())){
return ResponseResult.failure("不支持特殊符号字段查询");
}
cacheSearchKeyword(markSearchDTO.getKeyword(), "yuqing");
PageVO<MarkFlowEntity> yuqingMarkList = markDataService.getYuqingMarkList(markSearchDTO);
// 仅第一页增加平台进量(声量)统计
if (1 == markSearchDTO.getPage()) {
......@@ -238,6 +253,7 @@ public class AppSearchController extends BaseController {
@LogRecord(values = "keyword", description = "查原始数据", arguments = true, entity = true)
@PostMapping("/origin/list")
public ResponseResult getOriginList(@RequestBody MarkSearchDTO markSearchDTO) {
cacheSearchKeyword(markSearchDTO.getKeyword(), "yuqing");
PageVO<MarkFlowEntity> originList = markDataService.getOriginList(markSearchDTO);
// 仅第一页增加平台进量(声量)统计
if (1 == markSearchDTO.getPage() && !Objects.equals("视频", markSearchDTO.getSearchType())) {
......@@ -276,6 +292,7 @@ public class AppSearchController extends BaseController {
@LogRecord(values = "keyword", description = "查渠道", arguments = true, entity = true)
@PostMapping(value = "/channel/channelList")
public ResponseResult getChannelList(@RequestBody ChannelSearchDTO channelSearchDTO) {
cacheSearchKeyword(channelSearchDTO.getKeyword(), "channel");
return ResponseResult.success(channelService.getChannelListNew(channelSearchDTO.getPage(), channelSearchDTO.getPageSize(),
channelSearchDTO.getKeyword(), channelSearchDTO.getPlatform(), channelSearchDTO.getEmotions(), channelSearchDTO.getMediaTypes(), channelSearchDTO.getArticlesCount(), channelSearchDTO.getSorter()));
}
......@@ -314,6 +331,7 @@ public class AppSearchController extends BaseController {
@LogRecord(values = "keyword", description = "查事件", arguments = true, entity = true)
@PostMapping("/event/newList")
public ResponseResult getEventListMiddleware(@RequestBody BrandkbsEventSearchDTO dto){
cacheSearchKeyword(dto.getKeyword(), "event");
return ResponseResult.success(eventService.getEventListMiddleware(dto));
}
......@@ -324,6 +342,7 @@ public class AppSearchController extends BaseController {
if (StringUtils.isNotEmpty(markSearchDTO.getKeyword()) && Tools.checkUniteString(markSearchDTO.getKeyword())){
return ResponseResult.failure("不支持特殊符号字段查询");
}
cacheSearchKeyword(markSearchDTO.getKeyword(), "contend");
return ResponseResult.success(markDataService.getContendSearchList(markSearchDTO));
}
......@@ -333,4 +352,43 @@ public class AppSearchController extends BaseController {
return ResponseResult.success(markDataService.getContendSearchCriteria(contendId));
}
@ApiOperation("搜索-搜索关键词历史记录")
@GetMapping("/keyword/cache")
public ResponseResult getSearchKeywordCache(@ApiParam(name = "searchType",
value = "查舆情:yuqing,查渠道:channel,查事件:event,查热点:hot,查危机:crisis,查竞品:contend,全网搜:whole", required = true)
@RequestParam(value = "searchType", defaultValue = "yuqing") String searchType) {
return ResponseResult.success(getKeywordCache(searchType));
}
/**
* 获取搜索关键词历史记录
* @param searchType
* @return
*/
private List<String> getKeywordCache(String searchType){
String key = RedisUtil.getSearchKeywordCacheKey(UserThreadLocal.getProjectId(), UserThreadLocal.getUserId(), searchType);
String value = redisUtil.get(key);
return JSONArray.parseArray(value, String.class);
}
/**
* 记录搜索关键词历史记录
* @param keyword
* @param searchType
*/
private void cacheSearchKeyword(String keyword, String searchType){
String key = RedisUtil.getSearchKeywordCacheKey(UserThreadLocal.getProjectId(), UserThreadLocal.getUserId(), searchType);
String value = redisUtil.get(key);
List<String> keywords = Objects.isNull(JSONArray.parseArray(value, String.class))
? new ArrayList<>(SEARCH_KEYWORD_CACHE_MAX_SIZE)
: JSONArray.parseArray(value, String.class);
if (StringUtils.isNotBlank(keyword)){
keywords.remove(keyword);
keywords.add(0, keyword);
if (keywords.size() > SEARCH_KEYWORD_CACHE_MAX_SIZE){
keywords.remove(SEARCH_KEYWORD_CACHE_MAX_SIZE);
}
}
redisUtil.setExpire(key, JSONObject.toJSONString(keywords), 7, TimeUnit.DAYS);
}
}
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.ImportantChannel;
/**
* @ClassName: ImportantChannelDao
* @Description 重要渠道清单dao
* @author: cjz
* @date: 2024-06-14 14:03
*/
public interface ImportantChannelDao extends BaseMongoDao<ImportantChannel>{
}
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.ImportantChannelOverview;
/**
* @ClassName: ImportantChannelOverviewDao
* @Description 重要渠道清单概览dao
* @author: cjz
* @date: 2024-06-17 10:03
*/
public interface ImportantChannelOverviewDao extends BaseMongoDao<ImportantChannelOverview>{
}
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.ImportantChannelDao;
import com.zhiwei.brandkbs2.pojo.ImportantChannel;
import org.springframework.stereotype.Component;
/**
* @ClassName: ImportantChannelDaoImpl
* @Description 重要渠道清单dao
* @author: cjz
* @date: 2024-06-14 14:03
*/
@Component("importantChannelDao")
public class ImportantChannelDaoImpl extends BaseMongoDaoImpl<ImportantChannel> implements ImportantChannelDao {
private static final String COLLECTION_NAME = "brandkbs_important_channel";
public ImportantChannelDaoImpl() {
super(COLLECTION_NAME);
}
}
package com.zhiwei.brandkbs2.dao.impl;
import com.zhiwei.brandkbs2.dao.ImportantChannelOverviewDao;
import com.zhiwei.brandkbs2.pojo.ImportantChannelOverview;
import org.springframework.stereotype.Component;
/**
* @ClassName: ImportantChannelOverviewDao
* @Description 重要渠道清单概览dao
* @author: cjz
* @date: 2024-06-17 10:03
*/
@Component("importantChannelOverviewDao")
public class ImportantChannelOverviewDaoImpl extends BaseMongoDaoImpl<ImportantChannelOverview> implements ImportantChannelOverviewDao {
private static final String COLLECTION_NAME = "brandkbs_important_channel_overview";
public ImportantChannelOverviewDaoImpl() {
super(COLLECTION_NAME);
}
}
......@@ -20,12 +20,14 @@ public class CustomException extends RuntimeException {
private final Exception exception;
public CustomException(ResultCode resultCode) {
super(resultCode.message());
this.resultCode = resultCode;
this.errorMessage = null;
this.errorMessage = resultCode.message();
this.exception = null;
}
public CustomException(ResultCode resultCode, String errorMessage, Exception e) {
super(errorMessage);
this.resultCode = resultCode;
this.errorMessage = errorMessage;
this.exception = e;
......
......@@ -34,9 +34,9 @@ public class ExceptionCatch {
Exception exception = customException.getException();
//记录日志
if (null == exception) {
log.info("catch exception-custom:{}", customException.getErrorMessage());
log.error("catch exception-custom:{}", customException.getErrorMessage(), customException);
} else {
log.error("catch exception-custom:{}", customException.getErrorMessage(), exception);
log.error("catch exception:{}", customException.getErrorMessage(), exception);
}
return new ResponseResult(resultCode, Collections.EMPTY_LIST);
}
......
package com.zhiwei.brandkbs2.pojo;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author cjz
* @version 1.0
* @description 重要渠道清单
* @date 2024年6月14日10:06:46
*/
@Getter
@Setter
public class ImportantChannel extends AbstractBaseMongo{
/**
* 机构类型
*/
private String institution;
/**
* 机构标签
*/
private List<String> institutionTags;
/**
* 地域
*/
private String region;
/**
* 细分地域
*/
private String subdivideRegion;
/**
* 平台
*/
private String platform;
/**
* 渠道
*/
private String source;
/**
* 媒体类型
*/
private String media;
/**
* 媒体标签
*/
private List<String> mediaTags;
/**
* 主体
*/
private String mainBody;
/**
* 单位名称
*/
private String organization;
/**
* 应用程序
*/
private String application;
/**
* 创建时间
*/
private Long cTime;
/**
* 修改时间
*/
private Long uTime;
}
package com.zhiwei.brandkbs2.pojo;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author cjz
* @version 1.0
* @description 重要渠道清单
* @date 2024年6月14日10:06:46
*/
@Getter
@Setter
public class ImportantChannelOverview extends AbstractBaseMongo{
/**
* 机构类型
*/
private String type;
/**
* 机构标签
*/
private List<String> tags;
// /**
// * 媒体类型
// */
// private String media;
// /**
// * 媒体标签
// */
// private List<String> mediaTags;
// /**
// * 地域
// */
// private String region;
//
// /**
// * 单位名称
// */
// private String mainBody;
/**
* 具体信息
*/
private List<JSONObject> info;
// private List<String> source;
/**
* 创建时间
*/
private Long cTime;
/**
* 修改时间
*/
private Long uTime;
}
......@@ -142,6 +142,12 @@ public class MarkSearchDTO {
private String keyword;
/**
* 多个关键字
*/
@ApiModelProperty(value = "多个关键字")
private List<String> keywordList;
/**
* 渠道关键词
*/
@ApiModelProperty(value = "渠道关键词")
......
......@@ -309,5 +309,28 @@ public interface ChannelService {
*/
Map<String, JSONObject> getProjectEmotionChannelListData() throws IOException;
/**
* 匹配舆情重要渠道
* @param linkedGroupId
* @param source
* @return
*/
JSONObject matchYuQingSensitiveChannel(String linkedGroupId, String source);
/**
* 获取重要渠道清单列表
* @param type
* @param keyword
* @return
*/
List<JSONObject> getImportantChannelList(String type, String keyword);
/**
* 获取重要渠道清单列表详情
* @param type
* @param name
* @param keyword
* @return
*/
JSONObject getImportantChannelListDetail(String type, String name, String keyword);
}
......@@ -750,4 +750,11 @@ public interface MarkDataService {
* @return
*/
PageVO<JSONObject> getWholeSearchArticleList(MarkSearchDTO dto);
/**
* 原发溯源-扩大追溯范围
* @param dto
* @return
*/
List<String> expandOriginRange(MarkSearchDTO dto);
}
......@@ -69,6 +69,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
......@@ -120,6 +121,12 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "eventMiddlewareDao")
EventMiddlewareDao eventMiddlewareDao;
@Resource(name = "importantChannelDao")
private ImportantChannelDao importantChannelDao;
@Resource(name = "importantChannelOverviewDao")
private ImportantChannelOverviewDao importantChannelOverviewDao;
@Resource(name = "mongoUtil")
MongoUtil mongoUtil;
......@@ -759,6 +766,122 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public List<JSONObject> getImportantChannelList(String type, String keyword) {
Query query = new Query();
query.addCriteria(Criteria.where("type").is(type));
ImportantChannelOverview overview = importantChannelOverviewDao.findOne("type", type);
if (StringUtils.isNotEmpty(keyword)){
List<JSONObject> res = new ArrayList<>();
Pattern pattern = Pattern.compile(keyword);
for (JSONObject jsonObject : overview.getInfo()) {
List<String> sources = jsonObject.getJSONArray("source").toJavaList(String.class);
for (String source : sources) {
if (pattern.matcher(source).find()){
res.add(jsonObject);
break;
}
}
}
return res;
}
return overview.getInfo();
}
@Override
public JSONObject getImportantChannelListDetail(String type, String name, String keyword) {
String searchType = Arrays.asList("18家媒体", "区域媒体").contains(type) ? "media" : "institution";
String searchName = Objects.equals("18家媒体", type) ? "mainBody" : "region";
List<String> platformSort = Arrays.asList("18家媒体", "区域媒体").contains(type) ? Arrays.asList("新浪微博", "微信", "网媒", "B站", "头条", "抖音") : Arrays.asList("微信公众号", "新浪微博", "网媒");
// query
Query query = new Query();
query.addCriteria(Criteria.where(searchType).is(type));
query.addCriteria(Criteria.where(searchName).is(name));
if (StringUtils.isNotEmpty(keyword)){
importantChannelOverviewDao.addKeywordFuzz(query, keyword, "source");
}
List<ImportantChannel> list = importantChannelDao.findList(query);
// 顺序需按照平台命中 例:微博不为空的优先放前面
List<ImportantChannel> sortList = new ArrayList<>();
Map<String, List<ImportantChannel>> platformGroup = list.stream().collect(Collectors.groupingBy(ImportantChannel::getPlatform, LinkedHashMap::new, Collectors.toList()));
for (String platform : platformSort){
if (Objects.nonNull(platformGroup.get(platform))){
sortList.addAll(platformGroup.get(platform));
}
}
if (Objects.equals("区域媒体", type)){
return regionMediaDataProcess(sortList);
}else if (Arrays.asList("纪检委", "政法委").contains(type)){
return provinceDataProcess(sortList);
}else {
return dataProcess(sortList, type);
}
}
private JSONObject provinceDataProcess(List<ImportantChannel> sortList){
List<JSONObject> resList = new ArrayList<>();
JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
LinkedHashMap<String, List<ImportantChannel>> platformMap = sortList.stream().collect(Collectors.groupingBy(ImportantChannel::getPlatform, LinkedHashMap::new, Collectors.toList()));
for (Map.Entry<String, List<ImportantChannel>> entry : platformMap.entrySet()) {
jsonObject.put(entry.getKey(), entry.getValue().stream().map(ImportantChannel::getSource).collect(Collectors.toList()));
}
resList.add(jsonObject);
JSONObject res = new JSONObject();
res.put("count", sortList.size());
res.put("list", resList);
return res;
}
private JSONObject dataProcess(List<ImportantChannel> sortList, String type){
Map<String, List<ImportantChannel>> map = Objects.equals("18家媒体", type)
? sortList.stream().collect(Collectors.groupingBy(ImportantChannel::getOrganization, LinkedHashMap::new, Collectors.toList()))
: sortList.stream().collect(Collectors.groupingBy(ImportantChannel::getSubdivideRegion, LinkedHashMap::new, Collectors.toList()));
List<JSONObject> resList = new ArrayList<>();
for (Map.Entry<String, List<ImportantChannel>> entry : map.entrySet()) {
JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
jsonObject.put(Objects.equals("18家媒体", type) ? "单位名称" : "细分地域", entry.getKey());
if (Objects.equals("18家媒体", type)) {
jsonObject.put("应用程序", entry.getValue().stream().map(ImportantChannel::getApplication).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
}
LinkedHashMap<String, List<ImportantChannel>> platformMap = entry.getValue().stream().collect(Collectors.groupingBy(ImportantChannel::getPlatform, LinkedHashMap::new, Collectors.toList()));
for (Map.Entry<String, List<ImportantChannel>> platformEntry : platformMap.entrySet()) {
jsonObject.put(platformEntry.getKey(), platformEntry.getValue().stream().map(ImportantChannel::getSource).collect(Collectors.toList()));
}
resList.add(jsonObject);
}
JSONObject res = new JSONObject();
res.put("count", sortList.size());
res.put("list", resList);
return res;
}
private JSONObject regionMediaDataProcess(List<ImportantChannel> sortList){
Map<String, List<ImportantChannel>> map = sortList.stream().collect(Collectors.groupingBy(ImportantChannel::getMainBody, LinkedHashMap::new, Collectors.toList()));
List<JSONObject> resList = new ArrayList<>();
for (Map.Entry<String, List<ImportantChannel>> entry : map.entrySet()) {
JSONObject mainBodyJson = new JSONObject(new LinkedHashMap<>());
mainBodyJson.put("主体", entry.getKey());
LinkedHashMap<String, List<ImportantChannel>> organizationMap = entry.getValue().stream().collect(Collectors.groupingBy(ImportantChannel::getOrganization, LinkedHashMap::new, Collectors.toList()));
List<JSONObject> platformJson = new ArrayList<>();
for (Map.Entry<String, List<ImportantChannel>> organizationEntry : organizationMap.entrySet()) {
LinkedHashMap<String, List<ImportantChannel>> platformMap = organizationEntry.getValue().stream().collect(Collectors.groupingBy(ImportantChannel::getPlatform, LinkedHashMap::new, Collectors.toList()));
JSONObject dataJson = new JSONObject(new LinkedHashMap<>());
dataJson.put("单位名称", organizationEntry.getKey());
dataJson.put("应用程序", organizationEntry.getValue().stream().map(ImportantChannel::getApplication).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
for (Map.Entry<String, List<ImportantChannel>> platformEntry : platformMap.entrySet()) {
dataJson.put(platformEntry.getKey(), platformEntry.getValue().stream().map(ImportantChannel::getSource).collect(Collectors.toList()));
}
platformJson.add(dataJson);
}
mainBodyJson.put("list", platformJson);
resList.add(mainBodyJson);
}
JSONObject res = new JSONObject();
res.put("count", sortList.size());
res.put("list", resList);
return res;
}
@Override
public JSONObject getSpreadingTend(String channelId, String type, String contendIds, Long startTime, Long endTime) {
JSONObject res = new JSONObject();
// 默认全部 TODO
......
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.hankcs.hanlp.HanLP;
import com.zhiwei.base.category.ClassB;
import com.zhiwei.base.entity.subclass.mark.MarkInfo;
import com.zhiwei.brandkbs2.auth.UserThreadLocal;
......@@ -653,7 +654,8 @@ public class MarkDataServiceImpl implements MarkDataService {
contendOptional.ifPresent(contend -> markSearchDTO.setLinkedGroupId(contend.getBrandLinkedGroupId()));
}
// gid
String gid = redisUtil.get(RedisUtil.getNonManualProjectMarkMaxGidKey(UserThreadLocal.getProjectId(), markSearchDTO.getPlanId(), UserThreadLocal.getUserId()));
String key = RedisUtil.getNonManualProjectMarkMaxGidKey(projectId, markSearchDTO.getPlanId(), UserThreadLocal.getUserId());
String gid = redisUtil.get(key);
if (Objects.isNull(gid)) {
markSearchDTO.setGid(-1L);
}else {
......@@ -3551,6 +3553,34 @@ public class MarkDataServiceImpl implements MarkDataService {
return null;
}
@Override
public List<String> expandOriginRange(MarkSearchDTO dto) {
try {
// 默认近一个月
dto.setEndTime(System.currentTimeMillis());
dto.setStartTime(dto.getEndTime() - Constant.ONE_MONTH);
String[] indexes = esClientDao.getAllIndexes(dto.getStartTime(), dto.getEndTime());
BoolQueryBuilder query = QueryBuilders.boolQuery();
// nlp分词
String keyword = HanLP.segment(Tools.filterSpecialCharacter(dto.getKeyword())).stream().map(s -> s.word).distinct().collect(Collectors.joining(" "));
query.must(EsQueryTools.assembleNormalKeywordQuery(keyword, new String[]{GenericAttribute.ES_IND_FULL_TEXT}));
// time
query.must(QueryBuilders.rangeQuery(GenericAttribute.ES_TIME).gte(dto.getStartTime()).lte(dto.getEndTime()));
// 按score排序
FieldSortBuilder sort = SortBuilders.fieldSort("_score").order(SortOrder.DESC);
SearchHits hits = esClientDao.searchHits(indexes, query, null, null, sort, 0, 1000, null);
if (0 == hits.getTotalHits().value){
return Collections.emptyList();
}
// 取top5
return Arrays.stream(hits.getHits()).map(hit -> Tools.getBaseFromEsMap(hit.getSourceAsMap()).getTitle())
.filter(Objects::nonNull).distinct().limit(5).collect(Collectors.toList());
}catch (Exception e){
ExceptionCast.cast(CommonCodeEnum.FAIL, "原发溯源-扩大溯源范围异常expandOriginRange-", e);
}
return Collections.emptyList();
}
/**
* 原发溯源大库es查询
* @param dto
......@@ -3559,32 +3589,48 @@ public class MarkDataServiceImpl implements MarkDataService {
private BoolQueryBuilder getAllIndexSearchOriginQuery(MarkSearchDTO dto) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
// time
if (Objects.isNull(dto.getStartTime()) || Objects.isNull(dto.getEndTime())) {
dto.setEndTime(System.currentTimeMillis());
dto.setStartTime(dto.getEndTime() - Constant.ONE_MONTH);
}
query.must(QueryBuilders.rangeQuery("time").gte(dto.getStartTime()).lte(dto.getEndTime()));
String keyword = dto.getKeyword();
// 特殊符号、数字替换空格
String processedKeyword = Tools.canonicalKeyword(keyword.replaceAll(ORIGIN_SEARCH_PATTERN, " "));
// keyword
String[] fieldSearch = new String[]{GenericAttribute.ES_IND_FULL_TEXT};
BoolQueryBuilder keywordQuery = QueryBuilders.boolQuery();
// keyword条件一: 空格为且条件
if (StringUtils.isNotEmpty(processedKeyword)) {
BoolQueryBuilder keywordQuery1 = QueryBuilders.boolQuery();
String[] words = processedKeyword.split(" +");
for (int i = 0; i < words.length; i++) {
BoolQueryBuilder wordQuery = QueryBuilders.boolQuery();
if (i != words.length - 1) {
keywordQuery1.must(wordQuery.must(QueryBuilders.matchPhraseQuery(GenericAttribute.ES_IND_FULL_TEXT, words[i])));
} else {
keywordQuery1.must(wordQuery.must(QueryBuilders.matchPhrasePrefixQuery(GenericAttribute.ES_IND_FULL_TEXT, words[i])));
if (!Tools.isEmpty(dto.getKeywordList())) {
for (String keyword : dto.getKeywordList()) {
keywordQuery.should(QueryBuilders.matchPhrasePrefixQuery(GenericAttribute.ES_IND_FULL_TEXT, keyword));
// 关键词 数字符号替换后重组query
keywordQuery.should(EsQueryTools.assembleNormalKeywordQuery(Tools.canonicalKeyword(keyword.replaceAll(ORIGIN_SEARCH_PATTERN, " ")), fieldSearch));
}
}
keywordQuery.should(keywordQuery1);
}
// keyword条件二
BoolQueryBuilder keywordQuery2 = QueryBuilders.boolQuery();
keywordQuery2.must(QueryBuilders.matchPhrasePrefixQuery(GenericAttribute.ES_IND_FULL_TEXT, keyword));
// 两个keyword条件满足一个即可
keywordQuery.should(keywordQuery2).minimumShouldMatch(1);
} else {
keywordQuery.should(QueryBuilders.matchPhrasePrefixQuery(GenericAttribute.ES_IND_FULL_TEXT, dto.getKeyword()));
// 关键词 数字符号替换后重组query
keywordQuery.should(EsQueryTools.assembleNormalKeywordQuery(Tools.canonicalKeyword(dto.getKeyword().replaceAll(ORIGIN_SEARCH_PATTERN, " ")), fieldSearch));
}
// String keyword = dto.getKeyword();
// // 特殊符号、数字替换空格
// String processedKeyword = Tools.canonicalKeyword(keyword.replaceAll(ORIGIN_SEARCH_PATTERN, " "));
//// BoolQueryBuilder keywordQuery = QueryBuilders.boolQuery();
// // keyword条件一: 空格为且条件
// if (StringUtils.isNotEmpty(processedKeyword)) {
// BoolQueryBuilder keywordQuery1 = QueryBuilders.boolQuery();
// String[] words = processedKeyword.split(" +");
// for (int i = 0; i < words.length; i++) {
// BoolQueryBuilder wordQuery = QueryBuilders.boolQuery();
// if (i != words.length - 1) {
// keywordQuery1.must(wordQuery.must(QueryBuilders.matchPhraseQuery(GenericAttribute.ES_IND_FULL_TEXT, words[i])));
// } else {
// keywordQuery1.must(wordQuery.must(QueryBuilders.matchPhrasePrefixQuery(GenericAttribute.ES_IND_FULL_TEXT, words[i])));
// }
// }
// keywordQuery.should(keywordQuery1);
// }
// // keyword条件二
// BoolQueryBuilder keywordQuery2 = QueryBuilders.boolQuery();
// keywordQuery2.must(QueryBuilders.matchPhrasePrefixQuery(GenericAttribute.ES_IND_FULL_TEXT, keyword));
// // 两个keyword条件满足一个即可
// keywordQuery.should(keywordQuery2).minimumShouldMatch(1);
query.must(keywordQuery);
// platform
BoolQueryBuilder platformQuery = EsQueryTools.assemblePlatformQuery(GlobalPojo.PLATFORMS);
......
......@@ -233,27 +233,18 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
StringBuilder mediaChannel = new StringBuilder();
List<String> politicsLevels = config.getPoliticsLevels();
List<String> fields = config.getFields();
if(Tools.isEmpty(politicsLevels)){
if (Tools.isEmpty(politicsLevels) || politicsLevels.contains("全部")) {
key2Header += "【全部级别】";
}else if(politicsLevels.contains("全部")){
key2Header += "【重点级别】";
}else{
} else {
politicsLevels.forEach(politicsLevel -> mediaChannel.append(politicsLevel).append("、"));
}
if (Tools.isEmpty(fields)) {
if (0 != key2Header.length()) {
if (0 != key2Header.length() || fields.contains("全部")) {
key2Header += "、";
key2Header += "【全部领域】,";
} else {
key2Header += "【全部领域】";
}
} else if (fields.contains("全部")) {
if (0 != key2Header.length()) {
key2Header += "、";
key2Header += "【重点领域】,";
} else {
key2Header += "【重点领域】";
}
} else {
fields.forEach(field -> mediaChannel.append(field).append("、"));
}
......
......@@ -964,10 +964,11 @@ public class ToolsetServiceImpl implements ToolsetService {
String linkedGroupId = projectService.getProjectVOById(projectId).getBrandLinkedGroupId();
jsonObject = restTemplate.getForEntity(articleInfoUrl, JSONObject.class, url, linkedGroupId, UserThreadLocal.getNickname()).getBody();
} catch (Exception e) {
log.info("url:{},访问链接信息提取接口异常-", url, e);
log.error("url:{},访问链接信息提取接口异常-", url, e);
return null;
}
if (Objects.isNull(jsonObject) || !jsonObject.getBoolean("status")) {
log.error("url:{},访问链接信息提取接口异常-返回信息:{}", url, JSONObject.toJSONString(jsonObject));
return null;
}
return jsonObject.getJSONObject("data");
......@@ -994,7 +995,7 @@ public class ToolsetServiceImpl implements ToolsetService {
ResponseEntity<String> response = restTemplate.postForEntity(articleSummaryUrl, request, String.class);
return response.getBody();
}catch (Exception e){
log.info("访问摘要提取接口异常-", e);
log.error("访问摘要提取接口异常-", e);
return errorString;
}
}
......
......@@ -119,6 +119,10 @@ public class RedisUtil {
return RedisKeyPrefix.YUQING_ANALYZE_HIGH_WORD + Tools.concat(projectId, contendId, planId, startTime, endTime);
}
public static String getSearchKeywordCacheKey(String projectId, String userId, String searchType){
return RedisKeyPrefix.SEARCH_KEYWORD + Tools.concat(projectId, userId, searchType);
}
public void setExpire(String key, String value, long timeout, TimeUnit unit) {
stringRedisTemplate.opsForValue().set(key, value, timeout, unit);
}
......
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