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
9ee50458
Commit
9ee50458
authored
Oct 08, 2022
by
shenjunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2022/10/8 17:58
parent
28093d2d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
43 deletions
+45
-43
src/main/java/com/zhiwei/brandkbs2/controller/app/AppHotController.java
+32
-25
src/main/java/com/zhiwei/brandkbs2/pojo/Behavior.java
+2
-2
src/main/java/com/zhiwei/brandkbs2/service/impl/BehaviorServiceImpl.java
+3
-4
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
+8
-12
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/app/AppHotController.java
View file @
9ee50458
...
...
@@ -19,29 +19,29 @@ import org.apache.commons.lang3.time.DateUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
* @author cjz
* @ClassName AppCrisisController
* @Description 提供前台危机相关信息展示
* @author cjz
* @date 2022-07-19 16:17
*/
@RestController
@RequestMapping
(
"/app/hot"
)
@Api
(
tags
=
"前台热点库"
,
description
=
"提供前台热点相关信息展示"
)
@Api
(
tags
=
"前台热点库"
,
description
=
"提供前台热点相关信息展示"
)
@Auth
(
role
=
RoleEnum
.
CUSTOMER
)
public
class
AppHotController
extends
BaseController
{
private
static
final
long
ONE_HOUR
=
1L
;
...
...
@@ -63,6 +63,10 @@ public class AppHotController extends BaseController {
@Autowired
private
MarkDataService
markDataService
;
@Resource
(
name
=
"esSearchExecutor"
)
ThreadPoolTaskExecutor
executor
;
/**
* weibo 热搜
* weibo-topic 话题
...
...
@@ -74,19 +78,19 @@ public class AppHotController extends BaseController {
*/
@ApiOperation
(
"热点库-列表"
)
@GetMapping
(
"/getHotList"
)
public
ResponseResult
getHotList
(
@RequestParam
(
value
=
"sortType"
,
defaultValue
=
"realTime"
)
String
sortType
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"weibo"
)
String
type
)
{
public
ResponseResult
getHotList
(
@RequestParam
(
value
=
"sortType"
,
defaultValue
=
"realTime"
)
String
sortType
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"weibo"
)
String
type
)
{
ResponseEntity
<
JSONObject
>
jsonObjectResponseEntity
=
restTemplate
.
getForEntity
(
trendsListUrl
,
JSONObject
.
class
,
sortType
,
type
);
Object
data
=
jsonObjectResponseEntity
.
getBody
().
get
(
"data"
);
String
redisKey
=
RedisKeyPrefix
.
HOT_LIST
+
type
;
String
redisKey
=
RedisKeyPrefix
.
HOT_LIST
+
type
;
String
result
=
redisUtil
.
get
(
redisKey
);
//当舆论场崩溃时从缓存里获取
if
(
Objects
.
nonNull
(
data
))
{
if
(
Objects
.
nonNull
(
data
))
{
if
(
Objects
.
isNull
(
result
))
{
redisUtil
.
setExpire
(
redisKey
,
JSON
.
toJSONString
(
data
),
ONE_HOUR
,
TimeUnit
.
HOURS
);
}
return
ResponseResult
.
success
(
data
);
}
else
{
}
else
{
if
(
Objects
.
nonNull
(
result
))
{
return
ResponseResult
.
success
(
result
);
}
...
...
@@ -96,19 +100,19 @@ public class AppHotController extends BaseController {
@ApiOperation
(
"热点库-热点榜单"
)
@GetMapping
(
"/hot"
)
public
ResponseResult
hot
(){
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
getForEntity
(
longTimeInListSearchUrl
,
String
.
class
,
"weibo"
);
public
ResponseResult
hot
()
{
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
getForEntity
(
longTimeInListSearchUrl
,
String
.
class
,
"weibo"
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
responseEntity
.
getBody
());
String
redisKey
=
RedisKeyPrefix
.
HOT_RANK_LIST
;
String
result
=
redisUtil
.
get
(
redisKey
);
//当舆论场崩溃时从缓存里获取
if
(
jsonObject
.
getBoolean
(
"state"
))
{
if
(
jsonObject
.
getBoolean
(
"state"
))
{
Object
data
=
jsonObject
.
get
(
"data"
);
if
(
Objects
.
isNull
(
result
))
{
redisUtil
.
setExpire
(
redisKey
,
JSON
.
toJSONString
(
data
),
ONE_HOUR
,
TimeUnit
.
HOURS
);
}
return
ResponseResult
.
success
(
data
);
}
else
{
}
else
{
if
(
Objects
.
nonNull
(
result
))
{
return
ResponseResult
.
success
(
result
);
}
...
...
@@ -129,19 +133,22 @@ public class AppHotController extends BaseController {
markDataService
.
getMarkTopTitle
(
startDate
.
getTime
(),
endDate
.
getTime
(),
null
,
projectId
,
linkedGroupId
,
Constant
.
PRIMARY_CONTEND_ID
,
size
,
include
);
List
<
JSONObject
>
resultList
=
markTopTitleList
.
stream
().
map
(
map
->
{
JSONObject
resultJsonObject
=
new
JSONObject
();
resultJsonObject
.
put
(
"title"
,
map
.
getKey
());
resultJsonObject
.
put
(
"num"
,
map
.
getValue
());
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"title"
,
map
.
getKey
());
json
.
put
(
"num"
,
map
.
getValue
());
return
json
;
}).
collect
(
Collectors
.
toList
());
CompletableFuture
.
allOf
(
resultList
.
stream
().
map
(
json
->
CompletableFuture
.
supplyAsync
(()
->
{
try
{
BaseMap
firstArticle
=
markDataService
.
getFirstArticle
(
startDate
.
getTime
(),
endDate
.
getTime
(),
map
.
getKey
(
),
projectId
,
linkedGroupId
,
Constant
.
PRIMARY_CONTEND_ID
,
include
);
resultJsonObject
.
put
(
"content"
,
firstArticle
.
getContent
());
resultJsonObject
.
put
(
"url"
,
firstArticle
.
getUrl
());
resultJsonObject
.
put
(
"realSource"
,
firstArticle
.
getRealSource
());
resultJsonObject
.
put
(
"emotion"
,
firstArticle
.
getEmotion
());
BaseMap
firstArticle
=
markDataService
.
getFirstArticle
(
startDate
.
getTime
(),
endDate
.
getTime
(),
json
.
getString
(
"title"
),
projectId
,
linkedGroupId
,
Constant
.
PRIMARY_CONTEND_ID
,
include
);
json
.
put
(
"content"
,
firstArticle
.
getContent
());
json
.
put
(
"url"
,
firstArticle
.
getUrl
());
json
.
put
(
"realSource"
,
firstArticle
.
getRealSource
());
json
.
put
(
"emotion"
,
firstArticle
.
getEmotion
());
}
catch
(
IOException
ignored
)
{
}
return
resultJsonObject
;
}
).
collect
(
Collectors
.
toList
()
);
return
null
;
}
,
executor
)).
toArray
(
CompletableFuture
[]::
new
)).
join
(
);
return
ResponseResult
.
success
(
resultList
);
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/Behavior.java
View file @
9ee50458
...
...
@@ -26,9 +26,9 @@ public class Behavior extends AbstractBaseMongo {
*/
private
String
projectId
;
/**
* nick
N
ame
* nick
n
ame
*/
private
String
nick
N
ame
;
private
String
nick
n
ame
;
/**
* IP地址
*/
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/BehaviorServiceImpl.java
View file @
9ee50458
...
...
@@ -13,7 +13,6 @@ import com.zhiwei.brandkbs2.service.BehaviorService;
import
com.zhiwei.brandkbs2.util.MongoUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.data.mongodb.core.query.Criteria
;
...
...
@@ -26,7 +25,6 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -78,7 +76,8 @@ public class BehaviorServiceImpl implements BehaviorService {
Query
query
=
new
Query
();
query
.
addCriteria
(
Criteria
.
where
(
"cTime"
).
gte
(
startTime
).
lt
(
endTime
).
and
(
"backstage"
).
is
(
backstage
));
if
(
StringUtils
.
isNotEmpty
(
nickname
))
{
List
<
User
>
userList
=
userDao
.
findList
(
Query
.
query
(
Criteria
.
where
(
"nickname"
).
regex
(
Pattern
.
compile
(
"^.*"
+
nickname
+
".*$"
,
Pattern
.
CASE_INSENSITIVE
))));
userDao
.
addKeywordFuzz
(
query
,
nickname
,
"nickname"
);
List
<
User
>
userList
=
userDao
.
findList
(
query
);
// 根据nickname未查询
if
(
CollectionUtils
.
isEmpty
(
userList
))
{
return
PageVO
.
createPageVo
(
0
,
page
,
0
,
size
,
Collections
.
emptyList
());
...
...
@@ -108,7 +107,7 @@ public class BehaviorServiceImpl implements BehaviorService {
behaviorList
.
forEach
(
behavior
->
{
ExportBehaviorDTO
exportBehaviorDTO
=
new
ExportBehaviorDTO
();
Integer
roleId
=
getRoleId
(
behavior
.
getUserId
(),
behavior
.
getProjectId
());
exportBehaviorDTO
.
setNickname
(
behavior
.
getNick
N
ame
());
exportBehaviorDTO
.
setNickname
(
behavior
.
getNick
n
ame
());
exportBehaviorDTO
.
setIp
(
behavior
.
getIp
());
exportBehaviorDTO
.
setTime
(
new
Date
(
behavior
.
getCTime
()));
exportBehaviorDTO
.
setController
(
behavior
.
getController
());
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
View file @
9ee50458
...
...
@@ -593,8 +593,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// keyword
if
(
StringUtils
.
isNotEmpty
(
dto
.
getKeyword
()))
{
// Query
String
[]
fieldSearch
=
"仅标题"
.
equals
(
dto
.
getSearchField
())
?
new
String
[]{
GenericAttribute
.
ES_IND_TITLE
}
:
new
String
[]{
GenericAttribute
.
ES_IND_FULL_TEXT
};
String
[]
fieldSearch
=
"仅标题"
.
equals
(
dto
.
getSearchField
())
?
new
String
[]{
GenericAttribute
.
ES_IND_TITLE
}
:
new
String
[]{
GenericAttribute
.
ES_IND_FULL_TEXT
};
postFilter
.
must
(
EsQueryTools
.
assembleNormalKeywordQuery
(
dto
.
getKeyword
(),
fieldSearch
));
}
// sourceKeyword
...
...
@@ -812,7 +811,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// TODO script使用
// Script script = new Script("params._source.ind_title");
// TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("titles").script(script).order(BucketOrder.count(false)).size(60000);
TermsAggregationBuilder
aggregationBuilder
=
AggregationBuilders
.
terms
(
"titles"
).
field
(
"agg_title.keyword"
).
size
(
size
*
10
);
TermsAggregationBuilder
aggregationBuilder
=
AggregationBuilders
.
terms
(
"titles"
).
field
(
"agg_title.keyword"
).
size
(
size
+
1
);
// query
BoolQueryBuilder
query
;
if
(
include
)
{
...
...
@@ -1001,8 +1000,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// keyword
if
(
StringUtils
.
isNotEmpty
(
dto
.
getKeyword
()))
{
// Query
String
[]
fieldSearch
=
"仅标题"
.
equals
(
dto
.
getSearchField
())
?
new
String
[]{
GenericAttribute
.
ES_IND_TITLE
}
:
new
String
[]{
GenericAttribute
.
ES_IND_FULL_TEXT
};
String
[]
fieldSearch
=
"仅标题"
.
equals
(
dto
.
getSearchField
())
?
new
String
[]{
GenericAttribute
.
ES_IND_TITLE
}
:
new
String
[]{
GenericAttribute
.
ES_IND_FULL_TEXT
};
postFilter
.
must
(
EsQueryTools
.
assembleNormalKeywordQuery
(
dto
.
getKeyword
(),
fieldSearch
));
}
// sourceKeyword
...
...
@@ -1785,7 +1783,7 @@ public class MarkDataServiceImpl implements MarkDataService {
EsClientDao
.
SearchHelper
searchHelper
=
EsClientDao
.
createSearchHelper
();
BoolQueryBuilder
postFilter
=
projectLinkedGroupContendIdQuery
(
projectId
,
linkedGroupId
,
"0"
);
postFilter
.
must
(
QueryBuilders
.
rangeQuery
(
"time"
).
gte
(
startTime
).
lt
(
endTime
));
postFilter
.
must
(
EsQueryTools
.
cacheMapsNestedQuery
(
QueryBuilders
.
existsQuery
(
"brandkbs_cache_maps.channel_emotion"
)));
postFilter
.
must
Not
(
EsQueryTools
.
cacheMapsNestedQuery
(
QueryBuilders
.
termQuery
(
"brandkbs_cache_maps.channel_emotion"
,
0
)));
searchHelper
.
setPostFilter
(
postFilter
);
searchHelper
.
setFetchSource
(
new
String
[]{
GenericAttribute
.
ES_BRANDKBS_CACHE_MAPS
});
List
<
SearchResponse
>
searchResponses
=
esClientDao
.
searchScrollResponse
(
searchHelper
);
...
...
@@ -1803,9 +1801,9 @@ public class MarkDataServiceImpl implements MarkDataService {
}
}
long
total
=
emotionMap
.
values
().
stream
().
mapToInt
(
AtomicInteger:
:
getAndIncrement
).
sum
();
channelEmotionResult
.
put
(
"positivePercent"
,
(
double
)
emotionMap
.
get
(
ChannelEmotion
.
POSITIVE
.
getState
()).
get
()
/
total
);
channelEmotionResult
.
put
(
"negativePercent"
,
(
double
)
emotionMap
.
get
(
ChannelEmotion
.
NEGATIVE
.
getState
()).
get
()
/
total
);
channelEmotionResult
.
put
(
"neutralPercent"
,
(
double
)
emotionMap
.
get
(
ChannelEmotion
.
NEUTRAL
.
getState
()).
get
()
/
total
);
channelEmotionResult
.
put
(
"positivePercent"
,
total
==
0
?
0
:
(
double
)
emotionMap
.
get
(
ChannelEmotion
.
POSITIVE
.
getState
()).
get
()
/
total
);
channelEmotionResult
.
put
(
"negativePercent"
,
total
==
0
?
0
:
(
double
)
emotionMap
.
get
(
ChannelEmotion
.
NEGATIVE
.
getState
()).
get
()
/
total
);
channelEmotionResult
.
put
(
"neutralPercent"
,
total
==
0
?
0
:
(
double
)
emotionMap
.
get
(
ChannelEmotion
.
NEUTRAL
.
getState
()).
get
()
/
total
);
return
channelEmotionResult
;
}
...
...
@@ -1822,9 +1820,7 @@ public class MarkDataServiceImpl implements MarkDataService {
mediaTypeMap
.
put
(
channelEnum
.
name
().
toLowerCase
()
+
"Percent"
,
count
);
}
long
total
=
mediaTypeMap
.
values
().
stream
().
mapToLong
(
v
->
v
).
sum
();
mediaTypeMap
.
forEach
((
percentName
,
size
)
->
{
mediaTypePercent
.
put
(
percentName
,
(
double
)
size
/
total
==
0
?
1
:
total
);
});
mediaTypePercent
.
putAll
(
mediaTypeMap
);
return
mediaTypePercent
;
}
...
...
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