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
3415949b
Commit
3415949b
authored
Nov 24, 2022
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'dev'
Feature See merge request
!106
parents
5b5e2072
849ae8db
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
16 deletions
+99
-16
src/main/java/com/zhiwei/brandkbs2/controller/admin/EventController.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/service/EventService.java
+13
-0
src/main/java/com/zhiwei/brandkbs2/service/TaskService.java
+4
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/BehaviorServiceImpl.java
+23
-6
src/main/java/com/zhiwei/brandkbs2/service/impl/EventDataServiceImpl.java
+9
-3
src/main/java/com/zhiwei/brandkbs2/service/impl/EventServiceImpl.java
+19
-2
src/main/java/com/zhiwei/brandkbs2/service/impl/TaskServiceImpl.java
+17
-4
src/main/java/com/zhiwei/brandkbs2/task/ControlCenter.java
+13
-0
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/admin/EventController.java
View file @
3415949b
...
@@ -124,7 +124,7 @@ public class EventController extends BaseController {
...
@@ -124,7 +124,7 @@ public class EventController extends BaseController {
@ApiImplicitParam
(
name
=
"eventIds"
,
value
=
"事件ID集合"
,
paramType
=
"body"
,
dataType
=
"list"
)
@ApiImplicitParam
(
name
=
"eventIds"
,
value
=
"事件ID集合"
,
paramType
=
"body"
,
dataType
=
"list"
)
@PostMapping
(
"/analyze"
)
@PostMapping
(
"/analyze"
)
public
ResponseResult
analysisEvents
(
@RequestBody
JSONObject
info
)
{
public
ResponseResult
analysisEvents
(
@RequestBody
JSONObject
info
)
{
eventService
.
analysisEvents
(
info
.
getJSONArray
(
"eventIds"
).
toJavaList
(
String
.
class
));
eventService
.
analysisEvents
Async
(
info
.
getJSONArray
(
"eventIds"
).
toJavaList
(
String
.
class
));
behaviorService
.
pushBehaviorOld
(
OPERATION
,
"批量更新事件"
,
request
);
behaviorService
.
pushBehaviorOld
(
OPERATION
,
"批量更新事件"
,
request
);
return
ResponseResult
.
success
();
return
ResponseResult
.
success
();
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/EventService.java
View file @
3415949b
...
@@ -190,6 +190,12 @@ public interface EventService {
...
@@ -190,6 +190,12 @@ public interface EventService {
void
analysisEvents
(
List
<
String
>
eventIds
);
void
analysisEvents
(
List
<
String
>
eventIds
);
/**
/**
* 异步批量更新事件
* @param eventIds 事件ID集合
*/
void
analysisEventsAsync
(
List
<
String
>
eventIds
);
/**
* 搜索舆情全部事件标签
* 搜索舆情全部事件标签
*
*
* @param linkedGroupId 关联项目组ID
* @param linkedGroupId 关联项目组ID
...
@@ -278,4 +284,11 @@ public interface EventService {
...
@@ -278,4 +284,11 @@ public interface EventService {
*/
*/
List
<
JSONObject
>
getLastEventTop
(
String
keyword
,
int
limit
);
List
<
JSONObject
>
getLastEventTop
(
String
keyword
,
int
limit
);
/**
* 获取未结束的事件
* @param projectId
* @return
*/
List
<
Event
>
findNotEndEventByProjectId
(
String
projectId
);
}
}
src/main/java/com/zhiwei/brandkbs2/service/TaskService.java
View file @
3415949b
...
@@ -33,4 +33,8 @@ public interface TaskService{
...
@@ -33,4 +33,8 @@ public interface TaskService{
*/
*/
void
cleanAggreeTask
();
void
cleanAggreeTask
();
/**
* 事件相关更新
*/
void
eventUpdate
();
}
}
src/main/java/com/zhiwei/brandkbs2/service/impl/BehaviorServiceImpl.java
View file @
3415949b
...
@@ -11,6 +11,7 @@ import com.zhiwei.brandkbs2.pojo.vo.BehaviorVO;
...
@@ -11,6 +11,7 @@ import com.zhiwei.brandkbs2.pojo.vo.BehaviorVO;
import
com.zhiwei.brandkbs2.pojo.vo.PageVO
;
import
com.zhiwei.brandkbs2.pojo.vo.PageVO
;
import
com.zhiwei.brandkbs2.service.BehaviorService
;
import
com.zhiwei.brandkbs2.service.BehaviorService
;
import
com.zhiwei.brandkbs2.util.MongoUtil
;
import
com.zhiwei.brandkbs2.util.MongoUtil
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
...
@@ -77,8 +78,9 @@ public class BehaviorServiceImpl implements BehaviorService {
...
@@ -77,8 +78,9 @@ public class BehaviorServiceImpl implements BehaviorService {
query
.
addCriteria
(
Criteria
.
where
(
"cTime"
).
gte
(
startTime
).
lt
(
endTime
).
and
(
"backstage"
).
is
(
backstage
));
query
.
addCriteria
(
Criteria
.
where
(
"cTime"
).
gte
(
startTime
).
lt
(
endTime
).
and
(
"backstage"
).
is
(
backstage
));
behaviorDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
behaviorDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
if
(
StringUtils
.
isNotEmpty
(
nickname
))
{
if
(
StringUtils
.
isNotEmpty
(
nickname
))
{
userDao
.
addKeywordFuzz
(
query
,
nickname
,
"nickname"
);
Query
userQuery
=
new
Query
();
List
<
User
>
userList
=
userDao
.
findList
(
query
);
userDao
.
addKeywordFuzz
(
userQuery
,
nickname
,
"nickname"
);
List
<
User
>
userList
=
userDao
.
findList
(
userQuery
);
// 根据nickname未查询
// 根据nickname未查询
if
(
CollectionUtils
.
isEmpty
(
userList
))
{
if
(
CollectionUtils
.
isEmpty
(
userList
))
{
return
PageVO
.
createPageVo
(
0
,
page
,
0
,
size
,
Collections
.
emptyList
());
return
PageVO
.
createPageVo
(
0
,
page
,
0
,
size
,
Collections
.
emptyList
());
...
@@ -87,14 +89,29 @@ public class BehaviorServiceImpl implements BehaviorService {
...
@@ -87,14 +89,29 @@ public class BehaviorServiceImpl implements BehaviorService {
query
.
addCriteria
(
Criteria
.
where
(
"userId"
).
in
(
userList
.
stream
().
map
(
User:
:
getId
).
collect
(
Collectors
.
toList
())));
query
.
addCriteria
(
Criteria
.
where
(
"userId"
).
in
(
userList
.
stream
().
map
(
User:
:
getId
).
collect
(
Collectors
.
toList
())));
}
}
long
count
=
behaviorDao
.
count
(
query
,
collectionNames
);
long
count
=
behaviorDao
.
count
(
query
,
collectionNames
);
mongoUtil
.
start
(
page
,
size
,
query
);
// 保证数据分表时正常分页
List
<
Behavior
>
behaviorList
=
behaviorDao
.
findList
(
query
,
collectionNames
);
int
skipCount
=
(
page
-
1
)
*
size
;
List
<
Behavior
>
behaviorList
=
new
ArrayList
<>();
int
pageSizeFlag
=
size
;
if
(
0
!=
collectionNames
.
length
)
{
for
(
int
i
=
collectionNames
.
length
-
1
;
i
>=
0
;
i
--)
{
if
(
behaviorList
.
size
()
>=
size
)
{
break
;
}
else
{
query
.
limit
(
pageSizeFlag
);
query
.
skip
(
skipCount
);
List
<
Behavior
>
list
=
behaviorDao
.
findList
(
query
,
collectionNames
[
i
]);
behaviorList
.
addAll
(
list
);
}
skipCount
=
0
;
pageSizeFlag
=
size
-
behaviorList
.
size
();
}
}
List
<
BehaviorVO
>
resList
=
behaviorList
.
stream
().
map
(
behavior
->
{
List
<
BehaviorVO
>
resList
=
behaviorList
.
stream
().
map
(
behavior
->
{
Integer
roleId
=
getRoleId
(
behavior
.
getUserId
(),
behavior
.
getProjectId
());
Integer
roleId
=
getRoleId
(
behavior
.
getUserId
(),
behavior
.
getProjectId
());
return
BehaviorVO
.
createFromBehavior
(
behavior
,
roleId
);
return
BehaviorVO
.
createFromBehavior
(
behavior
,
roleId
);
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
MongoUtil
.
PageHelper
<
BehaviorVO
>
pageHelper
=
mongoUtil
.
pageHelperT
(
count
,
resList
);
return
PageVO
.
createPageVo
(
count
,
page
,
size
,
resList
);
return
PageVO
.
createPageVo
(
pageHelper
,
resList
);
}
}
@Override
@Override
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/EventDataServiceImpl.java
View file @
3415949b
...
@@ -64,13 +64,19 @@ public class EventDataServiceImpl implements EventDataService {
...
@@ -64,13 +64,19 @@ public class EventDataServiceImpl implements EventDataService {
@Override
@Override
public
void
analysisEvent
(
Event
event
)
{
public
void
analysisEvent
(
Event
event
)
{
long
startTime
=
event
.
getStartTime
();
long
startTime
=
event
.
getStartTime
();
long
endTime
=
event
.
isEndStatus
()
?
event
.
getEndTime
()
:
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
Period
periodDay
=
new
Period
(
startTime
,
endTime
,
PeriodType
.
days
());
// 时间异常
if
(
startTime
>=
now
){
return
;
}
long
endTime
=
event
.
isEndStatus
()
?
event
.
getEndTime
()
:
now
;
//时间区间大于40天 就不更新
//时间区间大于40天 就不更新
if
(
periodDay
.
getDays
()
>=
40
||
startTime
>
System
.
currentTimeMillis
())
{
if
(
new
Period
(
startTime
,
endTime
,
PeriodType
.
days
()).
getDays
()
>=
40
)
{
if
(!
event
.
isEndStatus
())
{
event
.
setEndTime
(
endTime
);
event
.
setEndTime
(
endTime
);
event
.
setEndStatus
(
true
);
event
.
setEndStatus
(
true
);
eventDao
.
updateOne
(
event
);
eventDao
.
updateOne
(
event
);
}
log
.
info
(
"analysisEvent-eventId:{},时间区间大于40天,不做更新"
,
event
.
getId
());
log
.
info
(
"analysisEvent-eventId:{},时间区间大于40天,不做更新"
,
event
.
getId
());
return
;
return
;
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/EventServiceImpl.java
View file @
3415949b
...
@@ -138,6 +138,7 @@ public class EventServiceImpl implements EventService {
...
@@ -138,6 +138,7 @@ public class EventServiceImpl implements EventService {
AtomicInteger
count
=
new
AtomicInteger
();
AtomicInteger
count
=
new
AtomicInteger
();
//事件太多塞满队列了
//事件太多塞满队列了
ApplicationProjectListener
.
getThreadPool
().
execute
(()
->
{
ApplicationProjectListener
.
getThreadPool
().
execute
(()
->
{
List
<
String
>
eventIds
=
new
ArrayList
<>();
yqEventList
.
forEach
(
yqEventDTO
->
{
yqEventList
.
forEach
(
yqEventDTO
->
{
Event
existEvent
=
eventDao
.
getEventByUniqueIds
(
yqEventDTO
.
getYqEventId
(),
projectId
,
contendId
);
Event
existEvent
=
eventDao
.
getEventByUniqueIds
(
yqEventDTO
.
getYqEventId
(),
projectId
,
contendId
);
Event
event
=
Event
.
createFromYqEventDTO
(
yqEventDTO
,
collectionName
,
projectId
,
contendId
);
Event
event
=
Event
.
createFromYqEventDTO
(
yqEventDTO
,
collectionName
,
projectId
,
contendId
);
...
@@ -149,12 +150,14 @@ public class EventServiceImpl implements EventService {
...
@@ -149,12 +150,14 @@ public class EventServiceImpl implements EventService {
event
.
setCTime
(
new
Date
().
getTime
());
event
.
setCTime
(
new
Date
().
getTime
());
eventDao
.
insertOne
(
event
);
eventDao
.
insertOne
(
event
);
}
}
eventIds
.
add
(
event
.
getId
());
if
(
count
.
incrementAndGet
()
==
yqEventList
.
size
())
{
if
(
count
.
incrementAndGet
()
==
yqEventList
.
size
())
{
stringRedisTemplate
.
opsForValue
().
set
(
redisKey
,
String
.
valueOf
(
100
),
1
,
TimeUnit
.
MINUTES
);
stringRedisTemplate
.
opsForValue
().
set
(
redisKey
,
String
.
valueOf
(
100
),
1
,
TimeUnit
.
MINUTES
);
}
else
{
}
else
{
stringRedisTemplate
.
opsForValue
().
set
(
redisKey
,
String
.
valueOf
((
count
.
get
())
*
100
/
yqEventList
.
size
()));
stringRedisTemplate
.
opsForValue
().
set
(
redisKey
,
String
.
valueOf
((
count
.
get
())
*
100
/
yqEventList
.
size
()));
}
}
});
});
analysisEventsAsync
(
eventIds
);
});
});
}
}
...
@@ -456,7 +459,10 @@ public class EventServiceImpl implements EventService {
...
@@ -456,7 +459,10 @@ public class EventServiceImpl implements EventService {
@Override
@Override
public
void
analysisEvents
(
List
<
String
>
eventIds
)
{
public
void
analysisEvents
(
List
<
String
>
eventIds
)
{
ApplicationProjectListener
.
getThreadPool
().
execute
(()
->
eventIds
.
forEach
(
eventId
->
{
if
(
Tools
.
isEmpty
(
eventIds
))
{
return
;
}
eventIds
.
forEach
(
eventId
->
{
String
redisKey
=
null
;
String
redisKey
=
null
;
try
{
try
{
Event
event
=
getEventById
(
eventId
);
Event
event
=
getEventById
(
eventId
);
...
@@ -469,7 +475,12 @@ public class EventServiceImpl implements EventService {
...
@@ -469,7 +475,12 @@ public class EventServiceImpl implements EventService {
log
.
error
(
"eventId:{}更新失败"
,
eventId
,
e
);
log
.
error
(
"eventId:{}更新失败"
,
eventId
,
e
);
redisUtil
.
set
(
redisKey
,
"-1"
);
redisUtil
.
set
(
redisKey
,
"-1"
);
}
}
}));
});
}
@Override
public
void
analysisEventsAsync
(
List
<
String
>
eventIds
)
{
ApplicationProjectListener
.
getThreadPool
().
execute
(()
->
analysisEvents
(
eventIds
));
}
}
@Override
@Override
...
@@ -666,6 +677,12 @@ public class EventServiceImpl implements EventService {
...
@@ -666,6 +677,12 @@ public class EventServiceImpl implements EventService {
}).
sorted
((
o1
,
o2
)
->
Long
.
compare
((
long
)
o2
.
get
(
"total"
),
(
long
)
o1
.
get
(
"total"
))).
collect
(
Collectors
.
toList
());
}).
sorted
((
o1
,
o2
)
->
Long
.
compare
((
long
)
o2
.
get
(
"total"
),
(
long
)
o1
.
get
(
"total"
))).
collect
(
Collectors
.
toList
());
}
}
@Override
public
List
<
Event
>
findNotEndEventByProjectId
(
String
projectId
)
{
Query
query
=
Query
.
query
(
Criteria
.
where
(
"projectId"
).
is
(
projectId
).
and
(
"endStatus"
).
is
(
false
));
return
eventDao
.
findList
(
query
);
}
/**
/**
* 获取时间筛选条件
* 获取时间筛选条件
*
*
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/TaskServiceImpl.java
View file @
3415949b
...
@@ -3,10 +3,7 @@ package com.zhiwei.brandkbs2.service.impl;
...
@@ -3,10 +3,7 @@ package com.zhiwei.brandkbs2.service.impl;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.common.GlobalPojo
;
import
com.zhiwei.brandkbs2.common.GlobalPojo
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.dao.AggreeResultDao
;
import
com.zhiwei.brandkbs2.dao.*
;
import
com.zhiwei.brandkbs2.dao.BrandkbsTaskDao
;
import
com.zhiwei.brandkbs2.dao.ChannelDao
;
import
com.zhiwei.brandkbs2.dao.ReportSettingsDao
;
import
com.zhiwei.brandkbs2.enmus.ReportTypeEnum
;
import
com.zhiwei.brandkbs2.enmus.ReportTypeEnum
;
import
com.zhiwei.brandkbs2.es.ChannelEsDao
;
import
com.zhiwei.brandkbs2.es.ChannelEsDao
;
import
com.zhiwei.brandkbs2.es.EsClientDao
;
import
com.zhiwei.brandkbs2.es.EsClientDao
;
...
@@ -75,6 +72,9 @@ public class TaskServiceImpl implements TaskService {
...
@@ -75,6 +72,9 @@ public class TaskServiceImpl implements TaskService {
@Resource
(
name
=
"commonServiceImpl"
)
@Resource
(
name
=
"commonServiceImpl"
)
CommonService
commonService
;
CommonService
commonService
;
@Resource
(
name
=
"eventServiceImpl"
)
EventService
eventService
;
@Resource
(
name
=
"taskServiceExecutor"
)
@Resource
(
name
=
"taskServiceExecutor"
)
ThreadPoolTaskExecutor
taskServiceExecutor
;
ThreadPoolTaskExecutor
taskServiceExecutor
;
...
@@ -277,6 +277,19 @@ public class TaskServiceImpl implements TaskService {
...
@@ -277,6 +277,19 @@ public class TaskServiceImpl implements TaskService {
log
.
info
(
"本次清理过期聚合:{}条"
,
deleteCount
);
log
.
info
(
"本次清理过期聚合:{}条"
,
deleteCount
);
}
}
@Override
public
void
eventUpdate
()
{
for
(
Project
project
:
projectService
.
getAllProjectsWithStart
())
{
List
<
Event
>
events
=
eventService
.
findNotEndEventByProjectId
(
project
.
getId
());
log
.
info
(
"{}项目,未结束事件{}个"
,
project
.
getProjectName
(),
events
.
size
());
if
(
Tools
.
isEmpty
(
events
))
{
continue
;
}
eventService
.
analysisEvents
(
events
.
stream
().
map
(
Event:
:
getId
).
collect
(
Collectors
.
toList
()));
log
.
info
(
"{}项目,未结束事件已更新{}个"
,
project
.
getProjectName
(),
events
.
size
());
}
}
private
boolean
reportSendByProject
(
Project
project
)
{
private
boolean
reportSendByProject
(
Project
project
)
{
boolean
flag
=
false
;
boolean
flag
=
false
;
// 扫描setting信息
// 扫描setting信息
...
...
src/main/java/com/zhiwei/brandkbs2/task/ControlCenter.java
View file @
3415949b
...
@@ -77,4 +77,17 @@ public class ControlCenter {
...
@@ -77,4 +77,17 @@ public class ControlCenter {
}
}
}
}
@Async
(
"scheduledExecutor"
)
@Scheduled
(
cron
=
"0 0 2 * * ?"
)
public
void
eventUpdate
()
{
log
.
info
(
"定时按天更新事件任务-启动"
);
try
{
taskService
.
eventUpdate
();
}
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