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
de677d03
authored
Oct 25, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: 机构类型区分居家还是养老,告警配置开关,设备同步定时器逻辑修改
parent
4d7339b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
118 deletions
server-service/src/main/java/com/makeit/task/IotSyncTask.java
server-service/src/main/java/com/makeit/task/IotSyncTask.java
View file @
de677d03
package
com
.
makeit
.
task
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.makeit.common.entity.BaseBusEntity
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.saas.PlatTenant
;
import
com.makeit.enums.CommonEnum
;
import
com.makeit.enums.report.DeviceNameEnum
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.module.iot.service.IotOrgService
;
import
com.makeit.module.iot.vo.DeviceInstanceEntity
;
import
com.makeit.module.iot.vo.DeviceState
;
import
com.makeit.module.system.service.SysDictionaryCategoryService
;
import
com.makeit.module.system.vo.DictionaryVo
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.elder.PlatElderDayReportDayService
;
import
com.makeit.service.platform.elder.PlatElderSleepService
;
import
com.makeit.service.saas.PlatTenantService
;
import
com.makeit.utils.DeviceCacheUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
@Component
@Slf4j
public
class
IotSyncTask
{
@Autowired
private
IotOrgService
iotOrgService
;
@Autowired
private
PlatTenantService
platTenantService
;
@Autowired
private
PlatDeviceService
platDeviceService
;
@Autowired
private
SysDictionaryCategoryService
sysDictionaryCategoryService
;
@Autowired
private
DeviceCacheUtil
deviceCacheUtil
;
@Autowired
private
PlatElderSleepService
platElderSleepService
;
@Autowired
private
PlatElderDayReportDayService
platElderDayReportDayService
;
/**
* 一小时同步一次
* 启用状态的租户才同步
* 新增和更新平台端设备表
*/
@Scheduled
(
cron
=
"0 0/
3
* * * ?"
)
@Scheduled
(
cron
=
"0 0/
1
* * * ?"
)
public
void
syncEquipmentInfo
()
{
savePlatDevice
();
}
public
void
savePlatDevice
(){
log
.
info
(
"开始执行同步设备信息接口"
);
LambdaQueryWrapper
<
PlatTenant
>
tenantLambdaQueryWrapper
=
new
LambdaQueryWrapper
<
PlatTenant
>().
eq
(
PlatTenant:
:
getStatus
,
CommonEnum
.
YES
.
getValue
());
List
<
PlatTenant
>
platTenants
=
platTenantService
.
list
(
tenantLambdaQueryWrapper
);
List
<
DictionaryVo
>
dictionaryVos
=
sysDictionaryCategoryService
.
getByCategoryCode
(
"device.category"
);
Map
<
String
,
String
>
dicNameIdMap
=
dictionaryVos
.
stream
().
collect
(
Collectors
.
toMap
(
DictionaryVo:
:
getName
,
DictionaryVo:
:
getValue
,
(
v1
,
v2
)
->
v1
));
for
(
PlatTenant
platTenant
:
platTenants
)
{
String
iotOrgId
=
platTenant
.
getIotOrgId
();
if
(
StringUtils
.
isBlank
(
iotOrgId
))
{
continue
;
}
//查询iot设备
List
<
DeviceInstanceEntity
>
iotDeviceList
=
iotOrgService
.
getOrgDevice
(
iotOrgId
);
//查询平台设备
Set
<
String
>
iotDeviceIdSet
=
iotDeviceList
.
stream
().
map
(
DeviceInstanceEntity:
:
getId
).
collect
(
Collectors
.
toSet
());
LambdaQueryWrapper
<
PlatDevice
>
deviceLambdaQueryWrapper
=
new
LambdaQueryWrapper
<
PlatDevice
>().
eq
(
BaseBusEntity:
:
getTenantId
,
platTenant
.
getId
())
.
in
(
PlatDevice:
:
getOriDeviceId
,
iotDeviceIdSet
);
iotDeviceIdSet
.
add
(
"-1"
);
//删除设备
LambdaQueryWrapper
<
PlatDevice
>
removeQw
=
new
LambdaQueryWrapper
<
PlatDevice
>().
notIn
(
PlatDevice:
:
getOriDeviceId
,
iotDeviceIdSet
)
.
eq
(
BaseBusEntity:
:
getTenantId
,
platTenant
.
getId
());
platDeviceService
.
remove
(
removeQw
);
List
<
PlatDevice
>
deviceList
=
platDeviceService
.
list
(
deviceLambdaQueryWrapper
);
//更新平台设备
Collection
<
PlatDevice
>
platDevices
=
convertToPlatDevice
(
iotDeviceList
,
deviceList
,
platTenant
.
getId
(),
dicNameIdMap
);
platDeviceService
.
saveOrUpdateBatch
(
platDevices
);
deviceCacheUtil
.
putAll
(
platDevices
);
}
log
.
info
(
"结束执行同步设备信息接口"
);
platDeviceService
.
savePlatDevice
();
}
private
Collection
<
PlatDevice
>
convertToPlatDevice
(
List
<
DeviceInstanceEntity
>
iotDeviceList
,
List
<
PlatDevice
>
deviceList
,
String
tenantId
,
Map
<
String
,
String
>
dicNameIdMap
)
{
Map
<
String
,
PlatDevice
>
deviceMap
=
deviceList
.
stream
().
collect
(
Collectors
.
toMap
(
PlatDevice:
:
getOriDeviceId
,
v
->
v
,
(
a
,
b
)
->
a
));
iotDeviceList
.
forEach
(
iotDevice
->
{
PlatDevice
platDevice
=
deviceMap
.
get
(
iotDevice
.
getId
());
if
(
platDevice
==
null
)
{
platDevice
=
new
PlatDevice
();
platDevice
.
setTenantId
(
tenantId
);
deviceMap
.
put
(
iotDevice
.
getId
(),
platDevice
);
}
platDevice
.
setOriDeviceId
(
iotDevice
.
getId
());
platDevice
.
setName
(
iotDevice
.
getName
());
platDevice
.
setOrgId
(
tenantId
);
String
productName
=
iotDevice
.
getProductName
();
platDevice
.
setProductName
(
productName
);
platDevice
.
setProductId
(
iotDevice
.
getProductId
());
if
(
iotDevice
.
getRegistryTime
()!=
null
)
{
LocalDateTime
registryTime
=
LocalDateTime
.
ofEpochSecond
(
iotDevice
.
getRegistryTime
()
/
1000
,
0
,
ZoneOffset
.
ofHours
(
8
));
platDevice
.
setRegistrationDate
(
registryTime
);
}
platDevice
.
setDescription
(
iotDevice
.
getDescribe
());
String
state
=
iotDevice
.
getState
();
DeviceState
deviceState
=
JSON
.
parseObject
(
state
,
DeviceState
.
class
);
platDevice
.
setStatus
(
deviceState
.
getValue
());
//todo 根据类型名称来匹配
String
categoryName
=
DeviceNameEnum
.
getNameByPrefix
(
productName
);
platDevice
.
setCategory
(
dicNameIdMap
.
get
(
categoryName
));
// platDevice.setFirmwareVersion();
// platDevice.setLastOnlineData();
// platDevice.setOrgId();
// platDevice.setCityOrgId();
// platDevice.setDistrictOrgId();
// platDevice.setStreetOrgId();
// platDevice.setOrgPath();
// platDevice.setId();
// platDevice.setCreateDate();
// platDevice.setUpdateDate();
// platDevice.setDelFlag();
// platDevice.setCreateBy();
// platDevice.setUpdateBy();
});
return
deviceMap
.
values
();
}
/**
* 床位id 绑定的所有设备
* 房间id 绑定的所有设备
...
...
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