Commit eed08ef5 by shenjunjie

2022/7/21 14:07

parent a78a5d28
...@@ -6,6 +6,7 @@ import com.zhiwei.brandkbs2.model.CommonCodeEnum; ...@@ -6,6 +6,7 @@ import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.UserInfo; import com.zhiwei.brandkbs2.pojo.UserInfo;
import com.zhiwei.brandkbs2.service.UserService; import com.zhiwei.brandkbs2.service.UserService;
import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.middleware.auth.util.JwtUtil; import com.zhiwei.middleware.auth.util.JwtUtil;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature; import org.aspectj.lang.Signature;
...@@ -25,7 +26,6 @@ import java.io.PrintWriter; ...@@ -25,7 +26,6 @@ import java.io.PrintWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* @author sjj * @author sjj
...@@ -53,22 +53,24 @@ public class AuthAspect { ...@@ -53,22 +53,24 @@ public class AuthAspect {
ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()); ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
HttpServletRequest request = servletRequestAttributes.getRequest(); HttpServletRequest request = servletRequestAttributes.getRequest();
String token = request.getHeader(jwtKey); String token = request.getHeader(jwtKey);
// 不存在token // 存在有效token
if (null == token || Objects.equals("undefined", token)) { if (null != token && !Tools.tokenEmpty(token)) {
return joinPoint.proceed();
}else {
Map<String, Object> tokenInfo = JwtUtil.unsign(token, Map.class); Map<String, Object> tokenInfo = JwtUtil.unsign(token, Map.class);
String uid = tokenInfo.get(GenericAttribute.USER_ID).toString(); String uid = tokenInfo.get(GenericAttribute.USER_ID).toString();
UserInfo userInfo = UserService.queryUserInfo(uid, request.getHeader("pid")); UserInfo userInfo = UserService.queryUserInfo(uid, request.getHeader("pid"));
if (null == userInfo) {
userInfo = new UserInfo().setUserId(uid).setProjectId(request.getHeader("pid"));
}
UserThreadLocal.set(userInfo); UserThreadLocal.set(userInfo);
// todo 操作记录收集
Object proceed = joinPoint.proceed(); Object proceed = joinPoint.proceed();
UserThreadLocal.clear(); UserThreadLocal.clear();
// todo 操作记录收集
return proceed; return proceed;
} }
return joinPoint.proceed();
} }
// @Around("auth()") // @Around("auth()")
public Object aroundCheckToken(ProceedingJoinPoint joinPoint) throws Throwable { public Object aroundCheckToken(ProceedingJoinPoint joinPoint) throws Throwable {
Signature signature = joinPoint.getSignature(); Signature signature = joinPoint.getSignature();
Method method = ((MethodSignature) signature).getMethod(); Method method = ((MethodSignature) signature).getMethod();
......
...@@ -27,14 +27,15 @@ public class GenericAttribute { ...@@ -27,14 +27,15 @@ public class GenericAttribute {
/** /**
* es followers_num * es followers_num
*/ */
public static final String ES_FOLLOWERS_NUM = "followers_num"; public static final String ES_FOLLOWERS_NUM = "channel_followers_num";
/** /**
* es media_type * es media_type
*/ */
public static final String ES_MEDIA_TYPE = "media_type"; public static final String ES_MEDIA_TYPE = "media_type";
// ss platform_id // es platform_id
// TODO 待修改为 platform_id public static final String ES_PLATFORM_ID= "platform_id";
public static final String ES_PLATFORM_ID= "platformId"; // es channel_influence
public static final String ES_CHANNEL_INDEX = "channel_influence";
/** /**
* es rootSource * es rootSource
**/ **/
...@@ -71,12 +72,12 @@ public class GenericAttribute { ...@@ -71,12 +72,12 @@ public class GenericAttribute {
/** es brandkbs_cache_maps **/ /** es brandkbs_cache_maps **/
public static final String ES_BRANDKBS_CACHE_MAPS = "brandkbs_cache_maps"; public static final String ES_BRANDKBS_CACHE_MAPS = "brandkbs_cache_maps";
/** es mark_cache_maps **/ /** es mark_cache_maps **/
public static final String ES_MARK_CACHE_MAPS = "mark_cache_maps"; public static final String ES_MARK_CACHE_MAPS = "brandkbs_mark_cache_maps";
public static final String LINKED_GROUP_ID = "linkedGroupId"; public static final String LINKED_GROUP_ID = "linkedGroupId";
// public static final String ES_CACHE_MAP_PROJECT = "brandkbs_cache_maps.projectId.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.linkedGroupId.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";
/** /**
......
...@@ -63,4 +63,13 @@ public class GlobalPojo { ...@@ -63,4 +63,13 @@ public class GlobalPojo {
log.info("{}-获取PLATFORMS-size:{},TAGS-size:{}", logMsg, PLATFORMS.size(), TAGS.size()); log.info("{}-获取PLATFORMS-size:{},TAGS-size:{}", logMsg, PLATFORMS.size(), TAGS.size());
} }
public static String getPlatformIdByName(String platformName){
for (MessagePlatform platform : PLATFORMS) {
if(platform.getName().equals(platformName)){
return platform.getId();
}
}
return null;
}
} }
...@@ -159,7 +159,7 @@ public class EventController extends BaseController { ...@@ -159,7 +159,7 @@ public class EventController extends BaseController {
} }
@ApiOperation("获取舆情事件导入进度") @ApiOperation("获取舆情事件导入进度")
@GetMapping("/yq/upload/progress/{linkedGroupId}") @GetMapping("/yq/upload/schedule/{linkedGroupId}")
public ResponseResult getYqEventsProgress(@PathVariable("linkedGroupId") String linkedGroupId) { public ResponseResult getYqEventsProgress(@PathVariable("linkedGroupId") String linkedGroupId) {
String progressKey = RedisKeyPrefix.yuqingProgressKey(linkedGroupId); String progressKey = RedisKeyPrefix.yuqingProgressKey(linkedGroupId);
Set<String> keys = stringRedisTemplate.keys(progressKey); Set<String> keys = stringRedisTemplate.keys(progressKey);
...@@ -170,14 +170,14 @@ public class EventController extends BaseController { ...@@ -170,14 +170,14 @@ public class EventController extends BaseController {
} }
@ApiOperation("事件上传进度获取") @ApiOperation("事件上传进度获取")
@GetMapping("data/upload/progress/{ticket}") @GetMapping("data/upload/schedule/{ticket}")
public ResponseResult getEventDataUploadProgress(@PathVariable String ticket) { public ResponseResult getEventDataUploadProgress(@PathVariable String ticket) {
return ResponseResult.success(eventService.getEventDataUploadProgress(ticket)); return ResponseResult.success(eventService.getEventDataUploadProgress(ticket));
} }
@ApiOperation("事件数据上传进度获取") @ApiOperation("事件数据上传进度获取")
@ApiImplicitParams(@ApiImplicitParam(name = "eventIds", value = "事件id列表", paramType = "body", dataType = "list")) @ApiImplicitParams(@ApiImplicitParam(name = "eventIds", value = "事件id列表", paramType = "body", dataType = "list"))
@PostMapping("analyze/progress") @PostMapping("analyze/schedule")
public ResponseResult getEventAnalyzeProgress(@RequestBody JSONObject info) { public ResponseResult getEventAnalyzeProgress(@RequestBody JSONObject info) {
return ResponseResult.success(eventService.getEventAnalyzeProgress(info.getJSONArray("eventIds").toJavaList(String.class))); return ResponseResult.success(eventService.getEventAnalyzeProgress(info.getJSONArray("eventIds").toJavaList(String.class)));
} }
......
package com.zhiwei.brandkbs2.controller.app; package com.zhiwei.brandkbs2.controller.app;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.auth.Auth; import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.controller.BaseController; import com.zhiwei.brandkbs2.controller.BaseController;
import com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil; import com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil;
...@@ -51,12 +52,14 @@ public class AppArticleController extends BaseController { ...@@ -51,12 +52,14 @@ public class AppArticleController extends BaseController {
@ApiOperation("舆情列表-生成聚合") @ApiOperation("舆情列表-生成聚合")
@PostMapping("/mark/aggree") @PostMapping("/mark/aggree")
public ResponseResult generateYuqingMarkAggreeList(@RequestBody MarkSearchDTO markSearchDTO) { public ResponseResult generateYuqingMarkAggreeList(@RequestBody JSONObject info) {
return ResponseResult.success(markDataService.generateYuqingMarkAggreeList(markSearchDTO)); Long startTime = info.getLong("startTime");
Long endTime = info.getLong("endTime");
return ResponseResult.success(markDataService.generateYuqingMarkAggreeList(startTime, endTime));
} }
@ApiOperation("舆情列表-聚合进度查询") @ApiOperation("舆情列表-聚合进度查询")
@GetMapping("/mark/aggree/progress/{aggreeId}") @GetMapping("/mark/aggree/schedule/{aggreeId}")
public ResponseResult getYuqingMarkAggreeProgress(@PathVariable String aggreeId) { public ResponseResult getYuqingMarkAggreeProgress(@PathVariable String aggreeId) {
return ResponseResult.success(markDataService.getYuqingMarkAggreeProgress(aggreeId)); return ResponseResult.success(markDataService.getYuqingMarkAggreeProgress(aggreeId));
} }
......
package com.zhiwei.brandkbs2.controller.app;
import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.controller.BaseController;
import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.service.ChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @ClassName: AppChannelController
* @Description 前台渠道信息展示
* @author: sjj
* @date: 2022-07-19 16:05
*/
@RestController
@RequestMapping("/app/channel")
@Api(tags = "前台渠道展示接口", description = "提供前台渠道相关信息展示")
@Auth(role = RoleEnum.CUSTOMER)
public class AppChannelController extends BaseController {
@Resource(name = "channelServiceImpl")
ChannelService channelService;
@ApiImplicitParams({@ApiImplicitParam(name = "linkedGroupId", value = "关联项目组id", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "platform", value = "平台", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "keyword", value = "关键字搜索", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "startTime", value = "起始时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "size", value = "选取前几", defaultValue = "50", paramType = "query", dataType = "int"),
})
@ApiOperation("渠道库-活跃渠道榜")
@GetMapping("/list/active")
public ResponseResult getActiveChannelList(@RequestParam(value = "linkedGroupId", required = false) String linkedGroupId,
@RequestParam(value = "platform", required = false) String platform,
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime,
@RequestParam(value = "size", defaultValue = "50") int size) {
return ResponseResult.success(channelService.getActiveChannelList(linkedGroupId, platform, keyword, startTime, endTime, size));
}
}
...@@ -24,6 +24,6 @@ public class ChannelTagDaoImpl extends BaseMongoDaoImpl<ChannelTag> implements C ...@@ -24,6 +24,6 @@ public class ChannelTagDaoImpl extends BaseMongoDaoImpl<ChannelTag> implements C
if (null == channelTag) { if (null == channelTag) {
return null; return null;
} }
return channelTag.getTag(); return channelTag.getTag().replaceAll(",", "|");
} }
} }
package com.zhiwei.brandkbs2.dao.impl; package com.zhiwei.brandkbs2.dao.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.dao.ReportDao; import com.zhiwei.brandkbs2.dao.ReportDao;
import com.zhiwei.brandkbs2.pojo.Report; import com.zhiwei.brandkbs2.pojo.Report;
import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.Aggregation;
...@@ -27,7 +28,9 @@ public class ReportDaoImpl extends BaseMongoDaoImpl<Report> implements ReportDao ...@@ -27,7 +28,9 @@ public class ReportDaoImpl extends BaseMongoDaoImpl<Report> implements ReportDao
@Override @Override
public List<JSONObject> getReportAggCount(String projectId) { public List<JSONObject> getReportAggCount(String projectId) {
// 添加渠道唯一标识 // 添加渠道唯一标识
Criteria criteria = Criteria.where("projectId").is(projectId).and("status").is(true); Criteria criteria = Criteria.where("projectId").is(projectId);
// personal简报
criteria.orOperator(Criteria.where("userId").exists(false), Criteria.where("userId").is(UserThreadLocal.getUserId()));
// 分组 // 分组
Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(criteria),
// //
......
...@@ -8,8 +8,9 @@ import com.alibaba.excel.read.metadata.ReadSheet; ...@@ -8,8 +8,9 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO; import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO;
import com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO; import com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -23,8 +24,8 @@ import java.util.List; ...@@ -23,8 +24,8 @@ import java.util.List;
* @description easyExcel解析工具类 * @description easyExcel解析工具类
* @date 2022年4月20日09:34:12 * @date 2022年4月20日09:34:12
*/ */
@Slf4j
public class EasyExcelUtil { public class EasyExcelUtil {
private static final Logger log = LogManager.getLogger(EasyExcelUtil.class);
private EasyExcelUtil() { private EasyExcelUtil() {
} }
......
...@@ -5,9 +5,12 @@ import com.alibaba.excel.event.AnalysisEventListener; ...@@ -5,9 +5,12 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.zhiwei.brandkbs2.dao.EventDao; import com.zhiwei.brandkbs2.dao.EventDao;
import com.zhiwei.brandkbs2.dao.EventDataDao; import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDataDTO; import com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDataDTO;
import com.zhiwei.brandkbs2.listener.ApplicationProjectListener;
import com.zhiwei.brandkbs2.pojo.Event; import com.zhiwei.brandkbs2.pojo.Event;
import com.zhiwei.brandkbs2.pojo.EventData; import com.zhiwei.brandkbs2.pojo.EventData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
/** /**
...@@ -16,9 +19,8 @@ import org.springframework.data.redis.core.StringRedisTemplate; ...@@ -16,9 +19,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
* @author: sjj * @author: sjj
* @date: 2022-05-23 13:54 * @date: 2022-05-23 13:54
*/ */
@Slf4j
public class EventDataListener extends AnalysisEventListener<UploadEventDataDTO> { public class EventDataListener extends AnalysisEventListener<UploadEventDataDTO> {
private static final Logger log = LogManager.getLogger(EventDataListener.class);
private final EventDao eventDao; private final EventDao eventDao;
private final EventDataDao eventDataDao; private final EventDataDao eventDataDao;
......
...@@ -5,6 +5,8 @@ import com.alibaba.excel.event.AnalysisEventListener; ...@@ -5,6 +5,8 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDTO; import com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDTO;
import com.zhiwei.brandkbs2.service.EventService; import com.zhiwei.brandkbs2.service.EventService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -15,8 +17,8 @@ import java.util.List; ...@@ -15,8 +17,8 @@ import java.util.List;
* @description 解析事件文件监听器 * @description 解析事件文件监听器
* @date 2019/11/12 9:00 * @date 2019/11/12 9:00
*/ */
@Slf4j
public class EventFileListener extends AnalysisEventListener<UploadEventDTO> { public class EventFileListener extends AnalysisEventListener<UploadEventDTO> {
private static final Logger log = LogManager.getLogger(EventFileListener.class);
/** /**
* 每隔5条执行保存更新事件信息,然后清理list,方便内存回收 * 每隔5条执行保存更新事件信息,然后清理list,方便内存回收
*/ */
......
...@@ -33,6 +33,13 @@ public enum ChannelEmotion { ...@@ -33,6 +33,13 @@ public enum ChannelEmotion {
this.name = name; this.name = name;
} }
public static String getNameFromState(Object state) {
if (state instanceof Integer) {
return getFromState((int) state).getName();
}
return null;
}
public static ChannelEmotion getFromState(int state) { public static ChannelEmotion getFromState(int state) {
for (ChannelEmotion value : ChannelEmotion.values()) { for (ChannelEmotion value : ChannelEmotion.values()) {
if (value.state == state) { if (value.state == state) {
......
package com.zhiwei.brandkbs2.exception; package com.zhiwei.brandkbs2.exception;
import com.google.common.collect.ImmutableMap;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.model.ResultCode; import com.zhiwei.brandkbs2.model.ResultCode;
import lombok.extern.slf4j.Slf4j; import org.apache.logging.log4j.LogManager;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.Collections; import java.util.Collections;
import java.util.Objects;
/** /**
* 控制器增强 * 控制器增强
...@@ -21,13 +19,8 @@ import java.util.Objects; ...@@ -21,13 +19,8 @@ import java.util.Objects;
* @date 2022年4月21日15:00:40 * @date 2022年4月21日15:00:40
*/ */
@RestControllerAdvice @RestControllerAdvice
@Slf4j
public class ExceptionCatch { public class ExceptionCatch {
private static final Logger log = LogManager.getLogger(ExceptionCatch.class);
/**
* 定义map,配置异常类型所对应的错误代码
*/
private static final ImmutableMap<Class<? extends Throwable>, ResultCode> EXCEPTIONS;
/** /**
* 捕获CustomException此类异常 * 捕获CustomException此类异常
...@@ -58,21 +51,8 @@ public class ExceptionCatch { ...@@ -58,21 +51,8 @@ public class ExceptionCatch {
public ResponseResult exception(Exception exception) { public ResponseResult exception(Exception exception) {
//记录日志 //记录日志
log.error("catch exception:", exception); log.error("catch exception:", exception);
//从EXCEPTIONS中找异常类型所对应的错误代码 //返回400操作失败
ResultCode resultCode = EXCEPTIONS.get(exception.getClass()); return new ResponseResult(CommonCodeEnum.FAIL, Collections.EMPTY_LIST);
if (Objects.nonNull(resultCode)) {
return new ResponseResult(resultCode, Collections.EMPTY_LIST);
} else {
//返回500系统繁忙异常
return new ResponseResult(CommonCodeEnum.SERVER_ERROR, Collections.EMPTY_LIST);
}
} }
static {
//定义异常类型所对应的错误代码
ImmutableMap.Builder<Class<? extends Throwable>, ResultCode> builder = ImmutableMap.builder();
builder.put(HttpMessageNotReadableException.class, CommonCodeEnum.INVALID_PARAM);
builder.put(NullPointerException.class, CommonCodeEnum.NULL_POINTER_EXCEPTION);
EXCEPTIONS = builder.build();
}
} }
package com.zhiwei.brandkbs2.interceptor; package com.zhiwei.brandkbs2.interceptor;
import com.zhiwei.brandkbs2.auth.Auth; import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.GenericAttribute; import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
...@@ -18,7 +17,6 @@ import org.springframework.web.servlet.HandlerInterceptor; ...@@ -18,7 +17,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
...@@ -54,7 +52,7 @@ public class MainAuthInterceptor implements HandlerInterceptor { ...@@ -54,7 +52,7 @@ public class MainAuthInterceptor implements HandlerInterceptor {
String token = request.getHeader("Token"); String token = request.getHeader("Token");
try { try {
// 不存在token 重新获取token // 不存在token 重新获取token
if (null == token || Objects.equals("undefined", token)) { if (Tools.tokenEmpty(token)) {
Tools.responseMessage(response, HttpServletResponse.SC_UNAUTHORIZED, new ResponseResult(CommonCodeEnum.UNAUTHENTICATED, null)); Tools.responseMessage(response, HttpServletResponse.SC_UNAUTHORIZED, new ResponseResult(CommonCodeEnum.UNAUTHENTICATED, null));
return false; return false;
} }
...@@ -73,7 +71,7 @@ public class MainAuthInterceptor implements HandlerInterceptor { ...@@ -73,7 +71,7 @@ public class MainAuthInterceptor implements HandlerInterceptor {
} }
// 权限不足 // 权限不足
if (userInfo.getRoleId() > auth.role().getState()) { if (userInfo.getRoleId() > auth.role().getState()) {
Tools.responseMessage(response, HttpServletResponse.SC_FORBIDDEN, new ResponseResult(CommonCodeEnum.UN_AUTHORISE, null)); Tools.responseMessage(response, HttpServletResponse.SC_FORBIDDEN, new ResponseResult(CommonCodeEnum.UN_AUTHORISE));
return false; return false;
} }
return true; return true;
...@@ -83,4 +81,59 @@ public class MainAuthInterceptor implements HandlerInterceptor { ...@@ -83,4 +81,59 @@ public class MainAuthInterceptor implements HandlerInterceptor {
} }
} }
// @Override
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// Auth auth = null;
// if (handler instanceof HandlerMethod) {
// HandlerMethod method = (HandlerMethod) handler;
// auth = method.getMethodAnnotation(Auth.class);
// if (null == auth) {
// auth = method.getMethod().getDeclaringClass().getAnnotation(Auth.class);
// }
// }
// String token = request.getHeader("Token");
// try {
// // 不需要验证权限
// boolean noAuth = null == auth;
// // 不存在token
// if (Tools.tokenEmpty(token)) {
// return unAuthenticatedResponse(noAuth, response);
// }
// Map<String, Object> tokenInfo = JwtUtil.unsign(token, Map.class);
// // 解析失败
// if (null == tokenInfo) {
// return unAuthenticatedResponse(noAuth, response);
// }
// String uid = tokenInfo.get(GenericAttribute.USER_ID).toString();
// UserInfo userInfo = UserService.queryUserInfo(uid, request.getHeader("pid"));
// // 需要权限且查询用户信息失败
// if (!noAuth && null == userInfo) {
// return unAuthenticatedResponse(false, response);
// }
// // 不需要权限或权限足够
// if (noAuth || (userInfo.getRoleId() <= auth.role().getState())) {
// if (null == userInfo) {
// // 缓存请求提供的用户信息
// userInfo = new UserInfo().setUserId(uid).setProjectId(request.getHeader("pid"));
// }
// UserThreadLocal.set(userInfo);
// return true;
// } else {
// Tools.responseMessage(response, HttpServletResponse.SC_FORBIDDEN, new ResponseResult(CommonCodeEnum.UN_AUTHORISE));
// }
// } catch (Exception e) {
// log.error("拦截鉴权出错;token:{}", token, e);
//
// }
// return false;
// }
//
// private boolean unAuthenticatedResponse(boolean noAuth, HttpServletResponse response) throws Exception {
// if (noAuth) {
// return true;
// }
// Tools.responseMessage(response, HttpServletResponse.SC_UNAUTHORIZED, new ResponseResult(CommonCodeEnum.UNAUTHENTICATED));
// return false;
// }
} }
package com.zhiwei.brandkbs2.listener; package com.zhiwei.brandkbs2.listener;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.*; import java.util.concurrent.*;
...@@ -12,8 +15,8 @@ import java.util.concurrent.*; ...@@ -12,8 +15,8 @@ import java.util.concurrent.*;
* @date 2019/9/2 14:00 * @date 2019/9/2 14:00
*/ */
@Component @Component
@Slf4j
public class ApplicationProjectListener { public class ApplicationProjectListener {
private static final Logger log = LogManager.getLogger(ApplicationProjectListener.class);
private static final int CORE_POOL_SIZE = 50; private static final int CORE_POOL_SIZE = 50;
private static final int MAX_POOL_SIZE = 200; private static final int MAX_POOL_SIZE = 200;
private static final int QUEUE_SIZE = 128; private static final int QUEUE_SIZE = 128;
......
...@@ -51,6 +51,10 @@ public class ResponseResult { ...@@ -51,6 +51,10 @@ public class ResponseResult {
@ApiModelProperty("返回数据") @ApiModelProperty("返回数据")
private Object data; private Object data;
public ResponseResult(ResultCode resultCode) {
this(resultCode, Collections.EMPTY_LIST);
}
public ResponseResult(ResultCode resultCode, Object data) { public ResponseResult(ResultCode resultCode, Object data) {
this.success = resultCode.success(); this.success = resultCode.success();
this.code = resultCode.code(); this.code = resultCode.code();
......
...@@ -22,6 +22,11 @@ import java.util.List; ...@@ -22,6 +22,11 @@ import java.util.List;
public class AggreeResult extends AbstractBaseMongo { public class AggreeResult extends AbstractBaseMongo {
/** /**
* 需要移除的属性
*/
private static final List<String> EXCLUDE_FIELD = Arrays.asList("mark_cache_maps", "brandkbs_cache_maps");
/**
* 任务id * 任务id
*/ */
private String taskId; private String taskId;
...@@ -96,7 +101,6 @@ public class AggreeResult extends AbstractBaseMongo { ...@@ -96,7 +101,6 @@ public class AggreeResult extends AbstractBaseMongo {
private static AggreeResult getInstance(JSONObject json, String taskId) { private static AggreeResult getInstance(JSONObject json, String taskId) {
AggreeResult aggreeResult = new AggreeResult(); AggreeResult aggreeResult = new AggreeResult();
aggreeResult.setTaskId(taskId); aggreeResult.setTaskId(taskId);
aggreeResult.setData(json);
BaseMap baseMap = Tools.getBaseFromEsMap(json); BaseMap baseMap = Tools.getBaseFromEsMap(json);
aggreeResult.setTime(baseMap.getTime()); aggreeResult.setTime(baseMap.getTime());
aggreeResult.setPlatformId(json.getString(GenericAttribute.ES_PLATFORM_ID)); aggreeResult.setPlatformId(json.getString(GenericAttribute.ES_PLATFORM_ID));
...@@ -106,6 +110,7 @@ public class AggreeResult extends AbstractBaseMongo { ...@@ -106,6 +110,7 @@ public class AggreeResult extends AbstractBaseMongo {
} }
aggreeResult.setTags(parseMatg(json.getString(GenericAttribute.ES_MTAG))); aggreeResult.setTags(parseMatg(json.getString(GenericAttribute.ES_MTAG)));
aggreeResult.setAggreeTitle(baseMap.getTitleNullOptionalContent()); aggreeResult.setAggreeTitle(baseMap.getTitleNullOptionalContent());
aggreeResult.setData(removeExclude(json));
return aggreeResult; return aggreeResult;
} }
...@@ -121,4 +126,11 @@ public class AggreeResult extends AbstractBaseMongo { ...@@ -121,4 +126,11 @@ public class AggreeResult extends AbstractBaseMongo {
return resList; return resList;
} }
private static JSONObject removeExclude(JSONObject json) {
for (String exclude : EXCLUDE_FIELD) {
json.remove(exclude);
}
return json;
}
} }
...@@ -51,12 +51,11 @@ public class Report extends AbstractBaseMongo { ...@@ -51,12 +51,11 @@ public class Report extends AbstractBaseMongo {
/** /**
* 竞品信息字符串 * 竞品信息字符串
*/ */
@Deprecated
private List<String> contends; private List<String> contends;
/** /**
* 生成状态 * 可查看的userId
*/ */
private boolean status; private String userId;
public static Report createFromReportDTO(ReportDTO reportDTO) { public static Report createFromReportDTO(ReportDTO reportDTO) {
Report report = new Report(); Report report = new Report();
...@@ -67,6 +66,9 @@ public class Report extends AbstractBaseMongo { ...@@ -67,6 +66,9 @@ public class Report extends AbstractBaseMongo {
report.setType(ReportTypeEnum.CUSTOM.getState()); report.setType(ReportTypeEnum.CUSTOM.getState());
report.setProjectId(UserThreadLocal.getProjectId()); report.setProjectId(UserThreadLocal.getProjectId());
report.setContends(reportDTO.getContends()); report.setContends(reportDTO.getContends());
if (reportDTO.isPersonal()) {
report.setUserId(UserThreadLocal.getUserId());
}
return report; return report;
} }
......
...@@ -19,6 +19,7 @@ public class UserInfo { ...@@ -19,6 +19,7 @@ public class UserInfo {
private String userId; private String userId;
private Integer roleId; private Integer roleId;
private String projectId; private String projectId;
private Integer exportAmount;
private String avatarUrl; private String avatarUrl;
public UserInfo setUserId(String userId){ public UserInfo setUserId(String userId){
...@@ -31,11 +32,6 @@ public class UserInfo { ...@@ -31,11 +32,6 @@ public class UserInfo {
return this; return this;
} }
public UserInfo setAvatarUrl(String avatarUrl){
this.avatarUrl = avatarUrl;
return this;
}
public Map<String, Object> toMap() { public Map<String, Object> toMap() {
Map<String, Object> res = new HashMap<>(); Map<String, Object> res = new HashMap<>();
res.put(GenericAttribute.NICK_NAME, this.nickname); res.put(GenericAttribute.NICK_NAME, this.nickname);
......
package com.zhiwei.brandkbs2.pojo.vo;
import lombok.Data;
import lombok.ToString;
/**
* 渠道榜
*/
@Data
@ToString
public class ChannelListVO {
/**
* 主键
*/
private String id;
/**
* 渠道
*/
private String source;
/**
* 平台
*/
private String platform;
/**
* 二级平台
*/
private String realSource;
/**
* 友好指数
*/
private Double number;
/**
* 发文数
*/
private Integer articleCount;
/**
* 情感倾向
*/
private String emotion;
/**
* logo图片
*/
private String imgUrl;
}
...@@ -4,9 +4,8 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,9 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO;
import com.zhiwei.brandkbs2.pojo.Channel;
import com.zhiwei.brandkbs2.pojo.ChannelIndex;
import com.zhiwei.brandkbs2.pojo.dto.ChannelDTO; import com.zhiwei.brandkbs2.pojo.dto.ChannelDTO;
import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import java.util.List; import java.util.List;
...@@ -114,4 +113,9 @@ public interface ChannelService { ...@@ -114,4 +113,9 @@ public interface ChannelService {
*/ */
List<String> getChannelLabels(String type); List<String> getChannelLabels(String type);
/**
* 获取活跃渠道榜
* @return ChannelListVO
*/
List<ChannelListVO> getActiveChannelList(String linkedGroupId, String platform, String keyword, Long startTime, Long endTime, int size);
} }
...@@ -34,7 +34,7 @@ public interface MarkDataService { ...@@ -34,7 +34,7 @@ public interface MarkDataService {
* *
* @return 聚合id * @return 聚合id
*/ */
String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO); String generateYuqingMarkAggreeList(Long startTime,Long endTime);
/** /**
* 获取聚合进度结果 * 获取聚合进度结果
......
package com.zhiwei.brandkbs2.service.impl; 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.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.dao.*; import com.zhiwei.brandkbs2.dao.*;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO;
...@@ -12,12 +15,19 @@ import com.zhiwei.brandkbs2.exception.ExceptionCast; ...@@ -12,12 +15,19 @@ import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.pojo.*; import com.zhiwei.brandkbs2.pojo.*;
import com.zhiwei.brandkbs2.pojo.dto.ChannelDTO; import com.zhiwei.brandkbs2.pojo.dto.ChannelDTO;
import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.service.ChannelService; import com.zhiwei.brandkbs2.service.ChannelService;
import com.zhiwei.brandkbs2.service.CommonService;
import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.MongoUtil; import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
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.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.springframework.data.mongodb.core.query.Criteria; 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.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
...@@ -55,6 +65,12 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -55,6 +65,12 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "channelTagDao") @Resource(name = "channelTagDao")
ChannelTagDao channelTagDao; ChannelTagDao channelTagDao;
@Resource(name = "projectServiceImpl")
ProjectService projectService;
@Resource(name = "commonServiceImpl")
CommonService commonService;
@Resource(name = "mongoUtil") @Resource(name = "mongoUtil")
MongoUtil mongoUtil; MongoUtil mongoUtil;
...@@ -244,6 +260,42 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -244,6 +260,42 @@ public class ChannelServiceImpl implements ChannelService {
return channelLabelDao.findList(Query.query(Criteria.where("type").is(type))).stream().map(ChannelLabel::getLabel).collect(Collectors.toList()); return channelLabelDao.findList(Query.query(Criteria.where("type").is(type))).stream().map(ChannelLabel::getLabel).collect(Collectors.toList());
} }
@Override
public List<ChannelListVO> getActiveChannelList(String linkedGroupId, String platform, String keyword, Long startTime, Long endTime, int size) {
String projectId = UserThreadLocal.getProjectId();
if (null == linkedGroupId) {
linkedGroupId = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getBrandLinkedGroupId();
}
String platformId = GlobalPojo.getPlatformIdByName(platform);
// 默认搜索一周
if (null == startTime || null == endTime) {
Long[] timeRangeWeek = commonService.getTimeRangeWeek();
startTime = timeRangeWeek[0];
endTime = timeRangeWeek[1];
}
EsClientDao.SearchHelper helper = EsClientDao.createSearchHelper();
// query
BoolQueryBuilder query = MarkDataServiceImpl.projectLinkedGroupQuery(projectId, linkedGroupId);
if (null != platformId) {
query.must(QueryBuilders.termQuery(GenericAttribute.ES_PLATFORM_ID, platformId));
}
// keyword
if (StringUtils.isNotEmpty(keyword)) {
query.must(QueryBuilders.fuzzyQuery("source", keyword));
}
// timeRange
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime));
helper.setQuery(query);
// 聚合查询
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("count").field("mark_cache_maps.name.keyword");
return null;
}
private Query channelListQuery(String linkedGroupId, Boolean show, String emotion, String platform, String keyword, String sorter) { private Query channelListQuery(String linkedGroupId, Boolean show, String emotion, String platform, String keyword, String sorter) {
Query query = new Query(); Query query = new Query();
query.addCriteria(Criteria.where("linkedGroupId").is(linkedGroupId)); query.addCriteria(Criteria.where("linkedGroupId").is(linkedGroupId));
......
...@@ -126,6 +126,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -126,6 +126,7 @@ public class MarkDataServiceImpl implements MarkDataService {
try { try {
ProjectVO project = projectService.getProjectVOById(UserThreadLocal.getProjectId()); ProjectVO project = projectService.getProjectVOById(UserThreadLocal.getProjectId());
List<ExportAppYuqingDTO> returnList = new ArrayList<>(); List<ExportAppYuqingDTO> returnList = new ArrayList<>();
defaultMarkSearch(markSearchDTO);
Pair<SearchHits[], Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO, false); Pair<SearchHits[], Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO, false);
for (SearchHits searchHits : hitsAndCounts.getLeft()) { for (SearchHits searchHits : hitsAndCounts.getLeft()) {
List<ExportAppYuqingDTO> collect = Arrays.stream(searchHits.getHits()).map(SearchHit::getSourceAsMap).map(ExportAppYuqingDTO::createFromEsMap).collect(Collectors.toList()); List<ExportAppYuqingDTO> collect = Arrays.stream(searchHits.getHits()).map(SearchHit::getSourceAsMap).map(ExportAppYuqingDTO::createFromEsMap).collect(Collectors.toList());
...@@ -140,10 +141,10 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -140,10 +141,10 @@ public class MarkDataServiceImpl implements MarkDataService {
} }
@Override @Override
public String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO) { public String generateYuqingMarkAggreeList(Long startTime, Long endTime) {
String uuid = Tools.getUUID(); String uuid = Tools.getUUID();
String projectId = UserThreadLocal.getProjectId(); String projectId = UserThreadLocal.getProjectId();
defaultMarkSearch4Aggree(markSearchDTO); MarkSearchDTO markSearchDTO = defaultMarkSearch4Aggree(startTime, endTime);
ApplicationProjectListener.getThreadPool().execute(() -> { ApplicationProjectListener.getThreadPool().execute(() -> {
String redisKey = RedisUtil.getAggreeCacheKey(uuid, projectId); String redisKey = RedisUtil.getAggreeCacheKey(uuid, projectId);
try { try {
...@@ -176,7 +177,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -176,7 +177,7 @@ public class MarkDataServiceImpl implements MarkDataService {
if (null == dto.getAggreeId()) { if (null == dto.getAggreeId()) {
ExceptionCast.cast(CommonCodeEnum.INVALID_PARAM.message("聚合id不得为空")); ExceptionCast.cast(CommonCodeEnum.INVALID_PARAM.message("聚合id不得为空"));
} }
defaultMarkSearch4Aggree(dto); defaultMarkSearch(dto);
Query query = assembleAggreeQuery(dto); Query query = assembleAggreeQuery(dto);
// 量查询 // 量查询
long count = aggreeResultDao.count(query); long count = aggreeResultDao.count(query);
...@@ -268,9 +269,9 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -268,9 +269,9 @@ public class MarkDataServiceImpl implements MarkDataService {
aggreeResultDao.insertOneWithoutId(aggreeResult); aggreeResultDao.insertOneWithoutId(aggreeResult);
} }
} }
if ((percent = (++count / list.size())) % (10 / list.size()) == 0) { // if ((percent = (++count / list.size())) % (10 / list.size()) == 0) {
log.info("taskId:{},fatherId:{} 入库完毕,进度:{}%", taskId, fatherId, percent); // log.info("taskId:{},fatherId:{} 入库完毕,进度:{}%", taskId, fatherId, percent);
} // }
} }
} }
...@@ -486,14 +487,24 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -486,14 +487,24 @@ public class MarkDataServiceImpl implements MarkDataService {
return null; return null;
} }
private void defaultMarkSearch4Aggree(MarkSearchDTO markSearchDTO) { private MarkSearchDTO defaultMarkSearch4Aggree(Long startTime, Long endTime) {
MarkSearchDTO markSearchDTO = new MarkSearchDTO();
markSearchDTO.setStartTime(startTime);
markSearchDTO.setEndTime(endTime);
// 时间范围默认一星期 // 时间范围默认一星期
if (Objects.isNull(markSearchDTO.getStartTime()) || Objects.isNull(markSearchDTO.getEndTime())) { if (Objects.isNull(markSearchDTO.getStartTime()) || Objects.isNull(markSearchDTO.getEndTime())) {
Date now = new Date(); Date now = new Date();
markSearchDTO.setEndTime(now.getTime()); markSearchDTO.setEndTime(now.getTime());
markSearchDTO.setStartTime(DateUtils.addDays(now, -7).getTime()); markSearchDTO.setStartTime(DateUtils.addDays(now, -7).getTime());
} }
defaultMarkSearch(markSearchDTO); String projectId = UserThreadLocal.getProjectId();
markSearchDTO.setProjectId(projectId);
String linkedGroupId = markSearchDTO.getLinkedGroupId();
if (null == linkedGroupId) {
linkedGroupId = projectService.getProjectVOById(projectId).getBrandLinkedGroupId();
markSearchDTO.setLinkedGroupId(linkedGroupId);
}
return markSearchDTO;
} }
private void defaultMarkSearch(MarkSearchDTO markSearchDTO) { private void defaultMarkSearch(MarkSearchDTO markSearchDTO) {
...@@ -563,15 +574,17 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -563,15 +574,17 @@ public class MarkDataServiceImpl implements MarkDataService {
helper.setQuery(query); helper.setQuery(query);
// sort // sort
FieldSortBuilder sort = null; FieldSortBuilder sort = null;
for (Map.Entry<String, Object> entry : dto.getSorter().entrySet()) { if (null != dto.getSorter()) {
// TODO 暂不支持 for (Map.Entry<String, Object> entry : dto.getSorter().entrySet()) {
if (entry.getKey().contains("influence")) { // TODO 暂不支持
continue; if (entry.getKey().contains("influence")) {
} continue;
if (entry.getValue().toString().contains("desc")) { }
sort = SortBuilders.fieldSort(entry.getKey()).order(SortOrder.DESC); if (entry.getValue().toString().contains("desc")) {
} else { sort = SortBuilders.fieldSort(entry.getKey()).order(SortOrder.DESC);
sort = SortBuilders.fieldSort(entry.getKey()).order(SortOrder.ASC); } else {
sort = SortBuilders.fieldSort(entry.getKey()).order(SortOrder.ASC);
}
} }
} }
helper.setSort(sort); helper.setSort(sort);
...@@ -701,7 +714,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -701,7 +714,7 @@ public class MarkDataServiceImpl implements MarkDataService {
String[] fieldSearch = "标题".equals(searchField) ? new String[]{GenericAttribute.ES_IND_TITLE} : new String[]{GenericAttribute.ES_IND_FULL_TEXT}; String[] fieldSearch = "标题".equals(searchField) ? new String[]{GenericAttribute.ES_IND_TITLE} : new String[]{GenericAttribute.ES_IND_FULL_TEXT};
query.must(EsQueryTools.assembleNormalKeywordQuery(keyword, fieldSearch)); query.must(EsQueryTools.assembleNormalKeywordQuery(keyword, fieldSearch));
} }
query.must(QueryBuilders.termQuery("brandkbs_cache_maps.linkedGroupId.keyword", linkedGroupId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.projectId.keyword", projectId)); query.must(QueryBuilders.termQuery("brandkbs_cache_maps.linked_group_id.keyword", linkedGroupId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.project_id.keyword", projectId));
// time range // time range
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)); query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime));
...@@ -804,7 +817,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -804,7 +817,7 @@ public class MarkDataServiceImpl implements MarkDataService {
TermsAggregationBuilder emotionAggregationBuilder = AggregationBuilders.terms("count").field("mark_cache_maps.name.keyword"); TermsAggregationBuilder emotionAggregationBuilder = AggregationBuilders.terms("count").field("mark_cache_maps.name.keyword");
// query // query
BoolQueryBuilder query = QueryBuilders.boolQuery(); BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)).must(QueryBuilders.termQuery("brandkbs_cache_maps.projectId.keyword", projectId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.linkedGroupId.keyword", linkedGroupId)); query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)).must(QueryBuilders.termQuery("brandkbs_cache_maps.project_id.keyword", projectId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.linked_group_id.keyword", linkedGroupId));
// 情感倾向限制 // 情感倾向限制
query.must(QueryBuilders.termQuery("mark_cache_maps.group_name.keyword", "情感倾向")); query.must(QueryBuilders.termQuery("mark_cache_maps.group_name.keyword", "情感倾向"));
// response // response
...@@ -970,8 +983,8 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -970,8 +983,8 @@ public class MarkDataServiceImpl implements MarkDataService {
return textList; return textList;
} }
private BoolQueryBuilder projectLinkedGroupQuery(String projectId, String linkedGroupId) { protected static BoolQueryBuilder projectLinkedGroupQuery(String projectId, String linkedGroupId) {
return QueryBuilders.boolQuery().must(QueryBuilders.termQuery("brandkbs_cache_maps.projectId.keyword", projectId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.linkedGroupId.keyword", linkedGroupId)); return QueryBuilders.boolQuery().must(QueryBuilders.termQuery("brandkbs_cache_maps.project_id.keyword", projectId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.linked_group_id.keyword", linkedGroupId));
} }
private List<MarkFlowEntity> getMarkFlowEntity(MarkSearchDTO markSearchDTO, SearchHits searchHits) { private List<MarkFlowEntity> getMarkFlowEntity(MarkSearchDTO markSearchDTO, SearchHits searchHits) {
......
...@@ -6,8 +6,9 @@ import com.zhiwei.base.category.ClassD; ...@@ -6,8 +6,9 @@ import com.zhiwei.base.category.ClassD;
import com.zhiwei.brandkbs2.auth.UserThreadLocal; import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.GenericAttribute; import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.config.Constant; import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.ChannelTagDao;
import com.zhiwei.brandkbs2.dao.ChannelDao; import com.zhiwei.brandkbs2.dao.ChannelDao;
import com.zhiwei.brandkbs2.dao.ChannelTagDao;
import com.zhiwei.brandkbs2.enmus.ChannelEmotion;
import com.zhiwei.brandkbs2.exception.ExceptionCast; import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.pojo.Channel; import com.zhiwei.brandkbs2.pojo.Channel;
...@@ -19,6 +20,9 @@ import com.zhiwei.brandkbs2.util.Tools; ...@@ -19,6 +20,9 @@ import com.zhiwei.brandkbs2.util.Tools;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/** /**
* @ClassName: MarkFlowServiceImpl * @ClassName: MarkFlowServiceImpl
...@@ -104,13 +108,11 @@ public class MarkFlowServiceImpl implements MarkFlowService { ...@@ -104,13 +108,11 @@ public class MarkFlowServiceImpl implements MarkFlowService {
JSONObject sourceDetails = new JSONObject(); JSONObject sourceDetails = new JSONObject();
String source = tJson.getString(GenericAttribute.ES_SOURCE); String source = tJson.getString(GenericAttribute.ES_SOURCE);
// 是否原创 // 是否原创
if (tJson.containsKey(GenericAttribute.ES_ROOT_SOURCE) if (tJson.containsKey(GenericAttribute.ES_ROOT_SOURCE) && isOrigin(source, tJson.getString(GenericAttribute.ES_ROOT_SOURCE))) {
&& isOrigin(source, tJson.getString(GenericAttribute.ES_ROOT_SOURCE))) {
sourceDetails.put("rootPublish", "原创"); sourceDetails.put("rootPublish", "原创");
} }
// C4,realSource提取展示 // C4,realSource提取展示
sourceDetails.put("clientFrom", getClientFrom(tJson.getIntValue(GenericAttribute.ES_C4), sourceDetails.put("clientFrom", getClientFrom(tJson.getIntValue(GenericAttribute.ES_C4), tJson.getString(GenericAttribute.ES_REAL_SOURCE)));
tJson.getString(GenericAttribute.ES_REAL_SOURCE)));
// source // source
sourceDetails.put("source", source); sourceDetails.put("source", source);
// 粉丝量提取 // 粉丝量提取
...@@ -122,11 +124,16 @@ public class MarkFlowServiceImpl implements MarkFlowService { ...@@ -122,11 +124,16 @@ public class MarkFlowServiceImpl implements MarkFlowService {
Channel channel = channelDao.queryUnique(ChannelIndex.createChannelIndex(tJson, projectId, linkedGroupId)); Channel channel = channelDao.queryUnique(ChannelIndex.createChannelIndex(tJson, projectId, linkedGroupId));
if (null != channel) { if (null != channel) {
sourceDetails.put("channelId", channel.getId()); sourceDetails.put("channelId", channel.getId());
sourceDetails.put("channelEmotion", channel.getEmotion()); sourceDetails.put("channelEmotion", ChannelEmotion.getNameFromState(channel.getEmotion()));
} else { } else {
sourceDetails.put("channelId", null); List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) tJson.get(GenericAttribute.ES_BRANDKBS_CACHE_MAPS);
sourceDetails.put("channelEmotion", null); if (null != cacheMaps) {
Map<String, Object> hitMap = cacheMaps.stream().filter(map -> projectId.equals(map.get("project_id")) && linkedGroupId.equals(map.get("linked_group_id"))).findAny().orElse(Collections.emptyMap());
sourceDetails.put("channelId", hitMap.get("channel_id"));
sourceDetails.put("channelEmotion", ChannelEmotion.getNameFromState(hitMap.get("channel_emotion")));
}
} }
sourceDetails.put("channelInfluence", tJson.getDoubleValue(GenericAttribute.ES_CHANNEL_INDEX));
return sourceDetails; return sourceDetails;
} }
......
...@@ -230,6 +230,8 @@ public class ReportServiceImpl implements ReportService { ...@@ -230,6 +230,8 @@ public class ReportServiceImpl implements ReportService {
if (StringUtils.isNotEmpty(reportSearch.getType())) { if (StringUtils.isNotEmpty(reportSearch.getType())) {
criteria.and("type").is(reportSearch.getType()); criteria.and("type").is(reportSearch.getType());
} }
// personal简报
criteria.orOperator(Criteria.where("userId").exists(false), Criteria.where("userId").is(UserThreadLocal.getUserId()));
Query query = new Query(criteria); Query query = new Query(criteria);
// 添加关键字查询并排序 // 添加关键字查询并排序
long count = reportDao.count(query, reportSearch.getKeyword(), new String[]{"title"}); long count = reportDao.count(query, reportSearch.getKeyword(), new String[]{"title"});
......
...@@ -86,6 +86,7 @@ public class UserServiceImpl implements UserService { ...@@ -86,6 +86,7 @@ public class UserServiceImpl implements UserService {
userInfo.setUserId(userId); userInfo.setUserId(userId);
userInfo.setRoleId(RoleEnum.SUPER_ADMIN.getState()); userInfo.setRoleId(RoleEnum.SUPER_ADMIN.getState());
userInfo.setAvatarUrl(user.getAvatarUrl()); userInfo.setAvatarUrl(user.getAvatarUrl());
userInfo.setExportAmount(10000);
return userInfo; return userInfo;
} }
AtomicBoolean hit = new AtomicBoolean(false); AtomicBoolean hit = new AtomicBoolean(false);
...@@ -96,6 +97,7 @@ public class UserServiceImpl implements UserService { ...@@ -96,6 +97,7 @@ public class UserServiceImpl implements UserService {
userInfo.setUserId(userId); userInfo.setUserId(userId);
userInfo.setRoleId(userRole.getRoleId()); userInfo.setRoleId(userRole.getRoleId());
userInfo.setAvatarUrl(user.getAvatarUrl()); userInfo.setAvatarUrl(user.getAvatarUrl());
userInfo.setExportAmount(userRole.getExportAmount());
}); });
if (!hit.get()) { if (!hit.get()) {
return null; return null;
......
...@@ -4,7 +4,6 @@ import com.alibaba.excel.EasyExcel; ...@@ -4,7 +4,6 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener; import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.base.category.ClassB;
import com.zhiwei.base.category.ClassCodec; import com.zhiwei.base.category.ClassCodec;
import com.zhiwei.base.entity.subclass.CompleteText; import com.zhiwei.base.entity.subclass.CompleteText;
import com.zhiwei.base.entity.subclass.IncompleteText; import com.zhiwei.base.entity.subclass.IncompleteText;
...@@ -314,14 +313,14 @@ public class Tools { ...@@ -314,14 +313,14 @@ public class Tools {
public static BaseMap getBaseFromEsMap(Map<String, Object> map) { public static BaseMap getBaseFromEsMap(Map<String, Object> map) {
// 设置source,forward,time // 设置source,forward,time
BaseMap res = Tools.convertMap(map, BaseMap.class); BaseMap res = Tools.convertMap(map, BaseMap.class);
res.setTypeB(ClassB.TypeB.fromEncode((int) map.get(GenericAttribute.ES_C2))); res.setTypeB(ClassCodec.decodeClassD((int) map.get(GenericAttribute.ES_C5)).typeB());
// 统一设置属性:realSource,platform,emotion // 统一设置属性:realSource,platform,emotion
res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE))); res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE)));
res.setPlatform(getPlatform(map)); res.setPlatform(getPlatform(map));
res.setEmotion(getEmotion(map)); res.setEmotion(getEmotion(map));
int c5 = Integer.parseInt(String.valueOf(map.get(GenericAttribute.ES_C5))); int c5 = Integer.parseInt(String.valueOf(map.get(GenericAttribute.ES_C5)));
// 单独设置属性title,content 部分url // 单独设置属性title,content 部分url
switch (ClassCodec.decodeClassD(c5).typeB()) { switch (res.getTypeB()) {
case COMPLETE: case COMPLETE:
CompleteText completeText = CompleteText.restoreFromEs(map); CompleteText completeText = CompleteText.restoreFromEs(map);
res.setTitle(completeText.getTitle()); res.setTitle(completeText.getTitle());
...@@ -367,6 +366,9 @@ public class Tools { ...@@ -367,6 +366,9 @@ public class Tools {
public static String getEmotion(Map<String, Object> map) { public static String getEmotion(Map<String, Object> map) {
List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) map.get(ES_MARK_CACHE_MAPS); List<Map<String, Object>> cacheMaps = (List<Map<String, Object>>) map.get(ES_MARK_CACHE_MAPS);
if (null == cacheMaps) {
return null;
}
for (Map<String, Object> cacheMap : cacheMaps) { for (Map<String, Object> cacheMap : cacheMaps) {
if ("情感倾向".equals(String.valueOf(cacheMap.get("group_name")))) { if ("情感倾向".equals(String.valueOf(cacheMap.get("group_name")))) {
return String.valueOf(cacheMap.get("name")); return String.valueOf(cacheMap.get("name"));
...@@ -579,4 +581,8 @@ public class Tools { ...@@ -579,4 +581,8 @@ public class Tools {
} }
} }
public static boolean tokenEmpty(String token) {
return null == token || Objects.equals("undefined", token);
}
} }
\ No newline at end of file
...@@ -9,7 +9,8 @@ import com.zhiwei.brandkbs2.dao.ReportDao; ...@@ -9,7 +9,8 @@ import com.zhiwei.brandkbs2.dao.ReportDao;
import com.zhiwei.brandkbs2.service.ReportService; import com.zhiwei.brandkbs2.service.ReportService;
import com.zhiwei.brandkbs2.service.TaskService; import com.zhiwei.brandkbs2.service.TaskService;
import com.zhiwei.brandkbs2.util.TextUtil; import com.zhiwei.brandkbs2.util.TextUtil;
import lombok.extern.slf4j.Slf4j; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -27,8 +28,8 @@ import java.util.List; ...@@ -27,8 +28,8 @@ import java.util.List;
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
@Slf4j
public class TestRunWith { public class TestRunWith {
private static final Logger log = LogManager.getLogger(TestRunWith.class);
@Autowired @Autowired
TaskService taskService; TaskService taskService;
......
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