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
65eb64c0
Commit
65eb64c0
authored
Nov 28, 2022
by
shenjunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整渠道参与事件查询逻辑
parent
849ae8db
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
7 deletions
+77
-7
src/main/java/com/zhiwei/brandkbs2/dao/EventDataDao.java
+10
-0
src/main/java/com/zhiwei/brandkbs2/dao/impl/EventDaoImpl.java
+32
-2
src/main/java/com/zhiwei/brandkbs2/dao/impl/EventDataDaoImpl.java
+15
-0
src/main/java/com/zhiwei/brandkbs2/easyexcel/dto/ExportAppChannelArticleDTO.java
+3
-2
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
+11
-2
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
+6
-1
No files found.
src/main/java/com/zhiwei/brandkbs2/dao/EventDataDao.java
View file @
65eb64c0
...
...
@@ -6,6 +6,7 @@ import com.zhiwei.brandkbs2.pojo.EventData;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.CompletableFuture
;
/**
...
...
@@ -70,4 +71,13 @@ public interface EventDataDao extends BaseMongoDao<EventData>, ShardingMongo {
* @return list
*/
long
findEventDataCount
(
String
eventId
,
String
collectionName
);
/**
* 查询渠道符合时间段内的所有事件id
* @param channelFid
* @param startTime
* @param endTime
* @return
*/
Set
<
String
>
findEventIdsByChannelFid
(
String
channelFid
,
long
startTime
,
long
endTime
);
}
src/main/java/com/zhiwei/brandkbs2/dao/impl/EventDaoImpl.java
View file @
65eb64c0
...
...
@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.dao.impl;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.dao.EventDao
;
import
com.zhiwei.brandkbs2.dao.EventDataDao
;
import
com.zhiwei.brandkbs2.enmus.EmotionEnum
;
import
com.zhiwei.brandkbs2.pojo.ChannelIndex
;
import
com.zhiwei.brandkbs2.pojo.Event
;
...
...
@@ -16,6 +17,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -32,6 +34,9 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
private
static
final
String
COLLECTION_NAME
=
"brandkbs_event"
;
@Resource
(
name
=
"eventDataDao"
)
EventDataDao
eventDataDao
;
public
EventDaoImpl
()
{
super
(
COLLECTION_NAME
);
}
...
...
@@ -64,12 +69,14 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
@Override
public
Map
<
Long
,
List
<
Event
>>
getEventDay
(
ChannelIndex
channelIndex
,
Long
startTime
,
Long
endTime
)
{
return
getEventTimePattern
(
channelIndex
,
startTime
,
endTime
,
8
+
2
);
// return getEventTimePattern(channelIndex, startTime, endTime, 8 + 2);
return
getEventTimePatternNew
(
channelIndex
,
startTime
,
endTime
,
false
);
}
@Override
public
Map
<
Long
,
List
<
Event
>>
getEventMonth
(
ChannelIndex
channelIndex
,
Long
startTime
,
Long
endTime
)
{
return
getEventTimePattern
(
channelIndex
,
startTime
,
endTime
,
6
+
1
);
// return getEventTimePattern(channelIndex, startTime, endTime, 6 + 1);
return
getEventTimePatternNew
(
channelIndex
,
startTime
,
endTime
,
true
);
}
@Override
...
...
@@ -214,6 +221,7 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
return
Aggregation
.
newAggregation
(
operations
);
}
@Deprecated
private
Map
<
Long
,
List
<
Event
>>
getEventTimePattern
(
ChannelIndex
channelIndex
,
Long
startTime
,
Long
endTime
,
int
nrOfChars
)
{
Map
<
Long
,
List
<
Event
>>
res
=
new
HashMap
<>();
// 事件筛选条件
...
...
@@ -247,6 +255,28 @@ public class EventDaoImpl extends BaseMongoDaoImpl<Event> implements EventDao {
return
res
;
}
private
Map
<
Long
,
List
<
Event
>>
getEventTimePatternNew
(
ChannelIndex
channelIndex
,
Long
startTime
,
Long
endTime
,
boolean
month
)
{
Map
<
Long
,
List
<
Event
>>
res
=
new
HashMap
<>();
String
pattern
;
if
(
month
)
{
pattern
=
Constant
.
MONTH_PATTERN
;
}
else
{
pattern
=
Constant
.
DAY_PATTERN
;
}
for
(
String
eventId
:
eventDataDao
.
findEventIdsByChannelFid
(
channelIndex
.
getFid
(),
startTime
,
endTime
))
{
Event
event
=
findOneById
(
eventId
);
Long
mapKey
=
Tools
.
truncDate
(
event
.
getStartTime
(),
pattern
);
res
.
putIfAbsent
(
mapKey
,
new
ArrayList
<>());
res
.
get
(
mapKey
).
add
(
event
);
}
// 时间降序
for
(
Map
.
Entry
<
Long
,
List
<
Event
>>
entry
:
res
.
entrySet
())
{
List
<
Event
>
newList
=
entry
.
getValue
().
stream
().
sorted
((
x
,
y
)
->
Long
.
compare
(
y
.
getStartTime
(),
x
.
getStartTime
())).
collect
(
Collectors
.
toList
());
res
.
put
(
entry
.
getKey
(),
newList
);
}
return
res
;
}
private
List
<
String
>
getAggreeCollections
(
int
years
)
{
List
<
String
>
res
=
new
ArrayList
<>();
Calendar
date
=
Calendar
.
getInstance
();
...
...
src/main/java/com/zhiwei/brandkbs2/dao/impl/EventDataDaoImpl.java
View file @
65eb64c0
...
...
@@ -4,14 +4,18 @@ import com.zhiwei.brandkbs2.dao.EventDataDao;
import
com.zhiwei.brandkbs2.pojo.ChannelIndex
;
import
com.zhiwei.brandkbs2.pojo.Event
;
import
com.zhiwei.brandkbs2.pojo.EventData
;
import
org.bson.types.ObjectId
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.stream.Collectors
;
/**
* @ClassName: EventDataDaoImpl
...
...
@@ -81,4 +85,15 @@ public class EventDataDaoImpl extends BaseMongoDaoImpl<EventData> implements Eve
return
mongoTemplate
.
count
(
query
,
EventData
.
class
,
collectionName
);
}
@Override
public
Set
<
String
>
findEventIdsByChannelFid
(
String
channelFid
,
long
startTime
,
long
endTime
)
{
Set
<
String
>
res
=
new
HashSet
<>();
Criteria
criteria
=
Criteria
.
where
(
"channelFid"
).
is
(
channelFid
).
and
(
"eventMapper.startTime"
).
gte
(
startTime
).
lt
(
endTime
);
for
(
String
eventDataCollection
:
generateCollectionNames
(
new
Date
(
startTime
),
new
Date
(
endTime
)))
{
List
<
ObjectId
>
list
=
mongoTemplate
.
findDistinct
(
Query
.
query
(
criteria
),
"eventMapper._id"
,
eventDataCollection
,
ObjectId
.
class
);
res
.
addAll
(
list
.
stream
().
map
(
ObjectId:
:
toString
).
collect
(
Collectors
.
toList
()));
}
return
res
;
}
}
src/main/java/com/zhiwei/brandkbs2/easyexcel/dto/ExportAppChannelArticleDTO.java
View file @
65eb64c0
...
...
@@ -32,11 +32,12 @@ public class ExportAppChannelArticleDTO {
@ExcelProperty
(
"情感倾向"
)
private
String
emotion
;
public
static
ExportAppChannelArticleDTO
createFromArticle
(
ChannelIndex
.
Article
article
,
String
url
,
String
title
)
{
public
static
ExportAppChannelArticleDTO
createFromArticle
(
ChannelIndex
.
Article
article
,
String
title
,
String
content
,
String
url
)
{
ExportAppChannelArticleDTO
dto
=
new
ExportAppChannelArticleDTO
();
dto
.
setTime
(
new
Date
(
article
.
getTime
()));
dto
.
setUrl
(
url
);
dto
.
setTitle
(
title
);
dto
.
setContent
(
content
);
dto
.
setUrl
(
url
);
dto
.
setEmotion
(
EmotionEnum
.
state2Name
(
article
.
getEmotion
()));
return
dto
;
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/ChannelServiceImpl.java
View file @
65eb64c0
...
...
@@ -697,8 +697,8 @@ public class ChannelServiceImpl implements ChannelService {
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
[]
title
Url
=
getTitleAnd
UrlById
(
article
.
getId
());
return
ExportAppChannelArticleDTO
.
createFromArticle
(
article
,
title
Url
[
0
],
titleUrl
[
1
]);
String
[]
title
ContentUrl
=
getTitleContent
UrlById
(
article
.
getId
());
return
ExportAppChannelArticleDTO
.
createFromArticle
(
article
,
title
ContentUrl
[
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
());
...
...
@@ -1471,6 +1471,15 @@ public class ChannelServiceImpl implements ChannelService {
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
()};
}
catch
(
IOException
ignored
)
{
}
return
new
String
[]{
null
,
null
,
null
};
}
private
boolean
hasEmotion
(
Channel
channel
)
{
if
(
"0"
.
equals
(
channel
.
getContendId
()))
{
return
true
;
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
View file @
65eb64c0
...
...
@@ -242,7 +242,12 @@ public class UserServiceImpl implements UserService {
Optional
.
ofNullable
(
projectDao
.
findOne
(
"projectName"
,
userProject
.
getProjectName
())).
ifPresent
(
project
->
{
// 排除已经有权限的Project
if
(
userRoles
.
stream
().
noneMatch
(
userRole
->
userRole
.
getProjectId
().
equals
(
project
.
getId
())))
{
userRoles
.
add
(
new
UserRole
(
project
.
getId
(),
userProject
.
getRoleId
(),
userProject
.
getExpiredTime
(),
userProject
.
getExportAmount
()));
Long
expiredTime
=
null
;
// 只有客户才有过期时间
if
(
RoleEnum
.
CUSTOMER
.
getState
()
==
userProject
.
getRoleId
())
{
expiredTime
=
userProject
.
getExpiredTime
();
}
userRoles
.
add
(
new
UserRole
(
project
.
getId
(),
userProject
.
getRoleId
(),
expiredTime
,
userProject
.
getExportAmount
()));
hit
.
set
(
true
);
}
});
...
...
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