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
b37abbcd
Commit
b37abbcd
authored
Nov 10, 2022
by
shenjunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加event结束状态判断2
parent
f60b13c1
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1099 additions
and
37 deletions
+1099
-37
src/main/java/com/zhiwei/brandkbs2/config/Constant.java
+2
-0
src/main/java/com/zhiwei/brandkbs2/controller/InterfaceController.java
+22
-0
src/main/java/com/zhiwei/brandkbs2/dao/EventDao.java
+12
-0
src/main/java/com/zhiwei/brandkbs2/dao/impl/EventDaoImpl.java
+34
-0
src/main/java/com/zhiwei/brandkbs2/es/EsQueryTools.java
+15
-0
src/main/java/com/zhiwei/brandkbs2/pojo/BaseMap.java
+4
-0
src/main/java/com/zhiwei/brandkbs2/pojo/external/BaseMapCompound.java
+24
-0
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsHotEventConfig.java
+44
-0
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsHotEventWarn.java
+18
-1
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsHotTopWarn.java
+56
-0
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsNewCaseWarn.java
+44
-0
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsWarnTemplate.java
+61
-8
src/main/java/com/zhiwei/brandkbs2/service/ProjectWarnService.java
+16
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/ProjectWarnServiceImpl.java
+424
-18
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
+10
-0
src/test/java/com/zhiwei/brandkbs2/BrandkbsIndexCreateTest.java
+302
-0
src/test/java/com/zhiwei/brandkbs2/ChannelServiceTest.java
+3
-7
src/test/java/com/zhiwei/brandkbs2/MarkDataServiceTest.java
+8
-3
No files found.
src/main/java/com/zhiwei/brandkbs2/config/Constant.java
View file @
b37abbcd
...
@@ -16,11 +16,13 @@ public class Constant {
...
@@ -16,11 +16,13 @@ public class Constant {
public
static
final
Long
ONE_DAY
=
24
*
60
*
60
*
1000L
;
public
static
final
Long
ONE_DAY
=
24
*
60
*
60
*
1000L
;
public
static
final
Long
ONE_MONTH
=
30
*
24
*
60
*
60
*
1000L
;
public
static
final
Long
ONE_MONTH
=
30
*
24
*
60
*
60
*
1000L
;
public
static
final
String
SPEC_MINUTE_PATTERN
=
"yyyy.MM.dd HH:mm"
;
public
static
final
String
HOUR_PATTERN
=
"yyyy-MM-dd HH"
;
public
static
final
String
HOUR_PATTERN
=
"yyyy-MM-dd HH"
;
public
static
final
String
DAY_PATTERN
=
"yyyy-MM-dd"
;
public
static
final
String
DAY_PATTERN
=
"yyyy-MM-dd"
;
public
static
final
String
MONTH_PATTERN
=
"yyyy-MM"
;
public
static
final
String
MONTH_PATTERN
=
"yyyy-MM"
;
public
static
final
String
YEAR_PATTERN
=
"yyyy"
;
public
static
final
String
YEAR_PATTERN
=
"yyyy"
;
public
static
final
FastDateFormat
SPEC_MINUTE_FORMAT
=
FastDateFormat
.
getInstance
(
SPEC_MINUTE_PATTERN
);
public
static
final
FastDateFormat
HOUR_FORMAT
=
FastDateFormat
.
getInstance
(
HOUR_PATTERN
);
public
static
final
FastDateFormat
HOUR_FORMAT
=
FastDateFormat
.
getInstance
(
HOUR_PATTERN
);
public
static
final
FastDateFormat
DAY_FORMAT
=
FastDateFormat
.
getInstance
(
DAY_PATTERN
);
public
static
final
FastDateFormat
DAY_FORMAT
=
FastDateFormat
.
getInstance
(
DAY_PATTERN
);
public
static
final
FastDateFormat
SPEC_DAY_FORMAT
=
FastDateFormat
.
getInstance
(
"yyyy/MM/dd"
);
public
static
final
FastDateFormat
SPEC_DAY_FORMAT
=
FastDateFormat
.
getInstance
(
"yyyy/MM/dd"
);
...
...
src/main/java/com/zhiwei/brandkbs2/controller/InterfaceController.java
View file @
b37abbcd
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsChannelConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsChannelConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsHotEventConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsHotEventConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsHotTopConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsYuQingConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsYuQingConfig
;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.service.ProjectWarnService
;
import
com.zhiwei.brandkbs2.service.ProjectWarnService
;
...
@@ -36,6 +37,12 @@ public class InterfaceController {
...
@@ -36,6 +37,12 @@ public class InterfaceController {
return
projectWarnService
.
getProjectWarnCriteria
(
projectId
,
type
);
return
projectWarnService
.
getProjectWarnCriteria
(
projectId
,
type
);
}
}
@ApiOperation
(
"获取项目预警详细信息默认值"
)
@GetMapping
(
"/getProjectWarnCriteria/default"
)
public
ResponseResult
getProjectWarnCriteriaDefault
(
String
projectId
,
String
type
)
{
return
projectWarnService
.
getProjectWarnCriteriaDefault
(
projectId
,
type
);
}
@ApiOperation
(
"根据userId获取拥有权限项目"
)
@ApiOperation
(
"根据userId获取拥有权限项目"
)
@GetMapping
(
"/getUserAllProjectsByUserId"
)
@GetMapping
(
"/getUserAllProjectsByUserId"
)
public
ResponseResult
getUserAllProjectsByUserId
(
String
userId
)
{
public
ResponseResult
getUserAllProjectsByUserId
(
String
userId
)
{
...
@@ -66,4 +73,19 @@ public class InterfaceController {
...
@@ -66,4 +73,19 @@ public class InterfaceController {
return
projectWarnService
.
getHotEventWaring
(
projectId
,
config
);
return
projectWarnService
.
getHotEventWaring
(
projectId
,
config
);
}
}
@ApiOperation
(
"获取热点事件-预警结果"
)
@PostMapping
(
"/warn/hotTop"
)
public
ResponseResult
getHotTopWaring
(
@RequestBody
JSONObject
json
)
{
String
projectId
=
json
.
getString
(
"projectId"
);
BrandkbsHotTopConfig
config
=
json
.
getObject
(
"config"
,
BrandkbsHotTopConfig
.
class
);
return
projectWarnService
.
getHotTopWaring
(
projectId
,
config
);
}
@ApiOperation
(
"获取热点事件-预警结果"
)
@PostMapping
(
"/warn/newCase"
)
public
ResponseResult
getNewCaseWaring
(
@RequestBody
JSONObject
json
)
{
String
projectId
=
json
.
getString
(
"projectId"
);
return
projectWarnService
.
getNewCaseWaring
(
projectId
);
}
}
}
src/main/java/com/zhiwei/brandkbs2/dao/EventDao.java
View file @
b37abbcd
...
@@ -94,6 +94,18 @@ public interface EventDao extends BaseMongoDao<Event> {
...
@@ -94,6 +94,18 @@ public interface EventDao extends BaseMongoDao<Event> {
*/
*/
List
<
Event
>
getEventsByProjectIdAndContendId
(
Long
startTime
,
Long
endTime
,
String
emotion
,
String
projectId
,
String
contendId
,
int
limit
);
List
<
Event
>
getEventsByProjectIdAndContendId
(
Long
startTime
,
Long
endTime
,
String
emotion
,
String
projectId
,
String
contendId
,
int
limit
);
/**
* 根据特征值获取事件
*
* @param startTime
* @param endTime
* @param emotions
* @param projectId
* @param contendId
* @return
*/
List
<
Event
>
getEventsByProjectIdAndContendId
(
Long
startTime
,
Long
endTime
,
List
<
String
>
emotions
,
String
projectId
,
String
contendId
,
int
limit
);
List
<
Event
>
getEventsByTotalChannelVolumeTop
(
Long
startTime
,
Long
endTime
,
String
emotion
,
String
projectId
,
String
contendId
,
int
limit
);
List
<
Event
>
getEventsByTotalChannelVolumeTop
(
Long
startTime
,
Long
endTime
,
String
emotion
,
String
projectId
,
String
contendId
,
int
limit
);
...
...
src/main/java/com/zhiwei/brandkbs2/dao/impl/EventDaoImpl.java
View file @
b37abbcd
...
@@ -7,6 +7,7 @@ import com.zhiwei.brandkbs2.enmus.EmotionEnum;
...
@@ -7,6 +7,7 @@ import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import
com.zhiwei.brandkbs2.pojo.ChannelIndex
;
import
com.zhiwei.brandkbs2.pojo.ChannelIndex
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.data.mongodb.core.aggregation.Aggregation
;
import
org.springframework.data.mongodb.core.aggregation.Aggregation
;
import
org.springframework.data.mongodb.core.aggregation.AggregationOperation
;
import
org.springframework.data.mongodb.core.aggregation.AggregationOperation
;
...
@@ -106,6 +107,17 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
...
@@ -106,6 +107,17 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
}
}
@Override
@Override
public
List
<
Event
>
getEventsByProjectIdAndContendId
(
Long
startTime
,
Long
endTime
,
List
<
String
>
emotions
,
String
projectId
,
String
contendId
,
int
limit
)
{
Query
query
=
new
Query
();
Criteria
criteria
=
eventCountCriteria
(
startTime
,
endTime
,
emotions
,
projectId
,
contendId
);
query
.
addCriteria
(
criteria
);
query
.
limit
(
limit
);
// 按影响力排序
addSort
(
query
,
"{\"influence\":\"descend\"}"
);
return
mongoTemplate
.
find
(
query
,
clazz
,
COLLECTION_NAME
);
}
@Override
public
List
<
Event
>
getEventsByTotalChannelVolumeTop
(
Long
startTime
,
Long
endTime
,
String
emotion
,
String
projectId
,
String
contendId
,
int
limit
)
{
public
List
<
Event
>
getEventsByTotalChannelVolumeTop
(
Long
startTime
,
Long
endTime
,
String
emotion
,
String
projectId
,
String
contendId
,
int
limit
)
{
Query
query
=
new
Query
();
Query
query
=
new
Query
();
Criteria
criteria
=
eventCountCriteria
(
startTime
,
endTime
,
emotion
,
projectId
,
contendId
);
Criteria
criteria
=
eventCountCriteria
(
startTime
,
endTime
,
emotion
,
projectId
,
contendId
);
...
@@ -132,6 +144,28 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
...
@@ -132,6 +144,28 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
return
criteria
;
return
criteria
;
}
}
private
Criteria
eventCountCriteria
(
Long
startTime
,
Long
endTime
,
List
<
String
>
emotions
,
String
projectId
,
String
contendId
)
{
Criteria
criteria
=
Criteria
.
where
(
"projectId"
).
is
(
projectId
);
criteria
.
and
(
"contendId"
).
is
(
contendId
);
Criteria
startTimeCriteria
=
criteria
.
and
(
"startTime"
);
if
(
null
!=
startTime
)
{
startTimeCriteria
.
gte
(
startTime
);
}
if
(
null
!=
endTime
)
{
startTimeCriteria
.
lt
(
endTime
);
}
List
<
Criteria
>
criteriaList
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
emotions
)
&&
!
emotions
.
contains
(
EmotionEnum
.
ALL
.
getName
()))
{
for
(
String
emotion
:
emotions
)
{
criteriaList
.
add
(
Criteria
.
where
(
"emotion"
).
is
(
emotion
));
}
}
if
(!
criteriaList
.
isEmpty
())
{
criteria
.
orOperator
(
criteriaList
.
toArray
(
new
Criteria
[
0
]));
}
return
criteria
;
}
/**
/**
* mongo版本不支持toString/toObjectId 表达式
* mongo版本不支持toString/toObjectId 表达式
* 已被getEventCount 代替
* 已被getEventCount 代替
...
...
src/main/java/com/zhiwei/brandkbs2/es/EsQueryTools.java
View file @
b37abbcd
...
@@ -110,6 +110,21 @@ public class EsQueryTools {
...
@@ -110,6 +110,21 @@ public class EsQueryTools {
return
nestedBoolQueryBuilder
;
return
nestedBoolQueryBuilder
;
}
}
public
static
BoolQueryBuilder
assembleCacheMapsQueryWithProject
(
String
projectId
,
List
<
String
>
mediaTypes
)
{
BoolQueryBuilder
nestedBoolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// must key
nestedBoolQueryBuilder
.
must
(
cacheMapsNestedQuery
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.project_id.keyword"
,
projectId
)));
// mediaType
if
(
CollectionUtils
.
isNotEmpty
(
mediaTypes
))
{
BoolQueryBuilder
mediaTypeQueryBuilder
=
QueryBuilders
.
boolQuery
();
mediaTypes
.
forEach
(
e
->
{
mediaTypeQueryBuilder
.
should
(
cacheMapsNestedQuery
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.channel_type.keyword"
,
e
)));
});
nestedBoolQueryBuilder
.
must
(
mediaTypeQueryBuilder
);
}
return
nestedBoolQueryBuilder
;
}
public
static
BoolQueryBuilder
assembleCacheMapsQueryExcludePrimaryId
(
String
projectId
){
public
static
BoolQueryBuilder
assembleCacheMapsQueryExcludePrimaryId
(
String
projectId
){
BoolQueryBuilder
query
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
query
=
QueryBuilders
.
boolQuery
();
query
.
must
(
cacheMapsNestedQuery
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.project_id.keyword"
,
projectId
)));
query
.
must
(
cacheMapsNestedQuery
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.project_id.keyword"
,
projectId
)));
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/BaseMap.java
View file @
b37abbcd
...
@@ -70,6 +70,10 @@ public class BaseMap {
...
@@ -70,6 +70,10 @@ public class BaseMap {
private
JSONObject
sourceJson
;
private
JSONObject
sourceJson
;
private
String
brandName
;
private
Double
channelEmotionIndex
;
/**
/**
* 当标题为空时用文本截取前20个字代替
* 当标题为空时用文本截取前20个字代替
*
*
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/external/BaseMapCompound.java
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
import
com.zhiwei.base.category.ClassB
;
import
com.zhiwei.brandkbs2.common.GlobalPojo
;
import
com.zhiwei.brandkbs2.pojo.BaseMap
;
import
com.zhiwei.brandkbs2.pojo.BaseMap
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -25,4 +28,24 @@ public class BaseMapCompound {
...
@@ -25,4 +28,24 @@ public class BaseMapCompound {
*/
*/
private
List
<
String
>
tags
;
private
List
<
String
>
tags
;
public
static
BaseMapCompound
createFromBaseMap
(
BaseMap
baseMap
,
String
projectId
)
{
List
<
String
>
tagList
=
new
ArrayList
<>();
// 情感倾向
tagList
.
add
(
baseMap
.
getEmotion
());
// 媒体类型
String
mediaType
=
GlobalPojo
.
getMediaType
(
projectId
,
baseMap
.
getPlatform
(),
baseMap
.
getSource
());
if
(
null
!=
mediaType
)
{
tagList
.
add
(
mediaType
);
}
// 仅针对微博平台的 原创/转发 标签
if
(
ClassB
.
TypeB
.
INCOMPLETE
.
equals
(
baseMap
.
getTypeB
()))
{
tagList
.
add
(
baseMap
.
isForward
()
?
"转发"
:
"原创"
);
}
// 竞品品牌标签
if
(
null
!=
baseMap
.
getBrandName
())
{
tagList
.
add
(
baseMap
.
getBrandName
());
}
return
new
BaseMapCompound
(
baseMap
,
tagList
);
}
}
}
\ No newline at end of file
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsHotEventConfig.java
0 → 100644
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
BrandkbsHotEventConfig
{
private
String
configName
;
/**
* 本品事件
*/
private
List
<
String
>
ownEvent
;
/**
* 竞品事件
*/
private
List
<
String
>
contendsEvent
;
/**
* zhiwei事件
*/
private
List
<
String
>
zhiWeiEvent
;
/**
* 事件top
*/
private
int
eventTop
;
/**
* 时间周期
*/
private
int
timeCycles
;
private
boolean
used
;
public
BrandkbsHotEventConfig
()
{
this
.
used
=
false
;
this
.
timeCycles
=
2
;
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsHotEventWarn.java
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* @ClassName: BrandkbsHotEventWarn
* @ClassName: BrandkbsHotEventWarn
...
@@ -18,7 +20,7 @@ public class BrandkbsHotEventWarn {
...
@@ -18,7 +20,7 @@ public class BrandkbsHotEventWarn {
private
List
<
HotEvent
>
hotEventList
;
private
List
<
HotEvent
>
hotEventList
;
@Data
@Data
public
static
class
HotEvent
{
public
static
class
HotEvent
{
/**
/**
* 类别名称
* 类别名称
...
@@ -59,6 +61,21 @@ public class BrandkbsHotEventWarn {
...
@@ -59,6 +61,21 @@ public class BrandkbsHotEventWarn {
*/
*/
private
List
<
String
>
tagList
;
private
List
<
String
>
tagList
;
public
static
HotEvent
createFromEvent
(
String
type
,
Event
event
)
{
HotEvent
hotEvent
=
new
HotEvent
();
hotEvent
.
setType
(
type
);
hotEvent
.
setTitle
(
event
.
getTitle
());
hotEvent
.
setEmotion
(
event
.
getEmotion
());
hotEvent
.
setTotalChannelVolume
(
event
.
getTotalChannelVolume
());
hotEvent
.
setTotalDisseminationVolume
(
event
.
getTotalDisseminationVolume
());
hotEvent
.
setStartTime
(
event
.
getStartTime
());
hotEvent
.
setInfluence
(
event
.
getInfluence
());
List
<
String
>
tagList
=
event
.
getEventTag
().
entrySet
().
stream
().
filter
(
entry
->
!
"情感倾向"
.
equals
(
entry
.
getKey
())).
map
(
entry
->
String
.
valueOf
(
entry
.
getValue
())).
collect
(
Collectors
.
toList
());
hotEvent
.
setTagList
(
tagList
);
return
hotEvent
;
}
}
}
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsHotTopWarn.java
0 → 100644
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
java.util.List
;
/**
* @ClassName: BrandkbsHotTopWarn
* @Description BrandkbsHotTopWarn
* @author: sjj
* @date: 2022-11-03 17:00
*/
@Data
@AllArgsConstructor
public
class
BrandkbsHotTopWarn
{
private
String
warnKeyword
;
private
String
filterKeyword
;
private
List
<
HotTop
>
list
;
@Data
public
static
class
HotTop
{
/**
* 热搜标题
*/
private
String
title
;
/**
* 上榜理由
*/
private
String
topReason
;
/**
* 上榜排名
*/
private
String
rank
;
/**
* 热度
*/
private
String
hot
;
/**
* 榜单名称
*/
private
String
topName
;
/**
* 上榜时间
*/
private
Long
time
;
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsNewCaseWarn.java
0 → 100644
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
pojo
.
external
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
java.util.List
;
/**
* @ClassName: BrandkbsNewCaseWarn
* @Description BrandkbsNewCaseWarn
* @author: sjj
* @date: 2022-11-03 17:11
*/
@Data
@AllArgsConstructor
public
class
BrandkbsNewCaseWarn
{
private
List
<
NewCase
>
list
;
@Data
public
static
class
NewCase
{
/**
* 标题
*/
private
String
title
;
/**
* 标签列表
*/
private
List
<
String
>
tagList
;
/**
* 正文本
*/
private
String
content
;
/**
* 公关传播效果指数
*/
private
Double
spreadIndex
;
/**
* 案例类别
*/
private
String
caseType
;
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/external/BrandkbsWarnTemplate.java
View file @
b37abbcd
...
@@ -11,13 +11,66 @@ import lombok.Data;
...
@@ -11,13 +11,66 @@ import lombok.Data;
*/
*/
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
public
class
BrandkbsWarnTemplate
<
T
>
{
public
class
BrandkbsWarnTemplate
{
int
firstCount
;
private
String
id
;
String
keyword1
;
private
String
detailsUrl
;
String
keyword2
;
private
int
firstCount
;
String
keyword3
;
private
String
keyword1
;
String
keyword4
;
private
String
keyword2
;
T
warnDetails
;
private
String
keyword3
;
private
String
keyword4
;
private
BrandkbsYuQingWarn
warn1
;
private
BrandkbsChannelWarn
warn2
;
private
BrandkbsHotEventWarn
warn3
;
private
BrandkbsHotTopWarn
warn4
;
private
BrandkbsNewCaseWarn
warn5
;
private
String
warnType
;
private
Long
pushTime
;
public
BrandkbsWarnTemplate
(
int
firstCount
,
String
keyword1
,
String
keyword2
,
String
keyword3
,
String
keyword4
,
BrandkbsYuQingWarn
warn1
)
{
this
.
firstCount
=
firstCount
;
this
.
keyword1
=
keyword1
;
this
.
keyword2
=
keyword2
;
this
.
keyword3
=
keyword3
;
this
.
keyword4
=
keyword4
;
this
.
warn1
=
warn1
;
}
public
BrandkbsWarnTemplate
(
int
firstCount
,
String
keyword1
,
String
keyword2
,
String
keyword3
,
String
keyword4
,
BrandkbsChannelWarn
warn2
)
{
this
.
firstCount
=
firstCount
;
this
.
keyword1
=
keyword1
;
this
.
keyword2
=
keyword2
;
this
.
keyword3
=
keyword3
;
this
.
keyword4
=
keyword4
;
this
.
warn2
=
warn2
;
}
public
BrandkbsWarnTemplate
(
int
firstCount
,
String
keyword1
,
String
keyword2
,
String
keyword3
,
String
keyword4
,
BrandkbsHotEventWarn
warn3
)
{
this
.
firstCount
=
firstCount
;
this
.
keyword1
=
keyword1
;
this
.
keyword2
=
keyword2
;
this
.
keyword3
=
keyword3
;
this
.
keyword4
=
keyword4
;
this
.
warn3
=
warn3
;
}
public
BrandkbsWarnTemplate
(
int
firstCount
,
String
keyword1
,
String
keyword2
,
String
keyword3
,
String
keyword4
,
BrandkbsHotTopWarn
warn4
)
{
this
.
firstCount
=
firstCount
;
this
.
keyword1
=
keyword1
;
this
.
keyword2
=
keyword2
;
this
.
keyword3
=
keyword3
;
this
.
keyword4
=
keyword4
;
this
.
warn4
=
warn4
;
}
public
BrandkbsWarnTemplate
(
int
firstCount
,
String
keyword1
,
String
keyword2
,
String
keyword3
,
String
keyword4
,
BrandkbsNewCaseWarn
warn5
)
{
this
.
firstCount
=
firstCount
;
this
.
keyword1
=
keyword1
;
this
.
keyword2
=
keyword2
;
this
.
keyword3
=
keyword3
;
this
.
keyword4
=
keyword4
;
this
.
warn5
=
warn5
;
}
}
}
src/main/java/com/zhiwei/brandkbs2/service/ProjectWarnService.java
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
service
;
package
com
.
zhiwei
.
brandkbs2
.
service
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsChannelConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsHotEventConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsHotTopConfig
;
import
com.zhiwei.brandkbs2.pojo.external.BrandkbsYuQingConfig
;
public
interface
ProjectWarnService
{
public
interface
ProjectWarnService
{
...
@@ -12,4 +16,16 @@ public interface ProjectWarnService {
...
@@ -12,4 +16,16 @@ public interface ProjectWarnService {
*/
*/
ResponseResult
getProjectWarnCriteria
(
String
projectId
,
String
type
);
ResponseResult
getProjectWarnCriteria
(
String
projectId
,
String
type
);
ResponseResult
getProjectWarnCriteriaDefault
(
String
projectId
,
String
type
);
ResponseResult
getYuqingWaring
(
String
projectId
,
BrandkbsYuQingConfig
brandkbsYuQingConfig
);
ResponseResult
getChannelWaring
(
String
projectId
,
BrandkbsChannelConfig
brandkbsChannelConfig
);
ResponseResult
getHotEventWaring
(
String
projectId
,
BrandkbsHotEventConfig
brandkbsHotEventConfig
);
ResponseResult
getHotTopWaring
(
String
projectId
,
BrandkbsHotTopConfig
config
);
ResponseResult
getNewCaseWaring
(
String
projectId
);
}
}
src/main/java/com/zhiwei/brandkbs2/service/impl/ProjectWarnServiceImpl.java
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
.
service
.
impl
;
package
com
.
zhiwei
.
brandkbs2
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
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.ChannelDao
;
import
com.zhiwei.brandkbs2.dao.EventDao
;
import
com.zhiwei.brandkbs2.enmus.EmotionEnum
;
import
com.zhiwei.brandkbs2.es.EsClientDao
;
import
com.zhiwei.brandkbs2.es.EsClientDao
;
import
com.zhiwei.brandkbs2.es.EsQueryTools
;
import
com.zhiwei.brandkbs2.es.EsQueryTools
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.AbstractProject
;
import
com.zhiwei.brandkbs2.pojo.*
;
import
com.zhiwei.brandkbs2.pojo.BaseMap
;
import
com.zhiwei.brandkbs2.pojo.external.*
;
import
com.zhiwei.brandkbs2.pojo.external.*
;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.service.ProjectWarnService
;
import
com.zhiwei.brandkbs2.service.ProjectWarnService
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.search.SearchHits
;
import
org.elasticsearch.search.SearchHits
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -36,12 +45,24 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
...
@@ -36,12 +45,24 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
private
static
final
Long
ONE_MINUTE
=
60
*
1000L
;
private
static
final
Long
ONE_MINUTE
=
60
*
1000L
;
@Value
(
"${ef.external.filterNew.url}"
)
private
String
getExternalFilterNewUrl
;
@Autowired
private
RestTemplate
restTemplate
;
@Resource
(
name
=
"projectServiceImpl"
)
@Resource
(
name
=
"projectServiceImpl"
)
ProjectService
projectService
;
ProjectService
projectService
;
@Resource
(
name
=
"esClientDao"
)
@Resource
(
name
=
"esClientDao"
)
EsClientDao
esClientDao
;
EsClientDao
esClientDao
;
@Resource
(
name
=
"channelDao"
)
ChannelDao
channelDao
;
@Resource
(
name
=
"eventDao"
)
EventDao
eventDao
;
@Override
@Override
public
ResponseResult
getProjectWarnCriteria
(
String
projectId
,
String
type
)
{
public
ResponseResult
getProjectWarnCriteria
(
String
projectId
,
String
type
)
{
Map
<
String
,
Object
>
res
=
new
HashMap
<>();
Map
<
String
,
Object
>
res
=
new
HashMap
<>();
...
@@ -115,16 +136,65 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
...
@@ -115,16 +136,65 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
return
ResponseResult
.
success
(
res
);
return
ResponseResult
.
success
(
res
);
}
}
@Override
public
ResponseResult
getProjectWarnCriteriaDefault
(
String
projectId
,
String
type
)
{
switch
(
type
)
{
case
"舆情动态"
:
BrandkbsYuQingConfig
config
=
new
BrandkbsYuQingConfig
();
config
.
setChannelTypes
(
Collections
.
singletonList
(
"央级"
));
config
.
setPrimary
(
Collections
.
singletonList
(
Boolean
.
TRUE
));
config
.
setMarkerTags
(
Collections
.
singletonList
(
"负面"
));
config
.
setDuplicate
(
Boolean
.
FALSE
);
config
.
setPushInterval
(
10
*
ONE_MINUTE
);
return
ResponseResult
.
success
(
config
);
case
"渠道参与"
:
BrandkbsChannelConfig
config2
=
new
BrandkbsChannelConfig
();
config2
.
setFriendlyChannel
(
null
);
config2
.
setPrimary
(
Collections
.
singletonList
(
Boolean
.
TRUE
));
config2
.
setMarkerTags
(
Collections
.
singletonList
(
"负面"
));
config2
.
setDuplicate
(
Boolean
.
TRUE
);
config2
.
setPushInterval
(
10
*
ONE_MINUTE
);
return
ResponseResult
.
success
(
config2
);
case
"热点事件"
:
BrandkbsHotEventConfig
config3
=
new
BrandkbsHotEventConfig
();
config3
.
setOwnEvent
(
Arrays
.
asList
(
"正面"
,
"中性"
,
"负面"
));
List
<
JSONObject
>
brands
=
projectService
.
getBrands
(
projectId
,
false
);
List
<
String
>
idList
=
brands
.
stream
().
map
(
json
->
json
.
getString
(
"contendId"
)).
collect
(
Collectors
.
toList
());
config3
.
setContendsEvent
(
idList
);
List
<
String
>
zhiWeiEventList
=
Arrays
.
asList
(
"社会"
,
"互联网"
,
"政务"
,
"财经"
,
"企业"
,
"娱乐"
,
"灾难"
,
"违法犯罪"
,
"国际"
,
"体育"
,
"谣言"
);
config3
.
setZhiWeiEvent
(
zhiWeiEventList
);
config3
.
setEventTop
(
10
);
// 对应周一
config3
.
setTimeCycles
(
2
);
return
ResponseResult
.
success
(
config3
);
case
"上榜热搜"
:
BrandkbsHotTopConfig
config4
=
new
BrandkbsHotTopConfig
();
config4
.
setListType
(
Collections
.
singletonList
(
"微博热搜"
));
config4
.
setFirstTop
(
true
);
config4
.
setNewHeight
(
true
);
config4
.
setTopNewHeight
(
5
);
config4
.
setTopOnceAgain
(
true
);
config4
.
setIntroduction
(
true
);
config4
.
setPushInterval
(
5
*
ONE_MINUTE
);
return
ResponseResult
.
success
(
config4
);
case
"案例上新"
:
}
return
ResponseResult
.
success
();
}
private
ResponseResult
yuqingWaringReal
(
String
projectId
,
BrandkbsYuQingConfig
config
)
{
private
ResponseResult
yuqingWaringReal
(
String
projectId
,
BrandkbsYuQingConfig
config
)
{
String
contendId
=
Constant
.
PRIMARY_CONTEND_ID
;
Project
project
=
null
;
AbstractProject
project
=
null
;
long
end
=
System
.
currentTimeMillis
();
long
start
=
end
-
config
.
getPushInterval
();
try
{
try
{
project
=
projectService
.
getProjectBy
ContendId
(
projectId
,
contend
Id
);
project
=
projectService
.
getProjectBy
Id
(
project
Id
);
log
.
info
(
"获取舆情动态预警开始,project:{}"
,
project
.
getProjectName
());
log
.
info
(
"获取舆情动态预警开始,project:{}"
,
project
.
getProjectName
());
EsClientDao
.
SearchHelper
helper
=
EsClientDao
.
createSearchHelper
();
EsClientDao
.
SearchHelper
helper
=
EsClientDao
.
createSearchHelper
();
// 发声渠道
// 发声渠道
BoolQueryBuilder
postFilter
=
EsQueryTools
.
assembleCacheMapsQuery
(
projectId
,
project
.
getBrandLinkedGroupId
(),
contendId
,
config
.
getChannelTypes
());
BoolQueryBuilder
postFilter
=
EsQueryTools
.
assembleCacheMapsQueryWithProject
(
projectId
,
config
.
getChannelTypes
());
// 时间(标注时间)
postFilter
.
must
(
QueryBuilders
.
rangeQuery
(
"mtime"
).
gte
(
start
).
lt
(
end
));
// 文章类型
// 文章类型
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getPrimary
())
&&
config
.
getPrimary
().
size
()
==
1
)
{
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getPrimary
())
&&
config
.
getPrimary
().
size
()
==
1
)
{
postFilter
.
must
(
EsQueryTools
.
assembleForwardQuery
(
config
.
getPrimary
().
get
(
0
)));
postFilter
.
must
(
EsQueryTools
.
assembleForwardQuery
(
config
.
getPrimary
().
get
(
0
)));
...
@@ -141,25 +211,325 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
...
@@ -141,25 +211,325 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
// 关键词命中
// 关键词命中
postFilter
.
must
(
EsQueryTools
.
assembleNormalKeywordQuery
(
config
.
getKeyword
(),
new
String
[]{
GenericAttribute
.
ES_IND_FULL_TEXT
}));
postFilter
.
must
(
EsQueryTools
.
assembleNormalKeywordQuery
(
config
.
getKeyword
(),
new
String
[]{
GenericAttribute
.
ES_IND_FULL_TEXT
}));
SearchHits
searchHits
=
esClientDao
.
searchHits
(
helper
);
SearchHits
searchHits
=
esClientDao
.
searchHits
(
helper
);
List
<
BaseMap
>
datas
=
Arrays
.
stream
(
searchHits
.
getHits
()).
map
(
hit
->
{
Map
<
String
,
Object
>
sourceMap
=
hit
.
getSourceAsMap
();
BaseMap
baseMap
=
Tools
.
getBaseFromEsMap
(
sourceMap
);
JSONObject
hitMap
=
Tools
.
getBrandkbsHitMapWithProjectId
(
sourceMap
,
projectId
);
if
(!
hitMap
.
isEmpty
()
&&
!
Constant
.
PRIMARY_CONTEND_ID
.
equals
(
hitMap
.
getString
(
"contend_id"
)))
{
baseMap
.
setBrandName
(
projectService
.
getProjectByContendId
(
projectId
,
hitMap
.
getString
(
"contend_id"
)).
getBrandName
());
}
return
baseMap
;
}).
collect
(
Collectors
.
toList
());
// 开启去重
// 开启去重
if
(
Boolean
.
TRUE
.
equals
(
config
.
getDuplicate
()))
{
if
(
Boolean
.
TRUE
.
equals
(
config
.
getDuplicate
()))
{
datas
=
duplicateBaseMapList
(
datas
);
}
}
log
.
info
(
"获取舆情动态预警结束,project:{}"
,
project
.
getProjectName
());
log
.
info
(
"获取舆情动态预警结束,project:{}"
,
project
.
getProjectName
());
}
catch
(
IOException
e
)
{
// 封装返回值
return
ResponseResult
.
success
(
brandkbsWarnTemplate4Yuqing
(
config
,
datas
,
start
,
end
,
project
));
}
catch
(
Exception
e
)
{
log
.
info
(
"获取舆情动态预警失败,project:{}"
,
project
.
getProjectName
(),
e
);
log
.
info
(
"获取舆情动态预警失败,project:{}"
,
project
.
getProjectName
(),
e
);
}
}
return
ResponseResult
.
failure
(
"获取舆情动态预警失败"
);
}
private
BrandkbsWarnTemplate
brandkbsWarnTemplate4Yuqing
(
BrandkbsYuQingConfig
config
,
List
<
BaseMap
>
datas
,
long
start
,
long
end
,
AbstractProject
project
)
{
if
(
datas
.
isEmpty
())
{
return
null
;
}
int
firstCount
=
datas
.
size
();
// key1
String
key1
=
"【品见】舆情动态"
+
project
.
getProjectName
();
// key2
String
key2Header
=
"全部"
;
StringBuilder
mediaChannel
=
new
StringBuilder
();
config
.
getChannelTypes
().
forEach
(
channelType
->
mediaChannel
.
append
(
channelType
).
append
(
"、"
));
if
(
0
!=
mediaChannel
.
length
())
{
key2Header
=
mediaChannel
.
deleteCharAt
(
mediaChannel
.
length
()
-
1
).
toString
();
}
key2Header
+=
"媒体,"
;
StringBuilder
dataType
=
new
StringBuilder
();
config
.
getMarkerTags
().
forEach
(
emotion
->
dataType
.
append
(
emotion
).
append
(
" "
));
dataType
.
append
(
"(本品)"
);
// 如果有竞品
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getContends
()))
{
dataType
.
append
(
","
);
config
.
getContends
().
forEach
(
contend
->
dataType
.
append
(
contend
).
append
(
" "
));
dataType
.
append
(
"(竞品)"
);
}
String
key2
=
key2Header
+
dataType
;
// key3
String
key3
=
Constant
.
SPEC_MINUTE_FORMAT
.
format
(
start
)
+
" ~ "
+
Constant
.
SPEC_MINUTE_FORMAT
.
format
(
end
);
// key4
String
key4
;
StringBuilder
keyBuilder4
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
BaseMap
baseMap
=
datas
.
get
(
i
);
String
platform
=
baseMap
.
getPlatform
();
String
source
=
baseMap
.
getSource
();
String
title
=
baseMap
.
getTitle
();
keyBuilder4
.
append
(
platform
).
append
(
"-"
).
append
(
source
).
append
(
"/r/n"
);
keyBuilder4
.
append
(
i
+
1
).
append
(
"、"
).
append
(
title
).
append
(
"/r/n"
);
}
if
(
datas
.
size
()
>
2
)
{
key4
=
keyBuilder4
.
append
(
"..."
).
toString
();
}
else
{
key4
=
keyBuilder4
.
substring
(
0
,
keyBuilder4
.
length
()
-
4
);
}
List
<
BaseMapCompound
>
collect
=
datas
.
stream
().
map
(
baseMap
->
BaseMapCompound
.
createFromBaseMap
(
baseMap
,
project
.
getId
())).
collect
(
Collectors
.
toList
());
return
new
BrandkbsWarnTemplate
(
firstCount
,
key1
,
key2
,
key3
,
key4
,
new
BrandkbsYuQingWarn
(
collect
));
}
private
ResponseResult
channelWarnReal
(
String
projectId
,
BrandkbsChannelConfig
config
)
{
Project
project
=
null
;
long
end
=
System
.
currentTimeMillis
();
long
start
=
end
-
config
.
getPushInterval
();
try
{
project
=
projectService
.
getProjectById
(
projectId
);
log
.
info
(
"获取渠道参与预警开始,project:{}"
,
project
.
getProjectName
());
EsClientDao
.
SearchHelper
helper
=
EsClientDao
.
createSearchHelper
();
BoolQueryBuilder
postFilter
=
EsQueryTools
.
assembleCacheMapsQuery
(
project
.
getId
(),
project
.
getBrandLinkedGroupId
(),
"0"
);
// 时间(标注时间)
postFilter
.
must
(
QueryBuilders
.
rangeQuery
(
"mtime"
).
gte
(
start
).
lt
(
end
));
// 自定义渠道
if
(
null
!=
config
.
getChannel
())
{
postFilter
.
must
(
QueryBuilders
.
termsQuery
(
"source"
,
Arrays
.
asList
(
config
.
getChannel
().
split
(
"\\|"
))));
}
// 文章类型
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getPrimary
())
&&
config
.
getPrimary
().
size
()
==
1
)
{
postFilter
.
must
(
EsQueryTools
.
assembleForwardQuery
(
config
.
getPrimary
().
get
(
0
)));
}
// 本品舆情
BoolQueryBuilder
sourceBuilder
=
QueryBuilders
.
boolQuery
();
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getMarkerTags
()))
{
sourceBuilder
.
should
(
QueryBuilders
.
termQuery
(
"brandkbs_mark_cache_maps.name.keyword"
,
config
.
getMarkerTags
()));
}
postFilter
.
must
(
sourceBuilder
);
// 搜索结果
SearchHits
searchHits
=
esClientDao
.
searchHits
(
helper
);
List
<
BaseMap
>
datas
=
Arrays
.
stream
(
searchHits
.
getHits
()).
map
(
hit
->
Tools
.
getBaseFromEsMap
(
hit
.
getSourceAsMap
())).
collect
(
Collectors
.
toList
());
// 开启去重
if
(
Boolean
.
TRUE
.
equals
(
config
.
getDuplicate
()))
{
datas
=
duplicateBaseMapList
(
datas
);
}
// 渠道指数筛选
if
(
null
!=
config
.
getFriendlyChannel
())
{
Map
<
String
,
BaseMap
>
collect
=
datas
.
stream
().
collect
(
Collectors
.
toMap
(
baseMap
->
Tools
.
getFid
(
projectId
,
"0"
,
baseMap
.
getPlatform
(),
baseMap
.
getRealSource
(),
baseMap
.
getSource
()),
map
->
map
));
// 通过筛选的fid列表
Map
<
String
,
Channel
>
fidChannel
=
channelDao
.
queryUniqueAsync
(
collect
.
keySet
()).
entrySet
().
stream
().
map
(
entry
->
{
Channel
channel
=
entry
.
getValue
();
if
(
config
.
getFriendlyChannel
())
{
// 需要友好渠道
if
(
EmotionEnum
.
POSITIVE
.
getState
()
!=
channel
.
getEmotion
())
{
return
null
;
return
null
;
}
}
}
else
{
// 需要敏感渠道
if
(
EmotionEnum
.
NEGATIVE
.
getState
()
!=
channel
.
getEmotion
())
{
return
null
;
}
}
// 需要达到额定阈值
if
(
channel
.
getEmotionIndex
()
<
config
.
getThreshold
())
{
return
null
;
}
return
entry
;
}).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
Map
.
Entry
::
getValue
));
// setChannelEmotionIndex
datas
=
collect
.
entrySet
().
stream
().
filter
(
entry
->
fidChannel
.
containsKey
(
entry
.
getKey
())).
map
(
entry
->
{
Channel
channel
=
fidChannel
.
get
(
entry
.
getKey
());
entry
.
getValue
().
setChannelEmotionIndex
(
channel
.
getEmotionIndex
());
return
entry
.
getValue
();
}).
collect
(
Collectors
.
toList
());
}
log
.
info
(
"获取渠道参与预警结束,project:{}"
,
project
.
getProjectName
());
// 封装返回值
return
ResponseResult
.
success
(
brandkbsWarnTemplate4Channel
(
config
,
datas
,
start
,
end
,
project
));
}
catch
(
Exception
e
)
{
log
.
info
(
"获取渠道参与预警失败,project:{}"
,
project
.
getProjectName
(),
e
);
}
return
ResponseResult
.
failure
(
"获取渠道参与预警失败"
);
}
private
<
T
>
BrandkbsWarnTemplate
<
T
>
getWarnTemplate
(
T
t
)
{
private
BrandkbsWarnTemplate
brandkbsWarnTemplate4Channel
(
BrandkbsChannelConfig
config
,
List
<
BaseMap
>
datas
,
long
start
,
long
end
,
AbstractProject
project
)
{
if
(
datas
.
isEmpty
())
{
return
null
;
}
int
firstCount
=
datas
.
size
();
// key1
String
key1
=
"【品见】渠道参与"
+
project
.
getProjectName
();
// key2
String
key2
=
"自定义渠道"
;
if
(
Boolean
.
TRUE
.
equals
(
config
.
getFriendlyChannel
()))
{
key2
=
"友好渠道"
;
}
else
if
(
Boolean
.
FALSE
.
equals
(
config
.
getFriendlyChannel
()))
{
key2
=
"敏感渠道"
;
}
// key3
String
key3
=
Constant
.
SPEC_MINUTE_FORMAT
.
format
(
start
)
+
" ~ "
+
Constant
.
SPEC_MINUTE_FORMAT
.
format
(
end
);
// key4
String
key4
;
StringBuilder
keyBuilder4
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
BaseMap
baseMap
=
datas
.
get
(
i
);
String
platform
=
baseMap
.
getPlatform
();
String
source
=
baseMap
.
getSource
();
String
title
=
baseMap
.
getTitle
();
keyBuilder4
.
append
(
platform
).
append
(
"-"
).
append
(
source
).
append
(
"/r/n"
);
keyBuilder4
.
append
(
i
+
1
).
append
(
"、"
).
append
(
title
).
append
(
"/r/n"
);
}
if
(
datas
.
size
()
>
2
)
{
key4
=
keyBuilder4
.
append
(
"..."
).
toString
();
}
else
{
key4
=
keyBuilder4
.
substring
(
0
,
keyBuilder4
.
length
()
-
4
);
}
List
<
BaseMapCompound
>
collect
=
datas
.
stream
().
map
(
baseMap
->
BaseMapCompound
.
createFromBaseMap
(
baseMap
,
project
.
getId
())).
collect
(
Collectors
.
toList
());
return
new
BrandkbsWarnTemplate
(
firstCount
,
key1
,
key2
,
key3
,
key4
,
new
BrandkbsYuQingWarn
(
collect
));
}
private
ResponseResult
hotEventWaring
(
String
projectId
,
BrandkbsHotEventConfig
config
)
{
Project
project
=
projectService
.
getProjectById
(
projectId
);
long
end
=
System
.
currentTimeMillis
();
long
start
=
end
-
Constant
.
ONE_DAY
*
7
;
try
{
log
.
info
(
"获取热点事件预警开始,project:{}"
,
project
.
getProjectName
());
Map
<
String
,
List
<
Event
>>
eventMap
=
new
LinkedHashMap
<>();
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getOwnEvent
()))
{
List
<
Event
>
ownEvents
=
eventDao
.
getEventsByProjectIdAndContendId
(
start
,
end
,
config
.
getOwnEvent
(),
projectId
,
"0"
,
config
.
getEventTop
());
eventMap
.
put
(
"品牌动态"
,
ownEvents
);
}
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getContendsEvent
()))
{
List
<
Event
>
contentEvents
=
new
ArrayList
<>();
for
(
String
contendId
:
config
.
getContendsEvent
())
{
contentEvents
.
addAll
(
eventDao
.
getEventsByProjectIdAndContendId
(
start
,
end
,
config
.
getOwnEvent
(),
projectId
,
contendId
,
config
.
getEventTop
()));
}
eventMap
.
put
(
"友商动态"
,
contentEvents
);
}
if
(
CollectionUtils
.
isNotEmpty
(
config
.
getZhiWeiEvent
()))
{
List
<
Event
>
externalEvents
=
new
ArrayList
<>();
ResponseEntity
<
String
>
forEntity
=
restTemplate
.
getForEntity
(
getExternalFilterNewUrl
,
String
.
class
,
config
.
getZhiWeiEvent
().
toArray
(),
start
,
end
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
forEntity
.
getBody
());
JSONArray
jsonArray
=
jsonObject
.
getJSONObject
(
"data"
).
getJSONArray
(
"events"
);
for
(
int
i
=
0
;
i
<
config
.
getEventTop
();
i
++)
{
JSONObject
zhiweiEvent
=
jsonArray
.
getJSONObject
(
i
);
Event
event
=
new
Event
();
event
.
setTitle
(
zhiweiEvent
.
getString
(
"eventname"
));
JSONObject
eventTag
=
new
JSONObject
();
// TODO 存疑
eventTag
.
put
(
"事件类型"
,
zhiweiEvent
.
getString
(
"type"
));
event
.
setEventTag
(
eventTag
);
event
.
setTotalDisseminationVolume
(
zhiweiEvent
.
getLong
(
"total"
));
event
.
setStartTime
(
zhiweiEvent
.
getLong
(
"startTime"
));
event
.
setInfluence
(
zhiweiEvent
.
getDouble
(
"index"
));
externalEvents
.
add
(
event
);
}
eventMap
.
put
(
"行业动态"
,
externalEvents
);
}
log
.
info
(
"获取热点事件预警结束,project:{}"
,
project
.
getProjectName
());
return
ResponseResult
.
success
(
brandkbsWarnTemplate4HotEvent
(
config
,
eventMap
,
start
,
end
,
project
));
}
catch
(
Exception
e
)
{
log
.
info
(
"获取热点事件预警失败,project:{}"
,
project
.
getProjectName
(),
e
);
}
return
ResponseResult
.
failure
(
"获取热点事件预警失败"
);
}
private
BrandkbsWarnTemplate
brandkbsWarnTemplate4HotEvent
(
BrandkbsHotEventConfig
config
,
Map
<
String
,
List
<
Event
>>
eventMap
,
long
start
,
long
end
,
AbstractProject
project
)
{
int
firstCount
=
eventMap
.
values
().
stream
().
mapToInt
(
List:
:
size
).
sum
();
if
(
firstCount
==
0
)
{
return
null
;
}
String
key1
=
"【品见】热点事件"
+
project
.
getProjectName
();
// key2
String
key2
=
null
;
// key3
String
key3
=
Constant
.
SPEC_MINUTE_FORMAT
.
format
(
start
)
+
" ~ "
+
Constant
.
SPEC_MINUTE_FORMAT
.
format
(
end
);
// key4
String
key4
;
StringBuilder
keyBuilder4
=
new
StringBuilder
();
int
limit
=
2
;
out:
for
(
List
<
Event
>
value
:
eventMap
.
values
())
{
for
(
Event
event
:
value
)
{
keyBuilder4
.
append
(
event
.
getTitle
()).
append
(
"/r/n"
);
if
(--
limit
==
0
)
{
break
out
;
}
}
}
if
(
firstCount
>
2
)
{
key4
=
keyBuilder4
.
append
(
"..."
).
toString
();
}
else
{
key4
=
keyBuilder4
.
substring
(
0
,
keyBuilder4
.
length
()
-
4
);
}
List
<
BrandkbsHotEventWarn
.
HotEvent
>
collect
=
eventMap
.
entrySet
().
stream
().
map
(
entry
->
entry
.
getValue
().
stream
().
map
(
event
->
BrandkbsHotEventWarn
.
HotEvent
.
createFromEvent
(
entry
.
getKey
(),
event
)).
collect
(
Collectors
.
toList
())).
collect
(
Collectors
.
toList
()).
stream
().
flatMap
(
List:
:
stream
).
collect
(
Collectors
.
toList
());
return
new
BrandkbsWarnTemplate
(
firstCount
,
key1
,
key2
,
key3
,
key4
,
new
BrandkbsHotEventWarn
(
collect
));
}
private
List
<
BaseMap
>
duplicateBaseMapList
(
List
<
BaseMap
>
datas
)
{
Map
<
String
,
BaseMap
>
duplicateMap
=
new
LinkedHashMap
<>();
for
(
BaseMap
data
:
datas
)
{
String
key
=
data
.
getTitleNullOptionalContent
();
BaseMap
newValue
;
if
(
duplicateMap
.
containsKey
(
key
))
{
BaseMap
oldValue
=
duplicateMap
.
get
(
key
);
// 取最早时间的数据
newValue
=
data
.
getTime
()
<
oldValue
.
getTime
()
?
data
:
oldValue
;
}
else
{
newValue
=
data
;
}
duplicateMap
.
put
(
key
,
newValue
);
}
return
new
ArrayList
<>(
duplicateMap
.
values
());
}
private
BrandkbsWarnTemplate
getWarnTemplate
(
BrandkbsYuQingWarn
warn1
)
{
int
firstCount
=
1
;
String
keyword1
=
"【品见】舆情动态-阿里"
;
String
keyword2
=
"央级、门户媒体,负面(本品)"
;
String
keyword3
=
"2022.02.03 08:00 ~ 2022.02.03 08:10"
;
String
keyword4
=
"网媒-人民网\r\n1、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n平媒-人民日报\r\n2、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n..."
;
return
new
BrandkbsWarnTemplate
(
firstCount
,
keyword1
,
keyword2
,
keyword3
,
keyword4
,
warn1
);
}
private
BrandkbsWarnTemplate
getWarnTemplate
(
BrandkbsChannelWarn
warn2
)
{
int
firstCount
=
1
;
int
firstCount
=
1
;
String
keyword1
=
"【品见】舆情动态-阿里"
;
String
keyword1
=
"【品见】舆情动态-阿里"
;
String
keyword2
=
"央级、门户媒体,负面(本品)"
;
String
keyword2
=
"央级、门户媒体,负面(本品)"
;
String
keyword3
=
"2022.02.03 08:00 ~ 2022.02.03 08:10"
;
String
keyword3
=
"2022.02.03 08:00 ~ 2022.02.03 08:10"
;
String
keyword4
=
"网媒-人民网\
n1、顺丰快递全球发售1.31亿股,引入阿里巴巴等\n平媒-人民日报
"
;
String
keyword4
=
"网媒-人民网\
r\n1、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n平媒-人民日报\r\n2、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n...
"
;
return
new
BrandkbsWarnTemplate
<>(
firstCount
,
keyword1
,
keyword2
,
keyword3
,
keyword4
,
t
);
return
new
BrandkbsWarnTemplate
(
firstCount
,
keyword1
,
keyword2
,
keyword3
,
keyword4
,
warn2
);
}
}
private
BrandkbsWarnTemplate
getWarnTemplate
(
BrandkbsHotEventWarn
warn3
)
{
int
firstCount
=
1
;
String
keyword1
=
"【品见】舆情动态-阿里"
;
String
keyword2
=
"央级、门户媒体,负面(本品)"
;
String
keyword3
=
"2022.02.03 08:00 ~ 2022.02.03 08:10"
;
String
keyword4
=
"网媒-人民网\r\n1、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n平媒-人民日报\r\n2、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n..."
;
return
new
BrandkbsWarnTemplate
(
firstCount
,
keyword1
,
keyword2
,
keyword3
,
keyword4
,
warn3
);
}
private
BrandkbsWarnTemplate
getWarnTemplate
(
BrandkbsHotTopWarn
warn4
)
{
int
firstCount
=
1
;
String
keyword1
=
"【品见】舆情动态-阿里"
;
String
keyword2
=
"央级、门户媒体,负面(本品)"
;
String
keyword3
=
"2022.02.03 08:00 ~ 2022.02.03 08:10"
;
String
keyword4
=
"网媒-人民网\r\n1、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n平媒-人民日报\r\n2、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n..."
;
return
new
BrandkbsWarnTemplate
(
firstCount
,
keyword1
,
keyword2
,
keyword3
,
keyword4
,
warn4
);
}
private
BrandkbsWarnTemplate
getWarnTemplate
(
BrandkbsNewCaseWarn
warn5
)
{
int
firstCount
=
1
;
String
keyword1
=
"【品见】舆情动态-阿里"
;
String
keyword2
=
"央级、门户媒体,负面(本品)"
;
String
keyword3
=
"2022.02.03 08:00 ~ 2022.02.03 08:10"
;
String
keyword4
=
"网媒-人民网\r\n1、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n平媒-人民日报\r\n2、顺丰快递全球发售1.31亿股,引入阿里巴巴等\r\n..."
;
return
new
BrandkbsWarnTemplate
(
firstCount
,
keyword1
,
keyword2
,
keyword3
,
keyword4
,
warn5
);
}
private
BaseMapCompound
getBaseMapCompoundTemplate
()
{
private
BaseMapCompound
getBaseMapCompoundTemplate
()
{
BaseMap
baseMap
=
new
BaseMap
();
BaseMap
baseMap
=
new
BaseMap
();
baseMap
.
setTitle
(
"和府捞面新故事难讲"
);
baseMap
.
setTitle
(
"和府捞面新故事难讲"
);
...
@@ -187,19 +557,55 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
...
@@ -187,19 +557,55 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
return
hotEvent
;
return
hotEvent
;
}
}
private
BrandkbsHotTopWarn
.
HotTop
getHotTopTemplate
()
{
BrandkbsHotTopWarn
.
HotTop
hotTop
=
new
BrandkbsHotTopWarn
.
HotTop
();
hotTop
.
setTitle
(
"阿里疫情防控"
);
hotTop
.
setTopReason
(
"排名新高"
);
hotTop
.
setRank
(
"18名"
);
hotTop
.
setHot
(
"44.5W"
);
hotTop
.
setTopName
(
"微博热搜"
);
hotTop
.
setTime
(
System
.
currentTimeMillis
());
return
hotTop
;
}
private
BrandkbsNewCaseWarn
.
NewCase
getNewCaseWarn
()
{
BrandkbsNewCaseWarn
.
NewCase
newCase
=
new
BrandkbsNewCaseWarn
.
NewCase
();
newCase
.
setTitle
(
"椰树集团直播带货风格引争议"
);
newCase
.
setTagList
(
Arrays
.
asList
(
"椰树集团"
,
"价值观问题"
));
newCase
.
setContent
(
"2022年10月8日,据媒体报道..."
);
newCase
.
setSpreadIndex
(
85.5
);
newCase
.
setCaseType
(
"营销风险"
);
return
newCase
;
}
@Override
@Override
public
ResponseResult
getYuqingWaring
(
String
projectId
,
BrandkbsYuQingConfig
config
)
{
public
ResponseResult
getYuqingWaring
(
String
projectId
,
BrandkbsYuQingConfig
config
)
{
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsYuQingWarn
(
Arrays
.
asList
(
getBaseMapCompoundTemplate
()))));
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsYuQingWarn
(
Arrays
.
asList
(
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
()))));
}
}
@Override
@Override
public
ResponseResult
getChannelWaring
(
String
projectId
,
BrandkbsChannelConfig
brandkbsChannelConfig
)
{
public
ResponseResult
getChannelWaring
(
String
projectId
,
BrandkbsChannelConfig
brandkbsChannelConfig
)
{
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsChannelWarn
(
Arrays
.
asList
(
getBaseMapCompoundTemplate
()),
"敏感渠道(敏感指数>70)"
)));
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsChannelWarn
(
Arrays
.
asList
(
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
(),
getBaseMapCompoundTemplate
()),
"敏感渠道(敏感指数>70)"
)));
}
}
@Override
@Override
public
ResponseResult
getHotEventWaring
(
String
projectId
,
BrandkbsHotEventConfig
brandkbsHotEventConfig
)
{
public
ResponseResult
getHotEventWaring
(
String
projectId
,
BrandkbsHotEventConfig
brandkbsHotEventConfig
)
{
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsHotEventWarn
(
Arrays
.
asList
(
getHotEventTemplate
()))));
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsHotEventWarn
(
Arrays
.
asList
(
getHotEventTemplate
(),
getHotEventTemplate
(),
getHotEventTemplate
(),
getHotEventTemplate
(),
getHotEventTemplate
()))));
}
@Override
public
ResponseResult
getHotTopWaring
(
String
projectId
,
BrandkbsHotTopConfig
config
)
{
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsHotTopWarn
(
"阿里"
,
"腾讯"
,
Arrays
.
asList
(
getHotTopTemplate
(),
getHotTopTemplate
(),
getHotTopTemplate
(),
getHotTopTemplate
(),
getHotTopTemplate
()))));
}
@Override
public
ResponseResult
getNewCaseWaring
(
String
projectId
)
{
return
ResponseResult
.
success
(
getWarnTemplate
(
new
BrandkbsNewCaseWarn
(
Arrays
.
asList
(
getNewCaseWarn
(),
getNewCaseWarn
(),
getNewCaseWarn
(),
getNewCaseWarn
(),
getNewCaseWarn
()))));
}
}
public
static
class
CriteriaHelper
{
public
static
class
CriteriaHelper
{
...
@@ -225,11 +631,11 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
...
@@ -225,11 +631,11 @@ public class ProjectWarnServiceImpl implements ProjectWarnService {
value
.
add
(
map
);
value
.
add
(
map
);
}
}
// 设置默认值
// 设置默认值
if
(
null
!=
defaultValue
)
{
//
if (null != defaultValue) {
Map
<
String
,
Object
>
defaultMap
=
new
HashMap
<>();
//
Map<String, Object> defaultMap = new HashMap<>();
defaultMap
.
put
(
"defaultValue"
,
defaultValue
);
//
defaultMap.put("defaultValue", defaultValue);
value
.
add
(
defaultMap
);
//
value.add(defaultMap);
}
//
}
warnCriteriaAdd
(
res
,
key
,
value
);
warnCriteriaAdd
(
res
,
key
,
value
);
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
View file @
b37abbcd
...
@@ -894,6 +894,16 @@ public class Tools {
...
@@ -894,6 +894,16 @@ public class Tools {
return
new
JSONObject
();
return
new
JSONObject
();
}
}
public
static
JSONObject
getBrandkbsHitMapWithProjectId
(
Map
<
String
,
Object
>
esMap
,
String
projectId
)
{
List
<
Map
<
String
,
Object
>>
cacheMaps
=
(
List
<
Map
<
String
,
Object
>>)
esMap
.
get
(
GenericAttribute
.
ES_BRANDKBS_CACHE_MAPS
);
for
(
Map
<
String
,
Object
>
cacheMap
:
cacheMaps
)
{
if
(
projectId
.
equals
(
cacheMap
.
get
(
"project_id"
)))
{
return
new
JSONObject
(
cacheMap
);
}
}
return
new
JSONObject
();
}
public
static
<
T
>
Map
<
String
,
T
>
sortTimeKeyMap
(
Map
<
String
,
T
>
map
,
FastDateFormat
timePattern
,
boolean
isDesc
)
{
public
static
<
T
>
Map
<
String
,
T
>
sortTimeKeyMap
(
Map
<
String
,
T
>
map
,
FastDateFormat
timePattern
,
boolean
isDesc
)
{
Map
<
String
,
T
>
res
=
new
LinkedHashMap
<>();
Map
<
String
,
T
>
res
=
new
LinkedHashMap
<>();
List
<
Map
.
Entry
<
String
,
T
>>
sortKey
=
map
.
entrySet
().
stream
().
sorted
((
x
,
y
)
->
{
List
<
Map
.
Entry
<
String
,
T
>>
sortKey
=
map
.
entrySet
().
stream
().
sorted
((
x
,
y
)
->
{
...
...
src/test/java/com/zhiwei/brandkbs2/BrandkbsIndexCreateTest.java
0 → 100644
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.indices.CreateIndexRequest
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.unit.TimeValue
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
BrandkbsIndexCreateTest
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
BrandkbsIndexCreateTest
.
class
);
@Resource
(
name
=
"esClient"
)
RestHighLevelClient
esClient
;
@Test
public
void
test1
()
throws
IOException
{
String
channelIndex
=
"brandkbs2_channel_record_2023"
;
// String brandkbsIndex = "brandkbs2_2022";
// putChannelIndex(channelIndex);
// putBrandkbsIndex("brandkbs2_2018","brandkbs2_2019","brandkbs2_2020","brandkbs2_2021");
putBrandkbsIndex
(
"brandkbs2_2017"
);
}
public
void
putChannelIndex
(
String
...
indexes
)
throws
IOException
{
for
(
String
index
:
indexes
)
{
CreateIndexRequest
createIndexRequest
=
new
CreateIndexRequest
(
index
);
// 设置分片和副本
createIndexRequest
.
settings
(
Settings
.
builder
().
put
(
"number_of_shards"
,
"7"
).
put
(
"number_of_replicas"
,
"1"
));
Map
<
String
,
Object
>
properties
=
new
HashMap
<>();
builder
(
properties
,
"long"
,
"article_count"
,
false
);
builder
(
properties
,
"text"
,
"channel_fid"
,
true
);
builder
(
properties
,
"text"
,
"channel_id"
,
true
);
builder
(
properties
,
"text"
,
"contend_id"
,
true
);
builder
(
properties
,
"integer"
,
"emotion"
,
false
);
builder
(
properties
,
"float"
,
"emotion_index"
,
false
);
builder
(
properties
,
"text"
,
"key"
,
true
);
builder
(
properties
,
"text"
,
"linked_group_id"
,
true
);
builder
(
properties
,
"keyword"
,
"platform_id"
,
false
);
builder
(
properties
,
"text"
,
"project_id"
,
true
);
builder
(
properties
,
"long"
,
"range_end_time"
,
false
);
builder
(
properties
,
"long"
,
"range_start_time"
,
false
);
builder
(
properties
,
"keyword"
,
"real_source"
,
false
);
builder
(
properties
,
"integer"
,
"shards"
,
false
);
builder
(
properties
,
"keyword"
,
"source"
,
false
);
recordCache
(
properties
);
Map
<
String
,
Object
>
mapping
=
new
HashMap
<>();
mapping
.
put
(
"properties"
,
properties
);
createIndexRequest
.
mapping
(
mapping
);
//设置超时时间 分钟
createIndexRequest
.
setTimeout
(
TimeValue
.
timeValueMinutes
(
1
));
//设置主节点超时时间
createIndexRequest
.
setMasterTimeout
(
TimeValue
.
timeValueMinutes
(
1
));
esClient
.
indices
().
create
(
createIndexRequest
,
RequestOptions
.
DEFAULT
);
log
.
info
(
"索引:{}已创建"
,
index
);
}
}
public
void
putBrandkbsIndex
(
String
...
indexes
)
throws
IOException
{
for
(
String
index
:
indexes
)
{
CreateIndexRequest
createIndexRequest
=
new
CreateIndexRequest
(
index
);
// 设置分片和副本
createIndexRequest
.
settings
(
Settings
.
builder
().
put
(
"number_of_shards"
,
"7"
).
put
(
"number_of_replicas"
,
"1"
));
Map
<
String
,
Object
>
properties
=
new
HashMap
<>();
builder
(
properties
,
"text"
,
"agg_title"
,
true
);
builder
(
properties
,
"text"
,
"answer_avatar_url"
,
true
);
builder
(
properties
,
"long"
,
"answer_comment_num"
,
false
);
builder
(
properties
,
"text"
,
"answer_ip_location"
,
true
);
builder
(
properties
,
"long"
,
"answer_like_num"
,
false
);
builder
(
properties
,
"long"
,
"answer_read_num"
,
false
);
builder
(
properties
,
"long"
,
"answer_time"
,
false
);
builder
(
properties
,
"text"
,
"answer_uid"
,
true
);
builder
(
properties
,
"text"
,
"answer_url"
,
true
);
builder
(
properties
,
"text"
,
"answer_user_url"
,
true
);
builder
(
properties
,
"text"
,
"answer_username"
,
true
);
builder
(
properties
,
"text"
,
"app_name"
,
true
);
builder
(
properties
,
"text"
,
"avatar_url"
,
true
);
brandkbsMapCache
(
properties
);
brandkbsMarkCache
(
properties
);
markMapCache
(
properties
);
builder
(
properties
,
"integer"
,
"c1"
,
false
);
builder
(
properties
,
"integer"
,
"c2"
,
false
);
builder
(
properties
,
"integer"
,
"c3"
,
false
);
builder
(
properties
,
"integer"
,
"c4"
,
false
);
builder
(
properties
,
"integer"
,
"c5"
,
false
);
builder
(
properties
,
"text"
,
"ccid"
,
true
);
builder
(
properties
,
"text"
,
"channel"
,
true
);
builder
(
properties
,
"long"
,
"channel_followers_num"
,
false
);
builder
(
properties
,
"float"
,
"channel_influence"
,
false
);
builder
(
properties
,
"text"
,
"channel_tag"
,
true
);
builder
(
properties
,
"long"
,
"cid"
,
false
);
builder
(
properties
,
"text"
,
"cname"
,
true
);
builder
(
properties
,
"text"
,
"columns"
,
true
);
builder
(
properties
,
"long"
,
"comment_num"
,
false
);
builder
(
properties
,
"text"
,
"company"
,
true
);
builder
(
properties
,
"long"
,
"created_at"
,
false
);
builder
(
properties
,
"long"
,
"ctime"
,
false
);
builder
(
properties
,
"text"
,
"description"
,
true
);
builder
(
properties
,
"text"
,
"editor"
,
true
);
builder
(
properties
,
"long"
,
"favourites_num"
,
false
);
builder
(
properties
,
"long"
,
"followers_num"
,
false
);
builder
(
properties
,
"integer"
,
"foreign"
,
false
);
builder
(
properties
,
"long"
,
"forward_num"
,
false
);
builder
(
properties
,
"long"
,
"friends_num"
,
false
);
builder
(
properties
,
"text"
,
"gender"
,
true
);
builder
(
properties
,
"long"
,
"gid"
,
false
);
builder
(
properties
,
"text"
,
"host"
,
true
);
builder
(
properties
,
"text"
,
"id"
,
true
);
builder
(
properties
,
"text"
,
"ind_content"
,
true
);
builder
(
properties
,
"text"
,
"ind_full_text"
,
true
);
builder
(
properties
,
"text"
,
"ind_title"
,
true
);
builder
(
properties
,
"text"
,
"ip_location"
,
true
);
builder
(
properties
,
"boolean"
,
"is_forward"
,
false
);
builder
(
properties
,
"text"
,
"length"
,
true
);
builder
(
properties
,
"long"
,
"like_num"
,
false
);
builder
(
properties
,
"text"
,
"location"
,
true
);
builder
(
properties
,
"long"
,
"mgid"
,
false
);
builder
(
properties
,
"text"
,
"mgroup"
,
true
);
builder
(
properties
,
"text"
,
"mid"
,
true
);
builder
(
properties
,
"text"
,
"mperson"
,
true
);
builder
(
properties
,
"text"
,
"mtag"
,
true
);
builder
(
properties
,
"long"
,
"mtime"
,
false
);
builder
(
properties
,
"text"
,
"mupdate"
,
true
);
builder
(
properties
,
"text"
,
"mupdate_two"
,
true
);
builder
(
properties
,
"text"
,
"origin"
,
true
);
builder
(
properties
,
"text"
,
"pic_urls"
,
true
);
builder
(
properties
,
"keyword"
,
"platform_id"
,
false
);
builder
(
properties
,
"long"
,
"play_num"
,
false
);
builder
(
properties
,
"text"
,
"position"
,
true
);
builder
(
properties
,
"long"
,
"post_num"
,
false
);
builder
(
properties
,
"long"
,
"question_answer_num"
,
false
);
builder
(
properties
,
"text"
,
"question_avatar_url"
,
true
);
builder
(
properties
,
"long"
,
"question_comment_num"
,
false
);
builder
(
properties
,
"long"
,
"question_followers_num"
,
false
);
builder
(
properties
,
"text"
,
"question_id"
,
true
);
builder
(
properties
,
"text"
,
"question_ip_location"
,
true
);
builder
(
properties
,
"long"
,
"question_like_num"
,
false
);
builder
(
properties
,
"long"
,
"question_read_num"
,
false
);
builder
(
properties
,
"long"
,
"question_time"
,
false
);
builder
(
properties
,
"text"
,
"question_uid"
,
true
);
builder
(
properties
,
"text"
,
"question_url"
,
true
);
builder
(
properties
,
"text"
,
"question_username"
,
true
);
builder
(
properties
,
"long"
,
"read_num"
,
false
);
builder
(
properties
,
"text"
,
"real_name"
,
true
);
builder
(
properties
,
"keyword"
,
"real_source"
,
false
);
builder
(
properties
,
"long"
,
"reply_num"
,
false
);
builder
(
properties
,
"text"
,
"reporter"
,
true
);
builder
(
properties
,
"text"
,
"root_app_name"
,
true
);
builder
(
properties
,
"text"
,
"root_avatar_url"
,
true
);
builder
(
properties
,
"long"
,
"root_comment_num"
,
false
);
builder
(
properties
,
"long"
,
"root_created_at"
,
false
);
builder
(
properties
,
"text"
,
"root_description"
,
true
);
builder
(
properties
,
"long"
,
"root_favourites_num"
,
false
);
builder
(
properties
,
"long"
,
"root_followers_num"
,
false
);
builder
(
properties
,
"long"
,
"root_forward_num"
,
false
);
builder
(
properties
,
"long"
,
"root_friends_num"
,
false
);
builder
(
properties
,
"text"
,
"root_gender"
,
true
);
builder
(
properties
,
"text"
,
"root_ip_location"
,
true
);
builder
(
properties
,
"long"
,
"root_like_num"
,
false
);
builder
(
properties
,
"text"
,
"root_location"
,
true
);
builder
(
properties
,
"text"
,
"root_mid"
,
true
);
builder
(
properties
,
"text"
,
"root_pic_urls"
,
true
);
builder
(
properties
,
"long"
,
"root_post_num"
,
false
);
builder
(
properties
,
"long"
,
"root_read_num"
,
false
);
builder
(
properties
,
"long"
,
"root_reply_num"
,
false
);
builder
(
properties
,
"text"
,
"root_screen_name"
,
true
);
builder
(
properties
,
"text"
,
"root_source"
,
true
);
builder
(
properties
,
"long"
,
"root_time"
,
false
);
builder
(
properties
,
"text"
,
"root_uid"
,
true
);
builder
(
properties
,
"text"
,
"root_url"
,
true
);
builder
(
properties
,
"boolean"
,
"root_verified"
,
false
);
builder
(
properties
,
"text"
,
"root_verified_reason"
,
true
);
builder
(
properties
,
"text"
,
"root_vtype"
,
true
);
builder
(
properties
,
"text"
,
"screen_name"
,
true
);
builder
(
properties
,
"long"
,
"share_num"
,
false
);
builder
(
properties
,
"keyword"
,
"source"
,
false
);
builder
(
properties
,
"long"
,
"stime"
,
false
);
builder
(
properties
,
"long"
,
"time"
,
false
);
builder
(
properties
,
"text"
,
"top_domain"
,
true
);
builder
(
properties
,
"text"
,
"uid"
,
true
);
builder
(
properties
,
"text"
,
"user_id"
,
true
);
builder
(
properties
,
"boolean"
,
"verified"
,
false
);
builder
(
properties
,
"text"
,
"video_urls"
,
true
);
builder
(
properties
,
"text"
,
"verified_reason"
,
true
);
builder
(
properties
,
"long"
,
"vtype"
,
false
);
Map
<
String
,
Object
>
mapping
=
new
HashMap
<>();
mapping
.
put
(
"properties"
,
properties
);
createIndexRequest
.
mapping
(
mapping
);
//设置超时时间 分钟
createIndexRequest
.
setTimeout
(
TimeValue
.
timeValueMinutes
(
1
));
//设置主节点超时时间
createIndexRequest
.
setMasterTimeout
(
TimeValue
.
timeValueMinutes
(
1
));
esClient
.
indices
().
create
(
createIndexRequest
,
RequestOptions
.
DEFAULT
);
log
.
info
(
"索引:{}已创建"
,
index
);
}
}
public
static
void
recordCache
(
Map
<
String
,
Object
>
properties
)
{
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj2
=
new
HashMap
<>();
builder
(
obj2
,
"integer"
,
"emotion"
,
false
);
builder
(
obj2
,
"text"
,
"id"
,
true
);
builder
(
obj2
,
"long"
,
"mtime"
,
false
);
builder
(
obj2
,
"long"
,
"time"
,
false
);
builder
(
obj2
,
"long"
,
"last_time"
,
false
);
message
.
put
(
"properties"
,
obj2
);
properties
.
put
(
"mark_cache_maps"
,
message
);
}
public
static
void
markMapCache
(
Map
<
String
,
Object
>
properties
)
{
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj2
=
new
HashMap
<>();
builder
(
obj2
,
"long"
,
"group_id"
,
false
);
builder
(
obj2
,
"long"
,
"id"
,
false
);
builder
(
obj2
,
"text"
,
"group_name"
,
true
);
builder
(
obj2
,
"text"
,
"mgroup"
,
true
);
builder
(
obj2
,
"text"
,
"name"
,
true
);
builder
(
obj2
,
"text"
,
"unique_id"
,
true
);
message
.
put
(
"properties"
,
obj2
);
properties
.
put
(
"mark_cache_maps"
,
message
);
}
public
static
void
brandkbsMarkCache
(
Map
<
String
,
Object
>
properties
)
{
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj2
=
new
HashMap
<>();
builder
(
obj2
,
"long"
,
"group_id"
,
false
);
builder
(
obj2
,
"text"
,
"group_name"
,
true
);
builder
(
obj2
,
"long"
,
"id"
,
false
);
builder
(
obj2
,
"text"
,
"mgroup"
,
true
);
builder
(
obj2
,
"text"
,
"name"
,
true
);
builder
(
obj2
,
"text"
,
"unique_id"
,
true
);
message
.
put
(
"properties"
,
obj2
);
properties
.
put
(
"brandkbs_mark_cache_maps"
,
message
);
}
public
static
void
brandkbsMapCache
(
Map
<
String
,
Object
>
properties
)
{
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj2
=
new
HashMap
<>();
builder
(
obj2
,
"integer"
,
"channel_emotion"
,
false
);
builder
(
obj2
,
"text"
,
"channel_id"
,
true
);
builder
(
obj2
,
"text"
,
"channel_type"
,
true
);
builder
(
obj2
,
"text"
,
"contend_id"
,
true
);
builder
(
obj2
,
"text"
,
"key"
,
true
);
builder
(
obj2
,
"text"
,
"linked_group_id"
,
true
);
builder
(
obj2
,
"text"
,
"project_id"
,
true
);
message
.
put
(
"properties"
,
obj2
);
// 设置为nested类型,支持文档独立索引
message
.
put
(
"type"
,
"nested"
);
properties
.
put
(
"brandkbs_cache_maps"
,
message
);
}
public
static
void
builder
(
Map
<
String
,
Object
>
properties
,
String
type
,
String
key
,
boolean
fields
)
{
if
(
fields
&&
!
"text"
.
equals
(
type
))
{
throw
new
RuntimeException
(
"mapping-builder错误"
);
}
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
message
.
put
(
"type"
,
type
);
if
(
fields
)
{
message
.
put
(
"fields"
,
fields
());
}
properties
.
put
(
key
,
message
);
}
public
static
Map
<
String
,
Object
>
fields
()
{
Map
<
String
,
Object
>
res
=
new
HashMap
<>();
Map
<
String
,
Object
>
keyword
=
new
HashMap
<>();
keyword
.
put
(
"type"
,
"keyword"
);
keyword
.
put
(
"ignore_above"
,
256
);
res
.
put
(
"keyword"
,
keyword
);
return
res
;
}
}
src/test/java/com/zhiwei/brandkbs2/ChannelServiceTest.java
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
;
package
com
.
zhiwei
.
brandkbs2
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.pojo.UserInfo
;
import
com.zhiwei.brandkbs2.pojo.vo.ChannelListVO
;
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.ChannelService
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -12,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -12,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.security.PublicKey
;
import
java.util.List
;
import
java.util.List
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
...
@@ -25,7 +21,7 @@ public class ChannelServiceTest {
...
@@ -25,7 +21,7 @@ public class ChannelServiceTest {
@Test
@Test
public
void
getActiveChannelListTest
(){
public
void
getActiveChannelListTest
(){
List
<
ChannelListVO
>
activeChannelList
=
List
<
ChannelListVO
>
activeChannelList
=
channelService
.
getActiveChannelList
(
"0"
,
null
,
null
,
null
,
null
,
50
);
channelService
.
getActiveChannelList
(
"0"
,
null
,
null
,
null
,
null
,
50
,
true
);
for
(
ChannelListVO
channelListVO
:
activeChannelList
)
{
for
(
ChannelListVO
channelListVO
:
activeChannelList
)
{
System
.
out
.
println
(
channelListVO
);
System
.
out
.
println
(
channelListVO
);
}
}
...
@@ -34,7 +30,7 @@ public class ChannelServiceTest {
...
@@ -34,7 +30,7 @@ public class ChannelServiceTest {
@Test
@Test
public
void
getPositiveListTest
(){
public
void
getPositiveListTest
(){
List
<
ChannelListVO
>
positiveList
=
List
<
ChannelListVO
>
positiveList
=
channelService
.
getPositiveList
(
"0"
,
null
,
null
,
"{\"index\":\"descend\"}"
,
null
,
null
,
50
);
channelService
.
getPositiveList
(
"0"
,
null
,
null
,
"{\"index\":\"descend\"}"
,
null
,
null
,
50
,
true
);
for
(
ChannelListVO
channelListVO
:
positiveList
)
{
for
(
ChannelListVO
channelListVO
:
positiveList
)
{
System
.
out
.
println
(
channelListVO
);
System
.
out
.
println
(
channelListVO
);
}
}
...
@@ -43,7 +39,7 @@ public class ChannelServiceTest {
...
@@ -43,7 +39,7 @@ public class ChannelServiceTest {
@Test
@Test
public
void
getNegativeListTest
(){
public
void
getNegativeListTest
(){
List
<
ChannelListVO
>
negativeList
=
List
<
ChannelListVO
>
negativeList
=
channelService
.
getNegativeList
(
"0"
,
null
,
null
,
"{\"index\":\"descend\"}"
,
null
,
null
,
50
);
channelService
.
getNegativeList
(
"0"
,
null
,
null
,
"{\"index\":\"descend\"}"
,
null
,
null
,
50
,
true
);
for
(
ChannelListVO
channelListVO
:
negativeList
)
{
for
(
ChannelListVO
channelListVO
:
negativeList
)
{
System
.
out
.
println
(
channelListVO
);
System
.
out
.
println
(
channelListVO
);
}
}
...
...
src/test/java/com/zhiwei/brandkbs2/MarkDataServiceTest.java
View file @
b37abbcd
package
com
.
zhiwei
.
brandkbs2
;
package
com
.
zhiwei
.
brandkbs2
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.
sun.media.sound.SoftTuning
;
import
com.
zhiwei.brandkbs2.enmus.EmotionEnum
;
import
com.zhiwei.brandkbs2.pojo.BaseMap
;
import
com.zhiwei.brandkbs2.pojo.BaseMap
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.pojo.MarkFlowEntity
;
import
com.zhiwei.brandkbs2.pojo.MarkFlowEntity
;
...
@@ -9,7 +9,6 @@ import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
...
@@ -9,7 +9,6 @@ import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import
com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO
;
import
com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO
;
import
com.zhiwei.brandkbs2.pojo.vo.PageVO
;
import
com.zhiwei.brandkbs2.pojo.vo.PageVO
;
import
com.zhiwei.brandkbs2.service.MarkDataService
;
import
com.zhiwei.brandkbs2.service.MarkDataService
;
import
org.checkerframework.checker.units.qual.K
;
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
;
...
@@ -204,9 +203,15 @@ public class MarkDataServiceTest {
...
@@ -204,9 +203,15 @@ public class MarkDataServiceTest {
@Test
@Test
public
void
getEsTopSourceTest
()
throws
IOException
{
public
void
getEsTopSourceTest
()
throws
IOException
{
List
<
Map
<
String
,
Object
>>
esTopSource
=
markDataService
.
getEsTopSource
(
1658073600000L
,
1661727700000L
,
"62beadd1bbf8eb20f96d2f2e"
,
"136"
,
"0"
,
null
,
5
);
List
<
Map
<
String
,
Object
>>
esTopSource
=
markDataService
.
getEsTopSource
(
1663516800000L
,
1666108800000L
,
"62beadd1bbf8eb20f96d2f1a"
,
"25"
,
"0"
,
EmotionEnum
.
POSITIVE
.
getName
(),
3
);
for
(
Map
<
String
,
Object
>
stringObjectMap
:
esTopSource
)
{
for
(
Map
<
String
,
Object
>
stringObjectMap
:
esTopSource
)
{
System
.
out
.
println
(
stringObjectMap
.
entrySet
());
System
.
out
.
println
(
stringObjectMap
.
entrySet
());
}
}
List
<
Map
<
String
,
Object
>>
esTopSource2
=
markDataService
.
getEsTopSource
(
1663516800000L
,
1666108800000L
,
"62beadd1bbf8eb20f96d2f1a"
,
"25"
,
"0"
,
EmotionEnum
.
NEGATIVE
.
getName
(),
3
);
for
(
Map
<
String
,
Object
>
stringObjectMap
:
esTopSource2
)
{
System
.
out
.
println
(
stringObjectMap
.
entrySet
());
}
}
}
}
}
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