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
b8dea545
Commit
b8dea545
authored
Apr 25, 2024
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'dev'
Feature See merge request
!491
parents
6fe16ea2
a40bb649
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
286 additions
and
41 deletions
+286
-41
src/main/java/com/zhiwei/brandkbs2/aop/AopLogRecord.java
+5
-4
src/main/java/com/zhiwei/brandkbs2/config/Constant.java
+2
-0
src/main/java/com/zhiwei/brandkbs2/controller/app/AppArticleController.java
+15
-1
src/main/java/com/zhiwei/brandkbs2/controller/app/AppHotController.java
+2
-0
src/main/java/com/zhiwei/brandkbs2/controller/app/AppUserCenterController.java
+1
-2
src/main/java/com/zhiwei/brandkbs2/dao/DailyReportDao.java
+12
-0
src/main/java/com/zhiwei/brandkbs2/dao/impl/DailyReportDaoImpl.java
+20
-0
src/main/java/com/zhiwei/brandkbs2/pojo/DailyReport.java
+65
-0
src/main/java/com/zhiwei/brandkbs2/service/MarkDataService.java
+22
-1
src/main/java/com/zhiwei/brandkbs2/service/TaskService.java
+5
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
+105
-33
src/main/java/com/zhiwei/brandkbs2/service/impl/TaskServiceImpl.java
+19
-0
src/main/java/com/zhiwei/brandkbs2/task/ControlCenter.java
+13
-0
No files found.
src/main/java/com/zhiwei/brandkbs2/aop/AopLogRecord.java
View file @
b8dea545
...
...
@@ -61,7 +61,7 @@ public class AopLogRecord {
private
static
final
List
<
String
>
URL_PATTERNS
=
Arrays
.
asList
(
"/getNewAll"
,
"/getNew"
,
"/schedule"
);
@AfterReturning
(
value
=
"execution(public * com..controller..admin..*Controller.*(..)) || execution(* com..controller..app..*Controller.*(..)) || execution(* com..controller..LoginController.checkBind())"
,
returning
=
"ResponseResult"
)
private
void
beforeLog
(
JoinPoint
joinPoint
,
ResponseResul
t
ResponseResult
)
{
private
void
beforeLog
(
JoinPoint
joinPoint
,
Objec
t
ResponseResult
)
{
try
{
long
now
=
System
.
currentTimeMillis
();
// RequestContextHolder 顾名思义 持有 request 上下文的容器
...
...
@@ -128,7 +128,7 @@ public class AopLogRecord {
}
}
private
UserLogRecord
userLogRecord
(
String
projectId
,
UserInfo
userInfo
,
JoinPoint
joinPoint
,
MethodSignature
methodSignature
,
ResponseResul
t
responseResult
)
{
private
UserLogRecord
userLogRecord
(
String
projectId
,
UserInfo
userInfo
,
JoinPoint
joinPoint
,
MethodSignature
methodSignature
,
Objec
t
responseResult
)
{
long
now
=
System
.
currentTimeMillis
();
Object
[]
args
=
joinPoint
.
getArgs
();
Method
method
=
methodSignature
.
getMethod
();
...
...
@@ -193,10 +193,11 @@ public class AopLogRecord {
return
new
UserLogRecord
(
projectId
,
userInfo
.
getUserId
(),
userInfo
.
getNickname
(),
prefix
+
suffix
,
userInfo
.
getRoleId
(),
now
,
now
);
}
// 获取接口返回值(value为获取返回值的具体字段)并与操作描述description拼接返回,返回值为实体
if
(!
method
.
getAnnotation
(
LogRecord
.
class
).
arguments
()
&&
method
.
getAnnotation
(
LogRecord
.
class
).
entity
())
{
if
(!
method
.
getAnnotation
(
LogRecord
.
class
).
arguments
()
&&
method
.
getAnnotation
(
LogRecord
.
class
).
entity
()
&&
Objects
.
nonNull
(
responseResult
)
)
{
List
<
Object
>
res
=
new
ArrayList
<>(
value
.
length
);
for
(
String
v
:
value
)
{
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
responseResult
.
getData
());
ResponseResult
result
=
(
ResponseResult
)
responseResult
;
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
result
.
getData
());
String
s
=
String
.
valueOf
(
jsonObject
.
get
(
v
));
if
(
Objects
.
nonNull
(
s
))
{
res
.
add
(
s
);
...
...
src/main/java/com/zhiwei/brandkbs2/config/Constant.java
View file @
b8dea545
...
...
@@ -20,12 +20,14 @@ public class Constant {
public
static
final
Long
ONE_YEAR
=
ONE_MONTH
*
12
;
public
static
final
String
SPEC_MINUTE_PATTERN
=
"yyyy.MM.dd HH:mm"
;
public
static
final
String
SPEC_DAY_PATTERN
=
"yyyy.MM.dd"
;
public
static
final
String
HOUR_PATTERN
=
"yyyy-MM-dd HH"
;
public
static
final
String
DAY_PATTERN
=
"yyyy-MM-dd"
;
public
static
final
String
MONTH_PATTERN
=
"yyyy-MM"
;
public
static
final
String
YEAR_PATTERN
=
"yyyy"
;
public
static
final
FastDateFormat
SPEC_MINUTE_FORMAT
=
FastDateFormat
.
getInstance
(
SPEC_MINUTE_PATTERN
);
public
static
final
FastDateFormat
SPEC_DAY_POINT_FORMAT
=
FastDateFormat
.
getInstance
(
SPEC_DAY_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
SPEC_DAY_FORMAT
=
FastDateFormat
.
getInstance
(
"yyyy/MM/dd"
);
...
...
src/main/java/com/zhiwei/brandkbs2/controller/app/AppArticleController.java
View file @
b8dea545
...
...
@@ -481,7 +481,7 @@ public class AppArticleController extends BaseController {
@ApiOperation
(
"新-舆情分析-活跃渠道"
)
@PostMapping
(
"/analyze/active-channel"
)
public
ResponseResult
getActiveChannels
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
return
ResponseResult
.
success
(
markDataService
.
getActiveChannels
(
markSearchDTO
));
return
ResponseResult
.
success
(
markDataService
.
getActiveChannels
(
markSearchDTO
,
20
));
}
@ApiOperation
(
"新-舆情分析-ip分布"
)
...
...
@@ -538,6 +538,20 @@ public class AppArticleController extends BaseController {
return
ResponseResult
.
success
(
markDataService
.
getSearchAnalyzeHighWord
(
markSearchDTO
));
}
@ApiOperation
(
"舆情简报-每日一报列表"
)
@GetMapping
(
"/daily-report/list"
)
public
ResponseResult
getDailyReportList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
Integer
page
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"10"
)
Integer
pageSize
)
{
return
ResponseResult
.
success
(
markDataService
.
getDailyReportList
(
page
,
pageSize
));
}
@ApiOperation
(
"舆情简报-每日一报详情"
)
@GetMapping
(
"/daily-report/detail/{id}"
)
@Auth
(
role
=
RoleEnum
.
NO_AUTHORISE
)
public
ResponseResult
getDailyReportDetail
(
@PathVariable
String
id
)
{
return
ResponseResult
.
success
(
markDataService
.
getDailyReportDetail
(
id
));
}
private
boolean
checkMTagIllegal
(
StringBuilder
mtag
)
{
List
<
MarkerTag
>
hitTags
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getHitTags
();
if
(!
Tools
.
isEmpty
(
hitTags
))
{
...
...
src/main/java/com/zhiwei/brandkbs2/controller/app/AppHotController.java
View file @
b8dea545
...
...
@@ -174,6 +174,7 @@ public class AppHotController extends BaseController {
@ApiOperation
(
"热点库-品牌热点-关键词调整"
)
@PutMapping
(
"/keyword/update"
)
@LogRecord
(
description
=
"热点库-关键词调整"
,
values
=
"list"
,
entity
=
true
,
arguments
=
true
)
public
ResponseResult
updateKeyword
(
@ApiParam
(
name
=
"json:{list:关键词数组,contendId:竞品id}"
)
@RequestBody
JSONObject
json
)
{
JSONArray
list
=
json
.
getJSONArray
(
"list"
);
String
contendId
=
json
.
getString
(
"contendId"
);
...
...
@@ -183,6 +184,7 @@ public class AppHotController extends BaseController {
@ApiOperation
(
"热点库-品牌热点-噪音词调整"
)
@PutMapping
(
"/filter-word/update"
)
@LogRecord
(
description
=
"热点库-噪音词调整"
,
values
=
"list"
,
entity
=
true
,
arguments
=
true
)
public
ResponseResult
updateFilterWord
(
@ApiParam
(
name
=
"json:{list:噪音词数组,contendId:竞品id}"
)
@RequestBody
JSONObject
json
)
{
JSONArray
list
=
json
.
getJSONArray
(
"list"
);
String
contendId
=
json
.
getString
(
"contendId"
);
...
...
src/main/java/com/zhiwei/brandkbs2/controller/app/AppUserCenterController.java
View file @
b8dea545
...
...
@@ -77,9 +77,8 @@ public class AppUserCenterController extends BaseController {
@ApiOperation
(
"任务中心-下载"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"任务id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"string"
)
@GetMapping
(
"/download-task/download/{id}"
)
public
ResponseResult
download
(
@PathVariable
String
id
)
{
public
void
download
(
@PathVariable
String
id
)
{
DownloadTask
task
=
downloadTaskService
.
findTask
(
id
);
Tools
.
downloadFile
(
task
.
getFileAddress
(),
response
);
return
ResponseResult
.
success
();
}
}
src/main/java/com/zhiwei/brandkbs2/dao/DailyReportDao.java
0 → 100644
View file @
b8dea545
package
com
.
zhiwei
.
brandkbs2
.
dao
;
import
com.zhiwei.brandkbs2.pojo.DailyReport
;
/**
* @ClassName: DailyReportDao
* @Description DailyReportDao
* @author: cjz
* @date: 2024-04-22 11:46
*/
public
interface
DailyReportDao
extends
BaseMongoDao
<
DailyReport
>{
}
src/main/java/com/zhiwei/brandkbs2/dao/impl/DailyReportDaoImpl.java
0 → 100644
View file @
b8dea545
package
com
.
zhiwei
.
brandkbs2
.
dao
.
impl
;
import
com.zhiwei.brandkbs2.dao.DailyReportDao
;
import
com.zhiwei.brandkbs2.pojo.DailyReport
;
import
org.springframework.stereotype.Component
;
/**
* @ClassName: DailyReportDaoImpl
* @Description DailyReportDaoImpl
* @author: cjz
* @date: 2024-04-22 11:46
*/
@Component
(
"dailyReportDao"
)
public
class
DailyReportDaoImpl
extends
BaseMongoDaoImpl
<
DailyReport
>
implements
DailyReportDao
{
private
static
final
String
COLLECTION_NAME
=
"brandkbs_daily_report"
;
public
DailyReportDaoImpl
()
{
super
(
COLLECTION_NAME
);
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/DailyReport.java
0 → 100644
View file @
b8dea545
package
com
.
zhiwei
.
brandkbs2
.
pojo
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
/**
* @author cjz
* @version 1.0
* @description 每日简报实体类
* @date 2024年4月22日10:06:46
*/
@Getter
@Setter
@AllArgsConstructor
public
class
DailyReport
extends
AbstractBaseMongo
{
private
String
name
;
/**
* 舆情概览
*/
private
JSONObject
summary
;
/**
* 舆情总量
*/
private
JSONObject
yuqingAmount
;
/**
* 情感分布
*/
private
JSONObject
yuqingEmotion
;
/**
* 重点平台
*/
private
JSONObject
platformPercentage
;
/**
* 高频标题
*/
private
List
<
JSONObject
>
topTitle
;
/**
* 发文渠道
*/
private
List
<
JSONObject
>
topSource
;
/**
* 项目id
*/
private
String
projectId
;
/**
* 项目
*/
private
String
project
;
/**
* 时间周期-开始时间
*/
private
Long
startTime
;
/**
* 时间周期-结束时间
*/
private
Long
endTime
;
/**
* 创建时间
*/
private
Long
cTime
;
}
src/main/java/com/zhiwei/brandkbs2/service/MarkDataService.java
View file @
b8dea545
...
...
@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.service;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.BaseMap
;
import
com.zhiwei.brandkbs2.pojo.DailyReport
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.pojo.MarkFlowEntity
;
import
com.zhiwei.brandkbs2.pojo.dto.*
;
...
...
@@ -581,7 +582,7 @@ public interface MarkDataService {
* @param dto 标注数据搜索传输类
* @return
*/
List
<
JSONObject
>
getActiveChannels
(
MarkSearchDTO
dto
);
List
<
JSONObject
>
getActiveChannels
(
MarkSearchDTO
dto
,
int
size
);
/**
* 新-舆情分析-ip分布
...
...
@@ -673,4 +674,24 @@ public interface MarkDataService {
PageVO
<
JSONObject
>
getArticleList
(
String
aggTitle
,
Long
startTime
,
Long
endTime
,
String
planId
,
String
platform
,
int
page
,
int
pageSize
);
PageVO
<
JSONObject
>
getArticleList
(
MarkSearchDTO
dto
);
/**
* 生成每日一报
*/
void
generateDailyReport
(
Long
startTime
,
Long
endTime
);
/**
* 每日一报列表
* @param page
* @param pageSize
* @return
*/
PageVO
<
JSONObject
>
getDailyReportList
(
int
page
,
int
pageSize
);
/**
* 获取每日一报详情
* @param id id
* @return
*/
DailyReport
getDailyReportDetail
(
String
id
);
}
src/main/java/com/zhiwei/brandkbs2/service/TaskService.java
View file @
b8dea545
...
...
@@ -57,4 +57,9 @@ public interface TaskService{
* 生成舆情分析词云缓存
*/
void
yuqingAnalyzeHighWordCache
();
/**
* 生成每日一报
*/
void
generateDailyReport
();
}
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
View file @
b8dea545
...
...
@@ -174,6 +174,9 @@ public class MarkDataServiceImpl implements MarkDataService {
@Resource
(
name
=
"markSearchAnalyzeTaskDao"
)
MarkSearchAnalyzeTaskDao
markSearchAnalyzeTaskDao
;
@Resource
(
name
=
"dailyReportDao"
)
DailyReportDao
dailyReportDao
;
@Resource
(
name
=
"toolsetServiceImpl"
)
private
ToolsetService
toolsetService
;
...
...
@@ -1002,18 +1005,18 @@ public class MarkDataServiceImpl implements MarkDataService {
return
Tools
.
getBaseFromEsMap
(
hits
.
getAt
(
0
).
getSourceAsMap
());
}
private
BaseMap
getAnalyzeFirstArticle
(
MarkSearchDTO
dto
)
throws
IOException
{
return
getArticleSort
(
dto
,
"{\"time\" : \"asc\"}"
);
private
BaseMap
getAnalyzeFirstArticle
(
MarkSearchDTO
dto
,
String
aggTitle
)
throws
IOException
{
return
getArticleSort
(
dto
,
"{\"time\" : \"asc\"}"
,
aggTitle
);
}
private
BaseMap
getAnalyzeLastArticle
(
MarkSearchDTO
dto
)
throws
IOException
{
return
getArticleSort
(
dto
,
"{\"time\" : \"desc\"}"
);
private
BaseMap
getAnalyzeLastArticle
(
MarkSearchDTO
dto
,
String
aggTitle
)
throws
IOException
{
return
getArticleSort
(
dto
,
"{\"time\" : \"desc\"}"
,
aggTitle
);
}
private
BaseMap
getArticleSort
(
MarkSearchDTO
dto
,
String
sorter
)
throws
IOException
{
private
BaseMap
getArticleSort
(
MarkSearchDTO
dto
,
String
sorter
,
String
aggTitle
)
throws
IOException
{
// 索引
String
[]
indexes
=
esClientDao
.
getIndexes
();
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
);
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
aggTitle
);
//sort
FieldSortBuilder
sort
=
new
FieldSortBuilder
(
"time"
).
order
(
SortOrder
.
ASC
);
JSONObject
sortJson
=
JSONObject
.
parseObject
(
sorter
);
...
...
@@ -2525,7 +2528,7 @@ public class MarkDataServiceImpl implements MarkDataService {
platformResult
.
put
(
"count"
,
bucket
.
getDocCount
());
list
.
add
(
platformResult
);
});
res
.
put
(
"platformCount"
,
list
.
stream
().
sorted
(
Comparator
.
comparingLong
((
JSONObject
json
)
->
json
.
getLongValue
(
"count"
)).
reversed
())
);
res
.
put
(
"platformCount"
,
list
);
JSONObject
overview
=
new
JSONObject
();
// 总量
overview
.
put
(
"total"
,
total
);
...
...
@@ -2533,11 +2536,11 @@ public class MarkDataServiceImpl implements MarkDataService {
int
days
=
new
Period
(
dto
.
getStartTime
(),
dto
.
getEndTime
(),
PeriodType
.
days
()).
getDays
();
days
=
0
==
days
?
1
:
days
;
double
avg
=
total
==
0
?
0
d
:
total
/
(
double
)
days
;
overview
.
put
(
"avg"
,
avg
);
// 项目均值
String
key
=
RedisUtil
.
getYuqingAnalyzePlatformAvgCountKey
(
projectId
,
Constant
.
PRIMARY_CONTEND_ID
,
dto
.
getPlanId
());
double
projectAvg
=
Objects
.
isNull
(
redisUtil
.
get
(
key
))
?
0
d
:
Double
.
parseDouble
(
redisUtil
.
get
(
key
));
overview
.
put
(
"compare"
,
compare
(
avg
,
projectAvg
));
overview
.
put
(
"avg"
,
projectAvg
);
res
.
put
(
"overview"
,
overview
);
return
res
;
}
catch
(
Exception
e
){
...
...
@@ -2640,11 +2643,9 @@ public class MarkDataServiceImpl implements MarkDataService {
BaseMap
totalBaseMaps
=
null
;
BaseMap
negativeBaseMaps
=
null
;
if
(
Objects
.
nonNull
(
negativeSpreadTendency
.
getLeft
())
||
Objects
.
nonNull
(
spreadTendency
.
getLeft
()))
{
CompletableFuture
.
allOf
(
Stream
.
of
(
spreadTendency
.
getLeft
(),
negativeSpreadTendency
.
getLeft
()).
filter
(
Objects:
:
nonNull
).
map
(
aggTitle
->
CompletableFuture
.
runAsync
(()
->
{
CompletableFuture
.
allOf
(
Stream
.
of
(
spreadTendency
.
getLeft
(),
negativeSpreadTendency
.
getLeft
()).
filter
(
Objects:
:
nonNull
).
map
(
aggTitle
->
CompletableFuture
.
runAsync
(()
->
{
try
{
dto
.
setAggTitle
(
aggTitle
);
baseMaps
.
put
(
aggTitle
,
getAnalyzeFirstArticle
(
dto
));
baseMaps
.
put
(
aggTitle
,
getAnalyzeFirstArticle
(
dto
,
aggTitle
));
}
catch
(
IOException
ignored
)
{
}
},
executor
)).
toArray
(
CompletableFuture
[]::
new
)).
join
();
...
...
@@ -2730,7 +2731,7 @@ public class MarkDataServiceImpl implements MarkDataService {
}
@Override
public
List
<
JSONObject
>
getActiveChannels
(
MarkSearchDTO
dto
)
{
public
List
<
JSONObject
>
getActiveChannels
(
MarkSearchDTO
dto
,
int
size
)
{
List
<
JSONObject
>
list
=
new
ArrayList
<>();
try
{
dto
.
setProjectId
(
UserThreadLocal
.
getProjectId
());
...
...
@@ -2739,7 +2740,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// query
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
);
// 渠道聚合,取前20
TermsAggregationBuilder
sourceAggregationBuilder
=
AggregationBuilders
.
terms
(
"source_count"
).
field
(
"source"
).
order
(
BucketOrder
.
count
(
false
)).
size
(
20
+
Tools
.
FILTER_SOURCE
.
size
());
TermsAggregationBuilder
sourceAggregationBuilder
=
AggregationBuilders
.
terms
(
"source_count"
).
field
(
"source"
).
order
(
BucketOrder
.
count
(
false
)).
size
(
size
+
Tools
.
FILTER_SOURCE
.
size
());
// 情感倾向子聚合
TermsAggregationBuilder
emotionAggregationBuilder
=
AggregationBuilders
.
terms
(
"emotion_count"
).
field
(
"brandkbs_mark_cache_maps.name.keyword"
);
SearchResponse
searchResponse
=
esClientDao
.
searchResponse
(
indexes
,
null
,
query
,
...
...
@@ -2909,7 +2910,7 @@ public class MarkDataServiceImpl implements MarkDataService {
List
<
JSONObject
>
markTopTitleList
=
getMarkTopTitle
(
dto
,
size
);
CompletableFuture
.
allOf
(
markTopTitleList
.
stream
().
map
(
json
->
CompletableFuture
.
supplyAsync
(()
->
{
try
{
BaseMap
firstArticle
=
getAnalyzeFirstArticle
(
dto
);
BaseMap
firstArticle
=
getAnalyzeFirstArticle
(
dto
,
json
.
getString
(
"title"
)
);
json
.
put
(
"content"
,
firstArticle
.
getContent
());
json
.
put
(
"url"
,
firstArticle
.
getUrl
());
json
.
put
(
"realSource"
,
firstArticle
.
getRealSource
());
...
...
@@ -2941,7 +2942,7 @@ public class MarkDataServiceImpl implements MarkDataService {
CompletableFuture
<
JSONObject
>
firstArticleFuture
=
CompletableFuture
.
supplyAsync
(()
->
{
try
{
// 最早发布
BaseMap
firstArticle
=
getAnalyzeFirstArticle
(
dto
);
BaseMap
firstArticle
=
getAnalyzeFirstArticle
(
dto
,
null
);
// 匹配重要渠道
JSONObject
firstSensitiveChannel
=
channelService
.
matchYuQingSensitiveChannel
(
linkedGroupId
,
firstArticle
.
getSource
());
JSONObject
firstArticleJson
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
firstArticle
));
...
...
@@ -2954,7 +2955,7 @@ public class MarkDataServiceImpl implements MarkDataService {
CompletableFuture
<
JSONObject
>
lastArticleFuture
=
CompletableFuture
.
supplyAsync
(()
->
{
try
{
// 最新发布
BaseMap
lastArticle
=
getAnalyzeLastArticle
(
dto
);
BaseMap
lastArticle
=
getAnalyzeLastArticle
(
dto
,
null
);
// 匹配重要渠道
JSONObject
lastSensitiveChannel
=
channelService
.
matchYuQingSensitiveChannel
(
linkedGroupId
,
lastArticle
.
getSource
());
JSONObject
lastArticleJson
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
lastArticle
));
...
...
@@ -3098,6 +3099,79 @@ public class MarkDataServiceImpl implements MarkDataService {
return
PageVO
.
createPageVo
(
0
,
page
,
pageSize
,
Collections
.
emptyList
());
}
@Override
public
void
generateDailyReport
(
Long
startTime
,
Long
endTime
)
{
MarkSearchDTO
dto
=
convertedToMarkSearch
(
null
,
startTime
,
endTime
,
null
);
// 舆情总量
JSONObject
yuqingAmount
=
getYuqingAmount
(
dto
);
// 情感分布
JSONObject
yuqingEmotion
=
getYuqingEmotionDistribution
(
dto
);
// 重点平台
JSONObject
platformPercentage
=
getImportantPlatformPercentage
(
dto
);
// 舆情概览
JSONObject
summary
=
getDailyReportSummary
(
yuqingAmount
,
yuqingEmotion
,
platformPercentage
);
// 高频标题
List
<
JSONObject
>
topTitle
=
getLastNews
(
dto
,
10
);
// 发文渠道
List
<
JSONObject
>
topSource
=
getActiveChannels
(
dto
,
10
);
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
projectName
=
projectService
.
getProjectById
(
projectId
).
getProjectName
();
String
name
=
"每日一报 "
+
Constant
.
SPEC_DAY_POINT_FORMAT
.
format
(
endTime
);
DailyReport
dailyReport
=
new
DailyReport
(
name
,
summary
,
yuqingAmount
,
yuqingEmotion
,
platformPercentage
,
topTitle
,
topSource
,
projectId
,
projectName
,
startTime
,
endTime
,
System
.
currentTimeMillis
());
dailyReportDao
.
insertOne
(
dailyReport
);
}
@Override
public
PageVO
<
JSONObject
>
getDailyReportList
(
int
page
,
int
pageSize
)
{
Query
query
=
new
Query
();
query
.
addCriteria
(
Criteria
.
where
(
"projectId"
).
is
(
UserThreadLocal
.
getProjectId
()));
long
total
=
dailyReportDao
.
count
(
query
);
query
.
limit
(
pageSize
);
query
.
skip
((
long
)
(
page
-
1
)
*
pageSize
);
dailyReportDao
.
addSort
(
query
,
"{\"endTime\":\"descend\"}"
);
List
<
DailyReport
>
list
=
dailyReportDao
.
findList
(
query
);
List
<
JSONObject
>
res
=
new
ArrayList
<>();
for
(
DailyReport
report
:
list
)
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"id"
,
report
.
getId
());
jsonObject
.
put
(
"name"
,
report
.
getName
());
res
.
add
(
jsonObject
);
}
return
PageVO
.
createPageVo
(
total
,
page
,
pageSize
,
res
);
}
@Override
public
DailyReport
getDailyReportDetail
(
String
id
)
{
return
dailyReportDao
.
findOneById
(
id
);
}
private
JSONObject
getDailyReportSummary
(
JSONObject
yuqingAmount
,
JSONObject
yuqingEmotion
,
JSONObject
platformPercentage
){
JSONObject
res
=
new
JSONObject
();
long
total
=
yuqingAmount
.
getLongValue
(
"total"
);
res
.
put
(
"total"
,
total
);
res
.
put
(
"positivePercent"
,
yuqingEmotion
.
getJSONObject
(
"positive"
).
getDoubleValue
(
"positivePercent"
));
res
.
put
(
"negativePercent"
,
yuqingEmotion
.
getJSONObject
(
"negative"
).
getDoubleValue
(
"negativePercent"
));
res
.
put
(
"neutralPercent"
,
yuqingEmotion
.
getJSONObject
(
"neutral"
).
getDoubleValue
(
"neutralPercent"
));
List
<
String
>
importantPlatforms
=
Arrays
.
asList
(
"微博"
,
"微信"
,
"抖音"
,
"小红书"
,
"今日头条"
,
"网媒"
);
List
<
JSONObject
>
platformCount
=
platformPercentage
.
getJSONArray
(
"platformCount"
).
toJavaList
(
JSONObject
.
class
);
List
<
String
>
platform
=
platformCount
.
stream
().
map
(
jsonObject
->
jsonObject
.
getString
(
"platform"
)).
collect
(
Collectors
.
toList
());
for
(
String
importantPlatform
:
importantPlatforms
)
{
if
(!
platform
.
contains
(
importantPlatform
)){
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"platform"
,
importantPlatform
);
jsonObject
.
put
(
"count"
,
0L
);
platformCount
.
add
(
jsonObject
);
}
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"platform"
,
"其他"
);
jsonObject
.
put
(
"count"
,
total
-
platformCount
.
stream
().
mapToLong
(
p
->
p
.
getLongValue
(
"count"
)).
sum
());
platformCount
.
add
(
jsonObject
);
res
.
put
(
"platformCount"
,
platformCount
);
return
res
;
}
private
MarkSearchDTO
convertedToMarkSearch
(
String
aggTitle
,
Long
startTime
,
Long
endTime
,
String
planId
){
MarkSearchDTO
dto
=
new
MarkSearchDTO
();
dto
.
setAggTitle
(
aggTitle
);
...
...
@@ -3173,7 +3247,7 @@ public class MarkDataServiceImpl implements MarkDataService {
TermsAggregationBuilder
titleAggregationBuilder
=
AggregationBuilders
.
terms
(
"titleAgg"
).
field
(
"agg_title.keyword"
).
order
(
BucketOrder
.
count
(
false
));
dto
.
setPlatforms
(
null
);
// query
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
emotion
);
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
emotion
,
null
);
// response
SearchResponse
searchResponse
=
esClientDao
.
searchResponse
(
indexes
,
null
,
query
,
daysAggregationBuilder
.
subAggregation
(
titleAggregationBuilder
),
null
,
null
,
0
,
0
,
null
);
...
...
@@ -3200,24 +3274,21 @@ public class MarkDataServiceImpl implements MarkDataService {
}
private
Long
getYuqingAnalyzeCount
(
MarkSearchDTO
dto
)
throws
IOException
{
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
null
);
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
null
,
null
);
return
esClientDao
.
count
(
query
);
}
private
Long
getYuqingAnalyzeCount
(
MarkSearchDTO
dto
,
String
emotion
)
throws
IOException
{
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
emotion
);
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
dto
,
emotion
,
null
);
return
esClientDao
.
count
(
query
);
}
private
Long
getYuqingAnalyzeCount
(
Long
startTime
,
Long
endTime
,
String
projectId
,
String
planId
,
String
emotion
,
List
<
String
>
platforms
)
throws
IOException
{
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
startTime
,
endTime
,
projectId
,
planId
,
emotion
,
platforms
,
null
);
BoolQueryBuilder
query
=
yuqingAnalyzeQuery
(
startTime
,
endTime
,
projectId
,
planId
,
emotion
,
platforms
);
return
esClientDao
.
count
(
query
);
}
private
BoolQueryBuilder
yuqingAnalyzeQuery
(
Long
startTime
,
Long
endTime
,
String
projectId
,
String
planId
,
String
emotion
,
List
<
String
>
platforms
,
String
aggTitle
){
if
(
Objects
.
isNull
(
projectId
))
{
projectId
=
UserThreadLocal
.
getProjectId
();
}
private
BoolQueryBuilder
yuqingAnalyzeQuery
(
Long
startTime
,
Long
endTime
,
String
projectId
,
String
planId
,
String
emotion
,
List
<
String
>
platforms
){
// project plan query
BoolQueryBuilder
query
=
EsQueryTools
.
assembleCacheMapsPlanQuery
(
projectId
,
planId
);
if
(
Objects
.
isNull
(
planId
)){
...
...
@@ -3244,17 +3315,18 @@ public class MarkDataServiceImpl implements MarkDataService {
if
(
Objects
.
nonNull
(
endTime
))
{
query
.
must
(
QueryBuilders
.
rangeQuery
(
"time"
).
lt
(
endTime
));
}
// aggTitle
if
(
Objects
.
nonNull
(
aggTitle
)){
query
.
must
(
QueryBuilders
.
termQuery
(
"agg_title.keyword"
,
aggTitle
));
}
return
query
;
}
private
BoolQueryBuilder
yuqingAnalyzeQuery
(
MarkSearchDTO
dto
){
return
yuqingAnalyzeQuery
(
dto
,
null
);
return
yuqingAnalyzeQuery
(
dto
,
null
,
null
);
}
private
BoolQueryBuilder
yuqingAnalyzeQuery
(
MarkSearchDTO
dto
,
String
emotion
){
private
BoolQueryBuilder
yuqingAnalyzeQuery
(
MarkSearchDTO
dto
,
String
aggTitle
){
return
yuqingAnalyzeQuery
(
dto
,
null
,
aggTitle
);
}
private
BoolQueryBuilder
yuqingAnalyzeQuery
(
MarkSearchDTO
dto
,
String
emotion
,
String
aggTitle
){
// projectId、contendId
String
projectId
=
dto
.
getProjectId
();
String
contendId
=
dto
.
getContendId
();
...
...
@@ -3310,8 +3382,8 @@ public class MarkDataServiceImpl implements MarkDataService {
postFilter
.
must
(
QueryBuilders
.
rangeQuery
(
GenericAttribute
.
ES_MGID
).
lt
(
dto
.
getPageGid
()));
}
// 聚合标题
if
(
Objects
.
nonNull
(
dto
.
getAggTitle
()
)){
postFilter
.
must
(
QueryBuilders
.
termQuery
(
"agg_title.keyword"
,
dto
.
getAggTitle
()
));
if
(
Objects
.
nonNull
(
aggTitle
)){
postFilter
.
must
(
QueryBuilders
.
termQuery
(
"agg_title.keyword"
,
aggTitle
));
}
return
postFilter
;
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/TaskServiceImpl.java
View file @
b8dea545
...
...
@@ -399,6 +399,25 @@ public class TaskServiceImpl implements TaskService {
CompletableFuture
.
allOf
(
projectFutures
.
toArray
(
new
CompletableFuture
[
0
])).
join
();
}
@Override
public
void
generateDailyReport
()
{
// 时间范围:当天早上八点-前一天早上八点
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
8
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
long
endTime
=
calendar
.
getTimeInMillis
();
long
startTime
=
endTime
-
Constant
.
ONE_DAY
;
AtomicInteger
total
=
new
AtomicInteger
();
CompletableFuture
.
allOf
(
GlobalPojo
.
PROJECT_MAP
.
values
().
stream
().
map
(
project
->
CompletableFuture
.
supplyAsync
(()
->
{
UserThreadLocal
.
set
(
new
UserInfo
().
setProjectId
(
project
.
getId
()));
markDataService
.
generateDailyReport
(
startTime
,
endTime
);
log
.
info
(
"项目:{}-{}-每日一报生成已完成:{}个"
,
project
.
getProjectName
(),
project
.
getId
(),
total
.
incrementAndGet
());
return
null
;
},
cacheServiceExecutor
)).
toArray
(
CompletableFuture
[]::
new
)).
join
();
}
private
boolean
reportSendByProject
(
Project
project
)
{
boolean
flag
=
false
;
// 扫描setting信息并生成对应报告
...
...
src/main/java/com/zhiwei/brandkbs2/task/ControlCenter.java
View file @
b8dea545
...
...
@@ -105,4 +105,17 @@ public class ControlCenter {
log
.
info
(
"定时按周计算项目均值-结束"
);
}
}
@Async
(
"scheduledExecutor"
)
@Scheduled
(
cron
=
"0 0 8 * * ?"
)
public
void
generateDailyReport
()
{
log
.
info
(
"定时生成每日一报-启动"
);
try
{
taskService
.
generateDailyReport
();
}
catch
(
Exception
e
)
{
log
.
error
(
"定时生成每日一报-出错"
,
e
);
}
finally
{
log
.
info
(
"定时生成每日一报-结束"
);
}
}
}
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