Commit badad774 by shenjunjie

Merge branch 'feature' into 'release'

Feature

See merge request !309
parents acee01fc 8ab6aa8a
package com.zhiwei.brandkbs2.common;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import java.util.List;
/**
* @ClassName: ChannelType
* @Description 渠道类型
* @author: sjj
* @date: 2023-04-14 17:27
*/
public class ChannelType {
private static final List<String> MAIN_BODY_TYPES = Arrays.asList("媒体", "团体", "普通用户", "企业", "名人", "政务机构");
private static final List<String> POLITICS_LEVELS = Arrays.asList("央级", "省级", "地级");
private static final List<String> FIELDS = Arrays.asList("情感", "综合", "财经", "家居", "社会", "时尚", "文化", "历史", "母婴育儿", "体育", "娱乐", "动漫", "汽车", "美食", "健康养生", "国际", "音乐", "游戏", "科技", "旅游", "军事", "时事", "教育");
private static final JSONArray REGION = GlobalPojo.CHINA_AREA_TAGS;
public static JSONObject channelOption = new JSONObject();
public static final List<String> COMMON_FIELDS = Arrays.asList("财经", "科技", "时政", "社会民生", "交通");
static {
channelOption.put("mainBodyTypes", MAIN_BODY_TYPES);
channelOption.put("politicsLevels", POLITICS_LEVELS);
channelOption.put("fields", FIELDS);
channelOption.put("regions", REGION);
}
}
...@@ -111,6 +111,25 @@ public class GenericAttribute { ...@@ -111,6 +111,25 @@ public class GenericAttribute {
public static final String ES_LINKED_GROUP_ID = "linked_group_id"; public static final String ES_LINKED_GROUP_ID = "linked_group_id";
public static final String ES_SENSITIVE_CHANNEL = "sensitive_channel";
/**
* 行政级别
*/
public static final String ES_POLITICS_LEVEL = "politics_level";
/**
* 主体类型
*/
public static final String ES_MAIN_BODY_TYPE = "main_body_type";
/**
* 领域
*/
public static final String ES_REGION = "region";
/**
* 地域
*/
public static final String ES_FIELD = "field";
// public static final String ES_CACHE_MAP_PROJECT = "brandkbs_cache_maps.project_id.keyword"; // public static final String ES_CACHE_MAP_PROJECT = "brandkbs_cache_maps.project_id.keyword";
// public static final String ES_CACHE_MAP_LINKED_GROUP_ID = "brandkbs_cache_maps.linked_group_id.keyword"; // public static final String ES_CACHE_MAP_LINKED_GROUP_ID = "brandkbs_cache_maps.linked_group_id.keyword";
// public static final String PLATFORM = "platform"; // public static final String PLATFORM = "platform";
......
package com.zhiwei.brandkbs2.common; package com.zhiwei.brandkbs2.common;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.pojo.ChannelTag; import com.zhiwei.brandkbs2.pojo.ChannelTag;
import com.zhiwei.brandkbs2.pojo.Project; import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.service.SystemInfoService; import com.zhiwei.brandkbs2.service.SystemInfoService;
import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform; import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import com.zhiwei.qbjc.bean.pojo.common.Tag; import com.zhiwei.qbjc.bean.pojo.common.Tag;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -29,6 +33,10 @@ import java.util.stream.Collectors; ...@@ -29,6 +33,10 @@ import java.util.stream.Collectors;
public class GlobalPojo { public class GlobalPojo {
public static final Logger log = LogManager.getLogger(GlobalPojo.class); public static final Logger log = LogManager.getLogger(GlobalPojo.class);
@Value("classpath:chinaAreaTag.json")
private org.springframework.core.io.Resource chinaAreaTag;
@Resource(name = "systemInfoServiceImpl") @Resource(name = "systemInfoServiceImpl")
private SystemInfoService systemInfoService; private SystemInfoService systemInfoService;
...@@ -62,6 +70,8 @@ public class GlobalPojo { ...@@ -62,6 +70,8 @@ public class GlobalPojo {
*/ */
public static List<JSONObject> YU_QING_PROJECTS; public static List<JSONObject> YU_QING_PROJECTS;
public static JSONArray CHINA_AREA_TAGS;
public static final List<String> PERMANENT_PLATFORM_NAMES = Arrays.asList("网媒", "微博", "微信", "今日头条"); public static final List<String> PERMANENT_PLATFORM_NAMES = Arrays.asList("网媒", "微博", "微信", "今日头条");
public static final String ELSE_PLATFORM_NAME = "其他自媒体"; public static final String ELSE_PLATFORM_NAME = "其他自媒体";
...@@ -69,6 +79,7 @@ public class GlobalPojo { ...@@ -69,6 +79,7 @@ public class GlobalPojo {
@PostConstruct @PostConstruct
public void start() { public void start() {
try { try {
initPojo();
updatePojo("启动获取"); updatePojo("启动获取");
} catch (Exception e) { } catch (Exception e) {
log.info("启动获取-出错", e); log.info("启动获取-出错", e);
...@@ -85,6 +96,10 @@ public class GlobalPojo { ...@@ -85,6 +96,10 @@ public class GlobalPojo {
} }
} }
private void initPojo() throws IOException {
CHINA_AREA_TAGS = JSONArray.parseArray(Tools.readJsonFile(chinaAreaTag.getInputStream()));
}
private void updatePojo(String logMsg) { private void updatePojo(String logMsg) {
try { try {
PLATFORMS = systemInfoService.getPlatforms(); PLATFORMS = systemInfoService.getPlatforms();
......
...@@ -5,7 +5,6 @@ import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform; ...@@ -5,7 +5,6 @@ import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import com.zhiwei.qbjc.bean.pojo.common.Tag; import com.zhiwei.qbjc.bean.pojo.common.Tag;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -27,7 +26,7 @@ public class QbjcPojoDaoImpl implements QbjcPojoDao { ...@@ -27,7 +26,7 @@ public class QbjcPojoDaoImpl implements QbjcPojoDao {
@Override @Override
public List<MessagePlatform> findMessagePlatformAll() { public List<MessagePlatform> findMessagePlatformAll() {
return mongoTemplate.find(new Query().with(Sort.by(Sort.Order.asc("_id"))), MessagePlatform.class); return mongoTemplate.find(new Query().with(Sort.by(Sort.Order.asc("createAt"))), MessagePlatform.class);
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
* @author: sjj * @author: sjj
* @date: 2022-05-26 15:51 * @date: 2022-05-26 15:51
*/ */
@Deprecated
public enum EventTagEnum{ public enum EventTagEnum{
EVENT_ATTRIBUTE("事件属性"), EVENT_ATTRIBUTE("事件属性"),
......
...@@ -11,6 +11,7 @@ import java.util.stream.Collectors; ...@@ -11,6 +11,7 @@ import java.util.stream.Collectors;
* @description 重要渠道枚举类 * @description 重要渠道枚举类
* @date 2019/9/6 14:08 * @date 2019/9/6 14:08
*/ */
@Deprecated
public enum ImportantChannelEnum { public enum ImportantChannelEnum {
/** /**
* 央级 * 央级
......
...@@ -4,6 +4,7 @@ import com.zhiwei.brandkbs2.common.GenericAttribute; ...@@ -4,6 +4,7 @@ import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo; import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.config.Constant; import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.enmus.ImportantChannelEnum; import com.zhiwei.brandkbs2.enmus.ImportantChannelEnum;
import com.zhiwei.brandkbs2.pojo.external.BrandkbsYuQingConfig;
import com.zhiwei.pushlog.tools.Tools; import com.zhiwei.pushlog.tools.Tools;
import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform; import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -95,14 +96,15 @@ public class EsQueryTools { ...@@ -95,14 +96,15 @@ public class EsQueryTools {
} }
public static BoolQueryBuilder assembleCacheMapsQuery(String projectId, String contendId) { public static BoolQueryBuilder assembleCacheMapsQuery(String projectId, String contendId) {
return assembleCacheMapsQuery(projectId, contendId, null); return assembleCacheMapsQuery(projectId, contendId, null, null, null, null, null);
} }
public static BoolQueryBuilder assembleCacheMapsQuery(String projectId, String contendId, List<String> mediaTypes) { public static BoolQueryBuilder assembleCacheMapsQuery(String projectId, String contendId, String politicsLevel, String field, String region, String mainBodyType) {
return assembleCacheMapsQuery(projectId, contendId, mediaTypes,null); return assembleCacheMapsQuery(projectId, contendId, politicsLevel, field, region, mainBodyType, null);
} }
public static BoolQueryBuilder assembleCacheMapsQuery(String projectId,String contendId, List<String> mediaTypes, Integer channelEmotion) { public static BoolQueryBuilder assembleCacheMapsQuery(String projectId,String contendId, String politicsLevel, String field, String region,
String mainBodyType,Integer channelEmotion) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
String key = concat(projectId, contendId); String key = concat(projectId, contendId);
BoolQueryBuilder nestedBoolBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder nestedBoolBuilder = QueryBuilders.boolQuery();
...@@ -113,20 +115,20 @@ public class EsQueryTools { ...@@ -113,20 +115,20 @@ public class EsQueryTools {
nestedBoolBuilder.must(QueryBuilders.termQuery("brandkbs_cache_maps.channel_emotion", channelEmotion)); nestedBoolBuilder.must(QueryBuilders.termQuery("brandkbs_cache_maps.channel_emotion", channelEmotion));
} }
boolQueryBuilder.must(cacheMapsNestedQuery(nestedBoolBuilder)); boolQueryBuilder.must(cacheMapsNestedQuery(nestedBoolBuilder));
// mediaTypes // sensitiveChannel
addMediaTypes(mediaTypes, boolQueryBuilder); addSensitiveChannel(politicsLevel, field, region, mainBodyType, boolQueryBuilder);
return boolQueryBuilder; return boolQueryBuilder;
} }
public static BoolQueryBuilder assembleCacheMapsQueryWithProject(String projectId, List<String> mediaTypes) { public static BoolQueryBuilder assembleCacheMapsQueryWithProject(String projectId, BrandkbsYuQingConfig config) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
BoolQueryBuilder nestedBoolBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder nestedBoolBuilder = QueryBuilders.boolQuery();
// 必要条件 // 必要条件
nestedBoolBuilder.must(QueryBuilders.termQuery("brandkbs_cache_maps.project_id.keyword", projectId)); nestedBoolBuilder.must(QueryBuilders.termQuery("brandkbs_cache_maps.project_id.keyword", projectId));
// 或需要添加其余nested字段 // 或需要添加其余nested字段
boolQueryBuilder.must(cacheMapsNestedQuery(nestedBoolBuilder)); boolQueryBuilder.must(cacheMapsNestedQuery(nestedBoolBuilder));
// mediaTypes // sensitiveChannel
addMediaTypes(mediaTypes, boolQueryBuilder); addSensitiveChannel(config, boolQueryBuilder);
// BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); // BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
// mediaTypes.forEach(e -> { // mediaTypes.forEach(e -> {
// BoolQueryBuilder mediaTypeQueryBuilder = QueryBuilders.boolQuery(); // BoolQueryBuilder mediaTypeQueryBuilder = QueryBuilders.boolQuery();
...@@ -325,6 +327,39 @@ public class EsQueryTools { ...@@ -325,6 +327,39 @@ public class EsQueryTools {
return regex.toString(); return regex.toString();
} }
public static void addSensitiveChannel(BrandkbsYuQingConfig config, BoolQueryBuilder boolQueryBuilder) {
if (!Tools.isEmpty(config.getPoliticsLevels()) && !config.getPoliticsLevels().contains("全部")) {
BoolQueryBuilder politicsLevelBool = QueryBuilders.boolQuery();
config.getPoliticsLevels().forEach(politicsLevel -> politicsLevelBool.should(QueryBuilders.termQuery(GenericAttribute.ES_SENSITIVE_CHANNEL + "." + GenericAttribute.ES_POLITICS_LEVEL + ".keyword", politicsLevel)));
boolQueryBuilder.must(politicsLevelBool);
}
if (!Tools.isEmpty(config.getFields()) && !config.getFields().contains("全部")) {
BoolQueryBuilder fieldBool = QueryBuilders.boolQuery();
config.getFields().forEach(field -> {
fieldBool.should(QueryBuilders.termQuery(GenericAttribute.ES_SENSITIVE_CHANNEL + "." + GenericAttribute.ES_FIELD + ".keyword", field));
});
boolQueryBuilder.must(fieldBool);
}
}
public static void addSensitiveChannel(String politicsLevel, String field, String region, String mainBodyType, BoolQueryBuilder boolQueryBuilder) {
if (null != politicsLevel) {
boolQueryBuilder.must(QueryBuilders.termQuery(GenericAttribute.ES_SENSITIVE_CHANNEL + "." + GenericAttribute.ES_POLITICS_LEVEL + ".keyword",
politicsLevel));
}
if (null != mainBodyType) {
boolQueryBuilder.must(QueryBuilders.matchPhraseQuery(GenericAttribute.ES_SENSITIVE_CHANNEL + "." + GenericAttribute.ES_MAIN_BODY_TYPE + ".keyword", mainBodyType));
}
if (null != field) {
boolQueryBuilder.must(QueryBuilders.termQuery(GenericAttribute.ES_SENSITIVE_CHANNEL + "." + GenericAttribute.ES_FIELD + ".keyword", field));
}
if (null != region) {
// 使用matchPhraseQuery,例如宁波市 能查询到 “宁波市|鄞州区”
boolQueryBuilder.must(QueryBuilders.matchPhraseQuery(GenericAttribute.ES_SENSITIVE_CHANNEL + "." + GenericAttribute.ES_REGION + ".keyword", region));
}
}
@Deprecated
private static void addMediaTypes(List<String> mediaTypes, BoolQueryBuilder boolQueryBuilder) { private static void addMediaTypes(List<String> mediaTypes, BoolQueryBuilder boolQueryBuilder) {
if (CollectionUtils.isNotEmpty(mediaTypes)) { if (CollectionUtils.isNotEmpty(mediaTypes)) {
BoolQueryBuilder mediaTypesBoolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder mediaTypesBoolQueryBuilder = QueryBuilders.boolQuery();
......
...@@ -73,9 +73,33 @@ public class MarkSearchDTO { ...@@ -73,9 +73,33 @@ public class MarkSearchDTO {
* 媒体类型 * 媒体类型
*/ */
@ApiModelProperty(value = "重要发声方") @ApiModelProperty(value = "重要发声方")
@Deprecated
private List<String> mediaTypes; private List<String> mediaTypes;
/** /**
* 行政级别
*/
@ApiModelProperty(value = "行政级别")
private String politicsLevel;
/**
* 领域
*/
@ApiModelProperty(value = "领域")
private String field;
/**
* 地域
*/
@ApiModelProperty(value = "地域")
private String region;
/**
* 主体类型
*/
@ApiModelProperty(value = "主体类型")
private String mainBodyType;
/**
* 标签筛选 * 标签筛选
*/ */
@ApiModelProperty(value = "舆情标签筛选") @ApiModelProperty(value = "舆情标签筛选")
......
...@@ -10,10 +10,13 @@ public class BrandkbsYuQingConfig { ...@@ -10,10 +10,13 @@ public class BrandkbsYuQingConfig {
private String configName; private String configName;
/** /**
* 发声渠道 * 行政级别
*/ */
private List<String> channelTypes; private List<String> politicsLevels;
/**
* 领域
*/
private List<String> fields;
/** /**
* 文章类型 * 文章类型
*/ */
......
...@@ -83,7 +83,16 @@ public class CommonServiceImpl implements CommonService { ...@@ -83,7 +83,16 @@ public class CommonServiceImpl implements CommonService {
@Override @Override
public List<JSONObject> getQbjcPlatform(String... includeFields) { public List<JSONObject> getQbjcPlatform(String... includeFields) {
List<JSONObject> collect = GlobalPojo.PLATFORMS.stream().filter(messagePlatform -> !"外媒".equals(messagePlatform.getName())).map(messagePlatform -> { List<JSONObject> collect = GlobalPojo.PLATFORMS.stream().filter(messagePlatform -> {
// if ("小红书".equals(messagePlatform.getName())) {
// return false;
// }
// if ("抖音".equals(messagePlatform.getName())) {
// return false;
// }
return !"外媒".equals(messagePlatform.getName());
}
).map(messagePlatform -> {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("id", messagePlatform.getId()); json.put("id", messagePlatform.getId());
json.put("name", messagePlatform.getName()); json.put("name", messagePlatform.getName());
......
package com.zhiwei.brandkbs2.service.impl; package com.zhiwei.brandkbs2.service.impl;
import com.zhiwei.brandkbs2.common.GenericAttribute; import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.es.EsClientDao; import com.zhiwei.brandkbs2.es.EsClientDao;
import com.zhiwei.brandkbs2.es.EsQueryTools; import com.zhiwei.brandkbs2.es.EsQueryTools;
import com.zhiwei.brandkbs2.function.ArticleFunction; import com.zhiwei.brandkbs2.function.ArticleFunction;
import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import com.zhiwei.brandkbs2.service.EsSearchService; import com.zhiwei.brandkbs2.service.EsSearchService;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
...@@ -23,7 +21,6 @@ import org.springframework.stereotype.Service; ...@@ -23,7 +21,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -77,7 +74,7 @@ public class EsSearchServiceImpl implements EsSearchService { ...@@ -77,7 +74,7 @@ public class EsSearchServiceImpl implements EsSearchService {
String contendId = dto.getContendId(); String contendId = dto.getContendId();
// PostFilter 后置过滤器 // PostFilter 后置过滤器
// 新增channelEmotion // 新增channelEmotion
BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQuery(projectId, contendId, dto.getMediaTypes(), dto.getChannelEmotion()); BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQuery(projectId, contendId, dto.getPoliticsLevel(), dto.getField(), dto.getRegion(), dto.getMainBodyType(), dto.getChannelEmotion());
// time // time
postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).gte(dto.getStartTime()).lt(dto.getEndTime())); postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).gte(dto.getStartTime()).lt(dto.getEndTime()));
// platform // platform
...@@ -143,7 +140,7 @@ public class EsSearchServiceImpl implements EsSearchService { ...@@ -143,7 +140,7 @@ public class EsSearchServiceImpl implements EsSearchService {
String projectId = dto.getProjectId(); String projectId = dto.getProjectId();
String contendId = dto.getContendId(); String contendId = dto.getContendId();
// PostFilter 后置过滤器 // PostFilter 后置过滤器
BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQuery(projectId, contendId, dto.getMediaTypes()); BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQuery(projectId, contendId, dto.getPoliticsLevel(), dto.getField(), dto.getRegion(), dto.getMainBodyType(), dto.getChannelEmotion());
// time // time
postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).gte(dto.getStartTime()).lt(dto.getEndTime())); postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).gte(dto.getStartTime()).lt(dto.getEndTime()));
// platform // platform
...@@ -249,14 +246,15 @@ public class EsSearchServiceImpl implements EsSearchService { ...@@ -249,14 +246,15 @@ public class EsSearchServiceImpl implements EsSearchService {
*/ */
private Map<String, Long> platformCount(int page, List<String> platforms, BoolQueryBuilder postFilter, EsClientDao esClientDao) throws IOException { private Map<String, Long> platformCount(int page, List<String> platforms, BoolQueryBuilder postFilter, EsClientDao esClientDao) throws IOException {
Map<String, Long> counts = new HashMap<>(); Map<String, Long> counts = new HashMap<>();
// TODO 平台进量暂不统计
//平台计量统计 仅第一页且无平台限制 //平台计量统计 仅第一页且无平台限制
if (1 == page && CollectionUtils.isEmpty(platforms)) { // if (1 == page && CollectionUtils.isEmpty(platforms)) {
for (MessagePlatform platform : GlobalPojo.PLATFORMS) { // for (MessagePlatform platform : GlobalPojo.PLATFORMS) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(postFilter).must(EsQueryTools.assemblePlatformQuery(Collections.singletonList(platform))); // BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(postFilter).must(EsQueryTools.assemblePlatformQuery(Collections.singletonList(platform)));
Long count = esClientDao.count(esClientDao.getIndexes(), queryBuilder, null); // Long count = esClientDao.count(esClientDao.getIndexes(), queryBuilder, null);
counts.put(platform.getName(), count); // counts.put(platform.getName(), count);
} // }
} // }
return counts; return counts;
} }
......
...@@ -8,6 +8,7 @@ import com.google.common.collect.ImmutableMap; ...@@ -8,6 +8,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.zhiwei.base.entity.subclass.mark.MarkInfo; import com.zhiwei.base.entity.subclass.mark.MarkInfo;
import com.zhiwei.brandkbs2.auth.UserThreadLocal; import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.ChannelType;
import com.zhiwei.brandkbs2.common.GenericAttribute; import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo; import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.common.RedisKeyPrefix; import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
...@@ -296,9 +297,11 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -296,9 +297,11 @@ public class MarkDataServiceImpl implements MarkDataService {
return json; return json;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
// 重要发声方 // 重要发声方
result.put("mediaTypeList", ImportantChannelEnum.getAllTagExceptSpec()); result.put("channelTypeList", ChannelType.channelOption);
// 其他标签组(筛选器) // 其他标签组(筛选器)
result.put("tagFilterList", tagFilterService.getTagFilter()); result.put("tagFilterList", tagFilterService.getTagFilter());
// 地域
result.put("regionList", getFilterRegionList());
// 自定义标签列表 // 自定义标签列表
List<CustomTagVo> customTagList = customTagService.findCustomTagList(1, 1).getList(); List<CustomTagVo> customTagList = customTagService.findCustomTagList(1, 1).getList();
if (CollectionUtils.isNotEmpty(customTagList)) { if (CollectionUtils.isNotEmpty(customTagList)) {
...@@ -307,6 +310,39 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -307,6 +310,39 @@ public class MarkDataServiceImpl implements MarkDataService {
return result; return result;
} }
private List<JSONObject> getFilterRegionList() {
List<JSONObject> res = new ArrayList<>();
JSONObject beijing = new JSONObject();
beijing.put("name","北京");
beijing.put("id","北京市");
res.add(beijing);
JSONObject shanghai = new JSONObject();
shanghai.put("name","上海");
shanghai.put("id","上海市");
res.add(shanghai);
JSONObject guangzhou = new JSONObject();
guangzhou.put("name","广州");
guangzhou.put("id","广东省|广州市");
res.add(guangzhou);
JSONObject shenzhen = new JSONObject();
shenzhen.put("name","深圳");
shenzhen.put("id","广东省|深圳市");
res.add(shenzhen);
JSONObject zhejiang = new JSONObject();
zhejiang.put("name","浙江");
zhejiang.put("id","浙江省");
res.add(zhejiang);
JSONObject sichuan = new JSONObject();
sichuan.put("name","四川");
sichuan.put("id","四川省");
res.add(sichuan);
JSONObject chongqing = new JSONObject();
chongqing.put("name","重庆");
chongqing.put("id","重庆市");
res.add(chongqing);
return res;
}
@Override @Override
public JSONObject getMobileYuqingMarkCriteria() { public JSONObject getMobileYuqingMarkCriteria() {
String projectId = UserThreadLocal.getProjectId(); String projectId = UserThreadLocal.getProjectId();
......
...@@ -29,10 +29,7 @@ import org.springframework.stereotype.Service; ...@@ -29,10 +29,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -212,24 +209,16 @@ public class MarkFlowServiceImpl implements MarkFlowService { ...@@ -212,24 +209,16 @@ public class MarkFlowServiceImpl implements MarkFlowService {
sourceDetails.put("followersNum", followersNum); sourceDetails.put("followersNum", followersNum);
} }
// 渠道标签 // 渠道标签
String channelTag = tJson.getString("channel_tag"); JSONObject sensitiveChannel = tJson.getJSONObject(GenericAttribute.ES_SENSITIVE_CHANNEL);
if (null != channelTag) { if (null != sensitiveChannel && !sensitiveChannel.isEmpty()) {
sourceDetails.put("channelTag", channelTag.replaceAll(",", "|")); StringBuilder sb = new StringBuilder();
addChannelTag(sensitiveChannel.getString(GenericAttribute.ES_POLITICS_LEVEL), sb);
addChannelTag(sensitiveChannel.getString(GenericAttribute.ES_MAIN_BODY_TYPE), sb);
addChannelTag(sensitiveChannel.getString(GenericAttribute.ES_FIELD), sb);
addChannelTagRegion(sensitiveChannel.getString(GenericAttribute.ES_REGION), sb);
sourceDetails.put("channelTag", sb.toString());
} }
// 渠道倾向及id(调整为快照属性) // 渠道倾向及id
// Channel channel = channelDao.queryUnique(ChannelIndex.createChannelIndex(tJson, projectId, contendId));
// if (null != channel) {
// sourceDetails.put("channelId", channel.getId());
// sourceDetails.put("channelEmotion", ChannelEmotion.getNameFromState(channel.getEmotion()));
// } else {
// List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) tJson.get(GenericAttribute.ES_BRANDKBS_CACHE_MAPS);
// if (null != cacheMaps) {
// Map<String, Object> hitMap =
// cacheMaps.stream().filter(map -> projectId.equals(map.get("project_id")) && contendId.equals(map.get("contend_id"))).findAny().orElse(Collections.emptyMap());
// sourceDetails.put("channelId", hitMap.get("channel_id"));
// sourceDetails.put("channelEmotion", ChannelEmotion.getNameFromState(hitMap.get("channel_emotion")));
// }
// }
JSONObject brandkbsHitJson = Tools.getBrandkbsHitMap(tJson, Tools.concat(markInfoSource.getProjectId(), markInfoSource.getContendId())); JSONObject brandkbsHitJson = Tools.getBrandkbsHitMap(tJson, Tools.concat(markInfoSource.getProjectId(), markInfoSource.getContendId()));
if (null != brandkbsHitJson.get("channel_emotion")) { if (null != brandkbsHitJson.get("channel_emotion")) {
sourceDetails.put("channelEmotion", ChannelEmotion.getNameFromState(brandkbsHitJson.getIntValue("channel_emotion"))); sourceDetails.put("channelEmotion", ChannelEmotion.getNameFromState(brandkbsHitJson.getIntValue("channel_emotion")));
...@@ -315,4 +304,35 @@ public class MarkFlowServiceImpl implements MarkFlowService { ...@@ -315,4 +304,35 @@ public class MarkFlowServiceImpl implements MarkFlowService {
return res; return res;
} }
private void addChannelTag(String value, StringBuilder channelTag) {
if (null != value) {
if (0 == channelTag.length()) {
channelTag.append(value);
} else {
channelTag.append("|").append(value);
}
}
}
private void addChannelTagRegion(String region, StringBuilder channelTag) {
if (null != region) {
StringBuilder newRegion = new StringBuilder();
String[] split = region.split("\\|", 2);
for (String s : split) {
if (0 == newRegion.length()) {
newRegion.append(s);
} else {
if (!newRegion.toString().contains(s)) {
newRegion.append(" ").append(s);
}
}
}
if (0 == channelTag.length()) {
channelTag.append(newRegion);
} else {
channelTag.append("|").append(newRegion);
}
}
}
} }
...@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.service.impl; ...@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.common.ChannelType;
import com.zhiwei.brandkbs2.common.RedisKeyPrefix; import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
import com.zhiwei.brandkbs2.config.Constant; import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.ChannelDao; import com.zhiwei.brandkbs2.dao.ChannelDao;
...@@ -12,10 +13,7 @@ import com.zhiwei.brandkbs2.enmus.EmotionEnum; ...@@ -12,10 +13,7 @@ import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.es.EsClientDao; import com.zhiwei.brandkbs2.es.EsClientDao;
import com.zhiwei.brandkbs2.es.EsQueryTools; import com.zhiwei.brandkbs2.es.EsQueryTools;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.AbstractProject; import com.zhiwei.brandkbs2.pojo.*;
import com.zhiwei.brandkbs2.pojo.BaseMap;
import com.zhiwei.brandkbs2.pojo.Channel;
import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.pojo.external.*; import com.zhiwei.brandkbs2.pojo.external.*;
import com.zhiwei.brandkbs2.pojo.vo.CrisisCaseWarnVO; import com.zhiwei.brandkbs2.pojo.vo.CrisisCaseWarnVO;
import com.zhiwei.brandkbs2.service.ProjectService; import com.zhiwei.brandkbs2.service.ProjectService;
...@@ -105,7 +103,8 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -105,7 +103,8 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
Map<String, Object> res = new HashMap<>(); Map<String, Object> res = new HashMap<>();
switch (type) { switch (type) {
case "舆情动态": case "舆情动态":
CriteriaHelper.warnCriteriaAddSimple(res, "channelTypes", Arrays.asList("央级", "门户", "财经", "科技", "其他"), Collections.singletonList("央级")); CriteriaHelper.warnCriteriaAddSimple(res, "politicsLevels", Arrays.asList("央级", "省级", "地级"), Collections.singletonList("央级"));
CriteriaHelper.warnCriteriaAddSimple(res, "fields", ChannelType.COMMON_FIELDS, Collections.singletonList("财经"));
CriteriaHelper.warnCriteriaAdd(res, "primary", Arrays.asList("原创", "转发"), Arrays.asList(false, true), Collections.singletonList("原创")); CriteriaHelper.warnCriteriaAdd(res, "primary", Arrays.asList("原创", "转发"), Arrays.asList(false, true), Collections.singletonList("原创"));
CriteriaHelper.warnCriteriaAddSimple(res, "markerTags", Arrays.asList("正面", "中性", "负面"), Collections.singletonList("负面")); CriteriaHelper.warnCriteriaAddSimple(res, "markerTags", Arrays.asList("正面", "中性", "负面"), Collections.singletonList("负面"));
List<JSONObject> brands = projectService.getBrands(projectId, false); List<JSONObject> brands = projectService.getBrands(projectId, false);
...@@ -172,7 +171,8 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -172,7 +171,8 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
switch (type) { switch (type) {
case "舆情动态": case "舆情动态":
BrandkbsYuQingConfig config = new BrandkbsYuQingConfig(); BrandkbsYuQingConfig config = new BrandkbsYuQingConfig();
config.setChannelTypes(Collections.singletonList("央级")); config.setPoliticsLevels(Collections.singletonList("央级"));
config.setFields(Collections.singletonList("财经"));
config.setPrimary(Collections.singletonList(Boolean.TRUE)); config.setPrimary(Collections.singletonList(Boolean.TRUE));
config.setMarkerTags(Collections.singletonList("负面")); config.setMarkerTags(Collections.singletonList("负面"));
config.setDuplicate(Boolean.FALSE); config.setDuplicate(Boolean.FALSE);
...@@ -221,13 +221,35 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -221,13 +221,35 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
// key1 // key1
String key1 = "【品见】舆情动态-" + project.getProjectName(); String key1 = "【品见】舆情动态-" + project.getProjectName();
// key2 // key2
String key2Header = "全部"; // String key2Header = "全部";
String key2Header = "";
StringBuilder mediaChannel = new StringBuilder(); StringBuilder mediaChannel = new StringBuilder();
config.getChannelTypes().forEach(channelType -> mediaChannel.append(channelType).append("、")); List<String> politicsLevels = config.getPoliticsLevels();
List<String> fields = config.getFields();
if ((!Tools.isEmpty(politicsLevels) && !politicsLevels.contains("全部"))) {
politicsLevels.forEach(politicsLevel -> mediaChannel.append(politicsLevel).append("、"));
} else {
key2Header += "【全部级别】";
}
if ((!Tools.isEmpty(fields) && !fields.contains("全部"))) {
fields.forEach(field -> mediaChannel.append(field).append("、"));
} else {
if (0 != key2Header.length()) {
key2Header += "、";
key2Header += "【全部领域】,";
} else {
key2Header += "【全部领域】";
}
}
// config.getChannelTypes().forEach(channelType -> mediaChannel.append(channelType).append("、"));
if (0 != mediaChannel.length()) { if (0 != mediaChannel.length()) {
key2Header = mediaChannel.deleteCharAt(mediaChannel.length() - 1).toString(); if (0 != key2Header.length()) {
key2Header += "、";
}
// 替换“全部” 并去掉末位的、
key2Header += mediaChannel.deleteCharAt(mediaChannel.length() - 1).toString();
key2Header += "媒体,";
} }
key2Header += "媒体,";
StringBuilder dataType = new StringBuilder(); StringBuilder dataType = new StringBuilder();
config.getMarkerTags().forEach(emotion -> dataType.append(emotion).append(" ")); config.getMarkerTags().forEach(emotion -> dataType.append(emotion).append(" "));
dataType.append("(本品)"); dataType.append("(本品)");
...@@ -593,7 +615,7 @@ public class ProjectWarnServiceImpl implements ProjectWarnService { ...@@ -593,7 +615,7 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
EsClientDao.SearchHelper helper = EsClientDao.createSearchHelper(); EsClientDao.SearchHelper helper = EsClientDao.createSearchHelper();
// 发声渠道 // 发声渠道
BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQueryWithProject(projectId, config.getChannelTypes()); BoolQueryBuilder postFilter = EsQueryTools.assembleCacheMapsQueryWithProject(projectId, config);
// 时间(标注时间) // 时间(标注时间)
postFilter.must(QueryBuilders.rangeQuery("mtime").gte(start).lt(end)); postFilter.must(QueryBuilders.rangeQuery("mtime").gte(start).lt(end));
// 文章类型 // 文章类型
......
...@@ -40,6 +40,7 @@ import java.nio.ByteBuffer; ...@@ -40,6 +40,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel; import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
...@@ -580,6 +581,28 @@ public class Tools { ...@@ -580,6 +581,28 @@ public class Tools {
return result; return result;
} }
/**
* 读取json文件,返回json串
*
* @param fileInputStream
* @return
*/
public static String readJsonFile(InputStream fileInputStream) {
try {
Reader reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
int ch = 0;
StringBuilder sb = new StringBuilder();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
reader.close();
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static Map<String, Integer> sortMap(Map<String, Integer> map, Integer maxSize) { public static Map<String, Integer> sortMap(Map<String, Integer> map, Integer maxSize) {
Map<String, Integer> result = new LinkedHashMap<>(); Map<String, Integer> result = new LinkedHashMap<>();
List<Map.Entry<String, Integer>> collect; List<Map.Entry<String, Integer>> collect;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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