Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
Project
Project
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
fulixin
dsk-operate-sys-cscec
Commits
3478638a
Commit
3478638a
authored
Mar 18, 2024
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
-
Signed-off-by:
Administrator
<
admin@example.com
>
parent
9f042eac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
46 deletions
+112
-46
PushMonitorRules.java
...ain/java/com/dsk/monitor/domain/dto/PushMonitorRules.java
+2
-2
PushScheduling.java
...api/src/main/java/com/dsk/monitor/job/PushScheduling.java
+110
-44
No files found.
dsk-module/dsk-biz-api/src/main/java/com/dsk/monitor/domain/dto/PushMonitorRules.java
View file @
3478638a
...
...
@@ -50,9 +50,9 @@ public class PushMonitorRules implements Serializable {
private
String
timePeriodEnd
;
/**
* 接收方式
手机:0 PC
:1
* 接收方式
开:0 关
:1
*/
private
String
receiveMode
;
private
Integer
receiveMode
;
/**
* 手机号码,多个逗号隔开
*/
...
...
dsk-module/dsk-biz-api/src/main/java/com/dsk/monitor/job/PushScheduling.java
View file @
3478638a
package
com
.
dsk
.
monitor
.
job
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.dsk.common.tenant.helper.TenantHelper
;
import
com.dsk.common.utils.DateUtils
;
import
com.dsk.common.utils.redis.RedisUtils
;
import
com.dsk.monitor.domain.dto.PushMonitorInfo
;
import
com.dsk.monitor.domain.dto.PushMonitorRules
;
import
com.dsk.monitor.domain.vo.ConditionVo
;
...
...
@@ -18,10 +20,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.time.Duration
;
import
java.util.*
;
/**
* @ClassName PushScheduling
...
...
@@ -42,9 +42,24 @@ public class PushScheduling {
@Resource
private
PushMonitorRulesMapper
rulesMapper
;
/**
* 关闭推动
*/
private
static
final
Integer
IS_SWITCH
=
1
;
// @Scheduled(cron = "0 0/2 * * * ?")
@Scheduled
(
cron
=
"0 0 * * * ?"
)
public
void
receiveModePhone
()
throws
Exception
{
TenantHelper
.
setTenantId
(
"1"
);
// 设置redisKey
String
lockKey
=
"stockKey"
;
// 设置redisValue
String
value
=
UUID
.
randomUUID
().
toString
();
// 这里默认设置超时时间为30秒
boolean
hasKey
=
RedisUtils
.
setObjectIfAbsent
(
lockKey
,
value
,
Duration
.
ofMillis
(
1000
*
30
));
if
(!
hasKey
)
{
return
;
}
// 是否是周末
boolean
isWeekend
=
DateUtil
.
isWeekend
(
new
Date
());
PushSettingHolidayVo
holidayVo
=
new
PushSettingHolidayVo
();
...
...
@@ -55,23 +70,15 @@ public class PushScheduling {
if
(
200
==
settingHolidayCode
)
{
isWeekend
=
!
settingHolidayData
;
}
TenantHelper
.
setTenantId
(
"1"
);
// 获取当前整点时间
Integer
concurrentHour
=
DateUtils
.
getHour
();
QueryWrapper
<
PushMonitorRules
>
queryWrapper
=
new
QueryWrapper
();
List
<
PushMonitorRules
>
detailList
=
rulesMapper
.
selectList
(
queryWrapper
);
Integer
timeStart
=
0
;
Integer
timeEnd
=
24
;
for
(
PushMonitorRules
detail
:
detailList
)
{
// 推送时段-起
String
timePeriodStart
=
detail
.
getTimePeriodStart
();
timePeriodStart
=
timePeriodStart
.
substring
(
0
,
2
);
if
(
timePeriodStart
.
contains
(
"0"
))
{
timePeriodStart
=
timePeriodStart
.
substring
(
1
,
2
);
}
// 推送时段-止
String
timePeriodEnd
=
detail
.
getTimePeriodEnd
();
timePeriodEnd
=
timePeriodEnd
.
substring
(
0
,
2
);
if
(
timePeriodEnd
.
contains
(
"0"
))
{
timePeriodEnd
=
timePeriodEnd
.
substring
(
1
,
2
);
if
(
IS_SWITCH
.
equals
(
detail
.
getReceiveMode
()))
{
continue
;
}
Integer
pushFrequency
=
detail
.
getPushFrequency
();
if
(
pushFrequency
>
1
)
{
...
...
@@ -79,42 +86,101 @@ public class PushScheduling {
continue
;
}
}
Integer
timeStart
=
Integer
.
valueOf
(
timePeriodStart
);
Integer
timeEnd
=
Integer
.
valueOf
(
timePeriodEnd
);
if
(
concurrentHour
>=
timeStart
&&
concurrentHour
<=
timeEnd
)
{
PushMonitorDynamicPageVo
pageVo
=
new
PushMonitorDynamicPageVo
();
pageVo
.
setUserId
(
detail
.
getUserId
());
ConditionVo
vo
=
new
ConditionVo
();
// 截止时间
vo
.
setEndTime
(
DateUtils
.
getDate
());
vo
.
setBeginTime
(
DateUtils
.
format
(
DateUtils
.
addDays
(
new
Date
(),-
1
)));
// 监控维度
vo
.
setDimension
(
getParamList
(
detail
.
getDimension
()));
vo
.
setUserId
(
detail
.
getUserId
());
pageVo
.
setCondition
(
vo
);;
Map
<
String
,
Object
>
resMap
=
monitorService
.
companyDynamicPageScheduled
(
pageVo
);
Integer
code
=
MapUtils
.
getInteger
(
resMap
,
"code"
,
300
);
Map
data
=
MapUtils
.
getMap
(
resMap
,
"data"
,
null
);
if
(
200
!=
code
)
{
continue
;
// 推送时段-起
String
timePeriodStart
=
detail
.
getTimePeriodStart
();
if
(
ObjectUtil
.
isNotEmpty
(
timePeriodStart
))
{
timePeriodStart
=
timePeriodStart
.
substring
(
0
,
2
);
if
(
timePeriodStart
.
contains
(
"0"
))
{
timePeriodStart
=
timePeriodStart
.
substring
(
1
,
2
);
}
Integer
count
=
MapUtils
.
getInteger
(
data
,
"totalCount"
,
0
);
if
(
count
>
0
)
{
SendMessageUtil
.
sendMessage
(
detail
.
getPhones
(),
count
.
toString
());
timeStart
=
Integer
.
valueOf
(
timePeriodStart
);
}
// 推送时段-止
String
timePeriodEnd
=
detail
.
getTimePeriodEnd
();
if
(
ObjectUtil
.
isNotEmpty
(
timePeriodEnd
))
{
timePeriodEnd
=
timePeriodEnd
.
substring
(
0
,
2
);
if
(
timePeriodEnd
.
contains
(
"0"
))
{
timePeriodEnd
=
timePeriodEnd
.
substring
(
1
,
2
);
}
if
(
count
>
0
)
{
PushMonitorInfo
pushMonitorInfo
=
new
PushMonitorInfo
();
pushMonitorInfo
.
setUserId
(
detail
.
getUserId
());
pushMonitorInfo
.
setCount
(
count
);
monitorInfoMapper
.
insert
(
pushMonitorInfo
);
timeEnd
=
Integer
.
valueOf
(
timePeriodEnd
);
}
if
(
ObjectUtil
.
isNotEmpty
(
timePeriodStart
)
&&
ObjectUtil
.
isEmpty
(
timePeriodEnd
))
{
if
(
concurrentHour
>=
timeStart
)
{
savePushMonitorInfo
(
detail
);
}
}
if
(
ObjectUtil
.
isEmpty
(
timePeriodStart
)
&&
ObjectUtil
.
isNotEmpty
(
timePeriodEnd
))
{
if
(
concurrentHour
<=
timeEnd
)
{
savePushMonitorInfo
(
detail
);
}
}
if
(
ObjectUtil
.
isEmpty
(
timePeriodStart
)
&&
ObjectUtil
.
isEmpty
(
timePeriodEnd
))
{
savePushMonitorInfo
(
detail
);
}
if
(
ObjectUtil
.
isNotEmpty
(
timePeriodStart
)
&&
ObjectUtil
.
isNotEmpty
(
timePeriodEnd
))
{
if
(
concurrentHour
>=
timeStart
&&
concurrentHour
<=
timeEnd
)
{
savePushMonitorInfo
(
detail
);
}
}
}
}
/***
*@Description: 查询并保存动态信息
*@Param:
*@return: void
*@Author: Dgm
*@date: 2024/3/17 14:30
*/
private
void
savePushMonitorInfo
(
PushMonitorRules
detail
)
throws
Exception
{
PushMonitorDynamicPageVo
pageVo
=
new
PushMonitorDynamicPageVo
();
pageVo
.
setUserId
(
detail
.
getUserId
());
ConditionVo
vo
=
new
ConditionVo
();
// 截止时间
vo
.
setEndTime
(
DateUtils
.
getTime
());
vo
.
setBeginTime
(
DateUtils
.
format
(
DateUtils
.
addDays
(
new
Date
(),-
1
)));
// 条件查询监控维度子级名称数组
vo
.
setDimension
(
getParamList
(
detail
.
getDimension
()));
// 条件查询监控维度父级名称数组
vo
.
setParentDimension
(
getParamList
((
detail
.
getRiskType
())));
vo
.
setUserId
(
detail
.
getUserId
());
pageVo
.
setCondition
(
vo
);;
Map
<
String
,
Object
>
resMap
=
monitorService
.
companyDynamicPageScheduled
(
pageVo
);
Integer
code
=
MapUtils
.
getInteger
(
resMap
,
"code"
,
300
);
Map
data
=
MapUtils
.
getMap
(
resMap
,
"data"
,
null
);
if
(
200
!=
code
)
{
return
;
}
Integer
count
=
MapUtils
.
getInteger
(
data
,
"totalCount"
,
0
);
if
(
count
>
0
)
{
SendMessageUtil
.
sendMessage
(
detail
.
getPhones
(),
count
.
toString
());
// SendMessageUtil.sendMessage(detail.getPhones(), getContent(count));
}
if
(
count
>
0
)
{
PushMonitorInfo
pushMonitorInfo
=
new
PushMonitorInfo
();
pushMonitorInfo
.
setUserId
(
detail
.
getUserId
());
pushMonitorInfo
.
setCount
(
count
);
monitorInfoMapper
.
insert
(
pushMonitorInfo
);
}
}
public
List
<
String
>
getParamList
(
String
dimension
)
{
List
<
String
>
getParamList
=
Arrays
.
asList
(
dimension
.
split
(
","
));
public
static
List
<
String
>
getParamList
(
String
dimension
)
{
List
<
String
>
getParamList
=
new
ArrayList
<>();
if
(
ObjectUtil
.
isNotEmpty
(
dimension
))
{
getParamList
=
Arrays
.
asList
(
dimension
.
split
(
","
));
}
return
getParamList
;
}
/**
*@Description: 组装推送信息
*@Param:
*@return: java.lang.String
*@Author: Dgm
*@date: 2024/3/16 14:05
*/
private
String
getContent
(
Integer
number
)
{
return
"您监控的企业发生"
.
concat
(
number
.
toString
()).
concat
(
"条风险动态。"
);
}
}
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