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
91f220a8
authored
Oct 10, 2023
by
朱淼
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev' of
http://git.xmmakeit.com/huangjiay/iot-platform-server
into dev
parents
84745a85
b0757d62
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
14 deletions
server-service/src/main/java/com/makeit/dto/platform/device/PlatDeviceQueryDTO.java
server-service/src/main/java/com/makeit/mapper/platform/device/PlatDeviceMapper.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
server-service/src/main/java/com/makeit/vo/platform/device/PlatDeviceListVO.java
server-service/src/main/resources/mappers/PlatDeviceMapper.xml
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-service/src/main/java/com/makeit/dto/platform/device/PlatDeviceQueryDTO.java
View file @
91f220a8
...
@@ -38,5 +38,7 @@ public class PlatDeviceQueryDTO extends BaseTenantDTO {
...
@@ -38,5 +38,7 @@ public class PlatDeviceQueryDTO extends BaseTenantDTO {
@ApiModelProperty
(
value
=
"组织id"
)
@ApiModelProperty
(
value
=
"组织id"
)
private
String
orgId
;
private
String
orgId
;
private
String
spaceId
;
}
}
server-service/src/main/java/com/makeit/mapper/platform/device/PlatDeviceMapper.java
View file @
91f220a8
package
com
.
makeit
.
mapper
.
platform
.
device
;
package
com
.
makeit
.
mapper
.
platform
.
device
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.makeit.dto.platform.device.PlatDeviceQueryDTO
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.vo.platform.device.PlatDeviceListVO
;
import
org.apache.ibatis.annotations.Param
;
/**
/**
* <p>
* <p>
...
@@ -13,4 +17,7 @@ import com.makeit.entity.platform.device.PlatDevice;
...
@@ -13,4 +17,7 @@ import com.makeit.entity.platform.device.PlatDevice;
*/
*/
public
interface
PlatDeviceMapper
extends
BaseMapper
<
PlatDevice
>
{
public
interface
PlatDeviceMapper
extends
BaseMapper
<
PlatDevice
>
{
Page
<
PlatDeviceListVO
>
getDeviceIdsBySpaceId
(
@Param
(
"param"
)
PlatDeviceQueryDTO
param
,
Page
page
);
}
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
91f220a8
...
@@ -22,6 +22,7 @@ import com.makeit.entity.platform.auth.PlatOrg;
...
@@ -22,6 +22,7 @@ import com.makeit.entity.platform.auth.PlatOrg;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.device.PlatDeviceOther
;
import
com.makeit.entity.platform.device.PlatDeviceOther
;
import
com.makeit.entity.platform.space.PlatRegionSetting
;
import
com.makeit.entity.platform.space.PlatRegionSetting
;
import
com.makeit.entity.platform.space.PlatSpace
;
import
com.makeit.enums.CodeMessageEnum
;
import
com.makeit.enums.CodeMessageEnum
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.mapper.platform.device.PlatDeviceMapper
;
import
com.makeit.mapper.platform.device.PlatDeviceMapper
;
...
@@ -32,6 +33,7 @@ import com.makeit.service.platform.auth.PlatOrgService;
...
@@ -32,6 +33,7 @@ import com.makeit.service.platform.auth.PlatOrgService;
import
com.makeit.service.platform.device.PlatDeviceOtherService
;
import
com.makeit.service.platform.device.PlatDeviceOtherService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.space.PlatRegionSettingService
;
import
com.makeit.service.platform.space.PlatRegionSettingService
;
import
com.makeit.service.platform.space.PlatSpaceService
;
import
com.makeit.service.saas.PlatTenantService
;
import
com.makeit.service.saas.PlatTenantService
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
...
@@ -42,12 +44,17 @@ import com.makeit.utils.old.StringUtils;
...
@@ -42,12 +44,17 @@ import com.makeit.utils.old.StringUtils;
import
com.makeit.utils.sql.join.JoinUtil
;
import
com.makeit.utils.sql.join.JoinUtil
;
import
com.makeit.vo.platform.device.PlatDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
/**
* <p>
* <p>
...
@@ -75,34 +82,63 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
...
@@ -75,34 +82,63 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private
PlatRegionSettingService
platRegionSettingService
;
private
PlatRegionSettingService
platRegionSettingService
;
@Autowired
@Autowired
private
IotProductDeviceService
iotProductDeviceService
;
private
IotProductDeviceService
iotProductDeviceService
;
@Autowired
private
PlatSpaceService
platSpaceService
;
@Override
@Override
public
PageVO
<
PlatDeviceListVO
>
page
(
PageReqDTO
<
PlatDeviceQueryDTO
>
pageReqDTO
)
{
public
PageVO
<
PlatDeviceListVO
>
page
(
PageReqDTO
<
PlatDeviceQueryDTO
>
pageReqDTO
)
{
PlatDeviceQueryDTO
dto
=
pageReqDTO
.
getData
();
PlatDeviceQueryDTO
dto
=
pageReqDTO
.
getData
();
Page
<
PlatDevice
>
p
=
PageUtil
.
toMpPage
(
pageReqDTO
);
Page
<
PlatDevice
>
p
=
PageUtil
.
toMpPage
(
pageReqDTO
);
Page
<
PlatDevice
>
page
=
page
(
p
,
new
QueryWrapper
<
PlatDevice
>().
lambda
()
Page
<
PlatDeviceListVO
>
page
=
baseMapper
.
getDeviceIdsBySpaceId
(
dto
,
p
);
.
like
(
StringUtils
.
isNotBlank
(
dto
.
getOriDeviceId
()),
PlatDevice:
:
getOriDeviceId
,
dto
.
getOriDeviceId
())
.
like
(
StringUtils
.
isNotBlank
(
dto
.
getName
()),
PlatDevice:
:
getName
,
dto
.
getName
())
// Page<PlatDevice> page = page(p, new QueryWrapper<PlatDevice>().lambda()
.
eq
(
StringUtils
.
isNotBlank
(
dto
.
getStatus
()),
PlatDevice:
:
getStatus
,
dto
.
getStatus
())
// .like(StringUtils.isNotBlank(dto.getOriDeviceId()), PlatDevice::getOriDeviceId, dto.getOriDeviceId())
.
like
(
StringUtils
.
isNotBlank
(
dto
.
getProductName
()),
PlatDevice:
:
getProductName
,
dto
.
getProductName
())
// .like(StringUtils.isNotBlank(dto.getName()), PlatDevice::getName, dto.getName())
.
eq
(
StringUtils
.
isNotBlank
(
dto
.
getProductId
()),
PlatDevice:
:
getProductId
,
dto
.
getProductId
())
// .eq(StringUtils.isNotBlank(dto.getStatus()), PlatDevice::getStatus, dto.getStatus())
.
eq
(
StringUtils
.
isNotBlank
(
dto
.
getOrgId
()),
PlatDevice:
:
getOrgId
,
dto
.
getOrgId
())
// .like(StringUtils.isNotBlank(dto.getProductName()), PlatDevice::getProductName, dto.getProductName())
// .apply(StringUtils.isNotBlank(dto.getOrgId()), "find_in_set('" + dto.getOrgId() + "',org_path)")
// .eq(StringUtils.isNotBlank(dto.getProductId()), PlatDevice::getProductId, dto.getProductId())
.
orderByDesc
(
BaseEntity:
:
getUpdateDate
)
// .eq(StringUtils.isNotBlank(dto.getOrgId()),PlatDevice::getOrgId,dto.getOrgId())
);
// .orderByDesc(BaseEntity::getUpdateDate)
// );
List
<
PlatDeviceListVO
>
records
=
page
.
getRecords
();
//List<PlatDeviceListVO> voList = BeanDtoVoUtils.listVo(records, PlatDeviceListVO.class);
if
(
CollectionUtils
.
isEmpty
(
records
)){
return
new
PageVO
<>();
}
List
<
PlatDeviceListVO
>
voList
=
BeanDtoVoUtils
.
listVo
(
page
.
getRecords
(),
PlatDeviceListVO
.
class
);
List
<
String
>
spaceIdList
=
records
.
stream
().
flatMap
(
vo
->
{
String
spaceParentPath
=
vo
.
getSpaceParentPath
();
String
spp
=
Optional
.
ofNullable
(
spaceParentPath
).
orElse
(
""
);
return
Stream
.
of
(
spp
.
split
(
","
));
}).
collect
(
Collectors
.
toList
());
spaceIdList
.
add
(
"-1"
);
List
<
PlatSpace
>
platSpaces
=
platSpaceService
.
listByIds
(
spaceIdList
);
Map
<
String
,
String
>
spaceIdNameMap
=
platSpaces
.
stream
().
collect
(
Collectors
.
toMap
(
BaseEntity:
:
getId
,
vo
->
vo
.
getName
(),
(
v1
,
v2
)
->
v1
));
for
(
PlatDeviceListVO
record
:
records
)
{
String
spaceParentPath
=
record
.
getSpaceParentPath
();
if
(
StringUtils
.
isNotBlank
(
spaceParentPath
)){
String
spaceNameJoin
=
Stream
.
of
(
spaceParentPath
.
split
(
","
)).
map
(
vo
->
spaceIdNameMap
.
get
(
vo
)).
collect
(
Collectors
.
joining
(
"-"
));
record
.
setSpaceName
(
spaceNameJoin
+
"-"
+
record
.
getSpaceName
());
}
}
JoinUtil
.
join
(
voList
,
platOrgService
,
PlatDeviceListVO:
:
getOrgId
,
PlatOrg:
:
getId
,
(
d
,
o
)
->
{
JoinUtil
.
join
(
records
,
platOrgService
,
PlatDeviceListVO:
:
getOrgId
,
PlatOrg:
:
getId
,
(
d
,
o
)
->
{
d
.
setOrgName
(
o
.
getName
());
d
.
setOrgName
(
o
.
getName
());
});
});
JoinUtil
.
joinSplit
(
voList
,
platOrgService
,
PlatDeviceListVO:
:
getOrgPath
,
PlatOrg:
:
getId
,
(
d
,
o
)
->
{
JoinUtil
.
joinSplit
(
records
,
platOrgService
,
PlatDeviceListVO:
:
getOrgPath
,
PlatOrg:
:
getId
,
(
d
,
o
)
->
{
d
.
setOrgPathName
(
StreamUtil
.
join
(
o
,
PlatOrg:
:
getName
));
d
.
setOrgPathName
(
StreamUtil
.
join
(
o
,
PlatOrg:
:
getName
));
});
});
return
PageUtil
.
toPageVO
(
voList
,
page
);
return
PageUtil
.
toPageVO
(
records
,
page
);
}
}
...
...
server-service/src/main/java/com/makeit/vo/platform/device/PlatDeviceListVO.java
View file @
91f220a8
...
@@ -83,5 +83,11 @@ public class PlatDeviceListVO extends BaseTenantDTO {
...
@@ -83,5 +83,11 @@ public class PlatDeviceListVO extends BaseTenantDTO {
private
String
tenantName
;
private
String
tenantName
;
private
String
spaceParentPath
;
private
String
spaceParentPathName
;
private
String
spaceName
;
}
}
server-service/src/main/resources/mappers/PlatDeviceMapper.xml
0 → 100644
View file @
91f220a8
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.makeit.mapper.platform.device.PlatDeviceMapper"
>
<select
id=
"getDeviceIdsBySpaceId"
resultType=
"com.makeit.vo.platform.device.PlatDeviceListVO"
>
select
pd.*,
ps.parent_path as spaceParentPath,
ps.name as spaceName
from plat_device pd
left join plat_room_bed_device prbd on (pd.id = prbd.device_id and prbd.del_flag = 0)
left join plat_room pr on (pr.id = prbd.room_id and pr.del_flag = 0 )
left join plat_bed pb on ( pb.id = prbd.bed_id and pb.del_flag = 0)
left join plat_space ps on (ps.id = pb.space_id or ps.id = pr.space_id)
<where>
pd.del_flag = 0
<if
test=
"param.spaceId != null and param.spaceId != ''"
>
and ( FIND_IN_SET(#{param.spaceId},ps.parent_path) or ps.id = #{param.spaceId} )
</if>
<if
test=
"param.oriDeviceId != null and param.oriDeviceId != ''"
>
and pd.ori_device_id like concat('%',#{param.oriDeviceId},'%')
</if>
<if
test=
"param.name != null and param.name != ''"
>
and pd.name like concat('%',#{param.name},'%')
</if>
<if
test=
"param.status != null and param.status != '' "
>
and pd.status = #{param.status}
</if>
<if
test=
"param.productName != null and param.productName != '' "
>
and pd.product_name like concat('%',#{param.productName},'%')
</if>
<if
test=
"param.productId != null and param.productId != '' "
>
and pd.product_id = #{param.productId}
</if>
<if
test=
"param.orgId != null and param.orgId != '' "
>
and pd.org_id = #{param.orgId}
</if>
</where>
order by pd.update_date desc
</select>
</mapper>
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
91f220a8
...
@@ -2,16 +2,24 @@ package com.makeit.mqtt;
...
@@ -2,16 +2,24 @@ package com.makeit.mqtt;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.makeit.common.entity.BaseBusEntity
;
import
com.makeit.common.entity.BaseEntity
;
import
com.makeit.dto.platform.alarm.PlatAlarmCheckDTO
;
import
com.makeit.dto.platform.alarm.PlatAlarmCheckDTO
;
import
com.makeit.entity.platform.alarm.PlatAlarmConfig
;
import
com.makeit.entity.platform.alarm.PlatAlarmConfig
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.saas.PlatTenant
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.module.iot.enums.DeviceState
;
import
com.makeit.module.iot.vo.DeviceInfo
;
import
com.makeit.module.iot.vo.DeviceInfo
;
import
com.makeit.module.iot.vo.HeaderInfo
;
import
com.makeit.module.iot.vo.HeaderInfo
;
import
com.makeit.service.platform.alarm.alarmStrategy.IAlarm
;
import
com.makeit.service.platform.alarm.alarmStrategy.IAlarm
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.saas.PlatTenantService
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
import
org.eclipse.paho.client.mqttv3.MqttCallback
;
import
org.eclipse.paho.client.mqttv3.MqttCallback
;
import
org.eclipse.paho.client.mqttv3.MqttClient
;
import
org.eclipse.paho.client.mqttv3.MqttClient
;
...
@@ -21,10 +29,12 @@ import org.slf4j.LoggerFactory;
...
@@ -21,10 +29,12 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.StopWatch
;
import
org.springframework.util.StopWatch
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
@Component
@Component
...
@@ -43,6 +53,11 @@ public class PushCallback implements MqttCallback {
...
@@ -43,6 +53,11 @@ public class PushCallback implements MqttCallback {
@Autowired
@Autowired
private
List
<
IAlarm
>
alarmList
;
private
List
<
IAlarm
>
alarmList
;
@Autowired
private
PlatDeviceService
platDeviceService
;
@Autowired
private
PlatTenantService
platTenantService
;
@Override
@Override
public
void
connectionLost
(
Throwable
cause
)
{
public
void
connectionLost
(
Throwable
cause
)
{
...
@@ -82,12 +97,16 @@ public class PushCallback implements MqttCallback {
...
@@ -82,12 +97,16 @@ public class PushCallback implements MqttCallback {
public
void
checkAlarm
(
DeviceInfo
device
)
{
public
void
checkAlarm
(
DeviceInfo
device
)
{
HeaderInfo
headers
=
device
.
getHeaders
();
HeaderInfo
headers
=
device
.
getHeaders
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
for
(
HeaderInfo
.
Bind
binding
:
bindings
)
{
for
(
HeaderInfo
.
Bind
binding
:
bindings
)
{
try
{
try
{
String
iot_tenantId
=
binding
.
getId
();
String
iot_tenantId
=
binding
.
getId
();
StopWatch
stopWatch
=
new
StopWatch
();
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
(
"checkAlarm-1"
);
stopWatch
.
start
(
"checkAlarm-1"
);
String
deviceId
=
device
.
getDeviceId
();
String
deviceId
=
device
.
getDeviceId
();
String
messageType
=
device
.
getMessageType
();
//更新设备状态
updateDeviceStatus
(
messageType
,
deviceId
,
iot_tenantId
);
JSONObject
properties
=
device
.
getProperties
();
JSONObject
properties
=
device
.
getProperties
();
...
@@ -120,6 +139,8 @@ public class PushCallback implements MqttCallback {
...
@@ -120,6 +139,8 @@ public class PushCallback implements MqttCallback {
}
}
}
}
}
}
stopWatch
.
stop
();
stopWatch
.
stop
();
logger
.
info
(
stopWatch
.
prettyPrint
());
logger
.
info
(
stopWatch
.
prettyPrint
());
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
...
@@ -130,6 +151,35 @@ public class PushCallback implements MqttCallback {
...
@@ -130,6 +151,35 @@ public class PushCallback implements MqttCallback {
}
}
@Transactional
public
void
updateDeviceStatus
(
String
messageType
,
String
deviceId
,
String
iot_tenantId
)
{
if
(
StringUtils
.
equalsAnyIgnoreCase
(
messageType
,
DeviceState
.
offline
.
getValue
(),
DeviceState
.
online
.
getValue
())){
LambdaQueryWrapper
<
PlatTenant
>
platTenantLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
platTenantLambdaQueryWrapper
.
eq
(
PlatTenant:
:
getIotOrgId
,
iot_tenantId
);
List
<
PlatTenant
>
platTenants
=
platTenantService
.
list
(
platTenantLambdaQueryWrapper
);
if
(
CollectionUtils
.
isEmpty
(
platTenants
)){
return
;
}
List
<
String
>
tenantIdList
=
platTenants
.
stream
().
map
(
BaseEntity:
:
getId
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
PlatDevice
>
deviceLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
deviceLambdaQueryWrapper
.
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
)
.
in
(
BaseBusEntity:
:
getTenantId
,
tenantIdList
);
List
<
PlatDevice
>
deviceList
=
platDeviceService
.
list
(
deviceLambdaQueryWrapper
);
if
(
CollectionUtils
.
isEmpty
(
deviceList
)){
return
;
}
for
(
PlatDevice
platDevice
:
deviceList
)
{
platDevice
.
setStatus
(
messageType
.
toLowerCase
());
}
platDeviceService
.
updateBatchById
(
deviceList
);
deviceCacheUtil
.
putAll
(
deviceList
);
}
}
}
}
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