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
00fa99ea
Commit
00fa99ea
authored
Dec 27, 2022
by
shenjunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
渠道es部分修改
parent
3099ff29
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
200 additions
and
133 deletions
+200
-133
src/main/java/com/zhiwei/brandkbs2/dao/impl/ChannelDaoImpl.java
+0
-5
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
+200
-128
No files found.
src/main/java/com/zhiwei/brandkbs2/dao/impl/ChannelDaoImpl.java
View file @
00fa99ea
...
...
@@ -44,11 +44,6 @@ public class ChannelDaoImpl extends BaseMongoDaoImpl<Channel> implements Channel
if
(
null
==
channelIndex
)
{
return
null
;
}
// Query query = Query.query(Criteria.where("linkedGroupId").is(channelIndex.getLinkedGroupId()).
// and("projectId").is(channelIndex.getProjectId()).
// and("platform").is(channelIndex.getPlatform()).
// and("realSource").is(channelIndex.getRealSource()).
// and("source").is(channelIndex.getSource()));
return
queryUnique
(
channelIndex
.
getFid
());
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
View file @
00fa99ea
...
...
@@ -116,7 +116,8 @@ public class ChannelServiceImpl implements ChannelService {
ThreadPoolTaskExecutor
esSearchExecutor
;
@Override
public
PageVO
<
JSONObject
>
findChannelList
(
int
page
,
int
size
,
String
contendId
,
String
emotion
,
String
platform
,
Boolean
show
,
String
keyword
,
String
sorter
)
{
public
PageVO
<
JSONObject
>
findChannelList
(
int
page
,
int
size
,
String
contendId
,
String
emotion
,
String
platform
,
Boolean
show
,
String
keyword
,
String
sorter
)
{
Query
query
=
channelListQuery
(
contendId
,
show
,
emotion
,
platform
,
keyword
,
sorter
);
long
total
=
channelDao
.
count
(
query
);
// 开启分页
...
...
@@ -144,13 +145,15 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public
PageVO
<
JSONObject
>
findChannelListNew
(
int
page
,
int
size
,
String
contendId
,
String
emotion
,
String
platform
,
Boolean
show
,
String
keyword
,
String
sorter
)
{
public
PageVO
<
JSONObject
>
findChannelListNew
(
int
page
,
int
size
,
String
contendId
,
String
emotion
,
String
platform
,
Boolean
show
,
String
keyword
,
String
sorter
)
{
try
{
EsClientDao
.
SearchHelper
searchHelper
=
EsClientDao
.
createSearchHelper
();
List
<
Integer
>
emotions
=
null
==
emotion
?
null
:
Collections
.
singletonList
(
EmotionEnum
.
parseFromName
(
emotion
).
getState
());
List
<
Integer
>
emotions
=
null
==
emotion
?
null
:
Collections
.
singletonList
(
EmotionEnum
.
parseFromName
(
emotion
).
getState
());
List
<
String
>
platforms
=
null
==
platform
?
null
:
Collections
.
singletonList
(
platform
);
BoolQueryBuilder
postFilter
=
getChannelListQuery
(
UserThreadLocal
.
getProjectId
(),
contendId
,
keyword
,
platforms
,
emotions
,
null
,
null
);
BoolQueryBuilder
postFilter
=
getChannelListQuery
(
UserThreadLocal
.
getProjectId
(),
contendId
,
keyword
,
platforms
,
emotions
,
null
,
null
);
// show
if
(
null
!=
show
)
{
postFilter
.
must
(
QueryBuilders
.
termQuery
(
"show"
,
show
));
...
...
@@ -167,7 +170,7 @@ public class ChannelServiceImpl implements ChannelService {
}
searchHelper
.
setFrom
((
page
-
1
)
*
size
);
searchHelper
.
setSize
(
size
);
searchHelper
.
setIndexes
(
new
String
[]{
ChannelEsDao
.
CHANNEL_COPY_ES_INDEX_NAME
});
searchHelper
.
setIndexes
(
new
String
[]
{
ChannelEsDao
.
CHANNEL_COPY_ES_INDEX_NAME
});
SearchHits
searchHits
=
channelEsDao
.
searchHits
(
searchHelper
);
long
value
=
searchHits
.
getTotalHits
().
value
;
List
<
JSONObject
>
resList
=
Arrays
.
stream
(
searchHits
.
getHits
()).
map
(
hit
->
{
...
...
@@ -181,7 +184,8 @@ public class ChannelServiceImpl implements ChannelService {
result
.
put
(
"eventCount"
,
json
.
getLong
(
"event_count"
));
result
.
put
(
"emotion"
,
EmotionEnum
.
state2Name
(
json
.
getInteger
(
"emotion"
)));
result
.
put
(
"emotionIndex"
,
json
.
getDouble
(
"emotion_index"
));
result
.
put
(
"experienceLevel"
,
ExperienceEnum
.
getValueFromDataBaseName
(
json
.
getString
(
"experience_level"
)));
result
.
put
(
"experienceLevel"
,
ExperienceEnum
.
getValueFromDataBaseName
(
json
.
getString
(
"experience_level"
)));
result
.
put
(
"lastTime"
,
json
.
getLong
(
"last_time"
));
result
.
put
(
"show"
,
json
.
getBoolean
(
"show"
));
result
.
put
(
"imgUrl"
,
json
.
getString
(
"avatar_url"
));
...
...
@@ -269,7 +273,7 @@ public class ChannelServiceImpl implements ChannelService {
public
JSONObject
getChannel
(
String
channelId
)
{
Channel
channel
=
channelDao
.
findOneById
(
channelId
);
if
(
Objects
.
isNull
(
channel
))
{
//
抛出未查询到相关ID的渠道信息异常
//
抛出未查询到相关ID的渠道信息异常
ExceptionCast
.
cast
(
CommonCodeEnum
.
FAIL
,
"渠道不存在"
);
}
JSONObject
jsonObject
=
new
JSONObject
();
...
...
@@ -292,7 +296,8 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public
List
<
ExportChannelDTO
>
findDownloadChannelList
(
String
contendId
,
String
emotion
,
String
platform
,
Boolean
show
,
String
keyword
)
{
public
List
<
ExportChannelDTO
>
findDownloadChannelList
(
String
contendId
,
String
emotion
,
String
platform
,
Boolean
show
,
String
keyword
)
{
Query
query
=
channelListQuery
(
contendId
,
show
,
emotion
,
platform
,
keyword
,
null
);
List
<
Channel
>
list
=
channelDao
.
findList
(
query
);
return
list
.
stream
().
map
(
ExportChannelDTO:
:
createFromChannel
).
collect
(
Collectors
.
toList
());
...
...
@@ -337,7 +342,8 @@ public class ChannelServiceImpl implements ChannelService {
dto
.
setFirstSource
(
firstData
.
getSource
());
}
dto
.
setEventArticleCount
(
eventDataDao
.
getEventArticleCount
(
event
));
dto
.
setChannelArticleCount
(
eventDataDao
.
getEventArticleWithChannelCount
(
event
,
Tools
.
convertMap
(
channel
,
ChannelIndex
.
class
)));
dto
.
setChannelArticleCount
(
eventDataDao
.
getEventArticleWithChannelCount
(
event
,
Tools
.
convertMap
(
channel
,
ChannelIndex
.
class
)));
dto
.
setEventType
(
event
.
getEventTag
().
getString
(
EventTagEnum
.
EVENT_TYPE
.
getName
()));
return
dto
;
}).
collect
(
Collectors
.
toList
());
...
...
@@ -350,20 +356,25 @@ public class ChannelServiceImpl implements ChannelService {
@Override
public
List
<
String
>
getChannelLabels
(
String
type
)
{
return
channelLabelDao
.
findList
(
Query
.
query
(
Criteria
.
where
(
"type"
).
is
(
type
))).
stream
().
map
(
ChannelLabel:
:
getLabel
).
collect
(
Collectors
.
toList
());
return
channelLabelDao
.
findList
(
Query
.
query
(
Criteria
.
where
(
"type"
).
is
(
type
))).
stream
()
.
map
(
ChannelLabel:
:
getLabel
).
collect
(
Collectors
.
toList
());
}
@Override
public
List
<
ChannelListVO
>
getActiveChannelList
(
String
contendId
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
int
size
,
boolean
cache
)
{
return
getEmotionList
(
contendId
,
platform
,
keyword
,
null
,
startTime
,
endTime
,
size
,
EmotionEnum
.
ALL
.
getState
(),
cache
);
public
List
<
ChannelListVO
>
getActiveChannelList
(
String
contendId
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
int
size
,
boolean
cache
)
{
return
getEmotionList
(
contendId
,
platform
,
keyword
,
null
,
startTime
,
endTime
,
size
,
EmotionEnum
.
ALL
.
getState
(),
cache
);
}
@Deprecated
public
List
<
ChannelListVO
>
getActiveChannelList2
(
String
contendId
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
int
size
)
{
public
List
<
ChannelListVO
>
getActiveChannelList2
(
String
contendId
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
int
size
)
{
List
<
ChannelListVO
>
resList
=
new
ArrayList
<>();
try
{
String
projectId
=
UserThreadLocal
.
getProjectId
();
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
null
,
Collections
.
singleton
(
contendId
),
platform
,
keyword
,
startTime
,
endTime
);
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
null
,
Collections
.
singleton
(
contendId
),
platform
,
keyword
,
startTime
,
endTime
);
// 只需要聚合结果,不需返回hit
searchHelper
.
setSize
(
0
);
// aggregation
...
...
@@ -405,18 +416,21 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public
List
<
ChannelListVO
>
getPositiveList
(
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
Long
startTime
,
Long
endTime
,
int
size
,
boolean
cache
)
{
return
getEmotionList
(
contendId
,
platform
,
keyword
,
sorter
,
startTime
,
endTime
,
size
,
EmotionEnum
.
POSITIVE
.
getState
(),
cache
);
public
List
<
ChannelListVO
>
getPositiveList
(
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
Long
startTime
,
Long
endTime
,
int
size
,
boolean
cache
)
{
return
getEmotionList
(
contendId
,
platform
,
keyword
,
sorter
,
startTime
,
endTime
,
size
,
EmotionEnum
.
POSITIVE
.
getState
(),
cache
);
}
@Override
public
List
<
ChannelListVO
>
getNegativeList
(
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
Long
startTime
,
Long
endTime
,
int
size
,
boolean
cache
)
{
return
getEmotionList
(
contendId
,
platform
,
keyword
,
sorter
,
startTime
,
endTime
,
size
,
EmotionEnum
.
NEGATIVE
.
getState
(),
cache
);
public
List
<
ChannelListVO
>
getNegativeList
(
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
Long
startTime
,
Long
endTime
,
int
size
,
boolean
cache
)
{
return
getEmotionList
(
contendId
,
platform
,
keyword
,
sorter
,
startTime
,
endTime
,
size
,
EmotionEnum
.
NEGATIVE
.
getState
(),
cache
);
}
private
List
<
ChannelListVO
>
getEmotionList
(
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
Long
startTime
,
Long
endTime
,
int
size
,
int
emotion
,
boolean
cache
)
{
private
List
<
ChannelListVO
>
getEmotionList
(
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
Long
startTime
,
Long
endTime
,
int
size
,
int
emotion
,
boolean
cache
)
{
List
<
ChannelListVO
>
resList
=
new
ArrayList
<>();
try
{
String
projectId
=
UserThreadLocal
.
getProjectId
();
...
...
@@ -427,7 +441,8 @@ public class ChannelServiceImpl implements ChannelService {
return
JSON
.
parseArray
(
resultStr
,
ChannelListVO
.
class
);
}
Map
<
String
,
Pair
<
Long
,
ChannelRecord
>>
keyMap
=
new
HashMap
<>();
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
null
,
Collections
.
singleton
(
contendId
),
platform
,
keyword
,
startTime
,
endTime
);
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
null
,
Collections
.
singleton
(
contendId
),
platform
,
keyword
,
startTime
,
endTime
);
// 分页查询所有结果
List
<
SearchResponse
>
searchResponses
=
channelEsDao
.
searchScrollResponse
(
searchHelper
);
for
(
SearchResponse
searchResponse
:
searchResponses
)
{
...
...
@@ -453,7 +468,8 @@ public class ChannelServiceImpl implements ChannelService {
ChannelRecord
channelRecord
=
pair
.
getRight
();
// 情感过滤
if
(
emotion
==
EmotionEnum
.
ALL
.
getState
()
||
emotion
==
channelRecord
.
getEmotion
())
{
List
<
ChannelIndex
.
Article
>
articles
=
ChannelIndex
.
Record
.
filterArticles
(
startTime
,
endTime
,
channelRecord
.
getRecord
().
getArticles
());
List
<
ChannelIndex
.
Article
>
articles
=
ChannelIndex
.
Record
.
filterArticles
(
startTime
,
endTime
,
channelRecord
.
getRecord
().
getArticles
());
articles
.
sort
(
Comparator
.
comparingLong
(
ChannelIndex
.
Article
::
getTime
).
reversed
());
channelRecord
.
getRecord
().
setArticles
(
articles
);
return
channelRecord
;
...
...
@@ -531,7 +547,8 @@ public class ChannelServiceImpl implements ChannelService {
public
List
<
JSONObject
>
getCollectList
(
String
contendId
)
{
String
projectId
=
UserThreadLocal
.
getProjectId
();
Query
query
=
new
Query
();
query
.
addCriteria
(
Criteria
.
where
(
"projectId"
).
is
(
projectId
).
and
(
"contendId"
).
is
(
contendId
).
and
(
"isCollect"
).
is
(
true
));
query
.
addCriteria
(
Criteria
.
where
(
"projectId"
).
is
(
projectId
).
and
(
"contendId"
).
is
(
contendId
).
and
(
"isCollect"
).
is
(
true
));
channelDao
.
addSort
(
query
,
"{\"collectTime\":\"descend\"}"
);
return
channelDao
.
findList
(
query
).
stream
().
map
(
channel
->
{
JSONObject
json
=
new
JSONObject
();
...
...
@@ -600,7 +617,8 @@ public class ChannelServiceImpl implements ChannelService {
spreadDatas
.
add
(
json
);
}
}
else
{
for
(
Map
.
Entry
<
String
,
List
<
ChannelIndex
.
Article
>>
entry
:
getSourceContendMap
(
channelId
,
contendSet
,
startTime
,
endTime
).
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
ChannelIndex
.
Article
>>
entry
:
getSourceContendMap
(
channelId
,
contendSet
,
startTime
,
endTime
).
entrySet
())
{
JSONObject
json
=
new
JSONObject
();
String
timePattern
=
Constant
.
DAY_PATTERN
;
json
.
put
(
"spreadType"
,
"day"
);
...
...
@@ -632,7 +650,8 @@ public class ChannelServiceImpl implements ChannelService {
}
// 根据品牌分类
List
<
String
>
contendList
=
Arrays
.
asList
(
contends
.
split
(
","
));
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
contendMap
=
getSourceContendMap
(
channelId
,
contendList
,
startTime
,
endTime
);
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
contendMap
=
getSourceContendMap
(
channelId
,
contendList
,
startTime
,
endTime
);
Channel
channel
=
channelDao
.
findOneById
(
channelId
);
long
articleTotal
=
0
;
long
eventTotal
=
0
;
...
...
@@ -661,7 +680,8 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public
JSONObject
getArticlesByTime
(
Long
startTime
,
Long
endTime
,
Integer
dayLimit
,
int
page
,
int
pageSize
,
String
channelId
,
String
contendId
)
{
public
JSONObject
getArticlesByTime
(
Long
startTime
,
Long
endTime
,
Integer
dayLimit
,
int
page
,
int
pageSize
,
String
channelId
,
String
contendId
)
{
JSONObject
res
=
new
JSONObject
();
List
<
JSONObject
>
dayList
=
new
ArrayList
<>();
if
(
0
==
startTime
)
{
...
...
@@ -669,7 +689,8 @@ public class ChannelServiceImpl implements ChannelService {
// 限制起始时间并单天查询
List
<
Long
>
cutTimes
=
Tools
.
parseToDayList
(
startTime
,
endTime
);
for
(
Long
cutTime
:
cutTimes
)
{
List
<
ChannelIndex
.
Article
>
articles
=
getSourceContendMap
(
channelId
,
Collections
.
singleton
(
contendId
),
cutTime
,
cutTime
+
Constant
.
ONE_DAY
).
get
(
contendId
);
List
<
ChannelIndex
.
Article
>
articles
=
getSourceContendMap
(
channelId
,
Collections
.
singleton
(
contendId
),
cutTime
,
cutTime
+
Constant
.
ONE_DAY
).
get
(
contendId
);
if
(!
articles
.
isEmpty
())
{
dayList
.
add
(
getDayResult
(
articles
,
page
,
pageSize
,
cutTime
));
}
...
...
@@ -678,8 +699,10 @@ public class ChannelServiceImpl implements ChannelService {
}
}
}
else
{
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
sourceContendMap
=
getSourceContendMap
(
channelId
,
Collections
.
singleton
(
contendId
),
startTime
,
endTime
);
Map
<
Long
,
List
<
ChannelIndex
.
Article
>>
timeRangeList
=
partition
(
startTime
,
endTime
,
Constant
.
DAY_PATTERN
,
sourceContendMap
.
get
(
contendId
));
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
sourceContendMap
=
getSourceContendMap
(
channelId
,
Collections
.
singleton
(
contendId
),
startTime
,
endTime
);
Map
<
Long
,
List
<
ChannelIndex
.
Article
>>
timeRangeList
=
partition
(
startTime
,
endTime
,
Constant
.
DAY_PATTERN
,
sourceContendMap
.
get
(
contendId
));
for
(
Map
.
Entry
<
Long
,
List
<
ChannelIndex
.
Article
>>
longListEntry
:
timeRangeList
.
entrySet
())
{
Long
time
=
longListEntry
.
getKey
();
List
<
ChannelIndex
.
Article
>
list
=
longListEntry
.
getValue
();
...
...
@@ -698,13 +721,16 @@ public class ChannelServiceImpl implements ChannelService {
@Deprecated
private
Long
getStartTime
(
String
contendId
,
String
channelId
,
Long
endTime
)
{
try
{
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
UserThreadLocal
.
getProjectId
(),
channelId
,
Collections
.
singleton
(
contendId
),
null
,
null
,
null
,
endTime
,
false
);
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
UserThreadLocal
.
getProjectId
(),
channelId
,
Collections
.
singleton
(
contendId
),
null
,
null
,
null
,
endTime
,
false
);
searchHelper
.
setSort
(
SortBuilders
.
fieldSort
(
"record.articles.time"
).
order
(
SortOrder
.
ASC
));
searchHelper
.
setSize
(
1
);
SearchResponse
searchResponse
=
esClientDao
.
searchResponse
(
searchHelper
);
if
(
0
!=
searchResponse
.
getHits
().
getTotalHits
().
value
)
{
ChannelRecord
channelRecord
=
new
ChannelRecord
(
searchResponse
.
getHits
().
getAt
(
0
).
getSourceAsMap
());
return
channelRecord
.
getRecord
().
getArticles
().
stream
().
sorted
(
Comparator
.
comparingLong
(
ChannelIndex
.
Article
::
getTime
)).
limit
(
1
).
collect
(
Collectors
.
toList
()).
get
(
0
).
getTime
();
return
channelRecord
.
getRecord
().
getArticles
().
stream
()
.
sorted
(
Comparator
.
comparingLong
(
ChannelIndex
.
Article
::
getTime
)).
limit
(
1
)
.
collect
(
Collectors
.
toList
()).
get
(
0
).
getTime
();
}
}
catch
(
IOException
e
)
{
ExceptionCast
.
cast
(
CommonCodeEnum
.
FAIL
,
"es查询异常"
);
...
...
@@ -714,7 +740,8 @@ public class ChannelServiceImpl implements ChannelService {
private
JSONObject
getDayResult
(
List
<
ChannelIndex
.
Article
>
list
,
int
page
,
int
pageSize
,
Long
time
)
{
JSONObject
dayResult
=
new
JSONObject
();
List
<
CompletableFuture
<
JSONObject
>>
futureList
=
list
.
stream
().
skip
((
long
)
(
page
-
1
)
*
pageSize
).
limit
(
pageSize
).
map
(
article
->
CompletableFuture
.
supplyAsync
(()
->
{
List
<
CompletableFuture
<
JSONObject
>>
futureList
=
list
.
stream
().
skip
((
long
)
(
page
-
1
)
*
pageSize
)
.
limit
(
pageSize
).
map
(
article
->
CompletableFuture
.
supplyAsync
(()
->
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"emotion"
,
EmotionEnum
.
state2Name
(
article
.
getEmotion
()));
json
.
put
(
"time"
,
article
.
getTime
());
...
...
@@ -747,22 +774,28 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public
List
<
ExportAppChannelArticleDTO
>
downloadArticlesByTime
(
Long
startTime
,
Long
endTime
,
String
channelId
,
String
contendId
)
{
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
sourceContendMap
=
getSourceContendMap
(
channelId
,
Collections
.
singleton
(
contendId
),
startTime
,
endTime
);
List
<
CompletableFuture
<
ExportAppChannelArticleDTO
>>
futureList
=
sourceContendMap
.
get
(
contendId
).
stream
().
map
(
article
->
CompletableFuture
.
supplyAsync
(()
->
{
public
List
<
ExportAppChannelArticleDTO
>
downloadArticlesByTime
(
Long
startTime
,
Long
endTime
,
String
channelId
,
String
contendId
)
{
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
sourceContendMap
=
getSourceContendMap
(
channelId
,
Collections
.
singleton
(
contendId
),
startTime
,
endTime
);
List
<
CompletableFuture
<
ExportAppChannelArticleDTO
>>
futureList
=
sourceContendMap
.
get
(
contendId
).
stream
()
.
map
(
article
->
CompletableFuture
.
supplyAsync
(()
->
{
String
[]
titleContentUrl
=
getTitleContentUrlById
(
article
.
getId
());
return
ExportAppChannelArticleDTO
.
createFromArticle
(
article
,
titleContentUrl
[
0
],
titleContentUrl
[
1
],
titleContentUrl
[
2
]);
return
ExportAppChannelArticleDTO
.
createFromArticle
(
article
,
titleContentUrl
[
0
],
titleContentUrl
[
1
],
titleContentUrl
[
2
]);
},
esSearchExecutor
)).
collect
(
Collectors
.
toList
());
CompletableFuture
.
allOf
(
futureList
.
toArray
(
new
CompletableFuture
[
0
])).
join
();
return
futureList
.
stream
().
map
(
CompletableFuture:
:
join
).
collect
(
Collectors
.
toList
());
}
@Override
public
JSONObject
getEventsByTime
(
Long
startTime
,
Long
endTime
,
int
page
,
int
pageSize
,
String
channelId
,
String
contendId
)
{
public
JSONObject
getEventsByTime
(
Long
startTime
,
Long
endTime
,
int
page
,
int
pageSize
,
String
channelId
,
String
contendId
)
{
JSONObject
res
=
new
JSONObject
();
List
<
JSONObject
>
dayList
=
new
ArrayList
<>();
Channel
channel
=
channelDao
.
findOneById
(
channelId
);
Map
<
Long
,
List
<
Event
>>
eventDay
=
eventDao
.
getEventDay
(
new
ChannelIndex
(
channel
,
contendId
),
startTime
,
endTime
);
Map
<
Long
,
List
<
Event
>>
eventDay
=
eventDao
.
getEventDay
(
new
ChannelIndex
(
channel
,
contendId
),
startTime
,
endTime
);
eventDay
=
Tools
.
sortTimeKeyMap
(
eventDay
,
true
);
eventDay
.
forEach
((
time
,
list
)
->
dayList
.
add
(
getDayResultWithEvent
(
list
,
page
,
pageSize
,
time
)));
res
.
put
(
"list"
,
dayList
);
...
...
@@ -770,10 +803,12 @@ public class ChannelServiceImpl implements ChannelService {
}
@Override
public
List
<
ExportAppChannelEventDTO
>
downloadEventsByTime
(
Long
startTime
,
Long
endTime
,
String
channelId
,
String
contendId
)
{
public
List
<
ExportAppChannelEventDTO
>
downloadEventsByTime
(
Long
startTime
,
Long
endTime
,
String
channelId
,
String
contendId
)
{
List
<
ExportAppChannelEventDTO
>
res
=
new
ArrayList
<>();
Channel
channel
=
channelDao
.
findOneById
(
channelId
);
Map
<
Long
,
List
<
Event
>>
eventDay
=
eventDao
.
getEventDay
(
new
ChannelIndex
(
channel
,
contendId
),
startTime
,
endTime
);
Map
<
Long
,
List
<
Event
>>
eventDay
=
eventDao
.
getEventDay
(
new
ChannelIndex
(
channel
,
contendId
),
startTime
,
endTime
);
Tools
.
sortTimeKeyMap
(
eventDay
,
true
).
values
().
forEach
(
events
->
{
events
.
forEach
(
event
->
{
res
.
add
(
ExportAppChannelEventDTO
.
createFromEvent
(
event
));
...
...
@@ -794,23 +829,26 @@ public class ChannelServiceImpl implements ChannelService {
if
(!
hasEmotion
(
channel
))
{
return
channel
;
}
//
该渠道发布正面稿件
//
该渠道发布正面稿件
Long
positiveCount
=
markCountByEmotion
(
channel
,
EmotionEnum
.
POSITIVE
.
getName
());
//
该渠道发布中性稿件
//
该渠道发布中性稿件
Long
neutralCount
=
markCountByEmotion
(
channel
,
EmotionEnum
.
NEUTRAL
.
getName
());
//
该渠道发布负面稿件
//
该渠道发布负面稿件
Long
negativeCount
=
markCountByEmotion
(
channel
,
EmotionEnum
.
NEGATIVE
.
getName
());
//
是否友好渠道
//
是否友好渠道
boolean
isPositive
=
false
;
boolean
isNegative
=
false
;
long
specNegativeCount
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Arrays
.
asList
(
EmotionEnum
.
POSITIVE
.
getName
(),
EmotionEnum
.
NEUTRAL
.
getName
()),
EmotionEnum
.
NEGATIVE
.
getName
());
long
specPositiveCount
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Collections
.
singletonList
(
EmotionEnum
.
NEGATIVE
.
getName
()),
EmotionEnum
.
POSITIVE
.
getName
());
long
specNegativeCount
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Arrays
.
asList
(
EmotionEnum
.
POSITIVE
.
getName
(),
EmotionEnum
.
NEUTRAL
.
getName
()),
EmotionEnum
.
NEGATIVE
.
getName
());
long
specPositiveCount
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Collections
.
singletonList
(
EmotionEnum
.
NEGATIVE
.
getName
()),
EmotionEnum
.
POSITIVE
.
getName
());
// 特殊情况:若皆有发布过反常稿件
if
(
specNegativeCount
>
0
&&
specPositiveCount
>
0
)
{
//
正面稿件数>负面稿件数,为正面
//
正面稿件数>负面稿件数,为正面
if
(
positiveCount
>
negativeCount
)
{
isPositive
=
true
;
//
正面稿件数<负面稿件数,为负面
//
正面稿件数<负面稿件数,为负面
}
else
if
(
positiveCount
<
negativeCount
)
{
isNegative
=
true
;
}
...
...
@@ -818,10 +856,11 @@ public class ChannelServiceImpl implements ChannelService {
// 在正/中性事件中发布负面稿件||负面报道数>正面报道数(满足任一条件)
if
(
negativeCount
>
positiveCount
)
{
isNegative
=
true
;
//
如果有在正面事件中发布负面稿件
//
如果有在正面事件中发布负面稿件
}
else
if
(
specNegativeCount
>
0
)
{
// 或满足三者复合条件:发布正面稿件>负面稿件&&正面稿件>=中性稿件&&月均参与正面事件数≥4.64
if
(
positiveCount
>
negativeCount
&&
positiveCount
>=
neutralCount
&&
(
this
.
inEventCountMonthAverage
(
channel
,
EmotionEnum
.
POSITIVE
.
getName
())
>=
4.64
))
{
if
(
positiveCount
>
negativeCount
&&
positiveCount
>=
neutralCount
&&
(
this
.
inEventCountMonthAverage
(
channel
,
EmotionEnum
.
POSITIVE
.
getName
())
>=
4.64
))
{
isPositive
=
true
;
}
else
{
isNegative
=
true
;
...
...
@@ -831,13 +870,15 @@ public class ChannelServiceImpl implements ChannelService {
if
(
specPositiveCount
>
0
)
{
isPositive
=
true
;
// 或满足三者复合条件:发布正面稿件>负面稿件&&正面稿件>=中性稿件&&月均参与正面事件数≥4.64
}
else
if
(
positiveCount
>
negativeCount
&&
positiveCount
>=
neutralCount
&&
(
this
.
inEventCountMonthAverage
(
channel
,
EmotionEnum
.
POSITIVE
.
getName
())
>=
4.64
))
{
}
else
if
(
positiveCount
>
negativeCount
&&
positiveCount
>=
neutralCount
&&
(
this
.
inEventCountMonthAverage
(
channel
,
EmotionEnum
.
POSITIVE
.
getName
())
>=
4.64
))
{
isPositive
=
true
;
}
}
}
//更新渠道指数,渠道等级,情感倾向并记录变化
this
.
updateChannel
(
channel
,
project
,
positiveCount
,
neutralCount
,
negativeCount
,
isPositive
,
isNegative
,
specPositiveCount
,
specNegativeCount
);
// 更新渠道指数,渠道等级,情感倾向并记录变化
this
.
updateChannel
(
channel
,
project
,
positiveCount
,
neutralCount
,
negativeCount
,
isPositive
,
isNegative
,
specPositiveCount
,
specNegativeCount
);
}
catch
(
Exception
e
)
{
log
.
error
(
"calculateChannelEmotionIndex-"
,
e
);
}
...
...
@@ -849,8 +890,9 @@ public class ChannelServiceImpl implements ChannelService {
JSONObject
result
=
new
JSONObject
();
// 平台
result
.
put
(
"platformList"
,
commonService
.
getQbjcPlatform
(
"id"
,
"name"
));
//渠道倾向
List
<
ChannelEmotion
>
emotionList
=
Arrays
.
asList
(
ChannelEmotion
.
POSITIVE
,
ChannelEmotion
.
NEUTRAL
,
ChannelEmotion
.
NEGATIVE
);
// 渠道倾向
List
<
ChannelEmotion
>
emotionList
=
Arrays
.
asList
(
ChannelEmotion
.
POSITIVE
,
ChannelEmotion
.
NEUTRAL
,
ChannelEmotion
.
NEGATIVE
);
List
<
JSONObject
>
collect
=
emotionList
.
stream
().
map
(
emotion
->
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"id"
,
emotion
.
getState
());
...
...
@@ -862,18 +904,18 @@ public class ChannelServiceImpl implements ChannelService {
allEmotion
.
put
(
"name"
,
"全部"
);
collect
.
add
(
0
,
allEmotion
);
result
.
put
(
"emotionList"
,
collect
);
//
渠道级别
//
渠道级别
List
<
String
>
mediaTypeList
=
ImportantChannelEnum
.
getAllTagExceptSpec
();
mediaTypeList
.
add
(
0
,
"全部"
);
result
.
put
(
"mediaTypeList"
,
mediaTypeList
);
//
发文数量
//
发文数量
result
.
put
(
"articleList"
,
getArticleList
());
return
result
;
}
@Override
public
PageVO
<
ChannelVO
>
getChannelList
(
int
page
,
int
pageSize
,
String
keyword
,
List
<
String
>
platforms
,
List
<
Integer
>
emotions
,
List
<
String
>
mediaType
s
,
Integer
[]
articlesCount
,
String
sorter
)
{
public
PageVO
<
ChannelVO
>
getChannelList
(
int
page
,
int
pageSize
,
String
keyword
,
List
<
String
>
platform
s
,
List
<
Integer
>
emotions
,
List
<
String
>
mediaTypes
,
Integer
[]
articlesCount
,
String
sorter
)
{
long
s0
=
System
.
currentTimeMillis
();
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
contendId
=
"0"
;
...
...
@@ -881,7 +923,8 @@ public class ChannelServiceImpl implements ChannelService {
Query
query
=
new
Query
(
Criteria
.
where
(
"projectId"
).
is
(
projectId
).
and
(
"contendId"
).
is
(
contendId
));
channelDao
.
addKeywordFuzz
(
query
,
keyword
,
"source"
);
if
(!(
null
==
platforms
||
platforms
.
contains
(
"全部"
)))
{
query
.
addCriteria
(
Criteria
.
where
(
"platform"
).
in
(
platforms
.
stream
().
map
(
GlobalPojo:
:
getPlatformNameById
).
collect
(
Collectors
.
toList
())));
query
.
addCriteria
(
Criteria
.
where
(
"platform"
)
.
in
(
platforms
.
stream
().
map
(
GlobalPojo:
:
getPlatformNameById
).
collect
(
Collectors
.
toList
())));
}
if
(!(
null
==
emotions
||
emotions
.
contains
(-
1
)))
{
query
.
addCriteria
(
Criteria
.
where
(
"emotion"
).
in
(
emotions
));
...
...
@@ -900,16 +943,18 @@ public class ChannelServiceImpl implements ChannelService {
List
<
Channel
>
channelList
=
channelDao
.
findList
(
query
);
long
s2
=
System
.
currentTimeMillis
();
log
.
info
(
"渠道查询耗时:"
+
(
s2
-
s1
));
List
<
CompletableFuture
<
JSONObject
>>
futureList
=
channelList
.
stream
().
map
(
channel
->
CompletableFuture
.
supplyAsync
(()
->
{
List
<
CompletableFuture
<
JSONObject
>>
futureList
=
channelList
.
stream
()
.
map
(
channel
->
CompletableFuture
.
supplyAsync
(()
->
{
JSONObject
result
=
new
JSONObject
();
result
.
put
(
"id"
,
channel
.
getId
());
result
.
put
(
"channel"
,
channel
);
result
.
put
(
"lastArticle"
,
markDataService
.
getLastMarkData
(
projectId
,
linkedGroupId
,
contendId
,
channel
.
getPlatform
(),
channel
.
getRealSource
()
,
channel
.
getSource
()));
result
.
put
(
"lastArticle"
,
markDataService
.
getLastMarkData
(
projectId
,
linkedGroupId
,
contendId
,
channel
.
getPlatform
(),
channel
.
getRealSource
(),
channel
.
getSource
()));
return
result
;
},
esSearchExecutor
)).
collect
(
Collectors
.
toList
());
CompletableFuture
.
allOf
(
futureList
.
toArray
(
new
CompletableFuture
[
0
])).
join
();
Map
<
String
,
JSONObject
>
idMap
=
futureList
.
stream
().
map
(
CompletableFuture:
:
join
).
collect
(
Collectors
.
toMap
(
json
->
json
.
getString
(
"id"
),
a
->
a
));
Map
<
String
,
JSONObject
>
idMap
=
futureList
.
stream
().
map
(
CompletableFuture:
:
join
)
.
collect
(
Collectors
.
toMap
(
json
->
json
.
getString
(
"id"
),
a
->
a
));
// List<JSONObject> resultList = channelList.stream().map(channel -> {
// JSONObject result = new JSONObject();
// result.put("channelInfo", channel);
...
...
@@ -919,25 +964,29 @@ public class ChannelServiceImpl implements ChannelService {
long
s3
=
System
.
currentTimeMillis
();
log
.
info
(
"渠道发文查询耗时:"
+
(
s3
-
s2
));
return
PageVO
.
createPageVo
(
total
,
page
,
pageSize
,
channelList
.
stream
().
map
(
channel
->
ChannelVO
.
createFromChannelInfo
(
idMap
.
get
(
channel
.
getId
()),
projectId
)).
collect
(
Collectors
.
toList
()));
channelList
.
stream
()
.
map
(
channel
->
ChannelVO
.
createFromChannelInfo
(
idMap
.
get
(
channel
.
getId
()),
projectId
))
.
collect
(
Collectors
.
toList
()));
}
@Override
public
PageVO
<
ChannelVO
>
getChannelListNew
(
int
page
,
int
pageSize
,
String
keyword
,
List
<
String
>
platforms
,
List
<
Integer
>
emotions
,
List
<
String
>
mediaType
s
,
Integer
[]
articlesCount
,
String
sorter
)
{
public
PageVO
<
ChannelVO
>
getChannelListNew
(
int
page
,
int
pageSize
,
String
keyword
,
List
<
String
>
platform
s
,
List
<
Integer
>
emotions
,
List
<
String
>
mediaTypes
,
Integer
[]
articlesCount
,
String
sorter
)
{
try
{
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
contendId
=
"0"
;
EsClientDao
.
SearchHelper
searchHelper
=
EsClientDao
.
createSearchHelper
();
BoolQueryBuilder
postFilter
=
getChannelListQuery
(
projectId
,
contendId
,
keyword
,
platforms
,
emotions
,
mediaTypes
,
articlesCount
);
BoolQueryBuilder
postFilter
=
getChannelListQuery
(
projectId
,
contendId
,
keyword
,
platforms
,
emotions
,
mediaTypes
,
articlesCount
);
searchHelper
.
setPostFilter
(
postFilter
);
searchHelper
.
setSort
(
SortBuilders
.
fieldSort
(
"influence"
).
order
(
SortOrder
.
DESC
));
searchHelper
.
setFrom
((
page
-
1
)
*
pageSize
);
searchHelper
.
setSize
(
pageSize
);
searchHelper
.
setIndexes
(
new
String
[]{
ChannelEsDao
.
CHANNEL_COPY_ES_INDEX_NAME
});
searchHelper
.
setIndexes
(
new
String
[]
{
ChannelEsDao
.
CHANNEL_COPY_ES_INDEX_NAME
});
SearchHits
searchHits
=
channelEsDao
.
searchHits
(
searchHelper
);
long
value
=
searchHits
.
getTotalHits
().
value
;
List
<
ChannelVO
>
collect
=
Arrays
.
stream
(
searchHits
.
getHits
()).
map
(
hit
->
ChannelVO
.
createFromChannelCopyMap
(
hit
.
getSourceAsMap
())).
collect
(
Collectors
.
toList
());
List
<
ChannelVO
>
collect
=
Arrays
.
stream
(
searchHits
.
getHits
())
.
map
(
hit
->
ChannelVO
.
createFromChannelCopyMap
(
hit
.
getSourceAsMap
())).
collect
(
Collectors
.
toList
());
return
PageVO
.
createPageVo
(
value
,
page
,
pageSize
,
collect
);
}
catch
(
Exception
e
)
{
log
.
error
(
"getChannelListNew-"
,
e
);
...
...
@@ -945,8 +994,8 @@ public class ChannelServiceImpl implements ChannelService {
return
null
;
}
private
BoolQueryBuilder
getChannelListQuery
(
String
projectId
,
String
contendId
,
String
keyword
,
List
<
String
>
platforms
,
List
<
Integer
>
emotions
,
List
<
String
>
mediaTypes
,
Integer
[]
articlesCount
)
{
private
BoolQueryBuilder
getChannelListQuery
(
String
projectId
,
String
contendId
,
String
keyword
,
List
<
String
>
platforms
,
List
<
Integer
>
emotions
,
List
<
String
>
mediaTypes
,
Integer
[]
articlesCount
)
{
BoolQueryBuilder
postFilter
=
QueryBuilders
.
boolQuery
();
postFilter
.
must
(
QueryBuilders
.
termQuery
(
"project_id.keyword"
,
projectId
));
postFilter
.
must
(
QueryBuilders
.
termQuery
(
"contend_id.keyword"
,
contendId
));
...
...
@@ -957,7 +1006,8 @@ public class ChannelServiceImpl implements ChannelService {
// platform限制
if
(!(
Tools
.
isEmpty
(
platforms
)
||
platforms
.
contains
(
"全部"
)))
{
BoolQueryBuilder
platformBuilder
=
QueryBuilders
.
boolQuery
();
List
<
String
>
collect
=
platforms
.
stream
().
map
(
GlobalPojo:
:
getPlatformNameById
).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
List
<
String
>
collect
=
platforms
.
stream
().
map
(
GlobalPojo:
:
getPlatformNameById
).
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
if
(!
Tools
.
isEmpty
(
collect
))
{
platforms
=
collect
;
}
...
...
@@ -999,7 +1049,7 @@ public class ChannelServiceImpl implements ChannelService {
json
.
put
(
"value"
,
null
);
}
else
{
String
[]
split
=
name
.
substring
(
0
,
name
.
length
()
-
1
).
split
(
"-"
);
json
.
put
(
"value"
,
new
Long
[]{
Long
.
parseLong
(
split
[
0
]),
Long
.
parseLong
(
split
[
1
])
});
json
.
put
(
"value"
,
new
Long
[]
{
Long
.
parseLong
(
split
[
0
]),
Long
.
parseLong
(
split
[
1
])
});
}
res
.
add
(
json
);
}
...
...
@@ -1015,26 +1065,30 @@ public class ChannelServiceImpl implements ChannelService {
* @param neutralCount 中性稿件数
* @param negativeCount 负面稿件数
*/
private
void
updateChannel
(
Channel
channel
,
Project
project
,
long
positiveCount
,
long
neutralCount
,
long
negativeCount
,
boolean
isPositive
,
boolean
isNegative
,
long
specPositiveCount
,
long
specNegativeCount
)
{
private
void
updateChannel
(
Channel
channel
,
Project
project
,
long
positiveCount
,
long
neutralCount
,
long
negativeCount
,
boolean
isPositive
,
boolean
isNegative
,
long
specPositiveCount
,
long
specNegativeCount
)
{
double
index
;
int
emotion
;
// 负面渠道走负面渠道指数计算规则并更新
if
(
isNegative
)
{
//根据各指数计算最终渠道指数
index
=
this
.
negativeChannelIndexRule
(
channel
,
positiveCount
,
negativeCount
,
specNegativeCount
,
project
.
getNegativeChannelParams
());
// 根据各指数计算最终渠道指数
index
=
this
.
negativeChannelIndexRule
(
channel
,
positiveCount
,
negativeCount
,
specNegativeCount
,
project
.
getNegativeChannelParams
());
// TODO 添加或记录变化情况
// this.recordChannelChange(channel, rank, EmotionEnum.NEGATIVE.getState());
emotion
=
EmotionEnum
.
NEGATIVE
.
getState
();
//
正面渠道走正面渠道指数计算规则并更新
//
正面渠道走正面渠道指数计算规则并更新
}
else
if
(
isPositive
)
{
//根据各指数计算最终渠道指数
index
=
this
.
positiveChannelIndexRule
(
channel
,
positiveCount
,
neutralCount
,
negativeCount
,
specPositiveCount
,
project
.
getPositiveChannelParams
());
// 根据各指数计算最终渠道指数
index
=
this
.
positiveChannelIndexRule
(
channel
,
positiveCount
,
neutralCount
,
negativeCount
,
specPositiveCount
,
project
.
getPositiveChannelParams
());
// TODO 添加或记录变化情况
// this.recordChannelChange(channel, rank, EmotionEnum.POSITIVE.getState());
emotion
=
EmotionEnum
.
POSITIVE
.
getState
();
}
else
{
index
=
0
d
;
//
TODO 添加或记录变化情况
//
TODO 添加或记录变化情况
emotion
=
EmotionEnum
.
NEUTRAL
.
getState
();
}
channel
.
setEmotionIndex
(
index
);
...
...
@@ -1052,33 +1106,36 @@ public class ChannelServiceImpl implements ChannelService {
* @param positiveChannelMap 模块配置的正面渠道指数计算比例
* @return 计算指数
*/
private
double
positiveChannelIndexRule
(
Channel
channel
,
long
positiveCount
,
long
neutralCount
,
long
negativeCount
,
long
specPositiveCount
,
Map
<
String
,
Double
>
positiveChannelMap
)
{
//正面稿件数-中性稿件数
private
double
positiveChannelIndexRule
(
Channel
channel
,
long
positiveCount
,
long
neutralCount
,
long
negativeCount
,
long
specPositiveCount
,
Map
<
String
,
Double
>
positiveChannelMap
)
{
// 正面稿件数-中性稿件数
long
value
=
positiveCount
-
neutralCount
;
//
正面-中性得分
//
正面-中性得分
double
neutralScore
=
this
.
getNeutralScore
(
value
);
//
正面稿件数-负面稿件数
//
正面稿件数-负面稿件数
value
=
positiveCount
-
negativeCount
;
//
正面-负面得分
//
正面-负面得分
double
negativeScore
=
this
.
getNegativeScore
(
value
);
//正面事件
value
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Collections
.
singletonList
(
EmotionEnum
.
POSITIVE
.
getName
()),
null
);
//正面事件得分
// 正面事件
value
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Collections
.
singletonList
(
EmotionEnum
.
POSITIVE
.
getName
()),
null
);
// 正面事件得分
double
positiveEventScore
=
this
.
getPositiveEventScore
(
value
);
//
特殊稿件
//
特殊稿件
value
=
specPositiveCount
;
//
特殊稿件得分
//
特殊稿件得分
double
specialArticlesScore
=
this
.
getPositiveSpecialArticlesScore
(
value
);
//
经验评级
//
经验评级
String
experienceStr
=
channel
.
getExperienceLevel
();
//
经验评级得分
//
经验评级得分
double
experienceScore
=
this
.
getPositiveExperienceScore
(
experienceStr
);
Double
neutral
=
positiveChannelMap
.
get
(
"neutral"
);
Double
negative
=
positiveChannelMap
.
get
(
"negative"
);
Double
positiveEvent
=
positiveChannelMap
.
get
(
"positiveEvent"
);
Double
specialArticles
=
positiveChannelMap
.
get
(
"specialArticles"
);
Double
experience
=
positiveChannelMap
.
get
(
"experience"
);
return
neutralScore
*
neutral
+
negativeScore
*
negative
+
positiveEventScore
*
positiveEvent
+
specialArticlesScore
*
specialArticles
+
experienceScore
*
experience
;
return
neutralScore
*
neutral
+
negativeScore
*
negative
+
positiveEventScore
*
positiveEvent
+
specialArticlesScore
*
specialArticles
+
experienceScore
*
experience
;
}
/**
...
...
@@ -1230,27 +1287,29 @@ public class ChannelServiceImpl implements ChannelService {
* @param negativeChannelMap 项目模块配置的负面渠道指数计算比例
* @return 不友好渠道计算指数
*/
private
double
negativeChannelIndexRule
(
Channel
channel
,
long
positiveCount
,
long
negativeCount
,
long
specNegativeCount
,
Map
<
String
,
Double
>
negativeChannelMap
)
{
//负面稿件-正面稿件
private
double
negativeChannelIndexRule
(
Channel
channel
,
long
positiveCount
,
long
negativeCount
,
long
specNegativeCount
,
Map
<
String
,
Double
>
negativeChannelMap
)
{
// 负面稿件-正面稿件
long
value
=
negativeCount
-
positiveCount
;
//
负面稿件数得分
//
负面稿件数得分
double
negativeArticlesScore
=
this
.
getNegativeArticlesScore
(
value
);
//
参与负面事件
//
参与负面事件
value
=
eventDao
.
getEventCount
(
channel
,
Collections
.
singletonList
(
EmotionEnum
.
NEGATIVE
.
getName
()),
null
);
//
参与负面事件得分
//
参与负面事件得分
double
negativeEventScore
=
this
.
getNegativeEventScore
(
value
);
//
特殊稿件
//
特殊稿件
value
=
specNegativeCount
;
//
特殊稿件得分
//
特殊稿件得分
double
specialArticlesScore
=
this
.
getNegativeSpecialArticlesScore
(
value
);
String
experienceStr
=
channel
.
getExperienceLevel
();
//
经验评级得分
//
经验评级得分
double
experienceScore
=
this
.
getNegativeExperienceScore
(
experienceStr
);
Double
negativeArticles
=
negativeChannelMap
.
get
(
"negativeArticles"
);
Double
negativeEvent
=
negativeChannelMap
.
get
(
"negativeEvent"
);
Double
specialArticles
=
negativeChannelMap
.
get
(
"specialArticles"
);
Double
experience
=
negativeChannelMap
.
get
(
"experience"
);
return
negativeArticlesScore
*
negativeArticles
+
negativeEventScore
*
negativeEvent
+
specialArticlesScore
*
specialArticles
+
experienceScore
*
experience
;
return
negativeArticlesScore
*
negativeArticles
+
negativeEventScore
*
negativeEvent
+
specialArticlesScore
*
specialArticles
+
experienceScore
*
experience
;
}
/**
...
...
@@ -1315,7 +1374,6 @@ public class ChannelServiceImpl implements ChannelService {
return
negativeEventScore
;
}
/**
* 渠道计算占比公式
*
...
...
@@ -1357,22 +1415,25 @@ public class ChannelServiceImpl implements ChannelService {
}
private
double
inEventCountMonthAverage
(
Channel
channel
,
String
eventEmotion
)
{
long
eventCount
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Collections
.
singletonList
(
eventEmotion
),
null
);
long
eventCount
=
eventDao
.
getEventCount
(
new
ChannelIndex
(
channel
),
Collections
.
singletonList
(
eventEmotion
),
null
);
Period
periodDays
=
new
Period
(
channel
.
getCTime
(),
System
.
currentTimeMillis
(),
PeriodType
.
months
());
return
(
double
)
eventCount
/
periodDays
.
getMonths
();
}
private
Long
markCountByEmotion
(
Channel
channel
,
String
emotion
)
throws
IOException
{
BoolQueryBuilder
postFilter
=
markDataService
.
projectLinkedGroupContendIdQuery
(
channel
.
getProjectId
(),
channel
.
getLinkedGroup
Id
(),
channel
.
getContendId
());
BoolQueryBuilder
postFilter
=
markDataService
.
projectLinkedGroupContendIdQuery
(
channel
.
getProject
Id
(),
channel
.
getLinkedGroupId
(),
channel
.
getContendId
());
postFilter
.
must
(
QueryBuilders
.
termQuery
(
"brandkbs_mark_cache_maps.name.keyword"
,
emotion
));
return
esClientDao
.
count
(
postFilter
);
}
private
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
getSourceContendMap
(
String
channelId
,
Collection
<
String
>
contendIds
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
)
{
private
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
getSourceContendMap
(
String
channelId
,
Collection
<
String
>
contendIds
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
)
{
try
{
String
projectId
=
UserThreadLocal
.
getProjectId
();
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
channelId
,
contendIds
,
platform
,
keyword
,
startTime
,
endTime
);
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
channelId
,
contendIds
,
platform
,
keyword
,
startTime
,
endTime
);
// 分页查询所有结果
List
<
SearchResponse
>
searchResponses
=
channelEsDao
.
searchScrollResponse
(
searchHelper
);
// 根据品牌分类
...
...
@@ -1383,7 +1444,8 @@ public class ChannelServiceImpl implements ChannelService {
return
Collections
.
emptyMap
();
}
private
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
getSourceContendMap
(
String
channelId
,
Collection
<
String
>
contendIds
,
Long
startTime
,
Long
endTime
)
{
private
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
getSourceContendMap
(
String
channelId
,
Collection
<
String
>
contendIds
,
Long
startTime
,
Long
endTime
)
{
return
getSourceContendMap
(
channelId
,
contendIds
,
null
,
null
,
startTime
,
endTime
);
}
...
...
@@ -1405,8 +1467,10 @@ public class ChannelServiceImpl implements ChannelService {
res
.
put
(
"negativeCount"
,
negativeCount
);
res
.
put
(
"articleTotal"
,
total
);
// 做分母时不能为0
res
.
put
(
"positivePercent"
,
BigDecimal
.
valueOf
((
double
)
positiveCount
*
100
/
(
0
==
total
?
1
:
total
)).
setScale
(
1
,
RoundingMode
.
UP
));
res
.
put
(
"negativePercent"
,
BigDecimal
.
valueOf
((
double
)
negativeCount
*
100
/
(
0
==
total
?
1
:
total
)).
setScale
(
1
,
RoundingMode
.
UP
));
res
.
put
(
"positivePercent"
,
BigDecimal
.
valueOf
((
double
)
positiveCount
*
100
/
(
0
==
total
?
1
:
total
))
.
setScale
(
1
,
RoundingMode
.
UP
));
res
.
put
(
"negativePercent"
,
BigDecimal
.
valueOf
((
double
)
negativeCount
*
100
/
(
0
==
total
?
1
:
total
))
.
setScale
(
1
,
RoundingMode
.
UP
));
return
Pair
.
of
(
total
,
res
);
}
...
...
@@ -1439,7 +1503,8 @@ public class ChannelServiceImpl implements ChannelService {
return
Pair
.
of
(
totalEvent
,
res
);
}
private
List
<
JSONObject
>
spreadingTendData
(
Long
startTime
,
Long
endTime
,
List
<
ChannelIndex
.
Article
>
articleList
,
String
timePattern
)
{
private
List
<
JSONObject
>
spreadingTendData
(
Long
startTime
,
Long
endTime
,
List
<
ChannelIndex
.
Article
>
articleList
,
String
timePattern
)
{
// 按日分组并根据id去重保留最近标注时间
Map
<
Long
,
List
<
ChannelIndex
.
Article
>>
dateListMap
=
partition
(
startTime
,
endTime
,
timePattern
,
articleList
);
return
dateListMap
.
entrySet
().
stream
().
sorted
(
Comparator
.
comparingLong
(
Map
.
Entry
::
getKey
)).
map
(
e
->
{
...
...
@@ -1450,7 +1515,8 @@ public class ChannelServiceImpl implements ChannelService {
}).
collect
(
Collectors
.
toList
());
}
private
List
<
JSONObject
>
spreadingTendEvent
(
Long
startTime
,
Long
endTime
,
Channel
channel
,
String
contendId
,
String
timePattern
)
{
private
List
<
JSONObject
>
spreadingTendEvent
(
Long
startTime
,
Long
endTime
,
Channel
channel
,
String
contendId
,
String
timePattern
)
{
Map
<
Long
,
List
<
Event
>>
eventCount
=
completeTimes
(
startTime
,
endTime
,
timePattern
);
if
(
Constant
.
MONTH_PATTERN
.
equals
(
timePattern
))
{
eventCount
.
putAll
(
eventDao
.
getEventMonth
(
new
ChannelIndex
(
channel
,
contendId
),
startTime
,
endTime
));
...
...
@@ -1465,7 +1531,8 @@ public class ChannelServiceImpl implements ChannelService {
}).
collect
(
Collectors
.
toList
());
}
private
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
convert2ContendMap
(
List
<
SearchResponse
>
searchResponses
,
Long
startTime
,
Long
endTime
,
Collection
<
String
>
contendIds
)
{
private
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
convert2ContendMap
(
List
<
SearchResponse
>
searchResponses
,
Long
startTime
,
Long
endTime
,
Collection
<
String
>
contendIds
)
{
Map
<
String
,
List
<
ChannelIndex
.
Article
>>
contendMap
=
new
HashMap
<>();
for
(
SearchResponse
searchResponse
:
searchResponses
)
{
for
(
SearchHit
hit
:
searchResponse
.
getHits
().
getHits
())
{
...
...
@@ -1499,7 +1566,8 @@ public class ChannelServiceImpl implements ChannelService {
*
* @return
*/
private
Map
<
Long
,
List
<
ChannelIndex
.
Article
>>
partition
(
Long
startTime
,
Long
endTime
,
String
timePattern
,
List
<
ChannelIndex
.
Article
>
articles
)
{
private
Map
<
Long
,
List
<
ChannelIndex
.
Article
>>
partition
(
Long
startTime
,
Long
endTime
,
String
timePattern
,
List
<
ChannelIndex
.
Article
>
articles
)
{
Map
<
Long
,
List
<
ChannelIndex
.
Article
>>
res
=
completeTimes
(
startTime
,
endTime
,
timePattern
);
for
(
ChannelIndex
.
Article
article
:
articles
)
{
// 按日分组
...
...
@@ -1515,12 +1583,15 @@ public class ChannelServiceImpl implements ChannelService {
return
res
;
}
private
EsClientDao
.
SearchHelper
createSearchHelperByChannelCriteria
(
String
projectId
,
String
channelId
,
Collection
<
String
>
contendIds
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
)
{
return
createSearchHelperByChannelCriteria
(
projectId
,
channelId
,
contendIds
,
platform
,
keyword
,
startTime
,
endTime
,
true
);
private
EsClientDao
.
SearchHelper
createSearchHelperByChannelCriteria
(
String
projectId
,
String
channelId
,
Collection
<
String
>
contendIds
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
)
{
return
createSearchHelperByChannelCriteria
(
projectId
,
channelId
,
contendIds
,
platform
,
keyword
,
startTime
,
endTime
,
true
);
}
private
EsClientDao
.
SearchHelper
createSearchHelperByChannelCriteria
(
String
projectId
,
String
channelId
,
Collection
<
String
>
contendIds
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
boolean
defaultTime
)
{
private
EsClientDao
.
SearchHelper
createSearchHelperByChannelCriteria
(
String
projectId
,
String
channelId
,
Collection
<
String
>
contendIds
,
String
platform
,
String
keyword
,
Long
startTime
,
Long
endTime
,
boolean
defaultTime
)
{
EsClientDao
.
SearchHelper
helper
=
EsClientDao
.
createSearchHelper
();
// query
BoolQueryBuilder
query
=
QueryBuilders
.
boolQuery
();
...
...
@@ -1563,7 +1634,8 @@ public class ChannelServiceImpl implements ChannelService {
return
helper
;
}
private
Query
channelListQuery
(
String
contendId
,
Boolean
show
,
String
emotion
,
String
platform
,
String
keyword
,
String
sorter
)
{
private
Query
channelListQuery
(
String
contendId
,
Boolean
show
,
String
emotion
,
String
platform
,
String
keyword
,
String
sorter
)
{
Query
query
=
new
Query
();
query
.
addCriteria
(
Criteria
.
where
(
"projectId"
).
is
(
UserThreadLocal
.
getProjectId
()));
query
.
addCriteria
(
Criteria
.
where
(
"contendId"
).
is
(
contendId
));
...
...
@@ -1586,19 +1658,19 @@ public class ChannelServiceImpl implements ChannelService {
private
String
[]
getTitleAndUrlById
(
String
id
)
{
try
{
BaseMap
baseMap
=
Tools
.
getBaseFromEsMap
(
esClientDao
.
searchById
(
id
));
return
new
String
[]{
baseMap
.
getTitleNullOptionalContent
(),
baseMap
.
getUrl
()
};
return
new
String
[]
{
baseMap
.
getTitleNullOptionalContent
(),
baseMap
.
getUrl
()
};
}
catch
(
IOException
ignored
)
{
}
return
new
String
[]{
null
,
null
};
return
new
String
[]
{
null
,
null
};
}
private
String
[]
getTitleContentUrlById
(
String
id
)
{
try
{
BaseMap
baseMap
=
Tools
.
getBaseFromEsMap
(
esClientDao
.
searchById
(
id
));
return
new
String
[]{
baseMap
.
getTitle
(),
baseMap
.
getContent
(),
baseMap
.
getUrl
()
};
return
new
String
[]
{
baseMap
.
getTitle
(),
baseMap
.
getContent
(),
baseMap
.
getUrl
()
};
}
catch
(
IOException
ignored
)
{
}
return
new
String
[]{
null
,
null
,
null
};
return
new
String
[]
{
null
,
null
,
null
};
}
private
boolean
hasEmotion
(
Channel
channel
)
{
...
...
@@ -1607,7 +1679,7 @@ public class ChannelServiceImpl implements ChannelService {
}
AbstractProject
project
=
projectService
.
getProjectByContendId
(
channel
.
getProjectId
(),
channel
.
getContendId
());
if
(
project
instanceof
Contend
)
{
//
有情感倾向更新渠道指数
//
有情感倾向更新渠道指数
return
((
Contend
)
project
).
isHasEmotion
();
}
return
project
instanceof
Project
;
...
...
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