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
664eaf1e
authored
Sep 08, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat,修改机构同步iot
parent
eee34240
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
225 additions
and
17 deletions
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
server-common/src/main/java/com/makeit/module/iot/service/IotOrgService.java
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
server-common/src/main/java/com/makeit/module/iot/util/HeaderUtils.java
server-common/src/main/java/com/makeit/module/iot/vo/OrganizationEntity.java
server-service/src/main/java/com/makeit/service/platform/space/impl/PlatBedServiceImpl.java
server-service/src/main/java/com/makeit/service/saas/impl/PlatTenantServiceImpl.java
server-web/src/test/java/com/makeit/iotapi/IotTest.java
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
View file @
664eaf1e
...
...
@@ -42,12 +42,27 @@ public class IotCommonService {
return
request
;
}
public
ResponseMessage
sendPut
(
String
url
,
HttpRequest
request
)
throws
IOException
{
Response
response
=
request
.
put
();
ResponseMessage
responseMessage
=
getResponseMessage
(
url
,
response
);
return
responseMessage
;
}
public
ResponseMessage
sendGet
(
String
url
,
HttpRequest
request
)
throws
IOException
{
Response
response
=
request
.
get
();
ResponseMessage
responseMessage
=
getResponseMessage
(
url
,
response
);
return
responseMessage
;
}
public
ResponseMessage
sendPost
(
String
url
,
HttpRequest
request
)
throws
IOException
{
Response
response
=
request
.
post
();
ResponseMessage
responseMessage
=
getResponseMessage
(
url
,
response
);
return
responseMessage
;
}
private
static
ResponseMessage
getResponseMessage
(
String
url
,
Response
response
)
throws
IOException
{
Object
result
=
JSON
.
parse
(
response
.
asBytes
());
ResponseMessage
responseMessage
=
JSON
.
parseObject
(
result
.
toString
(),
ResponseMessage
.
class
);
log
.
info
(
"接口:{},返回信息:{}"
,
url
,
JSON
.
toJSONString
(
responseMessage
));
log
.
info
(
"接口:{},返回信息:{}"
,
url
,
JSON
.
toJSONString
(
responseMessage
));
return
responseMessage
;
}
...
...
@@ -72,7 +87,9 @@ public class IotCommonService {
IotQueryParam
iotQueryParam
=
new
IotQueryParam
();
iotQueryParam
.
setPageIndex
(
0
);
iotQueryParam
.
setPageSize
(
pageSize
);
buildSort
(
"timestamp"
);
iotQueryParam
.
setSorts
(
buildSort
(
"timestamp"
));
iotQueryParam
.
setTerms
(
Lists
.
newArrayList
());
return
iotQueryParam
;
}
...
...
server-common/src/main/java/com/makeit/module/iot/service/IotOrgService.java
View file @
664eaf1e
...
...
@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -31,10 +32,53 @@ public class IotOrgService extends IotCommonService{
public
static
final
String
DEVICE_PRODUCT_PREFIX_URL
=
"device-product/"
;
public
void
getIotOrgInfo
(
String
orgId
)
{
String
url
=
iotUrl
+
"organization/"
+
orgId
;
HttpRequest
request
=
new
SimpleHttpRequest
(
url
,
httpClient
);
request
.
headers
(
headerUtils
.
createHeadersOfParams
(
new
HashMap
<>()));
try
{
ResponseMessage
responseMessage
=
sendGet
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
OrganizationEntity
organizationEntity
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
OrganizationEntity
.
class
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
}
/**
* 更新iod
* @param orgId
* @param orgName
*/
public
void
updateIotOrgInfo
(
String
orgId
,
String
orgName
)
{
String
url
=
iotUrl
+
"organization/"
+
orgId
;
Map
<
String
,
Object
>
reqMap
=
Maps
.
newHashMap
();
reqMap
.
put
(
"name"
,
orgName
);
String
body
=
JSON
.
toJSONString
(
reqMap
);
HttpRequest
request
=
new
SimpleHttpRequest
(
url
,
httpClient
);
request
.
headers
(
headerUtils
.
createHeadersOfJsonString
(
body
));
request
.
requestBody
(
body
);
try
{
ResponseMessage
responseMessage
=
sendPut
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
log
.
info
(
"更新机构成功"
);
}
else
{
log
.
error
(
"更新机构失败:{}"
,
responseMessage
.
getMessage
());
}
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
}
/**
* iot同步新增组织机构
*/
public
OrganizationEntity
syncTenantInfoToIot
(
PlatTenantVO
platTenantVO
)
{
public
OrganizationEntity
addIotOrg
(
PlatTenantVO
platTenantVO
)
{
String
url
=
iotUrl
+
"organization"
;
Map
<
String
,
Object
>
reqMap
=
Maps
.
newHashMap
();
reqMap
.
put
(
"name"
,
platTenantVO
.
getName
());
...
...
@@ -45,7 +89,7 @@ public class IotOrgService extends IotCommonService{
request
.
headers
(
headerUtils
.
createHeadersOfJsonString
(
body
));
request
.
requestBody
(
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
OrganizationEntity
organizationEntity
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
OrganizationEntity
.
class
);
log
.
info
(
"新增机构成功,机构id:{}"
,
organizationEntity
.
getId
());
...
...
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
View file @
664eaf1e
...
...
@@ -4,13 +4,16 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONArray
;
import
com.google.common.collect.Lists
;
import
com.makeit.module.iot.dto.IotQueryParam
;
import
com.makeit.module.iot.dto.Term
;
import
com.makeit.module.iot.util.HttpRequest
;
import
com.makeit.module.iot.vo.DeviceInstanceEntity
;
import
com.makeit.module.iot.vo.DeviceOperationLogEntity
;
import
com.makeit.module.iot.vo.IotPagerResult
;
import
com.makeit.module.iot.vo.ResponseMessage
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.old.StringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
...
...
@@ -38,7 +41,6 @@ public class IotProductDeviceService extends IotCommonService {
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
IotPagerResult
pagerResult
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
IotPagerResult
.
class
);
...
...
@@ -54,16 +56,89 @@ public class IotProductDeviceService extends IotCommonService {
}
/**
* 获取最新一条设备日志
* @param deviceId
* @return
*/
public
DeviceOperationLogEntity
getLastDeviceLog
(
String
deviceId
)
{
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
getDeviceLog
(
deviceId
,
1
,
""
);
return
CollectionUtils
.
isNotEmpty
(
deviceOperationLogEntities
)
?
deviceOperationLogEntities
.
get
(
0
)
:
null
;
}
/**
*
* 根据类型查询设备日志
* text: "事件上报", value: "event"}
* {text: "读取属性", value: "readProperty"}
* {text: "修改属性", value: "writeProperty"}
* {text: "修改属性回复", value: "writePropertyReply"}
* {text: "属性上报", value: "reportProperty"}
* {text: "读取属性回复", value: "readPropertyReply"}
* {text: "子设备消息", value: "child"}
* {text: "子设备消息回复", value: "childReply"}
* {text: "调用功能", value: "functionInvoke"}
* {text: "调用功能回复", value: "functionReply"}
* {text: "设备注册", value: "register"}
* {text: "设备注销", value: "unregister"}
* {text: "读取固件信息", value: "readFirmware"}
* {text: "读取固件信息回复", value: "readFirmwareReply"}
* {text: "上报固件信息", value: "reportFirmware"}
* {text: "拉取固件信息", value: "pullFirmware"}
* {text: "拉取固件信息回复", value: "pullFirmwareReply"}
* {text: "推送固件信息", value: "upgradeFirmware"}
* {text: "推送固件信息回复", value: "upgradeFirmwareReply"}
* {text: "固件更新进度", value: "upgradeFirmwareProgress"}
* {text: "日志", value: "log"}
* {text: "标签更新", value: "tag"}
* {text: "离线", value: "offline"}
* {text: "上线", value: "online"}
* {text: "其它", value: "other"}
* {text: "透传", value: "direct"}
* {text: "应答", value: "acknowledge"}
* {text: "上报物模型", value: "metadata"}
* {text: "状态检查", value: "stateCheck"}
* {text: "状态检查回复", value: "stateCheckReply"}
* {text: "断开连接", value: "disconnect"}
* {text: "断开连接回复", value: "disconnectReply"}
* {text: "上报数采数据", value: "reportCollectorData"}
* {text: "读取数采数据", value: "readCollectorData"}
* {text: "读取数采数据回复", value: "readCollectorDataReply"}
* {text: "修改数采数据", value: "writeCollectorData"}
* {text: "修改数采数据回复", value: "writeCollectorDataReply"}
*
* @param deviceId
* @param typeValue
* @return
*/
public
List
<
DeviceOperationLogEntity
>
getDeviceLogByType
(
String
deviceId
,
String
typeValue
)
{
return
getDeviceLog
(
deviceId
,
10
,
typeValue
);
}
/**
* 获取设备的日志
*
* @param deviceId
* @param typeValue
*/
public
List
<
DeviceOperationLogEntity
>
getDeviceLog
(
String
deviceId
)
{
public
List
<
DeviceOperationLogEntity
>
getDeviceLog
(
String
deviceId
,
int
pageSize
,
String
typeValue
)
{
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
deviceId
+
"/logs"
;
IotQueryParam
iotQueryParam
=
buildQueryParam
(
10
);
IotQueryParam
iotQueryParam
=
buildQueryParam
(
pageSize
);
if
(
StringUtils
.
isNotEmpty
(
typeValue
))
{
List
<
Term
>
terms
=
Lists
.
newArrayList
();
Term
term
=
Term
.
builder
()
.
column
(
"type"
)
.
termType
(
"eq"
)
.
type
(
Term
.
Type
.
or
)
.
value
(
typeValue
)
.
terms
(
Lists
.
newArrayList
())
.
options
(
Lists
.
newArrayList
())
.
build
();
terms
.
add
(
term
);
iotQueryParam
.
setTerms
(
terms
);
}
String
body
=
JsonUtil
.
toJson
(
iotQueryParam
);
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
...
...
@@ -82,4 +157,7 @@ public class IotProductDeviceService extends IotCommonService {
}
}
server-common/src/main/java/com/makeit/module/iot/util/HeaderUtils.java
View file @
664eaf1e
...
...
@@ -27,6 +27,32 @@ public class HeaderUtils {
@Value
(
"${iot.secureKey}"
)
private
String
secureKey
;
public
Map
<
String
,
String
>
createHeadersOfParams
(
Map
<
String
,
Object
>
params
)
{
//时间戳
String
xTimestamp
=
String
.
valueOf
(
new
Date
().
getTime
());
//将参数按ASCII排序后拼接为k1=v1&k2=v2的格式
String
paramString
=
new
TreeMap
<>(
params
).
entrySet
()
.
stream
()
.
map
(
e
->
e
.
getKey
().
concat
(
"="
).
concat
(
String
.
valueOf
(
e
.
getValue
())))
.
collect
(
Collectors
.
joining
(
"&"
));
System
.
out
.
println
(
paramString
);
//param+X-Timestamp+SecureKey通过MD5加密
MessageDigest
digest
=
DigestUtils
.
getMd5Digest
();
System
.
out
.
println
(
paramString
+
xTimestamp
+
secureKey
);
digest
.
update
(
paramString
.
getBytes
());
digest
.
update
(
xTimestamp
.
getBytes
());
digest
.
update
(
secureKey
.
getBytes
());
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"X-Sign"
,
Hex
.
encodeHexString
(
digest
.
digest
()));
headers
.
put
(
"X-Client-Id"
,
clientId
);
headers
.
put
(
"X-Timestamp"
,
xTimestamp
);
return
headers
;
}
public
Map
<
String
,
String
>
createHeadersOfJsonString
(
String
jsonString
)
{
//时间戳
String
xTimestamp
=
String
.
valueOf
(
new
Date
().
getTime
());
...
...
server-common/src/main/java/com/makeit/module/iot/vo/OrganizationEntity.java
View file @
664eaf1e
...
...
@@ -2,6 +2,7 @@ package com.makeit.module.iot.vo;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
org.hibernate.validator.constraints.Length
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -9,11 +10,9 @@ import java.util.Map;
@Data
public
class
OrganizationEntity
{
@Schema
(
description
=
"ID"
)
private
String
id
;
@Schema
(
description
=
"编码"
)
private
String
code
;
...
...
@@ -43,4 +42,24 @@ public class OrganizationEntity {
private
Long
createTime
;
private
List
<
OrganizationEntity
>
children
;
@Schema
(
description
=
"父节点ID"
)
private
String
parentId
;
@Schema
(
description
=
"树结构路径"
)
private
String
path
;
@Schema
(
description
=
"排序序号"
)
private
Long
sortIndex
;
@Schema
(
description
=
"树层级"
)
private
Integer
level
;
}
server-service/src/main/java/com/makeit/service/platform/space/impl/PlatBedServiceImpl.java
View file @
664eaf1e
...
...
@@ -7,10 +7,7 @@ import com.makeit.common.dto.StatusDTO;
import
com.makeit.common.page.PageReqDTO
;
import
com.makeit.common.page.PageVO
;
import
com.makeit.dto.platform.device.PlatDeviceDTO
;
import
com.makeit.dto.platform.space.PlatBedDeviceQueryDTO
;
import
com.makeit.dto.platform.space.PlatBedEditDTO
;
import
com.makeit.dto.platform.space.PlatBedQueryDTO
;
import
com.makeit.dto.platform.space.PlatSpaceDeviceQueryDTO
;
import
com.makeit.dto.platform.space.*
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.platform.space.PlatBed
;
import
com.makeit.entity.platform.space.PlatRoom
;
...
...
@@ -206,4 +203,9 @@ public class PlatBedServiceImpl extends ServiceImpl<PlatBedMapper, PlatBed> impl
}
return
data
;
}
@Override
public
void
bindDevice
(
PlatRoomBindDeviceDTO
dto
)
{
}
}
server-service/src/main/java/com/makeit/service/saas/impl/PlatTenantServiceImpl.java
View file @
664eaf1e
...
...
@@ -206,7 +206,7 @@ implements PlatTenantService {
//新租户同步到iot
PlatTenantVO
platTenantVO
=
new
PlatTenantVO
();
platTenantVO
.
setName
(
dto
.
getName
());
OrganizationEntity
organizationEntity
=
iotOrgService
.
syncTenantInfoToIot
(
platTenantVO
);
OrganizationEntity
organizationEntity
=
iotOrgService
.
addIotOrg
(
platTenantVO
);
tntTenant
.
setIotOrgId
(
organizationEntity
.
getId
());
save
(
tntTenant
);
...
...
@@ -235,6 +235,8 @@ implements PlatTenantService {
PlatTenant
platTenant
=
getById
(
tntTenant
.
getId
());
updateById
(
tntTenant
);
iotOrgService
.
updateIotOrgInfo
(
tntTenant
.
getIotOrgId
(),
dto
.
getName
());
//更新用户的tenantId
if
(!
StringUtils
.
equals
(
dto
.
getPlatUserId
(),
platTenant
.
getPlatUserId
()))
{
platUserService
.
updatePlatUserTenantId
(
null
,
dto
.
getPlatUserId
());
...
...
server-web/src/test/java/com/makeit/iotapi/IotTest.java
View file @
664eaf1e
...
...
@@ -23,7 +23,7 @@ public class IotTest {
void
syncTenantInfoToIot
()
{
PlatTenantVO
platTenantVO
=
new
PlatTenantVO
();
platTenantVO
.
setName
(
"lxl2"
);
iotOrgService
.
syncTenantInfoToIot
(
platTenantVO
);
iotOrgService
.
addIotOrg
(
platTenantVO
);
}
...
...
@@ -49,6 +49,26 @@ public class IotTest {
@Test
void
getDeviceLog
()
{
iotProductDeviceService
.
getDeviceLog
(
"1694547143952007168"
);
iotProductDeviceService
.
getDeviceLog
(
"1694547143952007168"
,
10
,
""
);
}
@Test
void
getDeviceLogByType
()
{
iotProductDeviceService
.
getDeviceLogByType
(
"1694547143952007168"
,
"online"
);
}
@Test
void
getLastDeviceLog
()
{
iotProductDeviceService
.
getLastDeviceLog
(
"1694547143952007168"
);
}
@Test
void
getIotOrgInfo
()
{
iotOrgService
.
getIotOrgInfo
(
"1698964909267415040"
);
}
@Test
void
updateIotOrgInfo
()
{
iotOrgService
.
updateIotOrgInfo
(
"1698964909267415040"
,
"lxl2234"
);
}
}
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