Commit d6841459 by 陈健智

修改舆情外部接口

parent 8dfacb6d
......@@ -3,9 +3,11 @@ package com.zhiwei.brandkbs2.common;
import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.zhiwei.brandkbs2.pojo.ChannelTag;
import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.service.EventService;
import com.zhiwei.brandkbs2.service.SystemInfoService;
import com.zhiwei.middleware.mark.vo.MarkerTag;
import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import com.zhiwei.qbjc.bean.pojo.common.Tag;
import org.apache.logging.log4j.LogManager;
......@@ -47,6 +49,11 @@ public class GlobalPojo {
**/
public static Map<String, List<Tag>> TAGS;
/**
* 品见情感倾向标签
*/
public static List<Tag> LINKED_GROUP_ID_TAGS;
public static Map<String, String> CHANNEL_TAGS;
......@@ -89,12 +96,13 @@ public class GlobalPojo {
try {
PLATFORMS = systemInfoService.getPlatforms();
TAGS = systemInfoService.getTags().stream().collect(Collectors.groupingBy(Tag::getGroupName));
LINKED_GROUP_ID_TAGS = systemInfoService.findEmotionTagByLinkedGroupId();
CHANNEL_TAGS = systemInfoService.getChannelTags().stream().collect(Collectors.toMap(ChannelTag::getChannel, ChannelTag::getTag));
MEDIA_TYPE = systemInfoService.getMediaTypes();
PROJECT_MAP = systemInfoService.getProjects();
YU_QING_PROJECTS = systemInfoService.getYuQingProjects();
log.info("{}-获取PLATFORMS-size:{},TAGS-size:{},CHANNEL_TAGS:{},MEDIA_TYPE:{},PROJECT_MAP:{},YUQING-PROJECTS-size:{}", logMsg, PLATFORMS.size(), 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:{}", logMsg, PLATFORMS.size(), TAGS.size(),
LINKED_GROUP_ID_TAGS.size(), CHANNEL_TAGS.size(), MEDIA_TYPE.size(), PROJECT_MAP.size(), YU_QING_PROJECTS.size());
} catch (Exception e) {
log.info("{}-获取缓存值异常", logMsg, e);
}
......
......@@ -34,5 +34,5 @@ public interface QbjcPojoDao {
*
* @return tags
*/
List<Tag> findEmotionTagByLinkedGroupId(String linkedGroupId);
List<Tag> findEmotionTagByLinkedGroupId();
}
......@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* @ClassName: QbjcPojoDaoImpl
......@@ -35,8 +36,8 @@ public class QbjcPojoDaoImpl implements QbjcPojoDao {
}
@Override
public List<Tag> findEmotionTagByLinkedGroupId(String linkedGroupId) {
return mongoTemplate.find(new Query(Criteria.where("projectId").is(linkedGroupId)), Tag.class);
public List<Tag> findEmotionTagByLinkedGroupId() {
return mongoTemplate.find(new Query(), Tag.class).stream().filter(tag -> tag.getGroupName().equals("情感倾向")).collect(Collectors.toList());
}
......
......@@ -32,6 +32,13 @@ public interface SystemInfoService {
List<Tag> getTags();
/**
* 获取qbjcTag
*
* @return tags
*/
List<Tag> findEmotionTagByLinkedGroupId();
/**
* 获取ChannelTags
*
* @return List<ChannelTag>
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.ProjectDao;
import com.zhiwei.brandkbs2.dao.QbjcPojoDao;
import com.zhiwei.brandkbs2.dao.UserDao;
......@@ -60,6 +61,7 @@ import java.util.stream.Collectors;
public class ProjectServiceImpl implements ProjectService {
private static final Logger log = LogManager.getLogger(ProjectServiceImpl.class);
// 品见情感标签默认只需要这些
private static final List<String> EMOTION_MARKER_TAGS = Arrays.asList("正面", "负面", "中性", "敏感");
@Resource(name = "userDao")
......@@ -380,36 +382,40 @@ public class ProjectServiceImpl implements ProjectService {
// 暂且将测试项目排除
query.addCriteria(Criteria.where("_id").ne("632052f0abed641ef800476c"));
List<Project> projects = projectDao.findList(query);
// 情感倾向标签
List<Tag> tags = qbjcPojoDao.findEmotionTagByLinkedGroupId(linkedGroupId);
Map<String, List<MarkerTag>> emotionMarkerTags = tags
.stream().filter(tag -> tag.getGroupName().equals("情感倾向") && EMOTION_MARKER_TAGS.contains(tag.getName()))
.map(tag -> Tools.convertMap(tag, MarkerTag.class))
.sorted(Comparator.comparing(MarkerTag::getId))
.collect(Collectors.groupingBy(MarkerTag::getGroupName));
Map<String, List<MarkerTag>> tagsMap = new HashMap<>();
for (Project project : projects) {
if (Objects.equals(project.getBrandLinkedGroupId(), linkedGroupId)) {
Map<String, List<MarkerTag>> tagsMap = new HashMap<>();
JSONObject jsonObject = new JSONObject();
if (!Tools.isEmpty(project.getHitTags())) {
tagsMap.putAll(project.getHitTags().stream().collect(Collectors.groupingBy(MarkerTag::getGroupName)));
}
Map<String, List<MarkerTag>> emotionMarkerTags = getEmotionMarkerTags(project.getBrandLinkedGroup());
if (!Tools.isEmpty(tagsMap.get(Constant.EMOTION_LABEL_KEY))){
tagsMap.get(Constant.EMOTION_LABEL_KEY).addAll(0, emotionMarkerTags.get(Constant.EMOTION_LABEL_KEY));
}else {
tagsMap.putAll(emotionMarkerTags);
}
jsonObject.put("tags", tagsMap);
BrandkbsBasicInfo brandkbsBasicInfo = new BrandkbsBasicInfo(project.getProjectName(), project.getId(), project.getBrandName(), project.getId());
jsonObject.put("brandkbsBasicInfo", brandkbsBasicInfo);
result.add(jsonObject);
} else {
}
if (!Tools.isEmpty(project.getContendList())) {
for (Contend contend : project.getContendList()) {
Map<String, List<MarkerTag>> tagsMap = new HashMap<>();
if (Objects.equals(contend.getBrandLinkedGroupId(), linkedGroupId)) {
JSONObject jsonObject = new JSONObject();
if (!Tools.isEmpty(contend.getHitTags())) {
tagsMap.putAll(contend.getHitTags().stream().collect(Collectors.groupingBy(MarkerTag::getGroupName)));
}
if (contend.isHasEmotion()){
Map<String, List<MarkerTag>> emotionMarkerTags = getEmotionMarkerTags(contend.getBrandLinkedGroup());
if (!Tools.isEmpty(tagsMap.get(Constant.EMOTION_LABEL_KEY))){
tagsMap.get(Constant.EMOTION_LABEL_KEY).addAll(0, emotionMarkerTags.get(Constant.EMOTION_LABEL_KEY));
}else {
tagsMap.putAll(emotionMarkerTags);
}
}
jsonObject.put("tags", tagsMap);
BrandkbsBasicInfo brandkbsBasicInfo = new BrandkbsBasicInfo(project.getProjectName(), project.getId(), contend.getBrandName(), contend.getId());
jsonObject.put("brandkbsBasicInfo", brandkbsBasicInfo);
......@@ -418,7 +424,6 @@ public class ProjectServiceImpl implements ProjectService {
}
}
}
}
return ResponseResult.success(result);
}catch (Exception e){
log.error("外部接口获取hitTags出错", e);
......@@ -426,6 +431,19 @@ public class ProjectServiceImpl implements ProjectService {
}
}
/**
* 获取舆情对应项目的情感标签
* @param brandName
* @return
*/
private Map<String, List<MarkerTag>> getEmotionMarkerTags(String brandName){
return GlobalPojo.LINKED_GROUP_ID_TAGS
.stream().filter(tag -> !Tools.isEmpty(tag.getProject()) && tag.getProject().equals(brandName) && EMOTION_MARKER_TAGS.contains(tag.getName()))
.map(tag -> Tools.convertMap(tag, MarkerTag.class))
.sorted(Comparator.comparing(MarkerTag::getId))
.collect(Collectors.groupingBy(MarkerTag::getGroupName));
}
// public JSONObject getUserInfoAndProjectConfig(User user) {
// long start = System.currentTimeMillis();
// JSONObject result = new JSONObject();
......
......@@ -67,6 +67,11 @@ public class SystemInfoServiceImpl implements SystemInfoService {
}
@Override
public List<Tag> findEmotionTagByLinkedGroupId() {
return qbjcPojoDao.findEmotionTagByLinkedGroupId();
}
@Override
public List<ChannelTag> getChannelTags() {
return channelTagDao.findList(null);
}
......
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