Commit 8dfacb6d by 陈健智

舆情外部接口:增加情感倾向标签

parent 39cbeb45
......@@ -29,4 +29,10 @@ public interface QbjcPojoDao {
*/
List<Tag> findTagAll();
/**
* 获取qbjcTag
*
* @return tags
*/
List<Tag> findEmotionTagByLinkedGroupId(String linkedGroupId);
}
......@@ -5,6 +5,7 @@ import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import com.zhiwei.qbjc.bean.pojo.common.Tag;
import org.springframework.data.domain.Sort;
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.stereotype.Component;
......@@ -33,5 +34,11 @@ public class QbjcPojoDaoImpl implements QbjcPojoDao {
return mongoTemplate.find(new Query(), Tag.class);
}
@Override
public List<Tag> findEmotionTagByLinkedGroupId(String linkedGroupId) {
return mongoTemplate.find(new Query(Criteria.where("projectId").is(linkedGroupId)), Tag.class);
}
}
......@@ -5,6 +5,7 @@ import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.dao.ProjectDao;
import com.zhiwei.brandkbs2.dao.QbjcPojoDao;
import com.zhiwei.brandkbs2.dao.UserDao;
import com.zhiwei.brandkbs2.enmus.response.ProjectCodeEnum;
import com.zhiwei.brandkbs2.exception.ExceptionCast;
......@@ -16,7 +17,9 @@ import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.pojo.User;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.pojo.vo.ProjectVO;
import com.zhiwei.brandkbs2.service.CommonService;
import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.service.SystemInfoService;
import com.zhiwei.brandkbs2.service.UserService;
import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.Tools;
......@@ -25,8 +28,11 @@ import com.zhiwei.middleware.event.core.EventTagClient;
import com.zhiwei.middleware.event.pojo.dto.EventTagRelatedDTO;
import com.zhiwei.middleware.event.pojo.entity.BrandkbsBasicInfo;
import com.zhiwei.middleware.event.pojo.entity.Event;
import com.zhiwei.middleware.mark.pojo.enums.TagField;
import com.zhiwei.middleware.mark.vo.MarkerTag;
import com.zhiwei.qbjc.bean.pojo.common.Tag;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -40,6 +46,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
......@@ -53,12 +60,17 @@ 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")
private UserDao userDao;
@Resource(name = "projectDao")
private ProjectDao projectDao;
@Resource(name = "qbjcPojoDao")
private QbjcPojoDao qbjcPojoDao;
@Resource(name = "mongoUtil")
private com.zhiwei.brandkbs2.util.MongoUtil mongoUtil;
......@@ -368,21 +380,37 @@ 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)) {
JSONObject jsonObject = new JSONObject();
if (!Tools.isEmpty(project.getHitTags())) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("tags", project.getHitTags().stream().collect(Collectors.groupingBy(MarkerTag::getGroupName)));
BrandkbsBasicInfo brandkbsBasicInfo = new BrandkbsBasicInfo(project.getProjectName(), project.getId(), project.getBrandName(), project.getId());
jsonObject.put("brandkbsBasicInfo", brandkbsBasicInfo);
result.add(jsonObject);
tagsMap.putAll(project.getHitTags().stream().collect(Collectors.groupingBy(MarkerTag::getGroupName)));
}
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()) {
if (Objects.equals(contend.getBrandLinkedGroupId(), linkedGroupId) && !Tools.isEmpty(contend.getHitTags())) {
if (Objects.equals(contend.getBrandLinkedGroupId(), linkedGroupId)) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("tags", contend.getHitTags().stream().collect(Collectors.groupingBy(MarkerTag::getGroupName)));
if (!Tools.isEmpty(contend.getHitTags())) {
tagsMap.putAll(contend.getHitTags().stream().collect(Collectors.groupingBy(MarkerTag::getGroupName)));
}
if (contend.isHasEmotion()){
tagsMap.putAll(emotionMarkerTags);
}
jsonObject.put("tags", tagsMap);
BrandkbsBasicInfo brandkbsBasicInfo = new BrandkbsBasicInfo(project.getProjectName(), project.getId(), contend.getBrandName(), contend.getId());
jsonObject.put("brandkbsBasicInfo", brandkbsBasicInfo);
result.add(jsonObject);
......
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