Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
20f349ef
authored
Sep 11, 2023
by
李小龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
整理代码
parent
166bb587
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
40 deletions
server-common/src/main/java/com/makeit/utils/user/plat/PlatUserUtil.java
server-service/src/main/java/com/makeit/service/platform/alarm/PlatAlarmRecordService.java
server-service/src/main/java/com/makeit/service/platform/alarm/impl/PlatAlarmRecordServiceImpl.java
server-common/src/main/java/com/makeit/utils/user/plat/PlatUserUtil.java
View file @
20f349ef
...
...
@@ -19,7 +19,7 @@ public class PlatUserUtil {
public
static
boolean
isSuper
()
{
PlatUserVO
userVO
=
PlatUserUtil
.
getUserVO
();
return
IsFactoryAccountEnum
.
YES
.
getValue
().
equals
(
userVO
.
get
TenantId
())
return
IsFactoryAccountEnum
.
YES
.
getValue
().
equals
(
userVO
.
get
IsTenant
())
||
IdConst
.
SUPER_ADMIN_ID
.
equals
(
userVO
.
getId
());
}
...
...
server-service/src/main/java/com/makeit/service/platform/alarm/PlatAlarmRecordService.java
View file @
20f349ef
...
...
@@ -9,18 +9,16 @@ import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import
com.makeit.vo.platform.alarm.PlatAlarmRecordVO
;
/**
* @author lixl
* @description 针对表【plat_alarm_record(告警记录)】的数据库操作Service
* @createDate 2023-09-06 14:26:05
*/
* @author lixl
* @description 针对表【plat_alarm_record(告警记录)】的数据库操作Service
* @createDate 2023-09-06 14:26:05
*/
public
interface
PlatAlarmRecordService
extends
IService
<
PlatAlarmRecord
>
{
PageVO
<
PlatAlarmRecordVO
>
page
(
PageReqDTO
<
PlatAlarmRecordQueryDTO
>
dto
);
/**
* 子女端告警列表
* @param dto
* @return
*/
PageVO
<
PlatAlarmRecordVO
>
childrenPage
(
PageReqDTO
<
PlatAlarmRecordQueryDTO
>
dto
);
...
...
@@ -28,11 +26,30 @@ public interface PlatAlarmRecordService extends IService<PlatAlarmRecord> {
void
deal
(
String
recordId
);
/**
* 通知家属
* @param recordId
*/
void
noticeRelation
(
String
recordId
);
/**
* 通知家属
* 子女端小程序
* 短信
* 语音短信
*/
void
noticeChildren
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
);
void
noticeUser
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
);
/**
* 通知工作人员
* 短信
* 语音短信
* 邮件
*/
void
noticeUser
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
);
void
noticeDeviceAlarm
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
);
/**
* 设备告警调用 发送消息
*/
void
noticeDeviceAlarm
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
);
}
server-service/src/main/java/com/makeit/service/platform/alarm/impl/PlatAlarmRecordServiceImpl.java
View file @
20f349ef
...
...
@@ -3,6 +3,7 @@ package com.makeit.service.platform.alarm.impl;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.makeit.common.entity.BaseBusEntity
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.common.page.PageReqDTO
;
import
com.makeit.common.page.PageVO
;
...
...
@@ -17,6 +18,7 @@ import com.makeit.global.aspect.tenant.TenantIdIgnore;
import
com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper
;
import
com.makeit.service.platform.alarm.PlatAlarmConfigService
;
import
com.makeit.service.platform.alarm.PlatAlarmRecordService
;
import
com.makeit.service.platform.auth.PlatUserService
;
import
com.makeit.service.platform.elder.PlatElderChildrenInfoService
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
import
com.makeit.utils.data.convert.PageUtil
;
...
...
@@ -58,6 +60,9 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
private
PlatElderChildrenInfoService
platElderChildrenInfoService
;
@Autowired
private
PlatUserService
platUserService
;
@Autowired
private
MsgSendUtil
msgUtil
;
@Override
...
...
@@ -69,9 +74,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
List
<
PlatAlarmRecord
>
records
=
page
.
getRecords
();
List
<
PlatAlarmRecordVO
>
dtos
=
BeanDtoVoUtils
.
listVo
(
records
,
PlatAlarmRecordVO
.
class
);
JoinUtil
.
join
(
dtos
,
platAlarmConfigService
,
PlatAlarmRecordVO:
:
getAlarmId
,
BaseEntity:
:
getId
,
(
t
,
m
)
->
{
t
.
setNotifyRelation
(
m
.
getNotifyRelation
());
});
JoinUtil
.
join
(
dtos
,
platAlarmConfigService
,
PlatAlarmRecordVO:
:
getAlarmId
,
BaseEntity:
:
getId
,
(
t
,
m
)
->
t
.
setNotifyRelation
(
m
.
getNotifyRelation
()));
return
PageUtil
.
toPageVO
(
dtos
,
page
);
}
...
...
@@ -119,9 +122,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
public
PlatAlarmRecordVO
view
(
String
recordId
)
{
PlatAlarmRecord
platAlarmRecord
=
getById
(
recordId
);
PlatAlarmRecordVO
vo
=
BeanDtoVoUtils
.
convert
(
platAlarmRecord
,
PlatAlarmRecordVO
.
class
);
JoinUtil
.
join
(
Arrays
.
asList
(
vo
),
platAlarmConfigService
,
PlatAlarmRecordVO:
:
getAlarmId
,
BaseEntity:
:
getId
,
(
t
,
m
)
->
{
t
.
setNotifyRelation
(
m
.
getNotifyRelation
());
});
JoinUtil
.
join
(
Arrays
.
asList
(
vo
),
platAlarmConfigService
,
PlatAlarmRecordVO:
:
getAlarmId
,
BaseEntity:
:
getId
,
(
t
,
m
)
->
t
.
setNotifyRelation
(
m
.
getNotifyRelation
()));
return
vo
;
}
...
...
@@ -136,6 +137,10 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
updateById
(
platAlarmRecord
);
}
/**
* 通知家属
* @param recordId
*/
@Override
@Transactional
public
void
noticeRelation
(
String
recordId
)
{
...
...
@@ -145,15 +150,22 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
if
(
StringUtils
.
isBlank
(
elderIds
))
{
throw
new
BusinessException
(
"设备没绑定长者"
);
}
noticeChildren
(
platAlarmConfig
,
platAlarmRecord
);
noticeChildren
(
platAlarmConfig
,
platAlarmRecord
);
}
/**
* 发送消息
*
设备告警调用
发送消息
*/
@Transactional
@Override
public
void
noticeDeviceAlarm
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
){
@TenantIdIgnore
public
void
noticeDeviceAlarm
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
)
{
//判断是否需要同时通知家属
if
(
StringUtils
.
equals
(
alarmConfig
.
getNotifyRelation
(),
"1"
))
{
noticeChildren
(
alarmConfig
,
alarmRecord
);
}
//通知内部人员
noticeUser
(
alarmConfig
,
alarmRecord
);
}
...
...
@@ -162,12 +174,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
* 子女端小程序
* 短信
* 语音短信
*
* @param alarmConfig
* @param alarmRecord
*/
@Transactional
@TenantIdIgnore
public
void
noticeChildren
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
)
{
public
void
noticeChildren
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
)
{
String
elderIds
=
alarmRecord
.
getElderIds
();
List
<
PlatElderChildrenInfo
>
allChildInfoList
=
new
ArrayList
<>();
...
...
@@ -175,9 +188,8 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
//通知每个长者的子女
for
(
String
elderId
:
elderIdSplit
)
{
LambdaQueryWrapper
<
PlatElderChildrenInfo
>
childrenInfoLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
childrenInfoLambdaQueryWrapper
.
and
(
qw
->
{
qw
.
apply
(
"find_in_set('"
+
elderId
+
"',elder_id)"
);
});
childrenInfoLambdaQueryWrapper
.
eq
(
BaseBusEntity:
:
getTenantId
,
alarmConfig
.
getTenantId
());
childrenInfoLambdaQueryWrapper
.
and
(
qw
->
qw
.
apply
(
"find_in_set('"
+
elderId
+
"',elder_id)"
));
List
<
PlatElderChildrenInfo
>
childrenInfoList
=
platElderChildrenInfoService
.
list
(
childrenInfoLambdaQueryWrapper
);
if
(
CollectionUtils
.
isEmpty
(
childrenInfoList
))
{
log
.
debug
(
"子女端账号未绑定长者"
);
...
...
@@ -185,23 +197,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
}
allChildInfoList
.
addAll
(
childrenInfoList
);
Set
<
String
>
phoneSet
=
childrenInfoList
.
stream
().
map
(
PlatElderChildrenInfo:
:
getPhone
).
collect
(
Collectors
.
toSet
());
String
notifyChannel
=
alarmConfig
.
getNotifyChannel
();
String
[]
split
=
notifyChannel
.
split
(
","
);
//告警配置和租户告警 字典一致
List
<
SendTypeEnum
>
notifyChannelList
=
Arrays
.
asList
(
SendTypeEnum
.
SMS
,
SendTypeEnum
.
VOICE_SMS
,
SendTypeEnum
.
CHILD_WECHAT
);
for
(
String
sendType
:
split
)
{
SendTypeEnum
sendTypeEnum
=
SendTypeEnum
.
getByValue
(
sendType
);
boolean
contains
=
notifyChannelList
.
contains
(
sendTypeEnum
);
if
(
contains
)
{
MsgSendDTO
msgSendDTO
=
new
MsgSendDTO
();
msgSendDTO
.
setSendTypeEnum
(
sendTypeEnum
);
msgSendDTO
.
setReceiverList
(
phoneSet
);
msgSendDTO
.
setOriContent
(
alarmRecord
.
getContent
());
//todo 小程序消息
msgUtil
.
send
(
msgSendDTO
);
}
}
//发送消息
noticeByChannel
(
alarmConfig
,
alarmRecord
,
phoneSet
,
notifyChannelList
);
}
String
childIdJoin
=
allChildInfoList
.
stream
().
map
(
BaseEntity:
:
getId
).
collect
(
Collectors
.
joining
(
","
));
//通知的子女
...
...
@@ -216,18 +216,63 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
* 短信
* 语音短信
* 邮件
*
* @param alarmConfig
* @param alarmRecord
*/
@Transactional
@Override
@TenantIdIgnore
public
void
noticeUser
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
)
{
public
void
noticeUser
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
)
{
String
notifyWay
=
alarmConfig
.
getNotifyWay
();
List
<
PlatUser
>
platUserList
=
new
ArrayList
<>();
if
(
StringUtils
.
equals
(
notifyWay
,
"1"
)){
}
else
{
if
(
StringUtils
.
equals
(
notifyWay
,
"1"
))
{
LambdaQueryWrapper
<
PlatUser
>
platUserLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
platUserLambdaQueryWrapper
.
eq
(
PlatUser:
:
getTenantId
,
alarmConfig
.
getTenantId
())
.
eq
(
PlatUser:
:
getOrgId
,
alarmConfig
.
getOrgId
());
List
<
PlatUser
>
platUsers
=
platUserService
.
list
(
platUserLambdaQueryWrapper
);
platUserList
.
addAll
(
platUsers
);
}
else
{
String
notifyUser
=
alarmConfig
.
getNotifyUser
();
String
[]
userArray
=
notifyUser
.
split
(
","
);
List
<
PlatUser
>
platUsers
=
platUserService
.
listByIds
(
Arrays
.
asList
(
userArray
));
platUserList
.
addAll
(
platUsers
);
}
platUserList
.
removeIf
(
Objects:
:
isNull
);
if
(
CollectionUtils
.
isEmpty
(
platUserList
))
{
log
.
debug
(
"通知工作人员时,找不到人员数据;"
+
"orgId:"
+
alarmConfig
.
getOrgId
()
+
",tenantId:"
+
alarmConfig
.
getTenantId
()
+
"alarmConfigId:"
+
alarmConfig
.
getId
());
return
;
}
List
<
SendTypeEnum
>
notifyChannelList
=
Arrays
.
asList
(
SendTypeEnum
.
SMS
,
SendTypeEnum
.
VOICE_SMS
,
SendTypeEnum
.
MAIL
);
Set
<
String
>
phoneSet
=
platUserList
.
stream
().
map
(
PlatUser:
:
getMobile
).
collect
(
Collectors
.
toSet
());
//发送消息
noticeByChannel
(
alarmConfig
,
alarmRecord
,
phoneSet
,
notifyChannelList
);
}
/**
* 根据配置渠道发送消息
*
* @param alarmConfig
* @param alarmRecord
* @param phoneSet 工作人员手机号
* @param notifyChannelList 通知渠道
*/
private
void
noticeByChannel
(
PlatAlarmConfig
alarmConfig
,
PlatAlarmRecord
alarmRecord
,
Set
<
String
>
phoneSet
,
List
<
SendTypeEnum
>
notifyChannelList
)
{
String
notifyChannel
=
alarmConfig
.
getNotifyChannel
();
String
[]
split
=
notifyChannel
.
split
(
","
);
for
(
String
sendType
:
split
)
{
SendTypeEnum
sendTypeEnum
=
SendTypeEnum
.
getByValue
(
sendType
);
boolean
contains
=
notifyChannelList
.
contains
(
sendTypeEnum
);
if
(
contains
)
{
MsgSendDTO
msgSendDTO
=
new
MsgSendDTO
();
msgSendDTO
.
setSendTypeEnum
(
sendTypeEnum
);
msgSendDTO
.
setReceiverList
(
phoneSet
);
msgSendDTO
.
setOriContent
(
alarmRecord
.
getContent
());
//todo 小程序消息
msgUtil
.
send
(
msgSendDTO
);
}
}
}
}
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