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
ccc01d5e
Commit
ccc01d5e
authored
Jan 11, 2023
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release' into 'master'
Release See merge request
!167
parents
b66927b3
3903c936
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
65 deletions
+76
-65
src/main/java/com/zhiwei/brandkbs2/pojo/ChannelRecord.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
+75
-64
No files found.
src/main/java/com/zhiwei/brandkbs2/pojo/ChannelRecord.java
View file @
ccc01d5e
...
@@ -162,7 +162,7 @@ public class ChannelRecord {
...
@@ -162,7 +162,7 @@ public class ChannelRecord {
JSONObject
json
=
new
JSONObject
(
esMap
);
JSONObject
json
=
new
JSONObject
(
esMap
);
this
.
rangeStartTime
=
json
.
getLongValue
(
RANGE_START_TIME
);
this
.
rangeStartTime
=
json
.
getLongValue
(
RANGE_START_TIME
);
this
.
rangeEndTime
=
json
.
getLongValue
(
RANGE_END_TIME
);
this
.
rangeEndTime
=
json
.
getLongValue
(
RANGE_END_TIME
);
this
.
platform
=
json
.
getString
(
"platform"
);
this
.
platform
=
GlobalPojo
.
getPlatformNameById
(
json
.
getString
(
"platform_id"
)
);
this
.
realSource
=
json
.
getString
(
"real_source"
);
this
.
realSource
=
json
.
getString
(
"real_source"
);
this
.
source
=
json
.
getString
(
"source"
);
this
.
source
=
json
.
getString
(
"source"
);
this
.
projectId
=
json
.
getString
(
"project_id"
);
this
.
projectId
=
json
.
getString
(
"project_id"
);
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
View file @
ccc01d5e
...
@@ -434,65 +434,81 @@ public class ChannelServiceImpl implements ChannelService {
...
@@ -434,65 +434,81 @@ public class ChannelServiceImpl implements ChannelService {
List
<
ChannelListVO
>
resList
=
new
ArrayList
<>();
List
<
ChannelListVO
>
resList
=
new
ArrayList
<>();
try
{
try
{
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
redisKey
=
RedisUtil
.
getChannelRecordList
(
projectId
,
startTime
,
endTime
,
emotion
);
// 部分条件不缓存
if
(
null
!=
keyword
)
{
return
getEmotionList
(
projectId
,
contendId
,
platform
,
keyword
,
sorter
,
startTime
,
endTime
,
size
,
emotion
,
cache
);
}
String
redisKey
=
RedisUtil
.
getChannelRecordList
(
projectId
,
startTime
,
endTime
,
platform
,
emotion
);
String
resultStr
;
String
resultStr
;
// 返回缓存
// 返回缓存
if
(
cache
&&
StringUtils
.
isNotEmpty
(
resultStr
=
redisUtil
.
get
(
redisKey
)))
{
if
(
cache
&&
StringUtils
.
isNotEmpty
(
resultStr
=
redisUtil
.
get
(
redisKey
)))
{
return
JSON
.
parseArray
(
resultStr
,
ChannelListVO
.
class
);
return
JSON
.
parseArray
(
resultStr
,
ChannelListVO
.
class
);
}
}
Map
<
String
,
Pair
<
Long
,
ChannelRecord
>>
keyMap
=
new
HashMap
<>();
resList
=
getEmotionList
(
projectId
,
contendId
,
platform
,
keyword
,
sorter
,
startTime
,
endTime
,
size
,
emotion
,
cache
);
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
null
,
// 配合天级缓存开启
Collections
.
singleton
(
contendId
),
platform
,
keyword
,
startTime
,
endTime
);
redisUtil
.
setExpire
(
redisKey
,
JSON
.
toJSONString
(
resList
));
// 分页查询所有结果
}
catch
(
IOException
e
)
{
List
<
SearchResponse
>
searchResponses
=
channelEsDao
.
searchScrollResponse
(
searchHelper
);
ExceptionCast
.
cast
(
CommonCodeEnum
.
FAIL
,
"es查询异常"
);
for
(
SearchResponse
searchResponse
:
searchResponses
)
{
}
for
(
SearchHit
hit
:
searchResponse
.
getHits
().
getHits
())
{
return
resList
;
ChannelRecord
channelRecord
=
new
ChannelRecord
(
hit
.
getSourceAsMap
());
}
keyMap
.
compute
(
channelRecord
.
getKey
(),
(
k
,
v
)
->
{
if
(
null
==
v
)
{
private
List
<
ChannelListVO
>
getEmotionList
(
String
projectId
,
String
contendId
,
String
platform
,
String
keyword
,
String
sorter
,
return
Pair
.
of
(
channelRecord
.
getRangeEndTime
(),
channelRecord
);
Long
startTime
,
Long
endTime
,
int
size
,
int
emotion
,
boolean
cache
)
throws
IOException
{
}
else
{
List
<
ChannelListVO
>
resList
=
new
ArrayList
<>();
// 比较数据时间
Map
<
String
,
Pair
<
Long
,
ChannelRecord
>>
keyMap
=
new
HashMap
<>();
if
(
channelRecord
.
getRangeEndTime
()
>
v
.
getLeft
())
{
EsClientDao
.
SearchHelper
searchHelper
=
createSearchHelperByChannelCriteria
(
projectId
,
null
,
v
.
getRight
().
setChannelInfo
(
channelRecord
);
Collections
.
singleton
(
contendId
),
platform
,
keyword
,
startTime
,
endTime
);
}
// 分页查询所有结果
// 合并文章数据
List
<
SearchResponse
>
searchResponses
=
channelEsDao
.
searchScrollResponse
(
searchHelper
);
v
.
getRight
().
getRecord
().
mergeRecord
(
channelRecord
.
getRecord
());
for
(
SearchResponse
searchResponse
:
searchResponses
)
{
return
v
;
for
(
SearchHit
hit
:
searchResponse
.
getHits
().
getHits
())
{
ChannelRecord
channelRecord
=
new
ChannelRecord
(
hit
.
getSourceAsMap
());
keyMap
.
compute
(
channelRecord
.
getKey
(),
(
k
,
v
)
->
{
if
(
null
==
v
)
{
return
Pair
.
of
(
channelRecord
.
getRangeEndTime
(),
channelRecord
);
}
else
{
// 比较数据时间
if
(
channelRecord
.
getRangeEndTime
()
>
v
.
getLeft
())
{
v
.
getRight
().
setChannelInfo
(
channelRecord
);
}
}
});
// 合并文章数据
}
v
.
getRight
().
getRecord
().
mergeRecord
(
channelRecord
.
getRecord
());
return
v
;
}
});
}
}
// 过滤掉不符合时间条件的数据并排序
}
List
<
ChannelRecord
>
channelRecords
=
keyMap
.
values
().
stream
().
map
(
pair
->
{
// 过滤掉不符合时间条件的数据并排序
ChannelRecord
channelRecord
=
pair
.
getRight
();
List
<
ChannelRecord
>
channelRecords
=
keyMap
.
values
().
stream
().
map
(
pair
->
{
// 情感过滤
ChannelRecord
channelRecord
=
pair
.
getRight
();
if
(
emotion
==
EmotionEnum
.
ALL
.
getState
()
||
emotion
==
channelRecord
.
getEmotion
())
{
// 情感过滤
List
<
ChannelIndex
.
Article
>
articles
=
ChannelIndex
.
Record
.
filterArticles
(
startTime
,
endTime
,
if
(
emotion
==
EmotionEnum
.
ALL
.
getState
()
||
emotion
==
channelRecord
.
getEmotion
())
{
channelRecord
.
getRecord
().
getArticles
());
List
<
ChannelIndex
.
Article
>
articles
=
ChannelIndex
.
Record
.
filterArticles
(
startTime
,
endTime
,
articles
.
sort
(
Comparator
.
comparingLong
(
ChannelIndex
.
Article
::
getTime
).
reversed
());
channelRecord
.
getRecord
().
getArticles
());
channelRecord
.
getRecord
().
setArticles
(
articles
);
articles
.
sort
(
Comparator
.
comparingLong
(
ChannelIndex
.
Article
::
getTime
).
reversed
());
return
channelRecord
;
channelRecord
.
getRecord
().
setArticles
(
articles
);
}
return
channelRecord
;
return
null
;
}
}).
filter
(
Objects:
:
nonNull
).
sorted
((
x
,
y
)
->
{
return
null
;
// emotionIndex降序
}).
filter
(
Objects:
:
nonNull
).
sorted
((
x
,
y
)
->
{
if
(
null
!=
sorter
&&
sorter
.
contains
(
"index"
))
{
// emotionIndex降序
if
(
x
.
getEmotionIndex
()
>
y
.
getEmotionIndex
())
{
if
(
null
!=
sorter
&&
sorter
.
contains
(
"index"
))
{
return
-
1
;
if
(
x
.
getEmotionIndex
()
>
y
.
getEmotionIndex
())
{
}
else
if
(
Objects
.
equals
(
x
.
getEmotionIndex
(),
y
.
getEmotionIndex
()))
{
return
0
;
}
return
1
;
}
// 稿件数排序
if
(
x
.
getRecord
().
getArticles
().
size
()
>
y
.
getRecord
().
getArticles
().
size
())
{
return
-
1
;
return
-
1
;
}
else
if
(
Objects
.
equals
(
x
.
get
Record
().
getArticles
().
size
(),
y
.
getRecord
().
getArticles
().
size
()))
{
}
else
if
(
Objects
.
equals
(
x
.
get
EmotionIndex
(),
y
.
getEmotionIndex
()))
{
return
0
;
return
0
;
}
}
return
1
;
return
1
;
}).
limit
(
size
)
}
// 稿件数排序
if
(
x
.
getRecord
().
getArticles
().
size
()
>
y
.
getRecord
().
getArticles
().
size
())
{
return
-
1
;
}
else
if
(
Objects
.
equals
(
x
.
getRecord
().
getArticles
().
size
(),
y
.
getRecord
().
getArticles
().
size
()))
{
return
0
;
}
return
1
;
}).
limit
(
size
)
// .map(channelRecord -> {
// .map(channelRecord -> {
// Channel channel = channelDao.queryUnique(channelRecord.getChannelFid());
// Channel channel = channelDao.queryUnique(channelRecord.getChannelFid());
// if (null != channel) {
// if (null != channel) {
...
@@ -502,22 +518,17 @@ public class ChannelServiceImpl implements ChannelService {
...
@@ -502,22 +518,17 @@ public class ChannelServiceImpl implements ChannelService {
// return ChannelListVO.createFromChannel(channelRecord, channelRecord.getRecord().getArticles().size());
// return ChannelListVO.createFromChannel(channelRecord, channelRecord.getRecord().getArticles().size());
// }
// }
// })
// })
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
Map
<
String
,
ChannelRecord
>
collect
=
Maps
.
uniqueIndex
(
channelRecords
,
ChannelRecord:
:
getChannelFid
);
Map
<
String
,
ChannelRecord
>
collect
=
Maps
.
uniqueIndex
(
channelRecords
,
ChannelRecord:
:
getChannelFid
);
Map
<
String
,
Channel
>
fidChannel
=
channelDao
.
queryUniqueAsync
(
collect
.
keySet
());
Map
<
String
,
Channel
>
fidChannel
=
channelDao
.
queryUniqueAsync
(
collect
.
keySet
());
collect
.
forEach
((
fid
,
record
)
->
{
collect
.
forEach
((
fid
,
record
)
->
{
Channel
channel
=
fidChannel
.
get
(
fid
);
Channel
channel
=
fidChannel
.
get
(
fid
);
if
(
null
!=
channel
)
{
if
(
null
!=
channel
)
{
resList
.
add
(
ChannelListVO
.
createFromChannel
(
channel
,
record
.
getRecord
().
getArticles
().
size
()));
resList
.
add
(
ChannelListVO
.
createFromChannel
(
channel
,
record
.
getRecord
().
getArticles
().
size
()));
}
else
{
}
else
{
resList
.
add
(
ChannelListVO
.
createFromChannel
(
record
,
record
.
getRecord
().
getArticles
().
size
()));
resList
.
add
(
ChannelListVO
.
createFromChannel
(
record
,
record
.
getRecord
().
getArticles
().
size
()));
}
}
});
});
// 配合天级缓存开启
redisUtil
.
setExpire
(
redisKey
,
JSON
.
toJSONString
(
resList
));
}
catch
(
IOException
e
)
{
ExceptionCast
.
cast
(
CommonCodeEnum
.
FAIL
,
"es查询异常"
);
}
return
resList
;
return
resList
;
}
}
...
...
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