Commit 4cad3cf3 by shenjunjie

2022/9/19 15:08

parent 2191b070
package com.zhiwei.brandkbs2.auth; package com.zhiwei.brandkbs2.auth;
import com.zhiwei.brandkbs2.enmus.response.LoginCodeEnum;
import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.pojo.UserInfo; import com.zhiwei.brandkbs2.pojo.UserInfo;
import java.util.Map; import java.util.Map;
...@@ -18,18 +20,22 @@ public class UserThreadLocal { ...@@ -18,18 +20,22 @@ public class UserThreadLocal {
} }
public static String getNickname() { public static String getNickname() {
checkExist();
return TOKEN_USER_INFO.get().getNickname(); return TOKEN_USER_INFO.get().getNickname();
} }
public static String getUserId() { public static String getUserId() {
checkExist();
return TOKEN_USER_INFO.get().getUserId(); return TOKEN_USER_INFO.get().getUserId();
} }
public static String getProjectId() { public static String getProjectId() {
checkExist();
return TOKEN_USER_INFO.get().getProjectId(); return TOKEN_USER_INFO.get().getProjectId();
} }
public static int getRoleId() { public static int getRoleId() {
checkExist();
return TOKEN_USER_INFO.get().getRoleId(); return TOKEN_USER_INFO.get().getRoleId();
} }
...@@ -41,4 +47,10 @@ public class UserThreadLocal { ...@@ -41,4 +47,10 @@ public class UserThreadLocal {
TOKEN_USER_INFO.remove(); TOKEN_USER_INFO.remove();
} }
private static void checkExist() {
if (null == TOKEN_USER_INFO.get()) {
ExceptionCast.cast(LoginCodeEnum.LOGIN_EXPIRED_ERROR);
}
}
} }
package com.zhiwei.brandkbs2.common; package com.zhiwei.brandkbs2.common;
import com.zhiwei.brandkbs2.pojo.ChannelTag; import com.zhiwei.brandkbs2.pojo.ChannelTag;
import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.service.SystemInfoService; import com.zhiwei.brandkbs2.service.SystemInfoService;
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;
...@@ -48,6 +49,8 @@ public class GlobalPojo { ...@@ -48,6 +49,8 @@ public class GlobalPojo {
*/ */
public static Map<String, Map<String, String>> MEDIA_TYPE; public static Map<String, Map<String, String>> MEDIA_TYPE;
public static Map<String, Project> PROJECT_MAP;
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 = "其他自媒体";
...@@ -76,7 +79,9 @@ public class GlobalPojo { ...@@ -76,7 +79,9 @@ public class GlobalPojo {
TAGS = systemInfoService.getTags().stream().collect(Collectors.groupingBy(Tag::getGroupName)); TAGS = systemInfoService.getTags().stream().collect(Collectors.groupingBy(Tag::getGroupName));
CHANNEL_TAGS = systemInfoService.getChannelTags().stream().collect(Collectors.toMap(ChannelTag::getChannel, ChannelTag::getTag)); CHANNEL_TAGS = systemInfoService.getChannelTags().stream().collect(Collectors.toMap(ChannelTag::getChannel, ChannelTag::getTag));
MEDIA_TYPE = systemInfoService.getMediaTypes(); MEDIA_TYPE = systemInfoService.getMediaTypes();
log.info("{}-获取PLATFORMS-size:{},TAGS-size:{},CHANNEL_TAGS:{}", logMsg, PLATFORMS.size(), TAGS.size(), CHANNEL_TAGS.size()); PROJECT_MAP = systemInfoService.getProjects();
log.info("{}-获取PLATFORMS-size:{},TAGS-size:{},CHANNEL_TAGS:{},MEDIA_TYPE:{},PROJECT_MAP:{}", logMsg, PLATFORMS.size(), TAGS.size(),
CHANNEL_TAGS.size(), MEDIA_TYPE.size(), PROJECT_MAP.size());
} }
public static String getPlatformIdByName(String platformName) { public static String getPlatformIdByName(String platformName) {
......
...@@ -10,6 +10,7 @@ import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO; ...@@ -10,6 +10,7 @@ import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO; import com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.elasticsearch.index.query.BoolQueryBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
...@@ -308,4 +309,5 @@ public interface MarkDataService { ...@@ -308,4 +309,5 @@ public interface MarkDataService {
JSONObject getLastMarkData(String projectId, String linkedGroupId, String contendId, String platform, String realSource, String source); JSONObject getLastMarkData(String projectId, String linkedGroupId, String contendId, String platform, String realSource, String source);
BoolQueryBuilder projectLinkedGroupContendIdQuery(String projectId, String linkedGroupId, String contendId);
} }
...@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.service; ...@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.service;
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.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;
...@@ -39,8 +40,11 @@ public interface SystemInfoService { ...@@ -39,8 +40,11 @@ public interface SystemInfoService {
Map<String, Map<String, String>> getMediaTypes(); Map<String, Map<String, String>> getMediaTypes();
Map<String, Project> getProjects();
/** /**
* 从舆情系统 获取舆情查询额外参数 * 从舆情系统 获取舆情查询额外参数
*
* @return JSONObject * @return JSONObject
*/ */
JSONObject getExtraParam(); JSONObject getExtraParam();
......
...@@ -1220,7 +1220,8 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -1220,7 +1220,8 @@ public class ChannelServiceImpl implements ChannelService {
} }
private Long markCountByEmotion(Channel channel, String emotion) throws IOException { private Long markCountByEmotion(Channel channel, String emotion) throws IOException {
BoolQueryBuilder postFilter = MarkDataServiceImpl.projectLinkedGroupContendIdQuery(channel.getProjectId(), channel.getLinkedGroupId(), channel.getContendId()); BoolQueryBuilder postFilter = markDataService.projectLinkedGroupContendIdQuery(channel.getProjectId(), channel.getLinkedGroupId(),
channel.getContendId());
postFilter.must(QueryBuilders.termQuery("brandkbs_mark_cache_maps.name.keyword", emotion)); postFilter.must(QueryBuilders.termQuery("brandkbs_mark_cache_maps.name.keyword", emotion));
return esClientDao.count(postFilter); return esClientDao.count(postFilter);
} }
......
...@@ -1852,7 +1852,10 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1852,7 +1852,10 @@ public class MarkDataServiceImpl implements MarkDataService {
return textList; return textList;
} }
protected static BoolQueryBuilder projectLinkedGroupContendIdQuery(String projectId, String linkedGroupId, String contendId) { public BoolQueryBuilder projectLinkedGroupContendIdQuery(String projectId, String linkedGroupId, String contendId) {
if (null == linkedGroupId) {
linkedGroupId = projectService.getProjectByContendId(projectId, contendId).getBrandLinkedGroupId();
}
return EsQueryTools.assembleCacheMapsQuery(projectId, linkedGroupId, contendId); return EsQueryTools.assembleCacheMapsQuery(projectId, linkedGroupId, contendId);
} }
......
...@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.service.impl; ...@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.auth.UserThreadLocal; import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.dao.ProjectDao; import com.zhiwei.brandkbs2.dao.ProjectDao;
import com.zhiwei.brandkbs2.dao.UserDao; import com.zhiwei.brandkbs2.dao.UserDao;
import com.zhiwei.brandkbs2.enmus.response.ProjectCodeEnum; import com.zhiwei.brandkbs2.enmus.response.ProjectCodeEnum;
...@@ -228,7 +229,8 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -228,7 +229,8 @@ public class ProjectServiceImpl implements ProjectService {
@Override @Override
public AbstractProject getProjectByContendId(String projectId, String contendId) { public AbstractProject getProjectByContendId(String projectId, String contendId) {
Project project = projectDao.findOneById(projectId); GlobalPojo.PROJECT_MAP.get(projectId)
// Project project = projectDao.findOneById(projectId);
if ("0".equals(contendId)) { if ("0".equals(contendId)) {
return project; return project;
} }
......
...@@ -2,11 +2,14 @@ package com.zhiwei.brandkbs2.service.impl; ...@@ -2,11 +2,14 @@ package com.zhiwei.brandkbs2.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.zhiwei.brandkbs2.dao.ChannelTagDao; import com.zhiwei.brandkbs2.dao.ChannelTagDao;
import com.zhiwei.brandkbs2.dao.MediaTypeDao; import com.zhiwei.brandkbs2.dao.MediaTypeDao;
import com.zhiwei.brandkbs2.dao.ProjectDao;
import com.zhiwei.brandkbs2.dao.QbjcPojoDao; import com.zhiwei.brandkbs2.dao.QbjcPojoDao;
import com.zhiwei.brandkbs2.pojo.ChannelTag; import com.zhiwei.brandkbs2.pojo.ChannelTag;
import com.zhiwei.brandkbs2.pojo.MediaType; import com.zhiwei.brandkbs2.pojo.MediaType;
import com.zhiwei.brandkbs2.pojo.Project;
import com.zhiwei.brandkbs2.service.SystemInfoService; import com.zhiwei.brandkbs2.service.SystemInfoService;
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;
...@@ -40,6 +43,9 @@ public class SystemInfoServiceImpl implements SystemInfoService { ...@@ -40,6 +43,9 @@ public class SystemInfoServiceImpl implements SystemInfoService {
@Resource @Resource
private MediaTypeDao mediaTypeDao; private MediaTypeDao mediaTypeDao;
@Resource
private ProjectDao projectDao;
@Autowired @Autowired
private RestTemplate restTemplate; private RestTemplate restTemplate;
...@@ -73,6 +79,11 @@ public class SystemInfoServiceImpl implements SystemInfoService { ...@@ -73,6 +79,11 @@ public class SystemInfoServiceImpl implements SystemInfoService {
} }
@Override @Override
public Map<String, Project> getProjects() {
return Maps.uniqueIndex(projectDao.findList(null), Project::getId);
}
@Override
public JSONObject getExtraParam() { public JSONObject getExtraParam() {
ResponseEntity<String> forEntity = restTemplate.getForEntity(YU_QING_EXTRA_PARAM, String.class); ResponseEntity<String> forEntity = restTemplate.getForEntity(YU_QING_EXTRA_PARAM, String.class);
JSONObject jsonObject = JSON.parseObject(forEntity.getBody()); JSONObject jsonObject = JSON.parseObject(forEntity.getBody());
......
...@@ -282,11 +282,11 @@ public class UserServiceImpl implements UserService { ...@@ -282,11 +282,11 @@ public class UserServiceImpl implements UserService {
@Override @Override
public Map<String, Object> getLoginInfo() { public Map<String, Object> getLoginInfo() {
String userId = UserThreadLocal.getUserId(); // String userId = UserThreadLocal.getUserId();
String projectId = UserThreadLocal.getProjectId(); // String projectId = UserThreadLocal.getProjectId();
if (null == userId || null == projectId) { // if (null == userId || null == projectId) {
ExceptionCast.cast(LoginCodeEnum.LOGIN_EXPIRED_ERROR); // ExceptionCast.cast(LoginCodeEnum.LOGIN_EXPIRED_ERROR);
} // }
return queryUserInfo(UserThreadLocal.getUserId(), UserThreadLocal.getProjectId()).toMap(); return queryUserInfo(UserThreadLocal.getUserId(), UserThreadLocal.getProjectId()).toMap();
} }
......
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