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
5512630b
Commit
5512630b
authored
Dec 04, 2024
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release' into 'master'
Release See merge request
!600
parents
8569040e
6b660635
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
617 additions
and
48 deletions
+617
-48
src/main/java/com/zhiwei/brandkbs2/controller/admin/ProjectController.java
+15
-4
src/main/java/com/zhiwei/brandkbs2/controller/admin/UserController.java
+2
-2
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/BytedanceEventListener.java
+6
-7
src/main/java/com/zhiwei/brandkbs2/es/EsClientDao.java
+12
-2
src/main/java/com/zhiwei/brandkbs2/pojo/NonManualProjectPlan.java
+38
-2
src/main/java/com/zhiwei/brandkbs2/pojo/Project.java
+6
-0
src/main/java/com/zhiwei/brandkbs2/pojo/UserRole.java
+17
-4
src/main/java/com/zhiwei/brandkbs2/pojo/dto/NonManualProjectPlanDTO.java
+6
-0
src/main/java/com/zhiwei/brandkbs2/pojo/dto/UserDTO.java
+15
-0
src/main/java/com/zhiwei/brandkbs2/pojo/vo/ProjectVO.java
+6
-0
src/main/java/com/zhiwei/brandkbs2/service/ProjectService.java
+9
-2
src/main/java/com/zhiwei/brandkbs2/service/TaskService.java
+5
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
+4
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/ProjectServiceImpl.java
+43
-4
src/main/java/com/zhiwei/brandkbs2/service/impl/TaskServiceImpl.java
+149
-0
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
+31
-10
src/main/java/com/zhiwei/brandkbs2/task/ControlCenter.java
+13
-0
src/main/java/com/zhiwei/brandkbs2/util/RobotPushUtils.java
+211
-0
src/main/resources/application-local.properties
+4
-4
src/test/java/com/zhiwei/brandkbs2/BrandkbsIndexCreateTest.java
+23
-5
src/test/java/com/zhiwei/brandkbs2/MarkDataServiceTest.java
+1
-1
src/test/java/com/zhiwei/brandkbs2/ProjectServiceTest.java
+1
-1
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/admin/ProjectController.java
View file @
5512630b
...
@@ -83,8 +83,11 @@ public class ProjectController extends BaseController {
...
@@ -83,8 +83,11 @@ public class ProjectController extends BaseController {
@ApiImplicitParam
(
name
=
"size"
,
value
=
"每页记录数"
,
required
=
false
,
defaultValue
=
"10"
,
paramType
=
"query"
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
"size"
,
value
=
"每页记录数"
,
required
=
false
,
defaultValue
=
"10"
,
paramType
=
"query"
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
"keyword"
,
value
=
"搜索关键字"
,
required
=
false
,
defaultValue
=
""
,
paramType
=
"query"
,
dataType
=
"string"
)})
@ApiImplicitParam
(
name
=
"keyword"
,
value
=
"搜索关键字"
,
required
=
false
,
defaultValue
=
""
,
paramType
=
"query"
,
dataType
=
"string"
)})
@GetMapping
(
"/list"
)
@GetMapping
(
"/list"
)
public
ResponseResult
findProjectList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
int
page
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
int
size
,
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
)
{
public
ResponseResult
findProjectList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
int
page
,
return
ResponseResult
.
success
(
ProjectService
.
findProjectList
(
page
,
size
,
keyword
));
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
int
size
,
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
,
@RequestParam
(
value
=
"isStart"
,
required
=
false
)
Boolean
isStart
)
{
return
ResponseResult
.
success
(
ProjectService
.
findProjectList
(
page
,
size
,
keyword
,
isStart
));
}
}
...
@@ -286,8 +289,9 @@ public class ProjectController extends BaseController {
...
@@ -286,8 +289,9 @@ public class ProjectController extends BaseController {
public
ResponseResult
findNonManualProjectList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
int
page
,
public
ResponseResult
findNonManualProjectList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
int
page
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
int
size
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
int
size
,
@RequestParam
(
value
=
"sorter"
,
defaultValue
=
"{\"cTime\":\"descend\"}"
)
String
sorter
,
@RequestParam
(
value
=
"sorter"
,
defaultValue
=
"{\"cTime\":\"descend\"}"
)
String
sorter
,
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
)
{
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
,
return
ResponseResult
.
success
(
ProjectService
.
findNonManualProjectList
(
page
,
size
,
sorter
,
keyword
));
@RequestParam
(
value
=
"isStart"
,
required
=
false
)
Boolean
isStart
)
{
return
ResponseResult
.
success
(
ProjectService
.
findNonManualProjectList
(
page
,
size
,
sorter
,
keyword
,
isStart
));
}
}
@ApiOperation
(
"非人工项目-维护记录列表"
)
@ApiOperation
(
"非人工项目-维护记录列表"
)
...
@@ -316,4 +320,11 @@ public class ProjectController extends BaseController {
...
@@ -316,4 +320,11 @@ public class ProjectController extends BaseController {
public
ResponseResult
switchExternalDataSource
(
@PathVariable
String
id
){
public
ResponseResult
switchExternalDataSource
(
@PathVariable
String
id
){
return
ProjectService
.
switchExternalDataSource
(
id
);
return
ProjectService
.
switchExternalDataSource
(
id
);
}
}
@ApiOperation
(
"非人工项目-方案查看"
)
@GetMapping
(
"/non-manual/plan/{id}"
)
public
ResponseResult
findNonManualProjectPlan
(
@PathVariable
String
id
){
return
ProjectService
.
findNonManualProjectPlan
(
id
);
}
}
}
src/main/java/com/zhiwei/brandkbs2/controller/admin/UserController.java
View file @
5512630b
...
@@ -143,7 +143,7 @@ public class UserController extends BaseController {
...
@@ -143,7 +143,7 @@ public class UserController extends BaseController {
@PostMapping
(
"/all-user/single-update"
)
@PostMapping
(
"/all-user/single-update"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
updateOneUserRoles
(
@ApiParam
(
name
=
"json"
,
public
ResponseResult
updateOneUserRoles
(
@ApiParam
(
name
=
"json"
,
value
=
"json:{id:用户id,nickname:用户名,roleId:权限,expiredTime:过期时间,exportAmount:舆情导出数量,projectId:权限项目id,key:唯一key原封不动传回来即可}"
,
value
=
"json:{id:用户id,nickname:用户名,roleId:权限,expiredTime:过期时间,exportAmount:舆情导出数量,projectId:权限项目id,key:唯一key原封不动传回来即可
,searchWholeRights:全网搜权益,searchWholeRange:全网搜跨度
}"
,
required
=
true
)
@RequestBody
JSONObject
json
)
{
required
=
true
)
@RequestBody
JSONObject
json
)
{
return
userService
.
updateOneUserRoles
(
json
);
return
userService
.
updateOneUserRoles
(
json
);
}
}
...
@@ -151,7 +151,7 @@ public class UserController extends BaseController {
...
@@ -151,7 +151,7 @@ public class UserController extends BaseController {
@ApiOperation
(
"批量编辑项目权限"
)
@ApiOperation
(
"批量编辑项目权限"
)
@PostMapping
(
"/all-user/batch-update"
)
@PostMapping
(
"/all-user/batch-update"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
updateBatchUserRoles
(
@ApiParam
(
name
=
"json"
,
value
=
"json:{id:用户id,roles:[{projectId:权限项目id,roleId:权限,exportAmount:舆情导出数量,expiredTime:过期时间},{},...]}"
,
public
ResponseResult
updateBatchUserRoles
(
@ApiParam
(
name
=
"json"
,
value
=
"json:{id:用户id,roles:[{projectId:权限项目id,roleId:权限,exportAmount:舆情导出数量,expiredTime:过期时间
,searchWholeRights:全网搜权益,searchWholeRange:全网搜跨度
},{},...]}"
,
required
=
true
)
required
=
true
)
@RequestBody
JSONObject
json
)
{
@RequestBody
JSONObject
json
)
{
return
userService
.
updateBatchUserRoles
(
json
);
return
userService
.
updateBatchUserRoles
(
json
);
...
...
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/BytedanceEventListener.java
View file @
5512630b
...
@@ -5,10 +5,10 @@ import com.alibaba.excel.event.AnalysisEventListener;
...
@@ -5,10 +5,10 @@ import com.alibaba.excel.event.AnalysisEventListener;
import
com.zhiwei.brandkbs2.easyexcel.dto.UploadBytedanceEventDTO
;
import
com.zhiwei.brandkbs2.easyexcel.dto.UploadBytedanceEventDTO
;
import
com.zhiwei.brandkbs2.pojo.BytedanceCustomEventUpdateTaskData
;
import
com.zhiwei.brandkbs2.pojo.BytedanceCustomEventUpdateTaskData
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
/**
/**
* @ClassName: BytedanceEventListener
* @ClassName: BytedanceEventListener
...
@@ -55,12 +55,11 @@ public class BytedanceEventListener extends AnalysisEventListener<UploadBytedanc
...
@@ -55,12 +55,11 @@ public class BytedanceEventListener extends AnalysisEventListener<UploadBytedanc
taskData
.
setPlatform
(
dto
.
getPlatform
());
taskData
.
setPlatform
(
dto
.
getPlatform
());
taskData
.
setChannel
(
dto
.
getChannel
());
taskData
.
setChannel
(
dto
.
getChannel
());
taskData
.
setEventName
(
dto
.
getEventName
());
taskData
.
setEventName
(
dto
.
getEventName
());
// 填 "/" 当作0处理
taskData
.
setReading
(
StringUtils
.
isNumeric
(
dto
.
getReading
())
?
Integer
.
parseInt
(
dto
.
getReading
())
:
0
);
taskData
.
setReading
(
Objects
.
isNull
(
dto
.
getReading
())
||
Objects
.
equals
(
"/"
,
dto
.
getReading
())
?
0
:
Integer
.
parseInt
(
dto
.
getReading
()));
taskData
.
setRead
(
StringUtils
.
isNumeric
(
dto
.
getRead
())
?
Integer
.
parseInt
(
dto
.
getRead
())
:
0
);
taskData
.
setRead
(
Objects
.
isNull
(
dto
.
getRead
())
||
Objects
.
equals
(
"/"
,
dto
.
getRead
())
?
0
:
Integer
.
parseInt
(
dto
.
getRead
()));
taskData
.
setLike
(
StringUtils
.
isNumeric
(
dto
.
getLike
())
?
Integer
.
parseInt
(
dto
.
getLike
())
:
0
);
taskData
.
setLike
(
Objects
.
isNull
(
dto
.
getLike
())
||
Objects
.
equals
(
"/"
,
dto
.
getLike
())
?
0
:
Integer
.
parseInt
(
dto
.
getLike
()));
taskData
.
setComment
(
StringUtils
.
isNumeric
(
dto
.
getComment
())
?
Integer
.
parseInt
(
dto
.
getComment
())
:
0
);
taskData
.
setComment
(
Objects
.
isNull
(
dto
.
getComment
())
||
Objects
.
equals
(
"/"
,
dto
.
getComment
())
?
0
:
Integer
.
parseInt
(
dto
.
getComment
()));
taskData
.
setForward
(
StringUtils
.
isNumeric
(
dto
.
getForward
())
?
Integer
.
parseInt
(
dto
.
getForward
())
:
0
);
taskData
.
setForward
(
Objects
.
isNull
(
dto
.
getForward
())
||
Objects
.
equals
(
"/"
,
dto
.
getForward
())
?
0
:
Integer
.
parseInt
(
dto
.
getForward
()));
data
.
add
(
taskData
);
data
.
add
(
taskData
);
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/es/EsClientDao.java
View file @
5512630b
...
@@ -40,7 +40,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilder;
...
@@ -40,7 +40,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilder;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder
;
import
org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder
;
import
org.elasticsearch.search.sort.FieldSortBuilder
;
import
org.elasticsearch.search.sort.FieldSortBuilder
;
import
org.elasticsearch.search.sort.SortOrder
;
import
org.joda.time.Period
;
import
org.joda.time.Period
;
import
org.joda.time.PeriodType
;
import
org.joda.time.PeriodType
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -102,13 +101,24 @@ public class EsClientDao {
...
@@ -102,13 +101,24 @@ public class EsClientDao {
* @return 渠道记录结果
* @return 渠道记录结果
*/
*/
public
List
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>
searchRecordRecentDay
(
int
day
)
{
public
List
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>
searchRecordRecentDay
(
int
day
)
{
List
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>
res
=
new
ArrayList
<>();
Calendar
calendar
=
Calendar
.
getInstance
();
Calendar
calendar
=
Calendar
.
getInstance
();
// 设置为当天0:00
// 设置为当天0:00
calendar
.
setTime
(
Tools
.
truncDate
(
calendar
.
getTime
(),
Constant
.
DAY_PATTERN
));
calendar
.
setTime
(
Tools
.
truncDate
(
calendar
.
getTime
(),
Constant
.
DAY_PATTERN
));
long
endTime
=
calendar
.
getTime
().
getTime
();
long
endTime
=
calendar
.
getTime
().
getTime
();
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
-
day
);
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
-
day
);
long
startTime
=
calendar
.
getTime
().
getTime
();
long
startTime
=
calendar
.
getTime
().
getTime
();
return
searchRecordRecent
(
startTime
,
endTime
);
}
/**
* 搜索近几天的数据
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 渠道记录结果
*/
public
List
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>
searchRecordRecent
(
long
startTime
,
long
endTime
)
{
List
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>
res
=
new
ArrayList
<>();
List
<
Long
[]>
cutTimes
=
Tools
.
cutTimeRange
(
startTime
,
endTime
,
ONE_HOUR
);
List
<
Long
[]>
cutTimes
=
Tools
.
cutTimeRange
(
startTime
,
endTime
,
ONE_HOUR
);
List
<
CompletableFuture
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>>
futures
=
new
ArrayList
<>(
cutTimes
.
size
());
List
<
CompletableFuture
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>>
futures
=
new
ArrayList
<>(
cutTimes
.
size
());
cutTimes
.
forEach
(
times
->
futures
.
add
(
CompletableFuture
.
supplyAsync
(()
->
searchRecord
(
times
[
0
],
times
[
1
]),
executor
)));
cutTimes
.
forEach
(
times
->
futures
.
add
(
CompletableFuture
.
supplyAsync
(()
->
searchRecord
(
times
[
0
],
times
[
1
]),
executor
)));
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/NonManualProjectPlan.java
View file @
5512630b
...
@@ -18,7 +18,7 @@ import java.util.List;
...
@@ -18,7 +18,7 @@ import java.util.List;
@Getter
@Getter
@Setter
@Setter
@NoArgsConstructor
@NoArgsConstructor
public
class
NonManualProjectPlan
extends
AbstractBaseMongo
{
public
class
NonManualProjectPlan
extends
AbstractBaseMongo
{
/**
/**
* 项目id
* 项目id
*/
*/
...
@@ -65,7 +65,12 @@ public class NonManualProjectPlan extends AbstractBaseMongo{
...
@@ -65,7 +65,12 @@ public class NonManualProjectPlan extends AbstractBaseMongo{
*/
*/
private
String
IStarShineSubjectTaskId
;
private
String
IStarShineSubjectTaskId
;
public
NonManualProjectPlan
(
NonManualProjectPlanDTO
dto
){
/**
* 情感倾向模型个性化配置
*/
private
ModelCustomConfig
modelCustomConfig
;
public
NonManualProjectPlan
(
NonManualProjectPlanDTO
dto
)
{
this
.
id
=
dto
.
getId
();
this
.
id
=
dto
.
getId
();
this
.
projectId
=
UserThreadLocal
.
getProjectId
();
this
.
projectId
=
UserThreadLocal
.
getProjectId
();
this
.
name
=
dto
.
getName
();
this
.
name
=
dto
.
getName
();
...
@@ -77,5 +82,36 @@ public class NonManualProjectPlan extends AbstractBaseMongo{
...
@@ -77,5 +82,36 @@ public class NonManualProjectPlan extends AbstractBaseMongo{
this
.
cTime
=
System
.
currentTimeMillis
();
this
.
cTime
=
System
.
currentTimeMillis
();
this
.
uTime
=
System
.
currentTimeMillis
();
this
.
uTime
=
System
.
currentTimeMillis
();
this
.
submitter
=
UserThreadLocal
.
getNickname
();
this
.
submitter
=
UserThreadLocal
.
getNickname
();
this
.
modelCustomConfig
=
dto
.
getModelCustomConfig
();
}
@Getter
@Setter
public
static
class
ModelCustomConfig
{
/**
* 核心词类型
*/
private
String
coreWordType
;
/**
* 核心词(最多5个不能组合)
*/
private
String
coreWord
;
/**
* 负面词(最多20个不能组合)
*/
private
String
negativeWord
;
/**
* 负面观点(最多5个)
*/
private
List
<
String
>
negativePoints
;
/**
* 正面词(最多20个不能组合)
*/
private
String
positiveWord
;
/**
* 正面观点(最多5个)
*/
private
List
<
String
>
positivePoints
;
}
}
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/Project.java
View file @
5512630b
...
@@ -119,6 +119,11 @@ public class Project extends AbstractProject {
...
@@ -119,6 +119,11 @@ public class Project extends AbstractProject {
private
Boolean
externalDataSource
;
private
Boolean
externalDataSource
;
/**
/**
* 标注模型(默认为0:nlp语料库,1:豆包模型)
*/
private
int
markModel
;
/**
* 项目主品牌配置信息转换
* 项目主品牌配置信息转换
*
*
* @return 项目对象
* @return 项目对象
...
@@ -149,6 +154,7 @@ public class Project extends AbstractProject {
...
@@ -149,6 +154,7 @@ public class Project extends AbstractProject {
projectVO
.
setPositiveChannelParams
(
this
.
getPositiveChannelParams
());
projectVO
.
setPositiveChannelParams
(
this
.
getPositiveChannelParams
());
projectVO
.
setBlackChannelGroup
(
this
.
getBlackChannelGroup
());
projectVO
.
setBlackChannelGroup
(
this
.
getBlackChannelGroup
());
projectVO
.
setMergeSensitive
(
true
);
projectVO
.
setMergeSensitive
(
true
);
projectVO
.
setMarkModel
(
this
.
getMarkModel
());
return
projectVO
;
return
projectVO
;
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/pojo/UserRole.java
View file @
5512630b
...
@@ -56,18 +56,32 @@ public class UserRole {
...
@@ -56,18 +56,32 @@ public class UserRole {
* 舆情导出数量默认1000,超管默认10000
* 舆情导出数量默认1000,超管默认10000
*/
*/
private
Integer
exportAmount
;
private
Integer
exportAmount
;
/**
* 全网搜索权益,1:近3月,2:近6月,3:近1年,4:近3年,5:近5年
* 月按:31天取
* 年按:365天取
*/
private
Integer
searchWholeRights
;
/**
* 搜索数据跨度,1:3月,2:1年,3:不限制
* 月按:31天取
* 年按:365天取
*/
private
Integer
searchWholeRange
;
public
void
setRoleId
(
Integer
roleId
)
{
public
void
setRoleId
(
Integer
roleId
)
{
this
.
roleId
=
roleId
;
this
.
roleId
=
roleId
;
this
.
key
=
Tools
.
concat
(
projectId
,
roleId
);
this
.
key
=
Tools
.
concat
(
projectId
,
roleId
);
}
}
public
UserRole
(
String
projectId
,
int
roleId
,
Long
expiredTime
,
Integer
exportAmount
)
{
public
UserRole
(
String
projectId
,
int
roleId
,
Long
expiredTime
,
Integer
exportAmount
,
int
rights
,
int
range
)
{
this
.
projectId
=
projectId
;
this
.
projectId
=
projectId
;
this
.
roleId
=
roleId
;
this
.
roleId
=
roleId
;
this
.
expiredTime
=
expiredTime
;
this
.
expiredTime
=
expiredTime
;
this
.
exportAmount
=
exportAmount
;
this
.
exportAmount
=
exportAmount
;
this
.
key
=
Tools
.
concat
(
projectId
,
roleId
);
this
.
key
=
Tools
.
concat
(
projectId
,
roleId
);
this
.
searchWholeRights
=
rights
;
this
.
searchWholeRange
=
range
;
}
}
public
static
UserRole
createFromUserDto
(
UserDTO
userDTO
)
{
public
static
UserRole
createFromUserDto
(
UserDTO
userDTO
)
{
...
@@ -86,11 +100,10 @@ public class UserRole {
...
@@ -86,11 +100,10 @@ public class UserRole {
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
expiredTime
=
calendar
.
getTime
().
getTime
();
expiredTime
=
calendar
.
getTime
().
getTime
();
}
}
return
new
UserRole
(
userDTO
.
getProjectId
(),
userDTO
.
getRoleId
(),
expiredTime
,
exportAmount
);
return
new
UserRole
(
userDTO
.
getProjectId
(),
userDTO
.
getRoleId
(),
expiredTime
,
exportAmount
,
userDTO
.
getSearchWholeRights
(),
userDTO
.
getSearchWholeRange
()
);
}
}
public
static
UserRole
defaultUserRole
(
Date
now
)
{
public
static
UserRole
defaultUserRole
(
Date
now
)
{
return
new
UserRole
(
DEFAULT_PROJECT_ID
,
DEFAULT_ROLE_ID
,
DateUtils
.
addDays
(
now
,
30
).
getTime
(),
DEFAULT_EXPORT_LIMIT
);
return
new
UserRole
(
DEFAULT_PROJECT_ID
,
DEFAULT_ROLE_ID
,
DateUtils
.
addDays
(
now
,
30
).
getTime
(),
DEFAULT_EXPORT_LIMIT
,
1
,
1
);
}
}
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/dto/NonManualProjectPlanDTO.java
View file @
5512630b
...
@@ -50,6 +50,11 @@ public class NonManualProjectPlanDTO {
...
@@ -50,6 +50,11 @@ public class NonManualProjectPlanDTO {
*/
*/
private
List
<
String
>
type
;
private
List
<
String
>
type
;
/**
* 情感模型个性化配置
*/
private
NonManualProjectPlan
.
ModelCustomConfig
modelCustomConfig
;
public
NonManualProjectPlanDTO
(
NonManualProjectPlan
plan
){
public
NonManualProjectPlanDTO
(
NonManualProjectPlan
plan
){
this
.
id
=
plan
.
getId
();
this
.
id
=
plan
.
getId
();
this
.
name
=
plan
.
getName
();
this
.
name
=
plan
.
getName
();
...
@@ -58,5 +63,6 @@ public class NonManualProjectPlanDTO {
...
@@ -58,5 +63,6 @@ public class NonManualProjectPlanDTO {
this
.
lasting
=
plan
.
getLasting
();
this
.
lasting
=
plan
.
getLasting
();
this
.
endTime
=
plan
.
getEndTime
();
this
.
endTime
=
plan
.
getEndTime
();
this
.
type
=
plan
.
getType
();
this
.
type
=
plan
.
getType
();
this
.
modelCustomConfig
=
plan
.
getModelCustomConfig
();
}
}
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/dto/UserDTO.java
View file @
5512630b
...
@@ -70,4 +70,19 @@ public class UserDTO {
...
@@ -70,4 +70,19 @@ public class UserDTO {
@ApiModelProperty
(
"舆情导出数量"
)
@ApiModelProperty
(
"舆情导出数量"
)
private
Integer
exportAmount
;
private
Integer
exportAmount
;
/**
* 全网搜索权益,1:近3月,2:近6月,3:近1年,4:近3年,5:近5年
* 月按:31天取
* 年按:365天取
*/
@ApiModelProperty
(
"全网搜索权益"
)
private
Integer
searchWholeRights
;
/**
* 搜索数据跨度,1:3月,2:1年,3:不限制
* 月按:31天取
* 年按:365天取
*/
@ApiModelProperty
(
"全网搜索数据跨度"
)
private
Integer
searchWholeRange
;
}
}
src/main/java/com/zhiwei/brandkbs2/pojo/vo/ProjectVO.java
View file @
5512630b
...
@@ -133,6 +133,11 @@ public class ProjectVO {
...
@@ -133,6 +133,11 @@ public class ProjectVO {
private
List
<
EventTagRelatedDTO
>
eventTagsList
;
private
List
<
EventTagRelatedDTO
>
eventTagsList
;
/**
/**
* 标注模型(默认为0:nlp语料库,1:豆包模型)
*/
private
int
markModel
;
/**
* 项目主品牌配置信息转换
* 项目主品牌配置信息转换
*
*
* @return 项目对象
* @return 项目对象
...
@@ -214,6 +219,7 @@ public class ProjectVO {
...
@@ -214,6 +219,7 @@ public class ProjectVO {
project
.
setManual
(
false
);
project
.
setManual
(
false
);
project
.
setShow
(
true
);
project
.
setShow
(
true
);
project
.
setStart
(
true
);
project
.
setStart
(
true
);
project
.
setMarkModel
(
vo
.
getMarkModel
());
project
.
setCTime
(
System
.
currentTimeMillis
());
project
.
setCTime
(
System
.
currentTimeMillis
());
project
.
setUTime
(
System
.
currentTimeMillis
());
project
.
setUTime
(
System
.
currentTimeMillis
());
return
project
;
return
project
;
...
...
src/main/java/com/zhiwei/brandkbs2/service/ProjectService.java
View file @
5512630b
...
@@ -32,7 +32,7 @@ public interface ProjectService {
...
@@ -32,7 +32,7 @@ public interface ProjectService {
* @param keyword 关键字
* @param keyword 关键字
* @return 项目列表
* @return 项目列表
*/
*/
PageVO
<
JSONObject
>
findProjectList
(
int
page
,
int
size
,
String
keyword
);
PageVO
<
JSONObject
>
findProjectList
(
int
page
,
int
size
,
String
keyword
,
Boolean
isStart
);
/**
/**
* 根据项目ID获取该项目信息
* 根据项目ID获取该项目信息
...
@@ -171,7 +171,7 @@ public interface ProjectService {
...
@@ -171,7 +171,7 @@ public interface ProjectService {
* @param keyword 关键词
* @param keyword 关键词
* @return
* @return
*/
*/
PageVO
<
JSONObject
>
findNonManualProjectList
(
int
page
,
int
size
,
String
sorter
,
String
keyword
);
PageVO
<
JSONObject
>
findNonManualProjectList
(
int
page
,
int
size
,
String
sorter
,
String
keyword
,
Boolean
isStart
);
/**
/**
* 非人工项目剩余数据量调整记录列表
* 非人工项目剩余数据量调整记录列表
...
@@ -216,4 +216,11 @@ public interface ProjectService {
...
@@ -216,4 +216,11 @@ public interface ProjectService {
* @param projectId
* @param projectId
*/
*/
ResponseResult
switchExternalDataSource
(
String
projectId
);
ResponseResult
switchExternalDataSource
(
String
projectId
);
/**
* 查看非人工项目方案列表
*
* @param projectId
*/
ResponseResult
findNonManualProjectPlan
(
String
projectId
);
}
}
src/main/java/com/zhiwei/brandkbs2/service/TaskService.java
View file @
5512630b
...
@@ -82,4 +82,9 @@ public interface TaskService{
...
@@ -82,4 +82,9 @@ public interface TaskService{
* 生成ai搜索参考提问缓存
* 生成ai搜索参考提问缓存
*/
*/
void
cacheAIQuestion
();
void
cacheAIQuestion
();
/**
* 非人工项目企业微信机器人数据用量预警
*/
void
wechatRobotWarnPush
();
}
}
src/main/java/com/zhiwei/brandkbs2/service/impl/MarkDataServiceImpl.java
View file @
5512630b
...
@@ -4046,6 +4046,10 @@ public class MarkDataServiceImpl implements MarkDataService {
...
@@ -4046,6 +4046,10 @@ public class MarkDataServiceImpl implements MarkDataService {
return
getAIReferenceQuestionTemplate
(
projectName
);
return
getAIReferenceQuestionTemplate
(
projectName
);
}
}
String
resultContent
=
pair
.
getLeft
();
String
resultContent
=
pair
.
getLeft
();
String
[]
split1
=
resultContent
.
split
(
":"
);
if
(
1
!=
split1
.
length
){
resultContent
=
split1
[
1
];
}
String
[]
splits
=
resultContent
.
split
(
"\\|"
);
String
[]
splits
=
resultContent
.
split
(
"\\|"
);
// 需记录本次耗费
// 需记录本次耗费
double
cost
=
calculateCost
(
pair
.
getRight
(),
model
);
double
cost
=
calculateCost
(
pair
.
getRight
(),
model
);
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/ProjectServiceImpl.java
View file @
5512630b
...
@@ -19,6 +19,7 @@ import com.zhiwei.brandkbs2.service.MarkDataService;
...
@@ -19,6 +19,7 @@ import com.zhiwei.brandkbs2.service.MarkDataService;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.service.UserService
;
import
com.zhiwei.brandkbs2.service.UserService
;
import
com.zhiwei.brandkbs2.util.MongoUtil
;
import
com.zhiwei.brandkbs2.util.MongoUtil
;
import
com.zhiwei.brandkbs2.util.RobotPushUtils
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
com.zhiwei.middleware.auth.util.JwtUtil
;
import
com.zhiwei.middleware.auth.util.JwtUtil
;
import
com.zhiwei.middleware.event.pojo.dto.EventTagRelatedDTO
;
import
com.zhiwei.middleware.event.pojo.dto.EventTagRelatedDTO
;
...
@@ -26,6 +27,7 @@ import com.zhiwei.middleware.event.pojo.entity.BrandkbsBasicInfo;
...
@@ -26,6 +27,7 @@ import com.zhiwei.middleware.event.pojo.entity.BrandkbsBasicInfo;
import
com.zhiwei.middleware.mark.vo.MarkerTag
;
import
com.zhiwei.middleware.mark.vo.MarkerTag
;
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.commons.lang3.tuple.Pair
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -39,6 +41,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
...
@@ -39,6 +41,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.text.MessageFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -142,13 +145,19 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -142,13 +145,19 @@ public class ProjectServiceImpl implements ProjectService {
}
}
@Override
@Override
public
PageVO
<
JSONObject
>
findProjectList
(
int
page
,
int
size
,
String
keyword
)
{
public
PageVO
<
JSONObject
>
findProjectList
(
int
page
,
int
size
,
String
keyword
,
Boolean
isStart
)
{
Query
query
=
new
Query
();
Query
query
=
new
Query
();
// 人工项目
query
.
addCriteria
(
Criteria
.
where
(
"isManual"
).
is
(
true
));
query
.
addCriteria
(
Criteria
.
where
(
"isManual"
).
is
(
true
));
// projectDao.addKeywordFuzz(query, keyword, "extraProjectName", "projectName");
// 状态
if
(
Objects
.
nonNull
(
isStart
)){
query
.
addCriteria
(
Criteria
.
where
(
"isStart"
).
is
(
isStart
));
}
if
(
StringUtils
.
isNotBlank
(
keyword
))
{
Criteria
extraProjectName
=
Criteria
.
where
(
"extraProjectName"
).
regex
(
keyword
,
"i"
);
Criteria
extraProjectName
=
Criteria
.
where
(
"extraProjectName"
).
regex
(
keyword
,
"i"
);
Criteria
projectName
=
Criteria
.
where
(
"projectName"
).
regex
(
keyword
,
"i"
);
Criteria
projectName
=
Criteria
.
where
(
"projectName"
).
regex
(
keyword
,
"i"
);
query
.
addCriteria
(
new
Criteria
().
orOperator
(
extraProjectName
,
projectName
));
query
.
addCriteria
(
new
Criteria
().
orOperator
(
extraProjectName
,
projectName
));
}
long
count
=
projectDao
.
count
(
query
);
long
count
=
projectDao
.
count
(
query
);
projectDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
projectDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
mongoUtil
.
start
(
page
,
size
,
query
);
mongoUtil
.
start
(
page
,
size
,
query
);
...
@@ -576,13 +585,19 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -576,13 +585,19 @@ public class ProjectServiceImpl implements ProjectService {
}
}
@Override
@Override
public
PageVO
<
JSONObject
>
findNonManualProjectList
(
int
page
,
int
size
,
String
sorter
,
String
keyword
)
{
public
PageVO
<
JSONObject
>
findNonManualProjectList
(
int
page
,
int
size
,
String
sorter
,
String
keyword
,
Boolean
isStart
)
{
Query
query
=
new
Query
();
Query
query
=
new
Query
();
// 人工项目
query
.
addCriteria
(
Criteria
.
where
(
"isManual"
).
is
(
false
));
query
.
addCriteria
(
Criteria
.
where
(
"isManual"
).
is
(
false
));
// projectDao.addKeywordFuzz(query, keyword, "extraProjectName", "projectName");
// 状态
if
(
Objects
.
nonNull
(
isStart
)){
query
.
addCriteria
(
Criteria
.
where
(
"isStart"
).
is
(
isStart
));
}
if
(
StringUtils
.
isNotBlank
(
keyword
))
{
Criteria
extraProjectName
=
Criteria
.
where
(
"extraProjectName"
).
regex
(
keyword
,
"i"
);
Criteria
extraProjectName
=
Criteria
.
where
(
"extraProjectName"
).
regex
(
keyword
,
"i"
);
Criteria
projectName
=
Criteria
.
where
(
"projectName"
).
regex
(
keyword
,
"i"
);
Criteria
projectName
=
Criteria
.
where
(
"projectName"
).
regex
(
keyword
,
"i"
);
query
.
addCriteria
(
new
Criteria
().
orOperator
(
extraProjectName
,
projectName
));
query
.
addCriteria
(
new
Criteria
().
orOperator
(
extraProjectName
,
projectName
));
}
long
count
=
projectDao
.
count
(
query
);
long
count
=
projectDao
.
count
(
query
);
if
(
Objects
.
isNull
(
sorter
)
||
Objects
.
isNull
(
JSONObject
.
parseObject
(
sorter
))
||
JSONObject
.
parseObject
(
sorter
).
isEmpty
()){
if
(
Objects
.
isNull
(
sorter
)
||
Objects
.
isNull
(
JSONObject
.
parseObject
(
sorter
))
||
JSONObject
.
parseObject
(
sorter
).
isEmpty
()){
projectDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
projectDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
...
@@ -636,6 +651,11 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -636,6 +651,11 @@ public class ProjectServiceImpl implements ProjectService {
projectDao
.
updateOneByIdWithField
(
projectId
,
update
);
projectDao
.
updateOneByIdWithField
(
projectId
,
update
);
NonManualProjectDataUpdateRecord
record
=
new
NonManualProjectDataUpdateRecord
(
projectId
,
project
.
getDataBalance
(),
currentCount
,
UserThreadLocal
.
getNickname
());
NonManualProjectDataUpdateRecord
record
=
new
NonManualProjectDataUpdateRecord
(
projectId
,
project
.
getDataBalance
(),
currentCount
,
UserThreadLocal
.
getNickname
());
nonManualProjectDataUpdateRecordDao
.
insertOne
(
record
);
nonManualProjectDataUpdateRecordDao
.
insertOne
(
record
);
String
message
=
"预警项目:{0}-数据额度调整"
+
"\n"
+
"调整前额度:{1}"
+
"\n"
+
"调整后额度:{2}"
+
"\n"
+
"调整人员:{3}"
;
RobotPushUtils
.
pushCommonMessage
(
MessageFormat
.
format
(
message
,
project
.
getProjectName
(),
project
.
getDataBalance
(),
currentCount
,
UserThreadLocal
.
getNickname
()));
}
}
@Override
@Override
...
@@ -747,6 +767,12 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -747,6 +767,12 @@ public class ProjectServiceImpl implements ProjectService {
return
ResponseResult
.
success
();
return
ResponseResult
.
success
();
}
}
@Override
public
ResponseResult
findNonManualProjectPlan
(
String
projectId
)
{
List
<
NonManualProjectPlan
>
list
=
nonManualProjectPlanDao
.
findList
(
Query
.
query
(
Criteria
.
where
(
"projectId"
).
is
(
projectId
)));
return
ResponseResult
.
success
(
list
);
}
/**
/**
* 获取舆情对应项目的情感标签
* 获取舆情对应项目的情感标签
* @param brandName
* @param brandName
...
@@ -763,6 +789,7 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -763,6 +789,7 @@ public class ProjectServiceImpl implements ProjectService {
protected
List
<
JSONObject
>
getProjectListByUser
(
User
user
,
boolean
retainExpired
)
{
protected
List
<
JSONObject
>
getProjectListByUser
(
User
user
,
boolean
retainExpired
)
{
List
<
Project
>
lists
;
List
<
Project
>
lists
;
Map
<
String
,
Date
>
roleExpired
=
new
HashMap
<>();
Map
<
String
,
Date
>
roleExpired
=
new
HashMap
<>();
Map
<
String
,
Pair
<
Integer
,
Integer
>>
searchWholeInfo
=
new
HashMap
<>();
if
(
user
.
isSuperAdmin
())
{
if
(
user
.
isSuperAdmin
())
{
lists
=
projectDao
.
findListByKeywordFuzz
(
null
,
null
);
lists
=
projectDao
.
findListByKeywordFuzz
(
null
,
null
);
}
else
{
}
else
{
...
@@ -773,6 +800,7 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -773,6 +800,7 @@ public class ProjectServiceImpl implements ProjectService {
if
(
null
!=
project
)
{
if
(
null
!=
project
)
{
lists
.
add
(
projectDao
.
findOneById
(
userRole
.
getProjectId
()));
lists
.
add
(
projectDao
.
findOneById
(
userRole
.
getProjectId
()));
roleExpired
.
put
(
userRole
.
getProjectId
(),
null
==
userRole
.
getExpiredTime
()
?
null
:
new
Date
(
userRole
.
getExpiredTime
()));
roleExpired
.
put
(
userRole
.
getProjectId
(),
null
==
userRole
.
getExpiredTime
()
?
null
:
new
Date
(
userRole
.
getExpiredTime
()));
searchWholeInfo
.
put
(
userRole
.
getProjectId
(),
Pair
.
of
(
userRole
.
getSearchWholeRights
(),
userRole
.
getSearchWholeRange
()));
}
}
});
});
}
}
...
@@ -786,6 +814,9 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -786,6 +814,9 @@ public class ProjectServiceImpl implements ProjectService {
json
.
put
(
"avatarUrl"
,
project
.
getAvatarUrl
());
json
.
put
(
"avatarUrl"
,
project
.
getAvatarUrl
());
json
.
put
(
"permission"
,
getPermissionList
(
project
));
json
.
put
(
"permission"
,
getPermissionList
(
project
));
json
.
put
(
"isManual"
,
project
.
isManual
());
json
.
put
(
"isManual"
,
project
.
isManual
());
if
(!
project
.
isManual
())
{
json
.
put
(
"markModel"
,
project
.
getMarkModel
());
}
Date
expiredTime
=
roleExpired
.
get
(
project
.
getId
());
Date
expiredTime
=
roleExpired
.
get
(
project
.
getId
());
if
(
null
==
expiredTime
||
expiredTime
.
after
(
new
Date
()))
{
if
(
null
==
expiredTime
||
expiredTime
.
after
(
new
Date
()))
{
json
.
put
(
"expired"
,
false
);
json
.
put
(
"expired"
,
false
);
...
@@ -796,6 +827,14 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -796,6 +827,14 @@ public class ProjectServiceImpl implements ProjectService {
return
null
;
return
null
;
}
}
}
}
if
(
user
.
isSuperAdmin
()){
json
.
put
(
"searchWholeRights"
,
5
);
json
.
put
(
"searchWholeRange"
,
3
);
}
else
{
Pair
<
Integer
,
Integer
>
pair
=
searchWholeInfo
.
get
(
project
.
getId
());
json
.
put
(
"searchWholeRights"
,
pair
.
getLeft
());
json
.
put
(
"searchWholeRange"
,
pair
.
getRight
());
}
return
json
;
return
json
;
}).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
}).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/TaskServiceImpl.java
View file @
5512630b
...
@@ -8,6 +8,7 @@ import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
...
@@ -8,6 +8,7 @@ import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.dao.*
;
import
com.zhiwei.brandkbs2.dao.*
;
import
com.zhiwei.brandkbs2.enmus.ReportTypeEnum
;
import
com.zhiwei.brandkbs2.enmus.ReportTypeEnum
;
import
com.zhiwei.brandkbs2.enmus.RoleEnum
;
import
com.zhiwei.brandkbs2.es.ChannelEsDao
;
import
com.zhiwei.brandkbs2.es.ChannelEsDao
;
import
com.zhiwei.brandkbs2.es.EsClientDao
;
import
com.zhiwei.brandkbs2.es.EsClientDao
;
import
com.zhiwei.brandkbs2.es.EsQueryTools
;
import
com.zhiwei.brandkbs2.es.EsQueryTools
;
...
@@ -17,9 +18,11 @@ import com.zhiwei.brandkbs2.model.CommonCodeEnum;
...
@@ -17,9 +18,11 @@ import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import
com.zhiwei.brandkbs2.pojo.*
;
import
com.zhiwei.brandkbs2.pojo.*
;
import
com.zhiwei.brandkbs2.service.*
;
import
com.zhiwei.brandkbs2.service.*
;
import
com.zhiwei.brandkbs2.util.RedisUtil
;
import
com.zhiwei.brandkbs2.util.RedisUtil
;
import
com.zhiwei.brandkbs2.util.RobotPushUtils
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
...
@@ -35,6 +38,7 @@ import org.springframework.stereotype.Service;
...
@@ -35,6 +38,7 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.text.MessageFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -83,6 +87,9 @@ public class TaskServiceImpl implements TaskService {
...
@@ -83,6 +87,9 @@ public class TaskServiceImpl implements TaskService {
@Resource
(
name
=
"xiaohongshuRecordDao"
)
@Resource
(
name
=
"xiaohongshuRecordDao"
)
private
XiaohongshuRecordDao
xiaohongshuRecordDao
;
private
XiaohongshuRecordDao
xiaohongshuRecordDao
;
@Resource
(
name
=
"userDao"
)
private
UserDao
userDao
;
@Resource
(
name
=
"customInteractionUpdateRecordDao"
)
@Resource
(
name
=
"customInteractionUpdateRecordDao"
)
private
CustomInteractionUpdateRecordDao
customInteractionUpdateRecordDao
;
private
CustomInteractionUpdateRecordDao
customInteractionUpdateRecordDao
;
...
@@ -185,6 +192,59 @@ public class TaskServiceImpl implements TaskService {
...
@@ -185,6 +192,59 @@ public class TaskServiceImpl implements TaskService {
log
.
info
(
"渠道统计-渠道记录-统计结束"
);
log
.
info
(
"渠道统计-渠道记录-统计结束"
);
}
}
public
void
messageFlowCount2
(
long
startTime
,
long
endTime
)
{
List
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>
rangeTimeRecords
=
esClientDao
.
searchRecordRecent
(
startTime
,
endTime
);
// 结果合并
List
<
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>
channelList
=
rangeTimeRecords
.
stream
().
map
(
Pair:
:
getRight
).
collect
(
Collectors
.
toList
());
// 合并渠道记录
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>
channelIndexRecordMap
=
ChannelIndex
.
mergeRecord
(
channelList
);
log
.
info
(
"渠道统计-搜索到的受影响渠道数{}条"
,
channelIndexRecordMap
.
size
());
long
handleSize
=
0
;
List
<
Channel
>
insertList
=
new
ArrayList
<>();
List
<
Channel
>
updateList
=
new
ArrayList
<>();
List
<
Map
.
Entry
<
ChannelIndex
,
ChannelIndex
.
Record
>>
batchList
=
new
ArrayList
<>();
// 新recordMap
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>
newRecordMap
=
new
ConcurrentHashMap
<>();
for
(
Map
.
Entry
<
ChannelIndex
,
ChannelIndex
.
Record
>
entry
:
channelIndexRecordMap
.
entrySet
())
{
batchList
.
add
(
entry
);
// 每100条做一次清算
if
(++
handleSize
%
100
==
0
||
handleSize
==
channelIndexRecordMap
.
size
())
{
Pair
<
List
<
Channel
>,
List
<
Channel
>>
listPair
=
batchHandle
(
batchList
,
newRecordMap
);
insertList
.
addAll
(
listPair
.
getLeft
());
updateList
.
addAll
(
listPair
.
getRight
());
batchList
=
new
ArrayList
<>();
}
if
(
handleSize
%
10000
==
0
)
{
log
.
info
(
"渠道统计-渠道总计-查询更新已完成{}/{}"
,
handleSize
,
channelIndexRecordMap
.
size
());
}
}
// 替换成新的记录map
channelIndexRecordMap
=
newRecordMap
;
ListUtils
.
partition
(
insertList
,
1000
).
forEach
(
list
->
{
channelDao
.
insertMany
(
list
);
});
log
.
info
(
"渠道统计-渠道总计-录入完毕,新增渠道{}条,更新渠道{}条"
,
insertList
.
size
(),
channelIndexRecordMap
.
size
()
-
insertList
.
size
());
// 获得单位时间内最小最大时间戳
Long
[]
timeMinMax
=
Tools
.
timeMinMax
(
rangeTimeRecords
.
stream
().
map
(
Pair:
:
getLeft
).
collect
(
Collectors
.
toList
()));
List
<
ChannelRecord
>
channelRecords
=
ChannelRecord
.
createChannelRecords
(
timeMinMax
[
0
],
timeMinMax
[
1
],
channelIndexRecordMap
);
channelEsDao
.
upsertChannelRecord
(
channelRecords
);
// 同步ES-channelCopy,区分insertList和updateList
for
(
int
i
=
1
;
i
<=
3
;
i
++)
{
try
{
ListUtils
.
partition
(
insertList
,
1000
).
forEach
(
list
->
{
channelEsDao
.
batchInsert
(
list
.
stream
().
map
(
Channel:
:
createChannelCopyMap
).
collect
(
Collectors
.
toList
()));
});
ListUtils
.
partition
(
updateList
,
1000
).
forEach
(
list
->
{
channelEsDao
.
batchInsert
(
list
.
stream
().
map
(
Channel:
:
createChannelCopyMap
).
collect
(
Collectors
.
toList
()));
});
break
;
}
catch
(
ElasticsearchStatusException
e
)
{
log
.
info
(
"渠道统计-es入库解析异常,正在重试第{}次"
,
i
);
}
}
log
.
info
(
"渠道统计-渠道记录-统计结束"
);
}
@Override
@Override
public
void
channelRecordListCache
()
{
public
void
channelRecordListCache
()
{
AtomicInteger
total
=
new
AtomicInteger
();
AtomicInteger
total
=
new
AtomicInteger
();
...
@@ -513,6 +573,95 @@ public class TaskServiceImpl implements TaskService {
...
@@ -513,6 +573,95 @@ public class TaskServiceImpl implements TaskService {
},
cacheServiceExecutor
)).
toArray
(
CompletableFuture
[]::
new
)).
join
();
},
cacheServiceExecutor
)).
toArray
(
CompletableFuture
[]::
new
)).
join
();
}
}
@Override
public
void
wechatRobotWarnPush
()
{
CompletableFuture
.
allOf
(
GlobalPojo
.
PROJECT_MAP
.
values
().
stream
().
filter
(
project
->
project
.
isStart
()
&&
!
project
.
isManual
()).
map
(
project
->
CompletableFuture
.
supplyAsync
(()
->
{
try
{
long
yestConsume
=
getYesterdayProjectPlanConsume
(
project
.
getId
(),
null
);
double
balanceCanUsedDay
=
0
>=
project
.
getDataBalance
()
?
0
:
0
==
yestConsume
?
project
.
getDataBalance
()
:
(
double
)
project
.
getDataBalance
()
/
yestConsume
;
// 项目管理员
Criteria
criteria
=
Criteria
.
where
(
"roles.projectId"
).
is
(
project
.
getId
()).
and
(
"superAdmin"
).
is
(
false
);
criteria
.
andOperator
(
Criteria
.
where
(
"roles.key"
).
is
(
Tools
.
concat
(
project
.
getId
(),
RoleEnum
.
ADMIN
.
getState
())));
List
<
String
>
adminList
=
userDao
.
findList
(
new
Query
(
criteria
)).
stream
().
map
(
User:
:
getNickname
).
collect
(
Collectors
.
toList
());
// 大数据量方案预警
if
(
yestConsume
>
10000
){
largeDataWarn
(
project
);
}
// 数据额度不足方案停用预警
if
(
0
==
balanceCanUsedDay
){
pushWarn
(
"数据额度不足方案停用"
,
project
,
yestConsume
,
adminList
);
return
null
;
}
// 数据额度不足7天预警
if
(
balanceCanUsedDay
<
7
){
pushWarn
(
"数据额度不足7天预警"
,
project
,
yestConsume
,
adminList
);
return
null
;
}
// 数据额度不足15天预警
if
(
balanceCanUsedDay
<
15
){
pushWarn
(
"数据额度不足15天预警"
,
project
,
yestConsume
,
adminList
);
return
null
;
}
// 数据额度不足30天预警
if
(
balanceCanUsedDay
<
30
){
pushWarn
(
"数据额度不足30天预警"
,
project
,
yestConsume
,
adminList
);
return
null
;
}
}
catch
(
Exception
e
){
log
.
error
(
"非人工项目:{}-{}-企业微信机器人预警出错-"
,
project
.
getProjectName
(),
project
.
getId
(),
e
);
}
return
null
;
},
cacheServiceExecutor
)).
toArray
(
CompletableFuture
[]::
new
)).
join
();
}
private
void
largeDataWarn
(
Project
project
)
throws
IOException
{
List
<
NonManualProjectPlan
>
plans
=
nonManualProjectPlanDao
.
findList
(
new
Query
(
Criteria
.
where
(
"projectId"
).
is
(
project
.
getId
())));
if
(
CollectionUtils
.
isEmpty
(
plans
)){
return
;
}
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
MessageFormat
.
format
(
"项目:{0}-{1}"
,
project
.
getProjectName
(),
"大数据量方案预警"
)).
append
(
"\n"
);
for
(
int
i
=
0
;
i
<
plans
.
size
();
i
++)
{
NonManualProjectPlan
plan
=
plans
.
get
(
i
);
long
count
=
getYesterdayProjectPlanConsume
(
project
.
getId
(),
plan
.
getId
());
String
message
=
MessageFormat
.
format
(
"方案{0}:{1}({2}),数据量:{3}"
,
i
+
1
,
plan
.
getName
(),
project
.
getProjectName
(),
count
);
sb
.
append
(
message
);
if
(
i
+
1
!=
plans
.
size
()){
sb
.
append
(
"\n"
);
}
}
RobotPushUtils
.
pushCommonMessage
(
sb
.
toString
());
}
private
void
pushWarn
(
String
warnType
,
Project
project
,
long
yestConsume
,
List
<
String
>
admins
){
String
template
=
"项目:{0}-{1}"
+
"\n"
+
"剩余额度:{2}"
+
"\n"
+
"昨日消耗:{3}"
+
"\n"
+
"项目管理员:{4}"
;
String
message
=
MessageFormat
.
format
(
template
,
project
.
getProjectName
(),
warnType
,
project
.
getDataBalance
(),
yestConsume
,
StringUtils
.
join
(
admins
,
","
));
RobotPushUtils
.
pushCommonMessage
(
message
);
}
private
long
getYesterdayProjectPlanConsume
(
String
projectId
,
String
planId
)
throws
IOException
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
-
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
long
yesterdayStartTime
=
calendar
.
getTimeInMillis
();
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
long
yesterdayEndTime
=
calendar
.
getTimeInMillis
();
BoolQueryBuilder
query
=
EsQueryTools
.
assembleCacheMapsQuery
(
projectId
,
Constant
.
PRIMARY_CONTEND_ID
);
if
(
Objects
.
nonNull
(
planId
)){
query
=
EsQueryTools
.
assembleCacheMapsPlanQuery
(
projectId
,
planId
);
}
// stime
query
.
must
(
QueryBuilders
.
rangeQuery
(
"stime"
).
gte
(
yesterdayStartTime
).
lt
(
yesterdayEndTime
));
return
esClientDao
.
count
(
query
);
}
private
void
updateRefreshTask
(
String
id
,
String
status
){
private
void
updateRefreshTask
(
String
id
,
String
status
){
Update
update
=
new
Update
();
Update
update
=
new
Update
();
update
.
set
(
"status"
,
status
);
update
.
set
(
"status"
,
status
);
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
View file @
5512630b
...
@@ -234,6 +234,11 @@ public class UserServiceImpl implements UserService {
...
@@ -234,6 +234,11 @@ public class UserServiceImpl implements UserService {
OptionalLong
.
of
(
userDTO
.
getExpiredTime
()).
ifPresent
(
userRole:
:
setExpiredTime
);
OptionalLong
.
of
(
userDTO
.
getExpiredTime
()).
ifPresent
(
userRole:
:
setExpiredTime
);
}
}
OptionalInt
.
of
(
userDTO
.
getExportAmount
()).
ifPresent
(
userRole:
:
setExportAmount
);
OptionalInt
.
of
(
userDTO
.
getExportAmount
()).
ifPresent
(
userRole:
:
setExportAmount
);
// 只有超管能修改全网搜权益
if
(
RoleEnum
.
SUPER_ADMIN
.
getState
()
==
UserThreadLocal
.
getRoleId
())
{
OptionalInt
.
of
(
userDTO
.
getSearchWholeRights
()).
ifPresent
(
userRole:
:
setSearchWholeRights
);
OptionalInt
.
of
(
userDTO
.
getSearchWholeRange
()).
ifPresent
(
userRole:
:
setSearchWholeRange
);
}
userDao
.
updateOneByIdWithField
(
userDTO
.
getId
(),
new
Update
().
set
(
"roles"
,
roles
));
userDao
.
updateOneByIdWithField
(
userDTO
.
getId
(),
new
Update
().
set
(
"roles"
,
roles
));
});
});
Optional
.
of
(
userDTO
.
getNickname
()).
ifPresent
(
nickName
->
userDao
.
updateOneByIdWithField
(
userDTO
.
getId
(),
new
Update
().
set
(
"nickname"
,
nickName
)));
Optional
.
of
(
userDTO
.
getNickname
()).
ifPresent
(
nickName
->
userDao
.
updateOneByIdWithField
(
userDTO
.
getId
(),
new
Update
().
set
(
"nickname"
,
nickName
)));
...
@@ -327,7 +332,8 @@ public class UserServiceImpl implements UserService {
...
@@ -327,7 +332,8 @@ public class UserServiceImpl implements UserService {
if
(
RoleEnum
.
CUSTOMER
.
getState
()
==
userProject
.
getRoleId
())
{
if
(
RoleEnum
.
CUSTOMER
.
getState
()
==
userProject
.
getRoleId
())
{
expiredTime
=
userProject
.
getExpiredTime
();
expiredTime
=
userProject
.
getExpiredTime
();
}
}
userRoles
.
add
(
new
UserRole
(
project
.
getId
(),
userProject
.
getRoleId
(),
expiredTime
,
userProject
.
getExportAmount
()));
// 给默认全网搜权益
userRoles
.
add
(
new
UserRole
(
project
.
getId
(),
userProject
.
getRoleId
(),
expiredTime
,
userProject
.
getExportAmount
(),
1
,
1
));
hit
.
set
(
true
);
hit
.
set
(
true
);
}
}
});
});
...
@@ -426,7 +432,7 @@ public class UserServiceImpl implements UserService {
...
@@ -426,7 +432,7 @@ public class UserServiceImpl implements UserService {
userDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
userDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
List
<
User
>
userList
=
userDao
.
findList
(
query
);
List
<
User
>
userList
=
userDao
.
findList
(
query
);
// roles总量
// roles总量
long
count
=
userList
.
stream
().
map
(
User:
:
getRoles
).
filter
(
Objects:
:
nonNull
).
mapToLong
(
Collection:
:
size
).
sum
();
//
long count = userList.stream().map(User::getRoles).filter(Objects::nonNull).mapToLong(Collection::size).sum();
Map
<
User
,
List
<
UserRole
>>
userRolesMap
=
userList
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
User:
:
getRoles
));
Map
<
User
,
List
<
UserRole
>>
userRolesMap
=
userList
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
User:
:
getRoles
));
List
<
JSONObject
>
resList
=
new
ArrayList
<>();
List
<
JSONObject
>
resList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
User
,
List
<
UserRole
>>
entry
:
userRolesMap
.
entrySet
())
{
for
(
Map
.
Entry
<
User
,
List
<
UserRole
>>
entry
:
userRolesMap
.
entrySet
())
{
...
@@ -454,10 +460,12 @@ public class UserServiceImpl implements UserService {
...
@@ -454,10 +460,12 @@ public class UserServiceImpl implements UserService {
jsonObject
.
put
(
"expiredTime"
,
role
.
getExpiredTime
());
jsonObject
.
put
(
"expiredTime"
,
role
.
getExpiredTime
());
jsonObject
.
put
(
"exportAmount"
,
role
.
getExportAmount
());
jsonObject
.
put
(
"exportAmount"
,
role
.
getExportAmount
());
jsonObject
.
put
(
"key"
,
role
.
getKey
());
jsonObject
.
put
(
"key"
,
role
.
getKey
());
jsonObject
.
put
(
"searchWholeRights"
,
role
.
getSearchWholeRights
());
jsonObject
.
put
(
"searchWholeRange"
,
role
.
getSearchWholeRange
());
resList
.
add
(
jsonObject
);
resList
.
add
(
jsonObject
);
}
}
}
}
return
PageVO
.
createPageVo
(
count
,
page
,
pageSize
,
resList
.
stream
().
skip
((
long
)
(
page
-
1
)
*
pageSize
).
limit
(
pageSize
).
collect
(
Collectors
.
toList
()));
return
PageVO
.
createPageVo
(
resList
.
size
()
,
page
,
pageSize
,
resList
.
stream
().
skip
((
long
)
(
page
-
1
)
*
pageSize
).
limit
(
pageSize
).
collect
(
Collectors
.
toList
()));
}
}
@Override
@Override
...
@@ -467,6 +475,8 @@ public class UserServiceImpl implements UserService {
...
@@ -467,6 +475,8 @@ public class UserServiceImpl implements UserService {
int
roleId
=
json
.
getIntValue
(
"roleId"
);
int
roleId
=
json
.
getIntValue
(
"roleId"
);
long
expiredTime
=
json
.
getLongValue
(
"expiredTime"
);
long
expiredTime
=
json
.
getLongValue
(
"expiredTime"
);
int
exportAmount
=
json
.
getIntValue
(
"exportAmount"
);
int
exportAmount
=
json
.
getIntValue
(
"exportAmount"
);
int
rights
=
json
.
getIntValue
(
"searchWholeRights"
);
int
range
=
json
.
getIntValue
(
"searchWholeRange"
);
String
projectId
=
json
.
getString
(
"projectId"
);
String
projectId
=
json
.
getString
(
"projectId"
);
String
key
=
json
.
getString
(
"key"
);
String
key
=
json
.
getString
(
"key"
);
User
user
=
userDao
.
findOneById
(
id
);
User
user
=
userDao
.
findOneById
(
id
);
...
@@ -489,6 +499,11 @@ public class UserServiceImpl implements UserService {
...
@@ -489,6 +499,11 @@ public class UserServiceImpl implements UserService {
OptionalLong
.
of
(
expiredTime
).
ifPresent
(
userRole:
:
setExpiredTime
);
OptionalLong
.
of
(
expiredTime
).
ifPresent
(
userRole:
:
setExpiredTime
);
}
}
OptionalInt
.
of
(
exportAmount
).
ifPresent
(
userRole:
:
setExportAmount
);
OptionalInt
.
of
(
exportAmount
).
ifPresent
(
userRole:
:
setExportAmount
);
// 只有超管可修改全网搜权益
if
(
RoleEnum
.
SUPER_ADMIN
.
getState
()
==
UserThreadLocal
.
getRoleId
())
{
OptionalInt
.
of
(
rights
).
ifPresent
(
userRole:
:
setSearchWholeRights
);
OptionalInt
.
of
(
range
).
ifPresent
(
userRole:
:
setSearchWholeRange
);
}
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"roles"
,
roles
));
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"roles"
,
roles
));
});
});
Optional
.
of
(
nickname
).
ifPresent
(
nickName
->
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"nickname"
,
nickName
)));
Optional
.
of
(
nickname
).
ifPresent
(
nickName
->
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"nickname"
,
nickName
)));
...
@@ -532,6 +547,8 @@ public class UserServiceImpl implements UserService {
...
@@ -532,6 +547,8 @@ public class UserServiceImpl implements UserService {
json
.
put
(
"roleId"
,
role
.
getRoleId
());
json
.
put
(
"roleId"
,
role
.
getRoleId
());
json
.
put
(
"exportAmount"
,
role
.
getExportAmount
());
json
.
put
(
"exportAmount"
,
role
.
getExportAmount
());
json
.
put
(
"expiredTime"
,
role
.
getExpiredTime
());
json
.
put
(
"expiredTime"
,
role
.
getExpiredTime
());
json
.
put
(
"searchWholeRights"
,
role
.
getSearchWholeRights
());
json
.
put
(
"searchWholeRange"
,
role
.
getSearchWholeRange
());
return
json
;
return
json
;
}).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
}).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
jsonObject
.
put
(
"roles"
,
roles
);
jsonObject
.
put
(
"roles"
,
roles
);
...
@@ -541,19 +558,21 @@ public class UserServiceImpl implements UserService {
...
@@ -541,19 +558,21 @@ public class UserServiceImpl implements UserService {
@Override
@Override
public
ResponseResult
updateBatchUserRoles
(
JSONObject
json
)
{
public
ResponseResult
updateBatchUserRoles
(
JSONObject
json
)
{
String
id
=
json
.
getString
(
"id"
);
String
id
=
json
.
getString
(
"id"
);
User
user
=
userDao
.
findOneById
(
id
);
List
<
UserRole
>
newRoles
=
json
.
getJSONArray
(
"roles"
).
toJavaList
(
UserRole
.
class
);
List
<
UserRole
>
newRoles
=
json
.
getJSONArray
(
"roles"
).
toJavaList
(
UserRole
.
class
);
List
<
String
>
keys
=
newRoles
.
stream
().
map
(
UserRole:
:
getKey
).
collect
(
Collectors
.
toList
());
// 无需被修改的权限列表
List
<
UserRole
>
oldRoles
=
user
.
getRoles
().
stream
().
filter
(
role
->
!
keys
.
contains
(
role
.
getKey
())).
collect
(
Collectors
.
toList
());
for
(
UserRole
role
:
newRoles
)
{
for
(
UserRole
role
:
newRoles
)
{
if
(
Objects
.
isNull
(
role
.
getExportAmount
()))
{
if
(
Objects
.
isNull
(
role
.
getExportAmount
()))
{
role
.
setExportAmount
(
1000
);
role
.
setExportAmount
(
1000
);
}
}
if
(
Objects
.
isNull
(
role
.
getExpiredTime
())
&&
RoleEnum
.
CUSTOMER
.
getState
()
==
role
.
getRoleId
()){
role
.
setExpiredTime
(
System
.
currentTimeMillis
()
+
Constant
.
ONE_WEEK
);
}
if
(
Objects
.
isNull
(
role
.
getSearchWholeRights
())
&&
Objects
.
isNull
(
role
.
getSearchWholeRange
()))
{
role
.
setSearchWholeRange
(
1
);
role
.
setSearchWholeRights
(
1
);
}
role
.
setKey
(
Tools
.
concat
(
role
.
getProjectId
(),
role
.
getRoleId
()));
role
.
setKey
(
Tools
.
concat
(
role
.
getProjectId
(),
role
.
getRoleId
()));
}
}
oldRoles
.
addAll
(
newRoles
);
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"roles"
,
newRoles
));
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"roles"
,
oldRoles
));
return
ResponseResult
.
success
();
return
ResponseResult
.
success
();
}
}
...
@@ -578,7 +597,7 @@ public class UserServiceImpl implements UserService {
...
@@ -578,7 +597,7 @@ public class UserServiceImpl implements UserService {
return
queryUserInfo
(
UserThreadLocal
.
getUserId
(),
UserThreadLocal
.
getProjectId
()).
toMap
();
return
queryUserInfo
(
UserThreadLocal
.
getUserId
(),
UserThreadLocal
.
getProjectId
()).
toMap
();
}
}
private
PageVO
<
JSONObject
>
findList
(
int
page
,
int
size
,
String
keyword
,
String
pid
,
Query
query
,
String
sorter
)
{
private
PageVO
<
JSONObject
>
findList
(
int
page
,
int
size
,
String
keyword
,
String
pid
,
Query
query
,
String
sorter
)
{
userDao
.
addKeywordFuzz
(
query
,
keyword
,
"nickname"
);
userDao
.
addKeywordFuzz
(
query
,
keyword
,
"nickname"
);
if
(
null
==
sorter
)
{
if
(
null
==
sorter
)
{
userDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
userDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
...
@@ -605,6 +624,8 @@ public class UserServiceImpl implements UserService {
...
@@ -605,6 +624,8 @@ public class UserServiceImpl implements UserService {
result
.
put
(
"roleId"
,
userRole
.
getRoleId
());
result
.
put
(
"roleId"
,
userRole
.
getRoleId
());
result
.
put
(
"expiredTime"
,
userRole
.
getExpiredTime
());
result
.
put
(
"expiredTime"
,
userRole
.
getExpiredTime
());
result
.
put
(
"exportAmount"
,
userRole
.
getExportAmount
());
result
.
put
(
"exportAmount"
,
userRole
.
getExportAmount
());
result
.
put
(
"searchWholeRights"
,
userRole
.
getSearchWholeRights
());
result
.
put
(
"searchWholeRange"
,
userRole
.
getSearchWholeRange
());
});
});
return
result
;
return
result
;
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
...
...
src/main/java/com/zhiwei/brandkbs2/task/ControlCenter.java
View file @
5512630b
...
@@ -146,4 +146,17 @@ public class ControlCenter {
...
@@ -146,4 +146,17 @@ public class ControlCenter {
log
.
info
(
"每十分钟拉取并进行渠道库更新任务-结束"
);
log
.
info
(
"每十分钟拉取并进行渠道库更新任务-结束"
);
}
}
}
}
@Async
(
"scheduledExecutor"
)
@Scheduled
(
cron
=
"0 0 6 * * ?"
)
public
void
wechatRobotWarnPush
()
{
log
.
info
(
"每天六点非人工项目企业微信机器人数据用量预警-启动"
);
try
{
taskService
.
wechatRobotWarnPush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"每天六点非人工项目企业微信机器人数据用量预警-出错"
,
e
);
}
finally
{
log
.
info
(
"每天六点非人工项目企业微信机器人数据用量预警-结束"
);
}
}
}
}
src/main/java/com/zhiwei/brandkbs2/util/RobotPushUtils.java
0 → 100644
View file @
5512630b
package
com
.
zhiwei
.
brandkbs2
.
util
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.zhiwei.pushlog.config.LogConfig
;
import
com.zhiwei.pushlog.pojo.CountExpireValue
;
import
com.zhiwei.pushlog.tools.HttpClientUtils
;
import
com.zhiwei.pushlog.tools.Tools
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.net.Inet4Address
;
import
java.net.InetAddress
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
/**
* Description:
*
* @author LiuMingHuan
* @classname RobotPushUtils
* @date 2020/3/13
*/
public
class
RobotPushUtils
{
private
static
final
String
[]
MENTION_MOBILE_LIST
=
new
String
[]{};
private
static
final
int
STAGE
=
50
;
private
static
final
String
WECHAT_ROBOT_ADDRESS
=
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=664bf154-5da9-4615-8043-a396c43301ac"
;
private
static
Cache
<
String
,
CountExpireValue
>
COUNT_RECORDS_CACHE
=
Caffeine
.
newBuilder
()
.
expireAfterWrite
(
1
,
TimeUnit
.
DAYS
)
.
maximumSize
(
1000
)
.
build
();
/**
* 错误消息推送
*
* @param message
* @param throwable
* @return
*/
public
static
String
pushErrorMessage
(
String
message
,
Throwable
throwable
)
{
// if (com.zhiwei.pushlog.tools.Tools.isEmpty(LogConfig.getAddress()) && LogConfig.loadProperties()) {
// throw new IllegalArgumentException("push.robot.address is null");
// }
if
(!
LogConfig
.
getAppName
().
contains
(
"prod"
)){
return
null
;
}
if
(
Objects
.
nonNull
(
throwable
)
&&
!
timeFilter
(
throwable
.
getClass
().
getName
()))
{
return
null
;
}
JSONObject
data
=
new
JSONObject
();
JSONObject
markdown
=
new
JSONObject
();
markdown
.
put
(
"content"
,
getMarkDownMessage
(
message
,
throwable
));
markdown
.
put
(
"mentioned_mobile_list"
,
MENTION_MOBILE_LIST
);
data
.
put
(
"msgtype"
,
"markdown"
);
data
.
put
(
"markdown"
,
markdown
);
// 缓存超时信息清除
if
(
Objects
.
nonNull
(
throwable
))
{
invalidate
(
throwable
.
getClass
().
getName
());
}
return
HttpClientUtils
.
httpPostJson
(
WECHAT_ROBOT_ADDRESS
,
data
.
toJSONString
());
}
/**
* pushCommonMessage
*
* @param message
* @return
*/
public
static
String
pushCommonMessage
(
String
message
)
{
// if (com.zhiwei.pushlog.tools.Tools.isEmpty(LogConfig.getAddress()) && LogConfig.loadProperties()) {
// throw new IllegalArgumentException("push.robot.address is null");
// }
if
(!
LogConfig
.
getAppName
().
contains
(
"prod"
)){
return
null
;
}
if
(
Objects
.
isNull
(
message
)
||
!
timeFilter
(
message
))
{
return
null
;
}
JSONObject
data
=
new
JSONObject
();
JSONObject
markdown
=
new
JSONObject
();
markdown
.
put
(
"content"
,
getMarkDownMessageCommon
(
message
));
markdown
.
put
(
"mentioned_mobile_list"
,
MENTION_MOBILE_LIST
);
data
.
put
(
"msgtype"
,
"markdown"
);
data
.
put
(
"markdown"
,
markdown
);
// 缓存超时信息清除
invalidate
(
message
);
return
HttpClientUtils
.
httpPostJson
(
WECHAT_ROBOT_ADDRESS
,
data
.
toJSONString
());
}
/**
* timeFilter
*
* @param exceptionName
* @return
*/
private
static
boolean
timeFilter
(
String
exceptionName
)
{
boolean
b
=
Objects
.
isNull
(
COUNT_RECORDS_CACHE
.
getIfPresent
(
exceptionName
));
if
(
b
)
{
// time 数值
CountExpireValue
value
=
new
CountExpireValue
(
System
.
currentTimeMillis
(),
LogConfig
.
getInterval
(),
1
);
COUNT_RECORDS_CACHE
.
put
(
exceptionName
,
value
);
}
else
{
CountExpireValue
value
=
COUNT_RECORDS_CACHE
.
getIfPresent
(
exceptionName
);
// 判断过期
if
(
Objects
.
nonNull
(
value
))
{
if
(
value
.
getTime
()
+
value
.
getExpire
()
<
System
.
currentTimeMillis
())
{
// 过期
return
true
;
}
else
{
// 累计
value
=
new
CountExpireValue
(
value
.
getTime
(),
value
.
getExpire
(),
value
.
getValue
()
+
1
);
COUNT_RECORDS_CACHE
.
put
(
exceptionName
,
value
);
}
}
}
return
b
;
}
/**
* timeoutCache invalidate
*
* @param exceptionName
*/
private
static
void
invalidate
(
String
exceptionName
)
{
CountExpireValue
value
=
COUNT_RECORDS_CACHE
.
getIfPresent
(
exceptionName
);
if
(
Objects
.
nonNull
(
value
)
&&
(
value
.
getTime
()
+
value
.
getExpire
()
<
System
.
currentTimeMillis
()))
{
COUNT_RECORDS_CACHE
.
invalidate
(
exceptionName
);
}
}
/**
* getMarkDownMessage
*
* @param message
* @param throwable
* @return
*/
public
static
String
getMarkDownMessage
(
String
message
,
Throwable
throwable
)
{
StringBuilder
stringBuilder
=
getPushHeader
(
"error"
);
String
stackTrace
=
!
com
.
zhiwei
.
pushlog
.
tools
.
Tools
.
isEmpty
(
throwable
)
?
getStackTrace
(
throwable
.
getStackTrace
())
:
"无"
;
String
exceptionType
=
!
com
.
zhiwei
.
pushlog
.
tools
.
Tools
.
isEmpty
(
throwable
)
?
throwable
.
getClass
().
getName
()
:
"无"
;
String
localizedMessage
=
!
com
.
zhiwei
.
pushlog
.
tools
.
Tools
.
isEmpty
(
throwable
)
?
throwable
.
getLocalizedMessage
()
:
"无"
;
stringBuilder
.
append
(
">"
).
append
(
"异常类型:"
).
append
(
"**"
).
append
(
exceptionType
).
append
(
"**\n"
);
stringBuilder
.
append
(
">"
).
append
(
"错误信息:"
).
append
(
"**"
).
append
(
message
).
append
(
"**\n"
);
stringBuilder
.
append
(
">"
).
append
(
"异常信息:"
).
append
(
localizedMessage
).
append
(
"\n"
);
CountExpireValue
countExpireValue
=
!
com
.
zhiwei
.
pushlog
.
tools
.
Tools
.
isEmpty
(
throwable
)
?
COUNT_RECORDS_CACHE
.
getIfPresent
(
throwable
.
getClass
().
getName
())
:
null
;
if
(!
Tools
.
isEmpty
(
countExpireValue
)
&&
countExpireValue
.
getValue
()
>
1
)
{
stringBuilder
.
append
(
">"
).
append
(
"相同异常统计过期前,累计出现次数:"
).
append
(
countExpireValue
.
getValue
()).
append
(
"\n"
);
}
stringBuilder
.
append
(
">"
).
append
(
"堆栈信息:\n"
).
append
(
"<font color=\"comment\">"
).
append
(
stackTrace
).
append
(
"</font>\n"
);
return
stringBuilder
.
toString
();
}
/**
* getMarkDownMessageCommon
*
* @param message
* @return
*/
private
static
String
getMarkDownMessageCommon
(
String
message
)
{
StringBuilder
stringBuilder
=
getPushHeader
(
"common"
);
stringBuilder
.
append
(
">"
).
append
(
"预警信息:"
).
append
(
"**"
).
append
(
message
).
append
(
"**\n"
);
return
stringBuilder
.
toString
();
}
/**
* getPushHeader
*
* @param type
* @return
*/
public
static
StringBuilder
getPushHeader
(
String
type
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
(
"本机信息:"
);
try
{
String
header
=
"error"
.
equals
(
type
)
?
"异常推送预警\n"
:
"日常预警推送\n"
;
InetAddress
localHost
=
Inet4Address
.
getLocalHost
();
stringBuilder
.
append
(
localHost
.
getHostAddress
()).
append
(
"\n"
).
append
(
LogConfig
.
getAppName
()).
append
(
" "
).
append
(
header
);
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"推送出错"
);
e
.
printStackTrace
();
}
return
stringBuilder
;
}
/**
* getStackTrace
*
* @param stackTraceElements
* @return
*/
private
static
String
getStackTrace
(
StackTraceElement
[]
stackTraceElements
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
if
(
stackTraceElements
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
stringBuilder
.
append
(
stackTraceElements
[
i
].
toString
());
if
(
i
!=
4
)
{
stringBuilder
.
append
(
"\n"
);
}
}
}
return
stringBuilder
.
toString
();
}
}
src/main/resources/application-local.properties
View file @
5512630b
...
@@ -36,10 +36,10 @@ mongo.autoConnectRetry=true
...
@@ -36,10 +36,10 @@ mongo.autoConnectRetry=true
mongo.socketKeepAlive
=
true
mongo.socketKeepAlive
=
true
mongo.socketTimeout
=
120000
mongo.socketTimeout
=
120000
mongo.slaveOk
=
true
mongo.slaveOk
=
true
#
\u6D4B\u8BD5
#
测试
#
primary.uri=mongodb://rsync:rsync1q2w3e4r@115.236.59.88:30001/brandkbs2?authSource=admin
primary.uri
=
mongodb://rsync:rsync1q2w3e4r@115.236.59.88:30001/brandkbs2?authSource=admin
#
\u7EBF\u4E0A
#
线上
primary.uri
=
mongodb://brandkbs2:3vh65l$i6qQA@202.107.192.94:17152/brandkbs2?authSource=admin
#
primary.uri=mongodb://brandkbs2:3vh65l$i6qQA@202.107.192.94:17152/brandkbs2?authSource=admin
secondary.uri
=
mongodb://qbjcuser:qbjc1q2w3e4r@202.107.192.94:17152/qbjc?authSource=admin
secondary.uri
=
mongodb://qbjcuser:qbjc1q2w3e4r@202.107.192.94:17152/qbjc?authSource=admin
#es
#es
...
...
src/test/java/com/zhiwei/brandkbs2/BrandkbsIndexCreateTest.java
View file @
5512630b
package
com
.
zhiwei
.
brandkbs2
;
package
com
.
zhiwei
.
brandkbs2
;
import
com.zhiwei.brandkbs2.es.ChannelEsDao
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.indices.CreateIndexRequest
;
import
org.elasticsearch.client.indices.CreateIndexRequest
;
import
org.elasticsearch.client.indices.GetIndexRequest
;
import
org.elasticsearch.client.indices.GetIndexResponse
;
import
org.elasticsearch.cluster.metadata.AliasMetadata
;
import
org.elasticsearch.cluster.metadata.MappingMetadata
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.unit.TimeValue
;
import
org.elasticsearch.common.unit.TimeValue
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -16,6 +19,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
...
@@ -16,6 +19,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -29,12 +33,24 @@ public class BrandkbsIndexCreateTest {
...
@@ -29,12 +33,24 @@ public class BrandkbsIndexCreateTest {
@Test
@Test
public
void
test1
()
throws
IOException
{
public
void
test1
()
throws
IOException
{
String
channelIndex
=
"brandkbs2_channel_record_2023"
;
//
String channelIndex = "brandkbs2_channel_record_2023";
// String brandkbsIndex = "brandkbs2_2022";
// String brandkbsIndex = "brandkbs2_2022";
// putChannelIndex(channelIndex);
// putBrandkbsIndex("brandkbs2_2018","brandkbs2_2019","brandkbs2_2020","brandkbs2_2021");
// putBrandkbsIndex("brandkbs2_2018","brandkbs2_2019","brandkbs2_2020","brandkbs2_2021");
// putBrandkbsIndex("brandkbs2_2017");
putChannelIndex
(
"brandkbs2_channel_record_2024"
);
putChannelCopyIndex
(
ChannelEsDao
.
CHANNEL_COPY_ES_INDEX_NAME
);
putBrandkbsIndex
(
"brandkbs2_2024"
);
// putChannelCopyIndex(ChannelEsDao.CHANNEL_COPY_ES_INDEX_NAME);
}
private
void
getIndexes
(
String
...
indexes
)
throws
IOException
{
GetIndexRequest
request
=
new
GetIndexRequest
(
indexes
);
GetIndexResponse
response
=
esClient
.
indices
().
get
(
request
,
RequestOptions
.
DEFAULT
);
Map
<
String
,
List
<
AliasMetadata
>>
aliases
=
response
.
getAliases
();
Map
<
String
,
MappingMetadata
>
mappings
=
response
.
getMappings
();
Map
<
String
,
Settings
>
settings
=
response
.
getSettings
();
System
.
out
.
println
(
aliases
);
System
.
out
.
println
(
mappings
);
System
.
out
.
println
(
settings
);
}
}
public
void
putChannelCopyIndex
(
String
...
indexes
)
throws
IOException
{
public
void
putChannelCopyIndex
(
String
...
indexes
)
throws
IOException
{
...
@@ -307,6 +323,8 @@ public class BrandkbsIndexCreateTest {
...
@@ -307,6 +323,8 @@ public class BrandkbsIndexCreateTest {
builder
(
obj2
,
"text"
,
"key"
,
true
);
builder
(
obj2
,
"text"
,
"key"
,
true
);
builder
(
obj2
,
"text"
,
"plan_key"
,
true
);
builder
(
obj2
,
"text"
,
"linked_group_id"
,
true
);
builder
(
obj2
,
"text"
,
"linked_group_id"
,
true
);
builder
(
obj2
,
"text"
,
"project_id"
,
true
);
builder
(
obj2
,
"text"
,
"project_id"
,
true
);
...
...
src/test/java/com/zhiwei/brandkbs2/MarkDataServiceTest.java
View file @
5512630b
...
@@ -179,7 +179,7 @@ public class MarkDataServiceTest {
...
@@ -179,7 +179,7 @@ public class MarkDataServiceTest {
@Test
@Test
public
void
searchWholeNetworkTest
(){
public
void
searchWholeNetworkTest
(){
SearchFilterDTO
dto
=
new
SearchFilterDTO
();
SearchFilterDTO
dto
=
new
SearchFilterDTO
();
dto
.
set
Search
(
"阿里"
);
dto
.
set
Keyword
(
"阿里"
);
JSONObject
jsonObject
=
markDataService
.
searchWholeNetworkWithBalance
(
dto
).
getLeft
();
JSONObject
jsonObject
=
markDataService
.
searchWholeNetworkWithBalance
(
dto
).
getLeft
();
System
.
out
.
println
(
jsonObject
);
System
.
out
.
println
(
jsonObject
);
}
}
...
...
src/test/java/com/zhiwei/brandkbs2/ProjectServiceTest.java
View file @
5512630b
...
@@ -24,7 +24,7 @@ public class ProjectServiceTest {
...
@@ -24,7 +24,7 @@ public class ProjectServiceTest {
@Test
@Test
public
void
findProjectListTest
(){
public
void
findProjectListTest
(){
PageVO
<
JSONObject
>
projectList
=
projectService
.
findProjectList
(
1
,
10
,
null
);
PageVO
<
JSONObject
>
projectList
=
projectService
.
findProjectList
(
1
,
10
,
null
,
null
);
for
(
JSONObject
jsonObject
:
projectList
.
getList
())
{
for
(
JSONObject
jsonObject
:
projectList
.
getList
())
{
System
.
out
.
println
(
jsonObject
);
System
.
out
.
println
(
jsonObject
);
}
}
...
...
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