Commit 81b2ec0d by shenjunjie

Merge branch 'feature' into 'release'

增加渠道库敏感、友好渠道榜隐藏逻辑

See merge request !444
parents 07aac508 384accc1
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.pojo.ChannelTag;
import com.zhiwei.brandkbs2.pojo.HighlightWord;
import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.service.ChannelService;
import com.zhiwei.brandkbs2.service.SystemInfoService;
import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.automaticmark.graphs.Graphs;
......@@ -46,6 +47,9 @@ public class GlobalPojo {
@Resource(name = "highlightWordDao")
private HighlightWordDao highlightWordDao;
@Resource(name = "channelServiceImpl")
private ChannelService channelService;
/**
* 监测系统平台
**/
......@@ -82,6 +86,8 @@ public class GlobalPojo {
public static Map<String, Graphs> PROJECT_GRAPHS = new HashMap<>();
public static Map<String, JSONObject> PROJECT_EMOTION_CHANNEL_DATA = new HashMap<>();
public static final List<String> PERMANENT_PLATFORM_NAMES = Arrays.asList("网媒", "微博", "微信", "今日头条");
public static final String ELSE_PLATFORM_NAME = "其他自媒体";
......@@ -119,9 +125,10 @@ public class GlobalPojo {
MEDIA_TYPE = systemInfoService.getMediaTypes();
PROJECT_MAP = systemInfoService.getProjects();
YU_QING_PROJECTS = systemInfoService.getYuQingProjects();
PROJECT_EMOTION_CHANNEL_DATA = channelService.getProjectEmotionChannelListData();
updateHighlightGraphs();
log.info("{}-获取PLATFORMS-size:{},TAGS-size:{},LINKED_GROUP_ID_TAGS:{},CHANNEL_TAGS:{},MEDIA_TYPE:{},PROJECT_MAP:{},YUQING-PROJECTS-size:{}", logMsg, PLATFORMS.size(), TAGS.size(),
LINKED_GROUP_ID_TAGS.size(), CHANNEL_TAGS.size(), MEDIA_TYPE.size(), PROJECT_MAP.size(), YU_QING_PROJECTS.size());
log.info("{}-获取PLATFORMS-size:{},TAGS-size:{},LINKED_GROUP_ID_TAGS:{},CHANNEL_TAGS:{},MEDIA_TYPE:{},PROJECT_MAP:{},YUQING-PROJECTS-size:{},PROJECT_EMOTION_CHANNEL_DATA-size:{}", logMsg, PLATFORMS.size(), TAGS.size(),
LINKED_GROUP_ID_TAGS.size(), CHANNEL_TAGS.size(), MEDIA_TYPE.size(), PROJECT_MAP.size(), YU_QING_PROJECTS.size(), PROJECT_EMOTION_CHANNEL_DATA.size());
} catch (Exception e) {
log.info("{}-获取缓存值异常", logMsg, e);
}
......
......@@ -12,7 +12,9 @@ import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.ChannelVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @ClassName: ChannelService
......@@ -300,4 +302,10 @@ public interface ChannelService {
JSONObject getMobileSpreadingTend(String channelId,String type);
/**
* 获取项目正面、负面渠道数据
* @return
* @throws IOException
*/
Map<String, JSONObject> getProjectEmotionChannelListData() throws IOException;
}
......@@ -45,8 +45,11 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedLongTerms;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.Sum;
......@@ -99,6 +102,9 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "channelTagDao")
ChannelTagDao channelTagDao;
@Resource(name = "projectDao")
private ProjectDao projectDao;
@Resource(name = "qbjcPojoDao")
private QbjcPojoDao qbjcPojoDao;
......@@ -1216,6 +1222,39 @@ public class ChannelServiceImpl implements ChannelService {
return result;
}
@Override
public Map<String, JSONObject> getProjectEmotionChannelListData() throws IOException {
int size = projectDao.findList(new Query()).size();
Map<String, JSONObject> res = new HashMap<>();
// query
BoolQueryBuilder query = QueryBuilders.boolQuery();
// contendId
query.must(QueryBuilders.termQuery("contend_id.keyword", Constant.PRIMARY_CONTEND_ID));
// emotion
query.mustNot(QueryBuilders.termQuery("emotion", EmotionEnum.NEUTRAL.getState()));
query.mustNot(QueryBuilders.termQuery("emotion", EmotionEnum.UNDEFINED.getState()));
// agg
TermsAggregationBuilder projectAgg = AggregationBuilders.terms("projectAgg").field("project_id.keyword").size(size);
TermsAggregationBuilder emotionAgg = AggregationBuilders.terms("emotionAgg").field("emotion");
// response
SearchResponse searchResponse = esClientDao.searchResponse(new String[]{"brandkbs2_channel_copy"}, null, query,
projectAgg.subAggregation(emotionAgg), null, null, 0, 0, null);
Map<String, Aggregation> aggMap = searchResponse.getAggregations().asMap();
ParsedStringTerms projectTeamAgg = (ParsedStringTerms) aggMap.get("projectAgg");
List<? extends Terms.Bucket> buckets = projectTeamAgg.getBuckets();
buckets.forEach(bucket -> {
JSONObject jsonObject = new JSONObject();
Map<String, Aggregation> map = bucket.getAggregations().asMap();
ParsedLongTerms emotionTeamAgg = (ParsedLongTerms) map.get("emotionAgg");
List<? extends Terms.Bucket> list = emotionTeamAgg.getBuckets();
for (Terms.Bucket eBucket : list) {
jsonObject.put(EmotionEnum.state2Name(eBucket.getKeyAsNumber().intValue()), eBucket.getDocCount());
}
res.put(bucket.getKeyAsString(), jsonObject);
});
return res;
}
private BoolQueryBuilder getChannelListQuery(String projectId, String contendId, String keyword,
List<String> platforms, List<Integer> emotions, List<String> mediaTypes, Integer[] articlesCount) {
BoolQueryBuilder postFilter = QueryBuilders.boolQuery();
......
......@@ -6,6 +6,7 @@ import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.*;
import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.enmus.response.ProjectCodeEnum;
import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.model.CommonCodeEnum;
......@@ -711,6 +712,12 @@ public class ProjectServiceImpl implements ProjectService {
Map<String, Object> originPermission = new HashMap<>();
originPermission.put("origin", Objects.nonNull(project.getModuleShowList()) && project.getModuleShowList().contains(2));
permissionList.add(originPermission);
// 友好渠道榜、敏感渠道榜是否有数据
Map<String, Object> channelPermission = new HashMap<>();
JSONObject jsonObject = GlobalPojo.PROJECT_EMOTION_CHANNEL_DATA.get(project.getId());
channelPermission.put("positiveChannel", Objects.nonNull(jsonObject) && Objects.nonNull(jsonObject.getLong(EmotionEnum.POSITIVE.getName())) && 0 != jsonObject.getLong(EmotionEnum.POSITIVE.getName()));
channelPermission.put("negativeChannel", Objects.nonNull(jsonObject) && Objects.nonNull(jsonObject.getLong(EmotionEnum.NEGATIVE.getName())) && 0 != jsonObject.getLong(EmotionEnum.NEGATIVE.getName()));
permissionList.add(channelPermission);
return permissionList;
}
......
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