Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenjunjie
brandkbs2
Commits
498b5142
Commit
498b5142
authored
Jul 21, 2022
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'dev'
Feature See merge request
!13
parents
048694ba
eed08ef5
Show whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
503 additions
and
85 deletions
+503
-85
src/main/java/com/zhiwei/brandkbs2/auth/AuthAspect.java
+23
-0
src/main/java/com/zhiwei/brandkbs2/common/GenericAttribute.java
+8
-7
src/main/java/com/zhiwei/brandkbs2/common/GlobalPojo.java
+9
-0
src/main/java/com/zhiwei/brandkbs2/controller/admin/EventController.java
+3
-3
src/main/java/com/zhiwei/brandkbs2/controller/app/AppArticleController.java
+6
-3
src/main/java/com/zhiwei/brandkbs2/controller/app/AppChannelController.java
+54
-0
src/main/java/com/zhiwei/brandkbs2/dao/impl/ChannelTagDaoImpl.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/dao/impl/ReportDaoImpl.java
+4
-1
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
+3
-2
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/EventDataListener.java
+4
-2
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/EventFileListener.java
+3
-1
src/main/java/com/zhiwei/brandkbs2/enmus/ChannelEmotion.java
+7
-0
src/main/java/com/zhiwei/brandkbs2/exception/ExceptionCatch.java
+5
-25
src/main/java/com/zhiwei/brandkbs2/interceptor/InterceptorConfig.java
+27
-0
src/main/java/com/zhiwei/brandkbs2/interceptor/MainAuthInterceptor.java
+139
-0
src/main/java/com/zhiwei/brandkbs2/listener/ApplicationProjectListener.java
+4
-1
src/main/java/com/zhiwei/brandkbs2/model/CommonCodeEnum.java
+2
-2
src/main/java/com/zhiwei/brandkbs2/model/ResponseResult.java
+4
-0
src/main/java/com/zhiwei/brandkbs2/pojo/AggreeResult.java
+13
-1
src/main/java/com/zhiwei/brandkbs2/pojo/Report.java
+5
-3
src/main/java/com/zhiwei/brandkbs2/pojo/UserInfo.java
+1
-5
src/main/java/com/zhiwei/brandkbs2/pojo/vo/ChannelListVO.java
+44
-0
src/main/java/com/zhiwei/brandkbs2/service/ChannelService.java
+6
-2
src/main/java/com/zhiwei/brandkbs2/service/MarkDataService.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
+52
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
+25
-12
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkFlowServiceImpl.java
+15
-8
src/main/java/com/zhiwei/brandkbs2/service/impl/ReportServiceImpl.java
+2
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
+2
-0
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
+28
-3
src/test/java/com/zhiwei/brandkbs2/TestRunWith.java
+3
-2
No files found.
src/main/java/com/zhiwei/brandkbs2/auth/AuthAspect.java
View file @
498b5142
...
...
@@ -6,6 +6,7 @@ import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.UserInfo
;
import
com.zhiwei.brandkbs2.service.UserService
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
com.zhiwei.middleware.auth.util.JwtUtil
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
...
...
@@ -48,6 +49,28 @@ public class AuthAspect {
}
@Around
(
"auth()"
)
public
Object
around
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
ServletRequestAttributes
servletRequestAttributes
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
());
HttpServletRequest
request
=
servletRequestAttributes
.
getRequest
();
String
token
=
request
.
getHeader
(
jwtKey
);
// 存在有效token
if
(
null
!=
token
&&
!
Tools
.
tokenEmpty
(
token
))
{
Map
<
String
,
Object
>
tokenInfo
=
JwtUtil
.
unsign
(
token
,
Map
.
class
);
String
uid
=
tokenInfo
.
get
(
GenericAttribute
.
USER_ID
).
toString
();
UserInfo
userInfo
=
UserService
.
queryUserInfo
(
uid
,
request
.
getHeader
(
"pid"
));
if
(
null
==
userInfo
)
{
userInfo
=
new
UserInfo
().
setUserId
(
uid
).
setProjectId
(
request
.
getHeader
(
"pid"
));
}
UserThreadLocal
.
set
(
userInfo
);
Object
proceed
=
joinPoint
.
proceed
();
UserThreadLocal
.
clear
();
// todo 操作记录收集
return
proceed
;
}
return
joinPoint
.
proceed
();
}
// @Around("auth()")
public
Object
aroundCheckToken
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Signature
signature
=
joinPoint
.
getSignature
();
Method
method
=
((
MethodSignature
)
signature
).
getMethod
();
...
...
src/main/java/com/zhiwei/brandkbs2/common/GenericAttribute.java
View file @
498b5142
...
...
@@ -27,14 +27,15 @@ public class GenericAttribute {
/**
* 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
*/
public
static
final
String
ES_MEDIA_TYPE
=
"media_type"
;
// ss platform_id
// TODO 待修改为 platform_id
public
static
final
String
ES_PLATFORM_ID
=
"platformId"
;
// es platform_id
public
static
final
String
ES_PLATFORM_ID
=
"platform_id"
;
// es channel_influence
public
static
final
String
ES_CHANNEL_INDEX
=
"channel_influence"
;
/**
* es rootSource
**/
...
...
@@ -71,12 +72,12 @@ public class GenericAttribute {
/** es brandkbs_cache_maps **/
public
static
final
String
ES_BRANDKBS_CACHE_MAPS
=
"brandkbs_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 ES_CACHE_MAP_PROJECT = "brandkbs_cache_maps.project
I
d.keyword";
// public static final String ES_CACHE_MAP_LINKED_GROUP_ID = "brandkbs_cache_maps.linked
GroupI
d.keyword";
// public static final String ES_CACHE_MAP_PROJECT = "brandkbs_cache_maps.project
_i
d.keyword";
// public static final String ES_CACHE_MAP_LINKED_GROUP_ID = "brandkbs_cache_maps.linked
_group_i
d.keyword";
// public static final String PLATFORM = "platform";
/**
...
...
src/main/java/com/zhiwei/brandkbs2/common/GlobalPojo.java
View file @
498b5142
...
...
@@ -63,4 +63,13 @@ public class GlobalPojo {
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
;
}
}
src/main/java/com/zhiwei/brandkbs2/controller/admin/EventController.java
View file @
498b5142
...
...
@@ -159,7 +159,7 @@ public class EventController extends BaseController {
}
@ApiOperation
(
"获取舆情事件导入进度"
)
@GetMapping
(
"/yq/upload/
progress
/{linkedGroupId}"
)
@GetMapping
(
"/yq/upload/
schedule
/{linkedGroupId}"
)
public
ResponseResult
getYqEventsProgress
(
@PathVariable
(
"linkedGroupId"
)
String
linkedGroupId
)
{
String
progressKey
=
RedisKeyPrefix
.
yuqingProgressKey
(
linkedGroupId
);
Set
<
String
>
keys
=
stringRedisTemplate
.
keys
(
progressKey
);
...
...
@@ -170,14 +170,14 @@ public class EventController extends BaseController {
}
@ApiOperation
(
"事件上传进度获取"
)
@GetMapping
(
"data/upload/
progress
/{ticket}"
)
@GetMapping
(
"data/upload/
schedule
/{ticket}"
)
public
ResponseResult
getEventDataUploadProgress
(
@PathVariable
String
ticket
)
{
return
ResponseResult
.
success
(
eventService
.
getEventDataUploadProgress
(
ticket
));
}
@ApiOperation
(
"事件数据上传进度获取"
)
@ApiImplicitParams
(
@ApiImplicitParam
(
name
=
"eventIds"
,
value
=
"事件id列表"
,
paramType
=
"body"
,
dataType
=
"list"
))
@PostMapping
(
"analyze/
progress
"
)
@PostMapping
(
"analyze/
schedule
"
)
public
ResponseResult
getEventAnalyzeProgress
(
@RequestBody
JSONObject
info
)
{
return
ResponseResult
.
success
(
eventService
.
getEventAnalyzeProgress
(
info
.
getJSONArray
(
"eventIds"
).
toJavaList
(
String
.
class
)));
}
...
...
src/main/java/com/zhiwei/brandkbs2/controller/app/AppArticleController.java
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
controller
.
app
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.auth.Auth
;
import
com.zhiwei.brandkbs2.controller.BaseController
;
import
com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil
;
...
...
@@ -51,12 +52,14 @@ public class AppArticleController extends BaseController {
@ApiOperation
(
"舆情列表-生成聚合"
)
@PostMapping
(
"/mark/aggree"
)
public
ResponseResult
generateYuqingMarkAggreeList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
return
ResponseResult
.
success
(
markDataService
.
generateYuqingMarkAggreeList
(
markSearchDTO
));
public
ResponseResult
generateYuqingMarkAggreeList
(
@RequestBody
JSONObject
info
)
{
Long
startTime
=
info
.
getLong
(
"startTime"
);
Long
endTime
=
info
.
getLong
(
"endTime"
);
return
ResponseResult
.
success
(
markDataService
.
generateYuqingMarkAggreeList
(
startTime
,
endTime
));
}
@ApiOperation
(
"舆情列表-聚合进度查询"
)
@GetMapping
(
"/mark/aggree/
progress
/{aggreeId}"
)
@GetMapping
(
"/mark/aggree/
schedule
/{aggreeId}"
)
public
ResponseResult
getYuqingMarkAggreeProgress
(
@PathVariable
String
aggreeId
)
{
return
ResponseResult
.
success
(
markDataService
.
getYuqingMarkAggreeProgress
(
aggreeId
));
}
...
...
src/main/java/com/zhiwei/brandkbs2/controller/app/AppChannelController.java
0 → 100644
View file @
498b5142
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
));
}
}
src/main/java/com/zhiwei/brandkbs2/dao/impl/ChannelTagDaoImpl.java
View file @
498b5142
...
...
@@ -24,6 +24,6 @@ public class ChannelTagDaoImpl extends BaseMongoDaoImpl<ChannelTag> implements C
if
(
null
==
channelTag
)
{
return
null
;
}
return
channelTag
.
getTag
();
return
channelTag
.
getTag
()
.
replaceAll
(
","
,
"|"
)
;
}
}
src/main/java/com/zhiwei/brandkbs2/dao/impl/ReportDaoImpl.java
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
dao
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.dao.ReportDao
;
import
com.zhiwei.brandkbs2.pojo.Report
;
import
org.springframework.data.mongodb.core.aggregation.Aggregation
;
...
...
@@ -27,7 +28,9 @@ public class ReportDaoImpl extends BaseMongoDaoImpl<Report> implements ReportDao
@Override
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
),
//
...
...
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
View file @
498b5142
...
...
@@ -8,8 +8,9 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO
;
import
com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO
;
import
lombok.extern.slf4j.Slf4j
;
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
javax.servlet.http.HttpServletResponse
;
...
...
@@ -23,8 +24,8 @@ import java.util.List;
* @description easyExcel解析工具类
* @date 2022年4月20日09:34:12
*/
@Slf4j
public
class
EasyExcelUtil
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
EasyExcelUtil
.
class
);
private
EasyExcelUtil
()
{
}
...
...
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/EventDataListener.java
View file @
498b5142
...
...
@@ -5,9 +5,12 @@ import com.alibaba.excel.event.AnalysisEventListener;
import
com.zhiwei.brandkbs2.dao.EventDao
;
import
com.zhiwei.brandkbs2.dao.EventDataDao
;
import
com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDataDTO
;
import
com.zhiwei.brandkbs2.listener.ApplicationProjectListener
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.pojo.EventData
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
/**
...
...
@@ -16,9 +19,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
* @author: sjj
* @date: 2022-05-23 13:54
*/
@Slf4j
public
class
EventDataListener
extends
AnalysisEventListener
<
UploadEventDataDTO
>
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
EventDataListener
.
class
);
private
final
EventDao
eventDao
;
private
final
EventDataDao
eventDataDao
;
...
...
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/EventFileListener.java
View file @
498b5142
...
...
@@ -5,6 +5,8 @@ import com.alibaba.excel.event.AnalysisEventListener;
import
com.zhiwei.brandkbs2.easyexcel.dto.UploadEventDTO
;
import
com.zhiwei.brandkbs2.service.EventService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -15,8 +17,8 @@ import java.util.List;
* @description 解析事件文件监听器
* @date 2019/11/12 9:00
*/
@Slf4j
public
class
EventFileListener
extends
AnalysisEventListener
<
UploadEventDTO
>
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
EventFileListener
.
class
);
/**
* 每隔5条执行保存更新事件信息,然后清理list,方便内存回收
*/
...
...
src/main/java/com/zhiwei/brandkbs2/enmus/ChannelEmotion.java
View file @
498b5142
...
...
@@ -33,6 +33,13 @@ public enum ChannelEmotion {
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
)
{
for
(
ChannelEmotion
value
:
ChannelEmotion
.
values
())
{
if
(
value
.
state
==
state
)
{
...
...
src/main/java/com/zhiwei/brandkbs2/exception/ExceptionCatch.java
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
exception
;
import
com.google.common.collect.ImmutableMap
;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.model.ResultCode
;
import
lombok.extern.slf4j.Slf4j
;
import
org.
springframework.http.converter.HttpMessageNotReadableException
;
import
org.apache.logging.log4j.LogManager
;
import
org.
apache.logging.log4j.Logger
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
java.util.Collections
;
import
java.util.Objects
;
/**
* 控制器增强
...
...
@@ -21,13 +19,8 @@ import java.util.Objects;
* @date 2022年4月21日15:00:40
*/
@RestControllerAdvice
@Slf4j
public
class
ExceptionCatch
{
/**
* 定义map,配置异常类型所对应的错误代码
*/
private
static
final
ImmutableMap
<
Class
<?
extends
Throwable
>,
ResultCode
>
EXCEPTIONS
;
private
static
final
Logger
log
=
LogManager
.
getLogger
(
ExceptionCatch
.
class
);
/**
* 捕获CustomException此类异常
...
...
@@ -58,21 +51,8 @@ public class ExceptionCatch {
public
ResponseResult
exception
(
Exception
exception
)
{
//记录日志
log
.
error
(
"catch exception:"
,
exception
);
//从EXCEPTIONS中找异常类型所对应的错误代码
ResultCode
resultCode
=
EXCEPTIONS
.
get
(
exception
.
getClass
());
if
(
Objects
.
nonNull
(
resultCode
))
{
return
new
ResponseResult
(
resultCode
,
Collections
.
EMPTY_LIST
);
}
else
{
//返回500系统繁忙异常
return
new
ResponseResult
(
CommonCodeEnum
.
SERVER_ERROR
,
Collections
.
EMPTY_LIST
);
}
//返回400操作失败
return
new
ResponseResult
(
CommonCodeEnum
.
FAIL
,
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
();
}
}
src/main/java/com/zhiwei/brandkbs2/interceptor/InterceptorConfig.java
0 → 100644
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
interceptor
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
javax.annotation.Resource
;
/**
* @Description: 统一拦截器配置 鉴权
* @Author: shentao
* @Date: 2022/7/20 11:04
*/
@Configuration
public
class
InterceptorConfig
implements
WebMvcConfigurer
{
@Resource
private
MainAuthInterceptor
mainAuthInterceptor
;
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
// 自定义拦截器,添加拦截路径和排除拦截路径
registry
.
addInterceptor
(
mainAuthInterceptor
).
addPathPatterns
(
"/app/**"
,
"/admin/**"
).
excludePathPatterns
();
}
}
src/main/java/com/zhiwei/brandkbs2/interceptor/MainAuthInterceptor.java
0 → 100644
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
interceptor
;
import
com.zhiwei.brandkbs2.auth.Auth
;
import
com.zhiwei.brandkbs2.common.GenericAttribute
;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.UserInfo
;
import
com.zhiwei.brandkbs2.service.UserService
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
com.zhiwei.middleware.auth.util.JwtUtil
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Map
;
/**
* @Description: 品见鉴权拦截器
* @Author: shentao
* @Date: 2022/7/20 11:20
*/
@Component
public
class
MainAuthInterceptor
implements
HandlerInterceptor
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
MainAuthInterceptor
.
class
);
private
final
UserService
UserService
;
public
MainAuthInterceptor
(
UserService
userService
)
{
UserService
=
userService
;
}
@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
);
}
}
// 不需要验证权限
if
(
null
==
auth
)
{
return
true
;
}
String
token
=
request
.
getHeader
(
"Token"
);
try
{
// 不存在token 重新获取token
if
(
Tools
.
tokenEmpty
(
token
))
{
Tools
.
responseMessage
(
response
,
HttpServletResponse
.
SC_UNAUTHORIZED
,
new
ResponseResult
(
CommonCodeEnum
.
UNAUTHENTICATED
,
null
));
return
false
;
}
Map
<
String
,
Object
>
tokenInfo
=
JwtUtil
.
unsign
(
token
,
Map
.
class
);
// 解析失败 token过期 重新登录
if
(
null
==
tokenInfo
)
{
Tools
.
responseMessage
(
response
,
HttpServletResponse
.
SC_UNAUTHORIZED
,
new
ResponseResult
(
CommonCodeEnum
.
UNAUTHENTICATED
,
null
));
return
false
;
}
String
uid
=
tokenInfo
.
get
(
GenericAttribute
.
USER_ID
).
toString
();
UserInfo
userInfo
=
UserService
.
queryUserInfo
(
uid
,
request
.
getHeader
(
"pid"
));
// 无用户信息 todo
if
(
null
==
userInfo
)
{
Tools
.
responseMessage
(
response
,
HttpServletResponse
.
SC_UNAUTHORIZED
,
new
ResponseResult
(
CommonCodeEnum
.
UNAUTHENTICATED
,
null
));
return
false
;
}
// 权限不足
if
(
userInfo
.
getRoleId
()
>
auth
.
role
().
getState
())
{
Tools
.
responseMessage
(
response
,
HttpServletResponse
.
SC_FORBIDDEN
,
new
ResponseResult
(
CommonCodeEnum
.
UN_AUTHORISE
));
return
false
;
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"拦截鉴权出错;token:{}"
,
token
,
e
);
return
false
;
}
}
// @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;
// }
}
src/main/java/com/zhiwei/brandkbs2/listener/ApplicationProjectListener.java
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
listener
;
import
com.google.common.util.concurrent.ThreadFactoryBuilder
;
import
com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.*
;
...
...
@@ -12,8 +15,8 @@ import java.util.concurrent.*;
* @date 2019/9/2 14:00
*/
@Component
@Slf4j
public
class
ApplicationProjectListener
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
ApplicationProjectListener
.
class
);
private
static
final
int
CORE_POOL_SIZE
=
50
;
private
static
final
int
MAX_POOL_SIZE
=
200
;
private
static
final
int
QUEUE_SIZE
=
128
;
...
...
src/main/java/com/zhiwei/brandkbs2/model/CommonCodeEnum.java
View file @
498b5142
...
...
@@ -10,7 +10,7 @@ public enum CommonCodeEnum implements ResultCode {
/**
* 非法参数
*/
INVALID_PARAM
(
false
,
40
3
,
"非法参数!"
,
200
),
INVALID_PARAM
(
false
,
40
4
,
"非法参数!"
,
200
),
/**
* 操作成功
*/
...
...
@@ -26,7 +26,7 @@ public enum CommonCodeEnum implements ResultCode {
/**
* 权限不足
*/
UN_AUTHORISE
(
false
,
40
2
,
"权限不足,无权操作!"
,
200
),
UN_AUTHORISE
(
false
,
40
3
,
"权限不足,无权操作!"
,
200
),
/**
* 系统异常
*/
...
...
src/main/java/com/zhiwei/brandkbs2/model/ResponseResult.java
View file @
498b5142
...
...
@@ -51,6 +51,10 @@ public class ResponseResult {
@ApiModelProperty
(
"返回数据"
)
private
Object
data
;
public
ResponseResult
(
ResultCode
resultCode
)
{
this
(
resultCode
,
Collections
.
EMPTY_LIST
);
}
public
ResponseResult
(
ResultCode
resultCode
,
Object
data
)
{
this
.
success
=
resultCode
.
success
();
this
.
code
=
resultCode
.
code
();
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/AggreeResult.java
View file @
498b5142
...
...
@@ -22,6 +22,11 @@ import java.util.List;
public
class
AggreeResult
extends
AbstractBaseMongo
{
/**
* 需要移除的属性
*/
private
static
final
List
<
String
>
EXCLUDE_FIELD
=
Arrays
.
asList
(
"mark_cache_maps"
,
"brandkbs_cache_maps"
);
/**
* 任务id
*/
private
String
taskId
;
...
...
@@ -96,7 +101,6 @@ public class AggreeResult extends AbstractBaseMongo {
private
static
AggreeResult
getInstance
(
JSONObject
json
,
String
taskId
)
{
AggreeResult
aggreeResult
=
new
AggreeResult
();
aggreeResult
.
setTaskId
(
taskId
);
aggreeResult
.
setData
(
json
);
BaseMap
baseMap
=
Tools
.
getBaseFromEsMap
(
json
);
aggreeResult
.
setTime
(
baseMap
.
getTime
());
aggreeResult
.
setPlatformId
(
json
.
getString
(
GenericAttribute
.
ES_PLATFORM_ID
));
...
...
@@ -106,6 +110,7 @@ public class AggreeResult extends AbstractBaseMongo {
}
aggreeResult
.
setTags
(
parseMatg
(
json
.
getString
(
GenericAttribute
.
ES_MTAG
)));
aggreeResult
.
setAggreeTitle
(
baseMap
.
getTitleNullOptionalContent
());
aggreeResult
.
setData
(
removeExclude
(
json
));
return
aggreeResult
;
}
...
...
@@ -121,4 +126,11 @@ public class AggreeResult extends AbstractBaseMongo {
return
resList
;
}
private
static
JSONObject
removeExclude
(
JSONObject
json
)
{
for
(
String
exclude
:
EXCLUDE_FIELD
)
{
json
.
remove
(
exclude
);
}
return
json
;
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/Report.java
View file @
498b5142
...
...
@@ -51,12 +51,11 @@ public class Report extends AbstractBaseMongo {
/**
* 竞品信息字符串
*/
@Deprecated
private
List
<
String
>
contends
;
/**
*
生成状态
*
可查看的userId
*/
private
boolean
status
;
private
String
userId
;
public
static
Report
createFromReportDTO
(
ReportDTO
reportDTO
)
{
Report
report
=
new
Report
();
...
...
@@ -67,6 +66,9 @@ public class Report extends AbstractBaseMongo {
report
.
setType
(
ReportTypeEnum
.
CUSTOM
.
getState
());
report
.
setProjectId
(
UserThreadLocal
.
getProjectId
());
report
.
setContends
(
reportDTO
.
getContends
());
if
(
reportDTO
.
isPersonal
())
{
report
.
setUserId
(
UserThreadLocal
.
getUserId
());
}
return
report
;
}
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/UserInfo.java
View file @
498b5142
...
...
@@ -19,6 +19,7 @@ public class UserInfo {
private
String
userId
;
private
Integer
roleId
;
private
String
projectId
;
private
Integer
exportAmount
;
private
String
avatarUrl
;
public
UserInfo
setUserId
(
String
userId
){
...
...
@@ -31,11 +32,6 @@ public class UserInfo {
return
this
;
}
public
UserInfo
setAvatarUrl
(
String
avatarUrl
){
this
.
avatarUrl
=
avatarUrl
;
return
this
;
}
public
Map
<
String
,
Object
>
toMap
()
{
Map
<
String
,
Object
>
res
=
new
HashMap
<>();
res
.
put
(
GenericAttribute
.
NICK_NAME
,
this
.
nickname
);
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/vo/ChannelListVO.java
0 → 100644
View file @
498b5142
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
;
}
src/main/java/com/zhiwei/brandkbs2/service/ChannelService.java
View file @
498b5142
...
...
@@ -4,9 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import
com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO
;
import
com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO
;
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.vo.ChannelListVO
;
import
com.zhiwei.brandkbs2.pojo.vo.PageVO
;
import
java.util.List
;
...
...
@@ -114,4 +113,9 @@ public interface ChannelService {
*/
List
<
String
>
getChannelLabels
(
String
type
);
/**
* 获取活跃渠道榜
* @return ChannelListVO
*/
List
<
ChannelListVO
>
getActiveChannelList
(
String
linkedGroupId
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
int
size
);
}
src/main/java/com/zhiwei/brandkbs2/service/MarkDataService.java
View file @
498b5142
...
...
@@ -34,7 +34,7 @@ public interface MarkDataService {
*
* @return 聚合id
*/
String
generateYuqingMarkAggreeList
(
MarkSearchDTO
markSearchDTO
);
String
generateYuqingMarkAggreeList
(
Long
startTime
,
Long
endTime
);
/**
* 获取聚合进度结果
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
View file @
498b5142
package
com
.
zhiwei
.
brandkbs2
.
service
.
impl
;
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.easyexcel.dto.ExportAdminChannelArticleDTO
;
import
com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO
;
...
...
@@ -12,12 +15,19 @@ import com.zhiwei.brandkbs2.exception.ExceptionCast;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.pojo.*
;
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.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.Tools
;
import
org.apache.commons.collections4.CollectionUtils
;
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.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
...
...
@@ -55,6 +65,12 @@ public class ChannelServiceImpl implements ChannelService {
@Resource
(
name
=
"channelTagDao"
)
ChannelTagDao
channelTagDao
;
@Resource
(
name
=
"projectServiceImpl"
)
ProjectService
projectService
;
@Resource
(
name
=
"commonServiceImpl"
)
CommonService
commonService
;
@Resource
(
name
=
"mongoUtil"
)
MongoUtil
mongoUtil
;
...
...
@@ -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
());
}
@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
)
{
Query
query
=
new
Query
();
query
.
addCriteria
(
Criteria
.
where
(
"linkedGroupId"
).
is
(
linkedGroupId
));
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
View file @
498b5142
...
...
@@ -126,6 +126,7 @@ public class MarkDataServiceImpl implements MarkDataService {
try
{
ProjectVO
project
=
projectService
.
getProjectVOById
(
UserThreadLocal
.
getProjectId
());
List
<
ExportAppYuqingDTO
>
returnList
=
new
ArrayList
<>();
defaultMarkSearch
(
markSearchDTO
);
Pair
<
SearchHits
[],
Map
<
String
,
Long
>>
hitsAndCounts
=
searchMarkHitsAndCount
(
markSearchDTO
,
false
);
for
(
SearchHits
searchHits
:
hitsAndCounts
.
getLeft
())
{
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 {
}
@Override
public
String
generateYuqingMarkAggreeList
(
MarkSearchDTO
markSearchDTO
)
{
public
String
generateYuqingMarkAggreeList
(
Long
startTime
,
Long
endTime
)
{
String
uuid
=
Tools
.
getUUID
();
String
projectId
=
UserThreadLocal
.
getProjectId
();
defaultMarkSearch4Aggree
(
markSearchDTO
);
MarkSearchDTO
markSearchDTO
=
defaultMarkSearch4Aggree
(
startTime
,
endTime
);
ApplicationProjectListener
.
getThreadPool
().
execute
(()
->
{
String
redisKey
=
RedisUtil
.
getAggreeCacheKey
(
uuid
,
projectId
);
try
{
...
...
@@ -176,7 +177,7 @@ public class MarkDataServiceImpl implements MarkDataService {
if
(
null
==
dto
.
getAggreeId
())
{
ExceptionCast
.
cast
(
CommonCodeEnum
.
INVALID_PARAM
.
message
(
"聚合id不得为空"
));
}
defaultMarkSearch
4Aggree
(
dto
);
defaultMarkSearch
(
dto
);
Query
query
=
assembleAggreeQuery
(
dto
);
// 量查询
long
count
=
aggreeResultDao
.
count
(
query
);
...
...
@@ -268,9 +269,9 @@ public class MarkDataServiceImpl implements MarkDataService {
aggreeResultDao
.
insertOneWithoutId
(
aggreeResult
);
}
}
if
((
percent
=
(++
count
/
list
.
size
()))
%
(
10
/
list
.
size
())
==
0
)
{
log
.
info
(
"taskId:{},fatherId:{} 入库完毕,进度:{}%"
,
taskId
,
fatherId
,
percent
);
}
//
if ((percent = (++count / list.size())) % (10 / list.size()) == 0) {
//
log.info("taskId:{},fatherId:{} 入库完毕,进度:{}%", taskId, fatherId, percent);
//
}
}
}
...
...
@@ -486,14 +487,24 @@ public class MarkDataServiceImpl implements MarkDataService {
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
()))
{
Date
now
=
new
Date
();
markSearchDTO
.
setEndTime
(
now
.
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
)
{
...
...
@@ -563,6 +574,7 @@ public class MarkDataServiceImpl implements MarkDataService {
helper
.
setQuery
(
query
);
// sort
FieldSortBuilder
sort
=
null
;
if
(
null
!=
dto
.
getSorter
())
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
dto
.
getSorter
().
entrySet
())
{
// TODO 暂不支持
if
(
entry
.
getKey
().
contains
(
"influence"
))
{
...
...
@@ -574,6 +586,7 @@ public class MarkDataServiceImpl implements MarkDataService {
sort
=
SortBuilders
.
fieldSort
(
entry
.
getKey
()).
order
(
SortOrder
.
ASC
);
}
}
}
helper
.
setSort
(
sort
);
// from size
helper
.
setFrom
((
dto
.
getPage
()
-
1
)
*
dto
.
getPageSize
());
...
...
@@ -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
};
query
.
must
(
EsQueryTools
.
assembleNormalKeywordQuery
(
keyword
,
fieldSearch
));
}
query
.
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.linked
GroupId.keyword"
,
linkedGroupId
)).
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.projectI
d.keyword"
,
projectId
));
query
.
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.linked
_group_id.keyword"
,
linkedGroupId
)).
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.project_i
d.keyword"
,
projectId
));
// time range
query
.
must
(
QueryBuilders
.
rangeQuery
(
"time"
).
gte
(
startTime
).
lt
(
endTime
));
...
...
@@ -804,7 +817,7 @@ public class MarkDataServiceImpl implements MarkDataService {
TermsAggregationBuilder
emotionAggregationBuilder
=
AggregationBuilders
.
terms
(
"count"
).
field
(
"mark_cache_maps.name.keyword"
);
// query
BoolQueryBuilder
query
=
QueryBuilders
.
boolQuery
();
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.linkedGroupI
d.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_i
d.keyword"
,
linkedGroupId
));
// 情感倾向限制
query
.
must
(
QueryBuilders
.
termQuery
(
"mark_cache_maps.group_name.keyword"
,
"情感倾向"
));
// response
...
...
@@ -970,8 +983,8 @@ public class MarkDataServiceImpl implements MarkDataService {
return
textList
;
}
pr
ivate
BoolQueryBuilder
projectLinkedGroupQuery
(
String
projectId
,
String
linkedGroupId
)
{
return
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.project
Id.keyword"
,
projectId
)).
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.linkedGroupI
d.keyword"
,
linkedGroupId
));
pr
otected
static
BoolQueryBuilder
projectLinkedGroupQuery
(
String
projectId
,
String
linkedGroupId
)
{
return
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.project
_id.keyword"
,
projectId
)).
must
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.linked_group_i
d.keyword"
,
linkedGroupId
));
}
private
List
<
MarkFlowEntity
>
getMarkFlowEntity
(
MarkSearchDTO
markSearchDTO
,
SearchHits
searchHits
)
{
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkFlowServiceImpl.java
View file @
498b5142
...
...
@@ -6,8 +6,9 @@ import com.zhiwei.base.category.ClassD;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.common.GenericAttribute
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.dao.ChannelTagDao
;
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.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.pojo.Channel
;
...
...
@@ -19,6 +20,9 @@ import com.zhiwei.brandkbs2.util.Tools;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
/**
* @ClassName: MarkFlowServiceImpl
...
...
@@ -104,13 +108,11 @@ public class MarkFlowServiceImpl implements MarkFlowService {
JSONObject
sourceDetails
=
new
JSONObject
();
String
source
=
tJson
.
getString
(
GenericAttribute
.
ES_SOURCE
);
// 是否原创
if
(
tJson
.
containsKey
(
GenericAttribute
.
ES_ROOT_SOURCE
)
&&
isOrigin
(
source
,
tJson
.
getString
(
GenericAttribute
.
ES_ROOT_SOURCE
)))
{
if
(
tJson
.
containsKey
(
GenericAttribute
.
ES_ROOT_SOURCE
)
&&
isOrigin
(
source
,
tJson
.
getString
(
GenericAttribute
.
ES_ROOT_SOURCE
)))
{
sourceDetails
.
put
(
"rootPublish"
,
"原创"
);
}
// C4,realSource提取展示
sourceDetails
.
put
(
"clientFrom"
,
getClientFrom
(
tJson
.
getIntValue
(
GenericAttribute
.
ES_C4
),
tJson
.
getString
(
GenericAttribute
.
ES_REAL_SOURCE
)));
sourceDetails
.
put
(
"clientFrom"
,
getClientFrom
(
tJson
.
getIntValue
(
GenericAttribute
.
ES_C4
),
tJson
.
getString
(
GenericAttribute
.
ES_REAL_SOURCE
)));
// source
sourceDetails
.
put
(
"source"
,
source
);
// 粉丝量提取
...
...
@@ -122,11 +124,16 @@ public class MarkFlowServiceImpl implements MarkFlowService {
Channel
channel
=
channelDao
.
queryUnique
(
ChannelIndex
.
createChannelIndex
(
tJson
,
projectId
,
linkedGroupId
));
if
(
null
!=
channel
)
{
sourceDetails
.
put
(
"channelId"
,
channel
.
getId
());
sourceDetails
.
put
(
"channelEmotion"
,
channel
.
getEmotion
(
));
sourceDetails
.
put
(
"channelEmotion"
,
ChannelEmotion
.
getNameFromState
(
channel
.
getEmotion
()
));
}
else
{
sourceDetails
.
put
(
"channelId"
,
null
);
sourceDetails
.
put
(
"channelEmotion"
,
null
);
List
<
Map
<
String
,
Object
>>
cacheMaps
=
(
List
<
Map
<
String
,
Object
>>)
tJson
.
get
(
GenericAttribute
.
ES_BRANDKBS_CACHE_MAPS
);
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
;
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/ReportServiceImpl.java
View file @
498b5142
...
...
@@ -230,6 +230,8 @@ public class ReportServiceImpl implements ReportService {
if
(
StringUtils
.
isNotEmpty
(
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
);
// 添加关键字查询并排序
long
count
=
reportDao
.
count
(
query
,
reportSearch
.
getKeyword
(),
new
String
[]{
"title"
});
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
View file @
498b5142
...
...
@@ -86,6 +86,7 @@ public class UserServiceImpl implements UserService {
userInfo
.
setUserId
(
userId
);
userInfo
.
setRoleId
(
RoleEnum
.
SUPER_ADMIN
.
getState
());
userInfo
.
setAvatarUrl
(
user
.
getAvatarUrl
());
userInfo
.
setExportAmount
(
10000
);
return
userInfo
;
}
AtomicBoolean
hit
=
new
AtomicBoolean
(
false
);
...
...
@@ -96,6 +97,7 @@ public class UserServiceImpl implements UserService {
userInfo
.
setUserId
(
userId
);
userInfo
.
setRoleId
(
userRole
.
getRoleId
());
userInfo
.
setAvatarUrl
(
user
.
getAvatarUrl
());
userInfo
.
setExportAmount
(
userRole
.
getExportAmount
());
});
if
(!
hit
.
get
())
{
return
null
;
...
...
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
View file @
498b5142
...
...
@@ -4,7 +4,6 @@ import com.alibaba.excel.EasyExcel;
import
com.alibaba.excel.read.listener.PageReadListener
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.base.category.ClassB
;
import
com.zhiwei.base.category.ClassCodec
;
import
com.zhiwei.base.entity.subclass.CompleteText
;
import
com.zhiwei.base.entity.subclass.IncompleteText
;
...
...
@@ -314,14 +313,14 @@ public class Tools {
public
static
BaseMap
getBaseFromEsMap
(
Map
<
String
,
Object
>
map
)
{
// 设置source,forward,time
BaseMap
res
=
Tools
.
convertMap
(
map
,
BaseMap
.
class
);
res
.
setTypeB
(
Class
B
.
TypeB
.
fromEncode
((
int
)
map
.
get
(
GenericAttribute
.
ES_C2
)
));
res
.
setTypeB
(
Class
Codec
.
decodeClassD
((
int
)
map
.
get
(
GenericAttribute
.
ES_C5
)).
typeB
(
));
// 统一设置属性:realSource,platform,emotion
res
.
setRealSource
(
String
.
valueOf
(
map
.
get
(
GenericAttribute
.
ES_REAL_SOURCE
)));
res
.
setPlatform
(
getPlatform
(
map
));
res
.
setEmotion
(
getEmotion
(
map
));
int
c5
=
Integer
.
parseInt
(
String
.
valueOf
(
map
.
get
(
GenericAttribute
.
ES_C5
)));
// 单独设置属性title,content 部分url
switch
(
ClassCodec
.
decodeClassD
(
c5
).
t
ypeB
())
{
switch
(
res
.
getT
ypeB
())
{
case
COMPLETE:
CompleteText
completeText
=
CompleteText
.
restoreFromEs
(
map
);
res
.
setTitle
(
completeText
.
getTitle
());
...
...
@@ -367,6 +366,9 @@ public class Tools {
public
static
String
getEmotion
(
Map
<
String
,
Object
>
map
)
{
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
)
{
if
(
"情感倾向"
.
equals
(
String
.
valueOf
(
cacheMap
.
get
(
"group_name"
))))
{
return
String
.
valueOf
(
cacheMap
.
get
(
"name"
));
...
...
@@ -561,4 +563,26 @@ public class Tools {
return
JSON
.
parseObject
(
JSON
.
toJSONString
(
obj
),
clazz
);
}
/**
* 自定义HttpStatus和response内容,返回response
* @param response
* @param status
* @param returnData
* @throws Exception
*/
public
static
void
responseMessage
(
HttpServletResponse
response
,
int
status
,
Object
returnData
)
throws
Exception
{
response
.
setStatus
(
status
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"application/json; charset=utf-8"
);
String
json
=
JSONObject
.
toJSONString
(
returnData
);
try
(
PrintWriter
writer
=
response
.
getWriter
())
{
writer
.
print
(
json
);
writer
.
flush
();
}
}
public
static
boolean
tokenEmpty
(
String
token
)
{
return
null
==
token
||
Objects
.
equals
(
"undefined"
,
token
);
}
}
\ No newline at end of file
src/test/java/com/zhiwei/brandkbs2/TestRunWith.java
View file @
498b5142
...
...
@@ -9,7 +9,8 @@ import com.zhiwei.brandkbs2.dao.ReportDao;
import
com.zhiwei.brandkbs2.service.ReportService
;
import
com.zhiwei.brandkbs2.service.TaskService
;
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.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -27,8 +28,8 @@ import java.util.List;
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
@Slf4j
public
class
TestRunWith
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
TestRunWith
.
class
);
@Autowired
TaskService
taskService
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment