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
b878669f
authored
Sep 05, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat:iot接口
parent
d1fe33b5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
1480 additions
and
3 deletions
saas-module/src/main/java/com/makeit/controller/saas/SaasDeviceController.java
server-common/pom.xml
server-common/server-common.iml
server-common/src/main/java/com/makeit/module/iot/dto/Condition.java
server-common/src/main/java/com/makeit/module/iot/dto/IotColumn.java
server-common/src/main/java/com/makeit/module/iot/dto/IotParam.java
server-common/src/main/java/com/makeit/module/iot/dto/IotQueryParam.java
server-common/src/main/java/com/makeit/module/iot/dto/IotSort.java
server-common/src/main/java/com/makeit/module/iot/dto/Term.java
server-common/src/main/java/com/makeit/module/iot/enums/DeviceLogType.java
server-common/src/main/java/com/makeit/module/iot/enums/DeviceState.java
server-common/src/main/java/com/makeit/module/iot/enums/DeviceType.java
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/util/HttpRequest.java
server-common/src/main/java/com/makeit/module/iot/util/Response.java
server-common/src/main/java/com/makeit/module/iot/util/SimpleHttpRequest.java
server-common/src/main/java/com/makeit/module/iot/util/SimpleResponse.java
server-common/src/main/java/com/makeit/module/iot/util/Utils.java
server-common/src/main/java/com/makeit/module/iot/vo/DeviceInstanceEntity.java
server-common/src/main/java/com/makeit/module/iot/vo/DeviceOperationLogEntity.java
server-common/src/main/java/com/makeit/module/iot/vo/DeviceProductEntity.java
server-common/src/main/java/com/makeit/module/iot/vo/IotPagerResult.java
server-common/src/main/java/com/makeit/module/iot/vo/OrganizationEntity.java
server-common/src/main/java/com/makeit/module/iot/vo/ResponseMessage.java
server-common/src/main/java/com/makeit/task/IotSyncTask.java
server-web/src/main/resources/application-dev.yml
server-web/src/test/java/com/makeit/iotapi/IotTest.java
saas-module/src/main/java/com/makeit/controller/saas/SaasDeviceController.java
View file @
b878669f
...
...
@@ -38,7 +38,8 @@ public class SaasDeviceController {
@ApiOperation
(
"设备编辑"
)
@PostMapping
(
"edit"
)
public
ApiResponseEntity
<
Void
>
edit
(
@RequestBody
PlatDevice
platDevice
)
{
return
ApiResponseUtils
.
success
(
platDeviceService
.
edit
(
platDevice
));
platDeviceService
.
edit
(
platDevice
);
return
ApiResponseUtils
.
success
();
}
@ApiOperation
(
"实时数据"
)
...
...
server-common/pom.xml
View file @
b878669f
...
...
@@ -109,6 +109,18 @@
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
${hutool.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.83
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
easyexcel
</artifactId>
</dependency>
...
...
server-common/server-common.iml
deleted
100644 → 0
View file @
d1fe33b5
This diff is collapsed.
Click to expand it.
server-common/src/main/java/com/makeit/module/iot/dto/Condition.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
Condition
{
private
String
assetType
;
private
List
<
Targets
>
targets
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
static
class
Targets
{
private
String
id
;
private
String
type
;
}
}
server-common/src/main/java/com/makeit/module/iot/dto/IotColumn.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
dto
;
import
io.swagger.v3.oas.annotations.Hidden
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.util.Map
;
@Data
public
class
IotColumn
{
@Schema
(
description
=
"字段名"
)
private
String
name
;
@Hidden
private
String
type
;
@Hidden
private
Map
<
String
,
Object
>
opts
;
}
server-common/src/main/java/com/makeit/module/iot/dto/IotParam.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
dto
;
import
lombok.Data
;
import
lombok.NonNull
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Set
;
@Data
public
class
IotParam
{
private
List
<
Term
>
terms
=
new
LinkedList
();
private
Set
<
String
>
includes
=
new
LinkedHashSet
();
private
Set
<
String
>
excludes
=
new
LinkedHashSet
();
}
server-common/src/main/java/com/makeit/module/iot/dto/IotQueryParam.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
dto
;
import
io.swagger.v3.oas.annotations.Hidden
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.util.List
;
import
java.util.Map
;
@Data
public
class
IotQueryParam
extends
IotParam
{
@Schema
(
description
=
"是否分页"
)
private
boolean
paging
=
true
;
@Schema
(
description
=
"第一页索引"
)
private
int
firstPageIndex
;
@Schema
(
description
=
"页码"
)
private
int
pageIndex
;
@Schema
(
description
=
"每页数量"
)
private
int
pageSize
;
private
List
<
IotSort
>
sorts
;
}
server-common/src/main/java/com/makeit/module/iot/dto/IotSort.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
dto
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
@Data
public
class
IotSort
extends
IotColumn
{
@Schema
(
description
=
"排序方式"
,
allowableValues
=
{
"asc"
,
"desc"
},
minLength
=
3
,
maxLength
=
4
)
private
String
order
=
"asc"
;
@Schema
(
description
=
"指定的值优先排序"
)
private
Object
value
;
}
server-common/src/main/java/com/makeit/module/iot/dto/Term.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
dto
;
import
com.google.common.collect.Lists
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
Term
{
@Schema
(
description
=
"字段名"
)
private
String
column
;
@Schema
(
description
=
"条件值"
)
private
Object
value
;
@Schema
(
description
=
"多个条件关联类型"
,
defaultValue
=
"and"
)
private
Type
type
;
@Schema
(
description
=
"动态条件类型"
,
defaultValue
=
"eq"
)
private
String
termType
;
@Schema
(
description
=
"拓展选项"
)
private
List
<
String
>
options
=
new
ArrayList
<>();
@Schema
(
description
=
"嵌套条件"
)
private
List
<
Term
>
terms
=
new
LinkedList
<>();
public
enum
Type
{
or
,
and
;
private
Type
()
{
}
}
}
server-common/src/main/java/com/makeit/module/iot/enums/DeviceLogType.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
enums
;
import
lombok.AllArgsConstructor
;
import
lombok.Generated
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
enum
DeviceLogType
{
event
(
"事件上报"
),
readProperty
(
"读取属性"
),
writeProperty
(
"修改属性"
),
writePropertyReply
(
"修改属性回复"
),
reportProperty
(
"属性上报"
),
readPropertyReply
(
"读取属性回复"
),
child
(
"子设备消息"
),
childReply
(
"子设备消息回复"
),
functionInvoke
(
"调用功能"
),
functionReply
(
"调用功能回复"
),
register
(
"设备注册"
),
unregister
(
"设备注销"
),
readFirmware
(
"读取固件信息"
),
readFirmwareReply
(
"读取固件信息回复"
),
reportFirmware
(
"上报固件信息"
),
pullFirmware
(
"拉取固件信息"
),
pullFirmwareReply
(
"拉取固件信息回复"
),
upgradeFirmware
(
"推送固件信息"
),
upgradeFirmwareReply
(
"推送固件信息回复"
),
upgradeFirmwareProgress
(
"固件更新进度"
),
log
(
"日志"
),
tag
(
"标签更新"
),
offline
(
"离线"
),
online
(
"上线"
),
other
(
"其它"
),
direct
(
"透传"
),
acknowledge
(
"应答"
),
metadata
(
"上报物模型"
),
stateCheck
(
"状态检查"
),
stateCheckReply
(
"状态检查回复"
),
//状态检查
disconnect
(
"断开连接"
),
disconnectReply
(
"断开连接回复"
),
reportCollectorData
(
"上报数采数据"
),
readCollectorData
(
"读取数采数据"
),
readCollectorDataReply
(
"读取数采数据回复"
),
writeCollectorData
(
"修改数采数据"
),
writeCollectorDataReply
(
"修改数采数据回复"
)
;
private
final
String
text
;
}
server-common/src/main/java/com/makeit/module/iot/enums/DeviceState.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
enums
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
enum
DeviceState
{
notActive
(
"禁用"
),
offline
(
"离线"
),
online
(
"在线"
);
private
final
String
text
;
}
server-common/src/main/java/com/makeit/module/iot/enums/DeviceType.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
enums
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
enum
DeviceType
{
device
(
"直连设备"
),
childrenDevice
(
"网关子设备"
),
gateway
(
"网关设备"
);
private
final
String
text
;
}
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.collect.Lists
;
import
com.makeit.module.iot.dto.Condition
;
import
com.makeit.module.iot.dto.IotQueryParam
;
import
com.makeit.module.iot.dto.IotSort
;
import
com.makeit.module.iot.dto.Term
;
import
com.makeit.module.iot.util.HeaderUtils
;
import
com.makeit.module.iot.util.HttpRequest
;
import
com.makeit.module.iot.util.Response
;
import
com.makeit.module.iot.util.SimpleHttpRequest
;
import
com.makeit.module.iot.vo.ResponseMessage
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.io.IOException
;
import
java.util.List
;
@Slf4j
public
class
IotCommonService
{
@Autowired
public
HeaderUtils
headerUtils
;
@Value
(
"${iot.url:}"
)
public
String
iotUrl
;
protected
static
HttpClient
httpClient
=
HttpClientBuilder
.
create
().
build
();
public
HttpRequest
buildRequest
(
String
url
,
String
body
)
{
log
.
info
(
"接口:{},请求参数:{}"
,
url
,
body
);
HttpRequest
request
=
new
SimpleHttpRequest
(
url
,
httpClient
);
request
.
headers
(
headerUtils
.
createHeadersOfJsonString
(
body
));
request
.
requestBody
(
body
);
return
request
;
}
public
ResponseMessage
sendPost
(
String
url
,
HttpRequest
request
)
throws
IOException
{
Response
response
=
request
.
post
();
Object
result
=
JSON
.
parse
(
response
.
asBytes
());
ResponseMessage
responseMessage
=
JSON
.
parseObject
(
result
.
toString
(),
ResponseMessage
.
class
);
log
.
info
(
"接口:{},返回信息:{}"
,
url
,
JSON
.
toJSONString
(
responseMessage
));
return
responseMessage
;
}
/**
* 默认按照时间倒叙
* 可以根据terms进行条件查询 格式
* [
* {
* "terms": [
* {
* "type": "or",
* "value": "%123%",
* "termType": "like",
* "column": "name"
* }
* ]
* }
* ]
* @return
*/
public
static
IotQueryParam
buildQueryParam
(
int
pageSize
)
{
IotQueryParam
iotQueryParam
=
new
IotQueryParam
();
iotQueryParam
.
setPageIndex
(
0
);
iotQueryParam
.
setPageSize
(
pageSize
);
buildSort
(
"timestamp"
);
iotQueryParam
.
setTerms
(
Lists
.
newArrayList
());
return
iotQueryParam
;
}
/**
*
* @param pageSize 页大小
* @param column 查询列
* @param termType 动态条件类型
* @param assetType
* @param pkId
* @param type
* @return
*/
public
static
IotQueryParam
buildQueryParam
(
int
pageSize
,
String
column
,
String
termType
,
String
assetType
,
String
pkId
,
String
type
,
String
sortColumn
)
{
IotQueryParam
iotQueryParam
=
new
IotQueryParam
();
iotQueryParam
.
setPageIndex
(
0
);
iotQueryParam
.
setPageSize
(
pageSize
);
List
<
Term
>
terms
=
getTerms
(
column
,
termType
,
assetType
,
pkId
,
type
);
iotQueryParam
.
setTerms
(
terms
);
List
<
IotSort
>
iotSortList
=
buildSort
(
sortColumn
);
iotQueryParam
.
setSorts
(
iotSortList
);
return
iotQueryParam
;
}
private
static
List
<
IotSort
>
buildSort
(
String
createTime
)
{
List
<
IotSort
>
iotSortList
=
Lists
.
newArrayList
();
IotSort
iotSort
=
new
IotSort
();
iotSort
.
setOrder
(
"desc"
);
iotSort
.
setName
(
createTime
);
iotSortList
.
add
(
iotSort
);
return
iotSortList
;
}
private
static
List
<
Term
>
getTerms
(
String
column
,
String
termType
,
String
assetType
,
String
pkId
,
String
type
)
{
List
<
Term
>
terms
=
Lists
.
newArrayList
();
if
(
StringUtils
.
isEmpty
(
column
))
{
return
terms
;
}
List
<
Condition
.
Targets
>
targets
=
Lists
.
newArrayList
();
Condition
.
Targets
target
=
Condition
.
Targets
.
builder
()
.
id
(
pkId
)
.
type
(
type
).
build
();
targets
.
add
(
target
);
Condition
condition
=
Condition
.
builder
()
.
assetType
(
assetType
)
.
targets
(
targets
)
.
build
();
Term
term
=
Term
.
builder
()
.
column
(
column
)
.
termType
(
termType
)
.
value
(
condition
)
.
terms
(
Lists
.
newArrayList
())
.
options
(
Lists
.
newArrayList
())
.
build
();
terms
.
add
(
term
);
return
terms
;
}
}
server-common/src/main/java/com/makeit/module/iot/service/IotOrgService.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.makeit.module.admin.vo.plat.PlatTenantVO
;
import
com.makeit.module.iot.dto.Condition
;
import
com.makeit.module.iot.dto.IotQueryParam
;
import
com.makeit.module.iot.dto.IotSort
;
import
com.makeit.module.iot.dto.Term
;
import
com.makeit.module.iot.util.HttpRequest
;
import
com.makeit.module.iot.util.Response
;
import
com.makeit.module.iot.util.SimpleHttpRequest
;
import
com.makeit.module.iot.vo.*
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
/**
* iot 组织机构相关接口
*/
@Component
@Slf4j
public
class
IotOrgService
extends
IotCommonService
{
public
static
final
String
DEVICE_PRODUCT_PREFIX_URL
=
"device-product/"
;
/**
* iot同步新增组织机构
*/
public
OrganizationEntity
syncTenantInfoToIot
(
PlatTenantVO
platTenantVO
)
{
String
url
=
iotUrl
+
"organization"
;
Map
<
String
,
Object
>
reqMap
=
Maps
.
newHashMap
();
reqMap
.
put
(
"name"
,
platTenantVO
.
getName
());
reqMap
.
put
(
"sortIndex"
,
5
);
String
body
=
JSON
.
toJSONString
(
reqMap
);
HttpRequest
request
=
new
SimpleHttpRequest
(
url
,
httpClient
);
request
.
headers
(
headerUtils
.
createHeadersOfJsonString
(
body
));
request
.
requestBody
(
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
OrganizationEntity
organizationEntity
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
OrganizationEntity
.
class
);
log
.
info
(
"新增机构成功,机构id:{}"
,
organizationEntity
.
getId
());
return
organizationEntity
;
}
log
.
error
(
"新增机构失败:{}"
,
responseMessage
.
getMessage
());
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
null
;
}
/**
* 获取iot组织机构绑定的产品
*/
public
List
<
DeviceProductEntity
>
getOrgProduct
(
String
iotOrgId
)
{
String
url
=
iotUrl
+
DEVICE_PRODUCT_PREFIX_URL
+
"_query"
;
IotQueryParam
queryParam
=
buildQueryParam
(
10
,
"id"
,
"dim-assets"
,
"product"
,
iotOrgId
,
"org"
,
"createTime"
);
String
body
=
JsonUtil
.
toJson
(
queryParam
);
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
IotPagerResult
pagerResult
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
IotPagerResult
.
class
);
List
<
DeviceProductEntity
>
deviceProductEntityList
=
JSONArray
.
parseArray
(
pagerResult
.
getData
().
toString
()).
toJavaList
(
DeviceProductEntity
.
class
);
return
deviceProductEntityList
;
}
else
{
log
.
error
(
"获取设备接口失败:{}"
,
responseMessage
.
getMessage
());
}
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
Lists
.
newArrayList
();
}
/**
* 获取iot组织机构绑定的设备
*/
public
List
<
DeviceInstanceEntity
>
getOrgDevice
(
String
iotOrgId
)
{
String
url
=
iotUrl
+
"device/instance/_query"
;
IotQueryParam
queryParam
=
buildQueryParam
(
10
,
"id"
,
"dim-assets"
,
"device"
,
iotOrgId
,
"org"
,
"createTime"
);
String
body
=
JsonUtil
.
toJson
(
queryParam
);
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
IotPagerResult
pagerResult
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
IotPagerResult
.
class
);
List
<
DeviceInstanceEntity
>
deviceInstanceEntityList
=
JSONArray
.
parseArray
(
pagerResult
.
getData
().
toString
()).
toJavaList
(
DeviceInstanceEntity
.
class
);
return
deviceInstanceEntityList
;
}
log
.
error
(
"获取设备接口失败:{}"
,
responseMessage
.
getMessage
());
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
Lists
.
newArrayList
();
}
}
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
service
;
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.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
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.List
;
/**
* iot产品设备相关接口
*/
@Component
@Slf4j
public
class
IotProductDeviceService
extends
IotCommonService
{
public
static
final
String
DEVICE_PREFIX_URL
=
"/device-instance/"
;
/**
* 获取设备信息
*/
public
List
<
DeviceInstanceEntity
>
getEquipmentInfo
()
{
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
"_query"
;
// 条件可以自己改
IotQueryParam
iotQueryParam
=
buildQueryParam
(
10
);
String
body
=
JsonUtil
.
toJson
(
iotQueryParam
);
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
IotPagerResult
pagerResult
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
IotPagerResult
.
class
);
List
<
DeviceInstanceEntity
>
deviceOperationLogEntities
=
JSONArray
.
parseArray
(
pagerResult
.
getData
().
toString
()).
toJavaList
(
DeviceInstanceEntity
.
class
);
return
deviceOperationLogEntities
;
}
log
.
error
(
"获取设备接口失败:{}"
,
responseMessage
.
getMessage
());
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
Lists
.
newArrayList
();
}
/**
* 获取设备的日志
*
* @param deviceId
*/
public
List
<
DeviceOperationLogEntity
>
getDeviceLog
(
String
deviceId
)
{
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
deviceId
+
"/logs"
;
IotQueryParam
iotQueryParam
=
buildQueryParam
(
10
);
String
body
=
JsonUtil
.
toJson
(
iotQueryParam
);
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
IotPagerResult
pagerResult
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
(),
IotPagerResult
.
class
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogEntities
=
JSONArray
.
parseArray
(
pagerResult
.
getData
().
toString
()).
toJavaList
(
DeviceOperationLogEntity
.
class
);
//Map maps = (Map) JSON.parse(datum.getContent().toString());
return
deviceOperationLogEntities
;
}
log
.
error
(
"获取设备接口失败:{}"
,
responseMessage
.
getMessage
());
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
Lists
.
newArrayList
();
}
}
server-common/src/main/java/com/makeit/module/iot/util/HeaderUtils.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.security.MessageDigest
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.stream.Collectors
;
/**
* @author wangzheng
* @see
* @since 1.0
*/
@Component
@Slf4j
public
class
HeaderUtils
{
@Value
(
"${iot.clientId}"
)
private
String
clientId
;
@Value
(
"${iot.secureKey}"
)
private
String
secureKey
;
public
Map
<
String
,
String
>
createHeadersOfJsonString
(
String
jsonString
)
{
//时间戳
String
xTimestamp
=
String
.
valueOf
(
new
Date
().
getTime
());
//openApi客户端id
//密钥
//param+X-Timestamp+SecureKey通过MD5加密
MessageDigest
digest
=
DigestUtils
.
getMd5Digest
();
System
.
out
.
println
(
jsonString
+
xTimestamp
+
secureKey
);
digest
.
update
(
jsonString
.
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
);
log
.
info
(
"请求头信息:{}"
,
Hex
.
encodeHexString
(
digest
.
digest
())
+
"|"
+
clientId
+
"|"
+
xTimestamp
);
return
headers
;
}
}
server-common/src/main/java/com/makeit/module/iot/util/HttpRequest.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
util
;
import
java.io.Closeable
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* @author wang
* @see
* @since 1.0
*/
public
interface
HttpRequest
extends
Closeable
{
Response
get
()
throws
IOException
;
Response
post
()
throws
IOException
;
Response
put
()
throws
IOException
;
Response
delete
()
throws
IOException
;
Response
patch
()
throws
IOException
;
HttpRequest
encode
(
String
encode
);
HttpRequest
contentType
(
String
type
);
HttpRequest
param
(
String
name
,
String
value
);
HttpRequest
params
(
Map
<
String
,
Object
>
params
);
HttpRequest
header
(
String
name
,
String
value
);
HttpRequest
headers
(
Map
<
String
,
String
>
headers
);
HttpRequest
requestBody
(
String
body
);
HttpRequest
resultAsJsonString
();
}
server-common/src/main/java/com/makeit/module/iot/util/Response.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
util
;
import
java.io.IOException
;
/**
* @author wang
* @see
* @since 1.0
*/
public
interface
Response
{
byte
[]
asBytes
()
throws
IOException
;
}
server-common/src/main/java/com/makeit/module/iot/util/SimpleHttpRequest.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
util
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.*
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author wang
* @see
* @since 1.0
*/
public
class
SimpleHttpRequest
implements
HttpRequest
{
private
Map
<
String
,
Object
>
params
=
new
LinkedHashMap
<>();
private
Map
<
String
,
String
>
headers
=
new
LinkedHashMap
<>();
private
String
url
;
private
String
requestBody
;
private
String
contentType
;
private
String
encode
=
"utf-8"
;
protected
HttpClient
httpClient
;
public
SimpleHttpRequest
(
String
url
)
{
this
.
url
=
url
;
createHttpClient
();
}
public
SimpleHttpRequest
(
String
url
,
HttpClient
client
)
{
this
.
url
=
url
;
this
.
httpClient
=
client
;
}
protected
void
createHttpClient
()
{
if
(
httpClient
==
null
)
{
HttpClientBuilder
builder
=
HttpClientBuilder
.
create
();
httpClient
=
builder
.
build
();
}
}
@Override
public
Response
get
()
throws
IOException
{
String
param
=
EntityUtils
.
toString
(
createUrlEncodedFormEntity
());
String
tmpUrl
=
url
+
(
url
.
contains
(
"?"
)
?
"&"
:
"?"
)
+
param
;
HttpGet
get
=
new
HttpGet
(
tmpUrl
);
HttpResponse
response
=
execute
(
get
);
return
getResultValue
(
response
);
}
@Override
public
Response
post
()
throws
IOException
{
HttpPost
post
=
new
HttpPost
(
url
);
if
(
requestBody
!=
null
)
post
.
setEntity
(
new
StringEntity
(
requestBody
,
ContentType
.
create
(
contentType
,
encode
)));
else
{
post
.
setEntity
(
createUrlEncodedFormEntity
());
}
HttpResponse
response
=
execute
(
post
);
return
getResultValue
(
response
);
}
@Override
public
Response
put
()
throws
IOException
{
HttpPut
put
=
new
HttpPut
(
url
);
if
(
requestBody
!=
null
)
put
.
setEntity
(
new
StringEntity
(
requestBody
,
ContentType
.
create
(
contentType
,
encode
)));
else
{
put
.
setEntity
(
createUrlEncodedFormEntity
());
}
HttpResponse
response
=
execute
(
put
);
return
getResultValue
(
response
);
}
protected
UrlEncodedFormEntity
createUrlEncodedFormEntity
()
throws
UnsupportedEncodingException
{
List
<
NameValuePair
>
nameValuePair
=
params
.
entrySet
()
.
stream
().
map
(
stringStringEntry
->
new
BasicNameValuePair
(
stringStringEntry
.
getKey
(),
String
.
valueOf
(
stringStringEntry
.
getValue
())))
.
collect
(
Collectors
.
toList
());
return
new
UrlEncodedFormEntity
(
nameValuePair
,
encode
);
}
@Override
public
Response
delete
()
throws
IOException
{
HttpDelete
delete
=
new
HttpDelete
(
url
);
HttpResponse
response
=
execute
(
delete
);
return
getResultValue
(
response
);
}
@Override
public
Response
patch
()
throws
IOException
{
HttpPatch
delete
=
new
HttpPatch
(
url
);
if
(
requestBody
!=
null
)
delete
.
setEntity
(
new
StringEntity
(
requestBody
,
ContentType
.
create
(
contentType
)));
else
{
delete
.
setEntity
(
createUrlEncodedFormEntity
());
}
return
getResultValue
(
execute
(
delete
));
}
@Override
public
void
close
()
throws
IOException
{
if
(
httpClient
!=
null
&&
httpClient
instanceof
CloseableHttpClient
)
{
((
CloseableHttpClient
)
httpClient
).
close
();
}
}
@Override
public
HttpRequest
resultAsJsonString
()
{
header
(
"Accept"
,
"application/json"
);
return
this
;
}
@Override
public
HttpRequest
requestBody
(
String
body
)
{
contentType
(
"application/json"
);
this
.
requestBody
=
body
;
return
this
;
}
@Override
public
HttpRequest
encode
(
String
encode
)
{
this
.
encode
=
encode
;
return
this
;
}
@Override
public
HttpRequest
contentType
(
String
type
)
{
this
.
contentType
=
type
;
return
this
;
}
@Override
public
HttpRequest
param
(
String
name
,
String
value
)
{
this
.
params
.
put
(
name
,
value
);
return
this
;
}
@Override
public
HttpRequest
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
.
putAll
(
params
);
return
this
;
}
@Override
public
HttpRequest
header
(
String
name
,
String
value
)
{
this
.
headers
.
put
(
name
,
value
);
return
this
;
}
@Override
public
HttpRequest
headers
(
Map
<
String
,
String
>
header
)
{
this
.
headers
.
putAll
(
header
);
return
this
;
}
private
Response
getResultValue
(
HttpResponse
res
)
throws
IOException
{
return
new
SimpleResponse
(
res
);
}
private
HttpResponse
execute
(
HttpRequestBase
request
)
throws
IOException
{
putHeader
(
request
);
return
httpClient
.
execute
(
request
);
}
private
void
putHeader
(
HttpUriRequest
request
)
{
headers
.
forEach
(
request:
:
setHeader
);
}
}
server-common/src/main/java/com/makeit/module/iot/util/SimpleResponse.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
util
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.util.EntityUtils
;
import
java.io.IOException
;
/**
* @author wang
* @see
* @since 1.0
*/
public
class
SimpleResponse
implements
Response
{
HttpResponse
response
;
public
SimpleResponse
(
HttpResponse
response
)
{
this
.
response
=
response
;
}
@Override
public
byte
[]
asBytes
()
throws
IOException
{
return
EntityUtils
.
toByteArray
(
response
.
getEntity
());
}
}
server-common/src/main/java/com/makeit/module/iot/util/Utils.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
util
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author wangzheng
* @see
* @since 1.0
*/
public
class
Utils
{
public
static
Map
<
String
,
String
>
queryStringToMap
(
String
queryString
,
String
charset
){
try
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
String
[]
decode
=
URLDecoder
.
decode
(
queryString
,
charset
).
split
(
"&"
);
for
(
String
keyValue
:
decode
)
{
String
[]
kv
=
keyValue
.
split
(
"[=]"
,
2
);
map
.
put
(
kv
[
0
],
kv
.
length
>
1
?
kv
[
1
]:
""
);
}
return
map
;
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
UnsupportedOperationException
(
e
);
}
}
}
server-common/src/main/java/com/makeit/module/iot/vo/DeviceInstanceEntity.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.util.Map
;
@Data
public
class
DeviceInstanceEntity
{
private
String
id
;
@Schema
(
description
=
"图片地址"
)
private
String
photoUrl
;
@Schema
(
description
=
"设备名称"
)
private
String
name
;
@Schema
(
description
=
"设备类型"
)
private
String
deviceType
;
@Schema
(
description
=
"说明"
)
private
String
describe
;
@Schema
(
description
=
"产品ID"
)
private
String
productId
;
@Schema
(
description
=
"产品名称"
)
private
String
productName
;
@Schema
(
description
=
"配置信息"
)
private
Map
<
String
,
Object
>
configuration
;
@Schema
(
description
=
"派生(独立)物模型"
)
private
String
deriveMetadata
;
@Schema
(
description
=
"状态(只读)"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
,
defaultValue
=
"notActive"
)
private
String
state
;
@Schema
(
description
=
"创建者ID(只读)"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
String
creatorId
;
@Schema
(
description
=
"创建者名称(只读)"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
String
creatorName
;
@Schema
(
description
=
"创建时间(只读)"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
Long
createTime
;
@Schema
(
description
=
"激活时间"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
Long
registryTime
;
@Schema
(
description
=
"机构ID"
,
hidden
=
true
)
//已弃用,机构和设备存在多对多关系,已由资产功能统一管理
@Deprecated
private
String
orgId
;
@Schema
(
description
=
"父级设备ID"
)
private
String
parentId
;
//拓展特性,比如是否为子设备独立状态管理。
// private DeviceFeature[] features;
@Schema
(
description
=
"修改时间"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
Long
modifyTime
;
@Schema
(
description
=
"修改人ID"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
String
modifierId
;
@Schema
(
description
=
"修改人名称"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
String
modifierName
;
}
server-common/src/main/java/com/makeit/module/iot/vo/DeviceOperationLogEntity.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
vo
;
import
com.makeit.module.iot.enums.DeviceLogType
;
import
io.swagger.v3.oas.annotations.Hidden
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.*
;
/**
* @author bsetfeng
* @since 1.0
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Generated
public
class
DeviceOperationLogEntity
{
private
static
final
long
serialVersionUID
=
-
6849794470754667710L
;
@Schema
(
description
=
"日志ID"
)
private
String
id
;
@Schema
(
description
=
"设备ID"
)
private
String
deviceId
;
@Schema
(
description
=
"产品ID"
)
private
String
productId
;
@Schema
(
description
=
"日志类型"
)
private
String
type
;
@Schema
(
description
=
"创建时间"
)
private
long
createTime
;
@Schema
(
description
=
"日志内容"
)
private
Object
content
;
@Schema
(
description
=
"消息ID"
)
private
String
messageId
;
@Hidden
private
String
orgId
;
@Schema
(
description
=
"数据时间"
)
private
long
timestamp
;
}
server-common/src/main/java/com/makeit/module/iot/vo/DeviceProductEntity.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
vo
;
import
io.swagger.v3.oas.annotations.Hidden
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.util.Map
;
@Data
public
class
DeviceProductEntity
{
private
String
id
;
@Schema
(
description
=
"产品名称"
)
private
String
name
;
@Schema
(
description
=
"所属项目"
)
private
String
projectId
;
@Schema
(
description
=
"图片地址"
)
private
String
photoUrl
;
@Schema
(
description
=
"项目名称"
)
@Hidden
private
String
projectName
;
@Schema
(
description
=
"说明"
)
private
String
describe
;
@Schema
(
description
=
"所属品类ID"
)
private
String
classifiedId
;
@Schema
(
description
=
"所属品类名称"
)
private
String
classifiedName
;
@Schema
(
description
=
"消息协议ID"
)
private
String
messageProtocol
;
@Schema
(
description
=
"消息协议名称"
)
private
String
protocolName
;
@Schema
(
description
=
"物模型定义"
)
private
String
metadata
;
@Schema
(
description
=
"传输协议"
)
private
String
transportProtocol
;
@Schema
(
description
=
"入网方式"
)
private
String
networkWay
;
@Schema
(
description
=
"设备类型"
)
private
String
deviceType
;
@Schema
(
description
=
"协议相关配置"
)
private
Map
<
String
,
Object
>
configuration
;
@Schema
(
description
=
"产品状态 1正常,0禁用"
)
private
Byte
state
;
@Schema
(
description
=
"创建者ID(只读)"
)
private
String
creatorId
;
@Schema
(
description
=
"创建者时间(只读)"
)
private
Long
createTime
;
@Schema
(
description
=
"机构ID"
)
@Deprecated
@Hidden
private
String
orgId
;
@Schema
(
description
=
"设备接入方式ID"
)
private
String
accessId
;
@Schema
(
description
=
"设备接入方式"
)
private
String
accessProvider
;
@Schema
(
description
=
"设备接入方式名称"
)
private
String
accessName
;
@Schema
(
description
=
"数据存储策略"
)
private
String
storePolicy
;
@Schema
(
description
=
"数据存储策略相关配置"
)
private
Map
<
String
,
Object
>
storePolicyConfiguration
;
@Schema
(
description
=
"修改人"
)
private
String
modifierId
;
@Schema
(
description
=
"修改时间"
)
private
Long
modifyTime
;
}
server-common/src/main/java/com/makeit/module/iot/vo/IotPagerResult.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.util.ArrayList
;
import
java.util.List
;
@Data
public
class
IotPagerResult
<
E
>
{
@Schema
(
description
=
"页码"
)
private
int
pageIndex
;
@Schema
(
description
=
"每页数据量"
)
private
int
pageSize
;
@Schema
(
description
=
"数据总量"
)
private
int
total
;
@Schema
(
description
=
"数据列表"
)
private
List
<
E
>
data
;
}
server-common/src/main/java/com/makeit/module/iot/vo/OrganizationEntity.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.util.List
;
import
java.util.Map
;
@Data
public
class
OrganizationEntity
{
@Schema
(
description
=
"ID"
)
private
String
id
;
@Schema
(
description
=
"编码"
)
private
String
code
;
@Schema
(
description
=
"名称"
)
private
String
name
;
@Schema
(
description
=
"类型"
)
private
String
type
;
@Schema
(
description
=
"说明"
)
private
String
describe
;
@Schema
(
description
=
"其他配置"
)
private
Map
<
String
,
Object
>
properties
;
@Schema
(
description
=
"创建者ID(只读)"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
String
creatorId
;
@Schema
(
description
=
"创建时间"
,
accessMode
=
Schema
.
AccessMode
.
READ_ONLY
)
private
Long
createTime
;
private
List
<
OrganizationEntity
>
children
;
}
server-common/src/main/java/com/makeit/module/iot/vo/ResponseMessage.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
module
.
iot
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
public
class
ResponseMessage
<
T
>
{
@Schema
(
description
=
"消息提示"
)
private
String
message
;
@Schema
(
description
=
"数据内容"
)
private
T
result
;
@Schema
(
description
=
"状态码"
)
private
int
status
;
@Schema
(
description
=
"业务码"
)
private
String
code
;
@Schema
(
description
=
"时间戳(毫秒)"
)
private
Long
timestamp
=
System
.
currentTimeMillis
();
public
ResponseMessage
()
{
}
public
static
<
T
>
ResponseMessage
<
T
>
ok
()
{
return
(
ResponseMessage
<
T
>)
ok
((
Object
)
null
);
}
public
static
<
T
>
ResponseMessage
<
T
>
ok
(
T
result
)
{
return
of
(
"success"
,
result
,
200
,
(
String
)
null
,
System
.
currentTimeMillis
());
}
public
static
<
T
>
ResponseMessage
<
T
>
error
(
String
message
)
{
return
error
(
"error"
,
message
);
}
public
static
<
T
>
ResponseMessage
<
T
>
error
(
String
code
,
String
message
)
{
return
error
(
500
,
code
,
message
);
}
public
static
<
T
>
ResponseMessage
<
T
>
error
(
int
status
,
String
code
,
String
message
)
{
return
(
ResponseMessage
<
T
>)
of
(
message
,
(
Object
)
null
,
status
,
code
,
System
.
currentTimeMillis
());
}
public
static
<
T
>
ResponseMessage
<
T
>
of
(
String
message
,
T
result
,
int
status
,
String
code
,
Long
timestamp
)
{
ResponseMessage
<
T
>
msg
=
new
ResponseMessage
<>();
msg
.
setMessage
(
message
);
msg
.
setResult
(
result
);
msg
.
setStatus
(
status
);
msg
.
setCode
(
code
);
msg
.
setTimestamp
(
timestamp
);
return
msg
;
}
public
ResponseMessage
<
T
>
result
(
T
result
)
{
this
.
result
=
result
;
return
this
;
}
public
String
getMessage
()
{
return
this
.
message
;
}
public
T
getResult
()
{
return
this
.
result
;
}
public
int
getStatus
()
{
return
this
.
status
;
}
public
String
getCode
()
{
return
this
.
code
;
}
public
Long
getTimestamp
()
{
return
this
.
timestamp
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
void
setResult
(
T
result
)
{
this
.
result
=
result
;
}
public
void
setStatus
(
int
status
)
{
this
.
status
=
status
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
void
setTimestamp
(
Long
timestamp
)
{
this
.
timestamp
=
timestamp
;
}
@Override
public
String
toString
()
{
return
"ResponseMessage{"
+
"message='"
+
message
+
'\''
+
", result="
+
result
+
", status="
+
status
+
", code='"
+
code
+
'\''
+
", timestamp="
+
timestamp
+
'}'
;
}
}
server-common/src/main/java/com/makeit/task/IotSyncTask.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
task
;
import
com.makeit.module.iot.service.IotOrgService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
@Component
@Slf4j
public
class
IotSyncTask
{
@Autowired
private
IotOrgService
iotOrgService
;
@Scheduled
(
cron
=
"0 */1 * * * ?"
)
public
void
syncEquipmentInfo
()
{
log
.
info
(
"开始执行同步设备信息接口"
);
log
.
info
(
"结束执行同步设备信息接口"
);
}
@Scheduled
(
cron
=
"0 0/1 * * * ?"
)
public
void
syncDeviceLog
()
{
log
.
info
(
"开始同步设备日志"
);
log
.
info
(
"同步设备日志结束"
);
}
}
server-web/src/main/resources/application-dev.yml
View file @
b878669f
...
...
@@ -86,4 +86,9 @@ maven:
redis
:
prefix
:
libreOffice
:
C:\\Program Files\\LibreOffice\\program\\soffice
\ No newline at end of file
libreOffice
:
C:\\Program Files\\LibreOffice\\program\\soffice
iot
:
url
:
http://iot.meiqicloud.com/api/
clientId
:
fyxmb5h52iKwE2Hi
secureKey
:
22fZbnH36wdHn7ZTyKKHraFw233npcez
\ No newline at end of file
server-web/src/test/java/com/makeit/iotapi/IotTest.java
0 → 100644
View file @
b878669f
package
com
.
makeit
.
iotapi
;
import
com.makeit.module.admin.vo.plat.PlatTenantVO
;
import
com.makeit.module.iot.service.IotOrgService
;
import
com.makeit.module.iot.service.IotProductDeviceService
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
public
class
IotTest
{
@Autowired
private
IotOrgService
iotOrgService
;
@Autowired
private
IotProductDeviceService
iotProductDeviceService
;
@Test
void
syncTenantInfoToIot
()
{
PlatTenantVO
platTenantVO
=
new
PlatTenantVO
();
platTenantVO
.
setName
(
"lxl2"
);
iotOrgService
.
syncTenantInfoToIot
(
platTenantVO
);
}
@Test
void
getEquipmentInfo
()
{
iotProductDeviceService
.
getEquipmentInfo
();
}
@Test
void
getOrgProduct
()
{
iotOrgService
.
getOrgProduct
(
"1698939546961244160"
);
}
@Test
void
getOrgDevice
()
{
iotOrgService
.
getOrgDevice
(
"1698939546961244160"
);
}
@Test
void
getDeviceLog
()
{
iotProductDeviceService
.
getDeviceLog
(
"1694547143952007168"
);
}
}
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