Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
iot-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
iot-service
Commits
c5806d06
Commit
c5806d06
authored
Aug 14, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into huangchb
parents
1a639a0f
fdc55079
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
502 additions
and
23 deletions
+502
-23
CommonConstants.java
.../esv/datacenter/iot/common/constants/CommonConstants.java
+7
-0
ECode.java
...in/java/com/esv/datacenter/iot/common/response/ECode.java
+4
-1
SqlUtils.java
...ain/java/com/esv/datacenter/iot/common/util/SqlUtils.java
+25
-0
DashboardServiceImpl.java
...t/module/dashboard/service/impl/DashboardServiceImpl.java
+8
-15
DataModelPropertyVO.java
...tacenter/iot/module/datamodel/vo/DataModelPropertyVO.java
+1
-1
DeviceDataController.java
...t/module/devicemodel/controller/DeviceDataController.java
+48
-0
DeviceInstanceController.java
...dule/devicemodel/controller/DeviceInstanceController.java
+18
-0
DeviceTypeDao.java
.../datacenter/iot/module/devicemodel/dao/DeviceTypeDao.java
+13
-2
DeviceTypeDto.java
.../datacenter/iot/module/devicemodel/dto/DeviceTypeDto.java
+51
-0
DeviceDataForm.java
...atacenter/iot/module/devicemodel/form/DeviceDataForm.java
+31
-0
DeviceDataService.java
...ter/iot/module/devicemodel/service/DeviceDataService.java
+18
-0
DeviceInstanceService.java
...iot/module/devicemodel/service/DeviceInstanceService.java
+9
-0
DeviceTypeService.java
...ter/iot/module/devicemodel/service/DeviceTypeService.java
+10
-2
DeviceDataServiceImpl.java
...odule/devicemodel/service/impl/DeviceDataServiceImpl.java
+105
-0
DeviceInstanceServiceImpl.java
...e/devicemodel/service/impl/DeviceInstanceServiceImpl.java
+13
-0
DeviceTypeServiceImpl.java
...odule/devicemodel/service/impl/DeviceTypeServiceImpl.java
+12
-2
DeviceDataPropertyVO.java
...enter/iot/module/devicemodel/vo/DeviceDataPropertyVO.java
+52
-0
DeviceDataVO.java
...sv/datacenter/iot/module/devicemodel/vo/DeviceDataVO.java
+38
-0
DeviceDetailVO.java
.../datacenter/iot/module/devicemodel/vo/DeviceDetailVO.java
+31
-0
DeviceTypeDao.xml
src/main/resources/mapper/devicemodel/DeviceTypeDao.xml
+8
-0
No files found.
src/main/java/com/esv/datacenter/iot/common/constants/CommonConstants.java
View file @
c5806d06
...
...
@@ -60,4 +60,11 @@ public class CommonConstants {
public
static
final
String
HTTP_HEADER_X_FORWARDED_FOR
=
"x-forwarded-for"
;
public
static
final
String
HTTP_HEADER_PROXY_CLIENT_IP
=
"Proxy-Client-IP"
;
public
static
final
String
HTTP_HEADER_WL_PROXY_CLIENT_IP
=
"WL-Proxy-Client-IP"
;
/**
* 模型数据表前缀
**/
public
static
final
String
MODEL_DATA_TABLE_PREFIX
=
"iot_data_model_"
;
}
src/main/java/com/esv/datacenter/iot/common/response/ECode.java
View file @
c5806d06
...
...
@@ -18,10 +18,13 @@ public class ECode {
public
static
final
ECode
PARAM_ERROR
=
new
ECode
(
600
,
"参数不合法"
);
public
static
final
ECode
TOKEN_INVALID
=
new
ECode
(
601
,
"无效的Token"
);
public
static
final
ECode
TOKEN_EXPIRED
=
new
ECode
(
602
,
"Token已过期"
);
public
static
final
ECode
NO_DATA
=
new
ECode
(
603
,
"没有数据"
);
public
static
final
ECode
BIZ_PARAM_ERROR
=
new
ECode
(
1000
,
"业务参数错误"
);
public
static
final
ECode
BATCHID_FORMATTOR_ERROR
=
new
ECode
(
11001
,
"时间格式错误"
);
public
static
final
ECode
BATCHID_LENTGH_ERROR
=
new
ECode
(
11001
,
"长度错误"
);
public
static
final
ECode
BATCHID_LENTGH_ERROR
=
new
ECode
(
11002
,
"长度错误"
);
public
static
final
ECode
DEVICE_NOT_FOUND
=
new
ECode
(
20001
,
"设备不存在"
);
public
ECode
(
int
code
,
String
message
)
{
this
.
code
=
code
;
...
...
src/main/java/com/esv/datacenter/iot/common/util/SqlUtils.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
common
.
util
;
import
java.util.List
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.common.util.SqlUtils
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:26
* @version: 1.0
*/
public
class
SqlUtils
{
public
static
String
makeSqlParams
(
List
<
String
>
collection
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
Object
key
:
collection
)
{
builder
.
append
(
","
);
builder
.
append
(
key
.
toString
());
}
return
builder
.
toString
();
}
}
src/main/java/com/esv/datacenter/iot/module/dashboard/service/impl/DashboardServiceImpl.java
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
dashboard
.
service
.
impl
;
import
com.esv.datacenter.iot.common.component.TimescaleComponent
;
import
com.esv.datacenter.iot.common.constants.CommonConstants
;
import
com.esv.datacenter.iot.common.util.SqlUtils
;
import
com.esv.datacenter.iot.module.dashboard.req.DashboardReq
;
import
com.esv.datacenter.iot.module.dashboard.req.HistoryDashboardReq
;
import
com.esv.datacenter.iot.module.dashboard.service.DashboardService
;
...
...
@@ -42,9 +44,9 @@ public class DashboardServiceImpl implements DashboardService {
List
<
ModelDataVO
>
modelDataVOList
=
new
ArrayList
<>();
for
(
DashboardReq
dashboardReq
:
dashboardReqList
)
{
Long
modelId
=
dashboardReq
.
getModelId
();
String
tableName
=
"iot_data_model_"
+
modelId
;
String
tableName
=
CommonConstants
.
MODEL_DATA_TABLE_PREFIX
+
modelId
;
String
sql
=
"select time"
+
get
SqlParams
(
dashboardReq
.
getPropertyCodeList
())
+
SqlUtils
.
make
SqlParams
(
dashboardReq
.
getPropertyCodeList
())
+
" from "
+
tableName
+
" where device_id = ?"
...
...
@@ -64,31 +66,22 @@ public class DashboardServiceImpl implements DashboardService {
List
<
ModelDataVO
>
modelDataVOList
=
new
ArrayList
<>();
for
(
DashboardReq
dashboardReq
:
dashboardReqList
)
{
Long
modelId
=
dashboardReq
.
getModelId
();
String
tableName
=
"iot_data_model_"
+
modelId
;
String
tableName
=
CommonConstants
.
MODEL_DATA_TABLE_PREFIX
+
modelId
;
String
sql
=
"select time"
+
get
SqlParams
(
dashboardReq
.
getPropertyCodeList
())
+
SqlUtils
.
make
SqlParams
(
dashboardReq
.
getPropertyCodeList
())
+
" from "
+
tableName
+
" where device_id = ?"
+
" and (time > ?)"
+
" and (time > ?
and time < ?
)"
+
" order by time"
;
log
.
info
(
"select modelData sql: {}"
,
sql
);
List
<
Map
<
String
,
Object
>>
dataList
=
jdbcTemplate
.
queryForList
(
sql
,
dashboardReq
.
getDeviceId
(),
beginTime
);
beginTime
,
endTime
);
ModelDataVO
modelDataVO
=
new
ModelDataVO
(
modelId
,
dataList
);
modelDataVOList
.
add
(
modelDataVO
);
}
return
modelDataVOList
;
}
private
String
getSqlParams
(
List
<
String
>
collection
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
Object
key
:
collection
)
{
builder
.
append
(
","
);
builder
.
append
(
key
.
toString
());
}
return
builder
.
toString
();
}
}
src/main/java/com/esv/datacenter/iot/module/datamodel/vo/DataModelPropertyVO.java
View file @
c5806d06
...
...
@@ -12,7 +12,7 @@ import lombok.Data;
public
class
DataModelPropertyVO
{
/**
*
*
主键
*/
private
Long
id
;
/**
...
...
src/main/java/com/esv/datacenter/iot/module/devicemodel/controller/DeviceDataController.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
controller
;
import
com.esv.datacenter.iot.common.response.ECode
;
import
com.esv.datacenter.iot.common.response.EResponse
;
import
com.esv.datacenter.iot.module.devicemodel.form.DeviceDataForm
;
import
com.esv.datacenter.iot.module.devicemodel.service.DeviceDataService
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.controller.DeviceDataController
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 16:47
* @version: 1.0
*/
@Slf4j
@RestController
@RequestMapping
(
"/deviceModel/data"
)
@Validated
public
class
DeviceDataController
{
private
DeviceDataService
deviceDataService
;
@Autowired
public
DeviceDataController
(
DeviceDataService
deviceDataService
)
{
this
.
deviceDataService
=
deviceDataService
;
}
@PostMapping
(
"getDataByModel"
)
public
EResponse
<
DeviceDataVO
>
currentData
(
@RequestBody
@Validated
DeviceDataForm
deviceDataForm
)
{
DeviceDataVO
deviceDataVO
=
deviceDataService
.
currentData
(
deviceDataForm
.
getDeviceId
(),
deviceDataForm
.
getDataModelId
());
if
(
deviceDataVO
==
null
)
{
return
EResponse
.
error
(
ECode
.
NO_DATA
);
}
return
EResponse
.
ok
(
deviceDataVO
);
}
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/controller/DeviceInstanceController.java
View file @
c5806d06
...
...
@@ -9,6 +9,9 @@ import com.esv.datacenter.iot.common.vo.PageResultVO;
import
com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm
;
import
com.esv.datacenter.iot.module.devicemodel.service.DeviceInstanceService
;
import
com.esv.datacenter.iot.module.devicemodel.service.DeviceTypeService
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceDetailVO
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -105,6 +108,21 @@ public class DeviceInstanceController {
return
EResponse
.
ok
(
pageResultVO
);
}
@PostMapping
(
"detail"
)
public
EResponse
<
DeviceDetailVO
>
detail
(
@RequestBody
@Validated
(
ValidatorDetail
.
class
)
DeviceInstanceForm
form
)
{
DeviceInstanceVO
deviceInstance
=
deviceInstanceService
.
deviceInstanceDetail
(
form
.
getId
());
if
(
deviceInstance
==
null
)
{
return
EResponse
.
error
(
ECode
.
DEVICE_NOT_FOUND
);
}
Long
deviceTypeId
=
deviceInstance
.
getDeviceTypeId
();
DeviceTypeVO
deviceTypeVO
=
deviceTypeService
.
deviceTypeDetail
(
deviceTypeId
);
DeviceDetailVO
deviceDetailVO
=
new
DeviceDetailVO
();
deviceDetailVO
.
setDeviceInstance
(
deviceInstance
);
deviceDetailVO
.
setDeviceType
(
deviceTypeVO
);
return
EResponse
.
ok
(
deviceDetailVO
);
}
/**
* @description 通过设备类型ID获取设备列表
* @param form:
...
...
src/main/java/com/esv/datacenter/iot/module/devicemodel/dao/DeviceTypeDao.java
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.esv.datacenter.iot.module.d
atamodel.form.DataModelForm
;
import
com.esv.datacenter.iot.module.d
evicemodel.dto.DeviceTypeDto
;
import
com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm
;
import
org.apache.ibatis.annotations.Mapper
;
...
...
@@ -26,4 +26,15 @@ public interface DeviceTypeDao extends BaseMapper<DeviceTypeEntity> {
* @createTime 2020/08/07 9:34
**/
IPage
select4Page
(
IPage
page
,
DeviceTypeForm
queryObj
);
/**
* description 查询设备类型详情
* param [id]
* return com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto
* author chenfm
* createTime 2020/8/13 16:16
**/
DeviceTypeDto
deviceTypeDetail
(
Long
id
);
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/dto/DeviceTypeDto.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
dto
;
import
lombok.Data
;
import
java.util.Date
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDTO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 16:13
* @version: 1.0
*/
@Data
public
class
DeviceTypeDto
{
/**
* 主键
*/
private
Long
id
;
/**
* 名称
*/
private
String
name
;
/**
* 描述
*/
private
String
description
;
/**
* 设备实例数量
*/
private
Long
instanceCount
;
/**
* 创建者
*/
private
String
createUser
;
/**
* 修改者
*/
private
String
updateUser
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 修改时间
*/
private
Date
updateTime
;
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/form/DeviceDataForm.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
form
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.form.DeviceDataForm
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:34
* @version: 1.0
*/
@Data
public
class
DeviceDataForm
{
/**
* 数据模型ID
*/
@NotNull
private
Long
dataModelId
;
/**
* 设备实例id
**/
@NotNull
private
Long
deviceId
;
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/service/DeviceDataService.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
service
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.service.DeviceDataService
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 16:49
* @version: 1.0
*/
public
interface
DeviceDataService
{
DeviceDataVO
currentData
(
Long
deviceId
,
Long
dataModelId
);
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/service/DeviceInstanceService.java
View file @
c5806d06
...
...
@@ -128,6 +128,15 @@ public interface DeviceInstanceService extends IService<DeviceInstanceEntity> {
**/
void
changeDeviceOnlineState
(
List
<
String
>
communicationIdList
);
/**
* description 设备实例详情
* param [deviceInstanceId]
* return com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO
* author chenfm
* createTime 2020/8/13 16:24
**/
DeviceInstanceVO
deviceInstanceDetail
(
Long
deviceInstanceId
);
/**
* @description 保存client Mqtt Topic发布/订阅权限
* @param deviceTypeId:
...
...
src/main/java/com/esv/datacenter/iot/module/devicemodel/service/DeviceTypeService.java
View file @
c5806d06
...
...
@@ -2,13 +2,12 @@ package com.esv.datacenter.iot.module.devicemodel.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.esv.datacenter.iot.common.vo.PageResultVO
;
import
com.esv.datacenter.iot.module.datamodel.vo.DataModelBriefVO
;
import
com.esv.datacenter.iot.module.datamodel.vo.DataModelDetailVO
;
import
com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity
;
import
com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeBriefVO
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeStatisticsVO
;
import
lombok.Data
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO
;
import
java.util.List
;
...
...
@@ -100,5 +99,14 @@ public interface DeviceTypeService extends IService<DeviceTypeEntity> {
**/
List
<
DeviceTypeStatisticsVO
>
getDeviceTypeStatistics
();
/**
* description 设备类型详细
* param [deviceTypeId]
* return com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO
* author chenfm
* createTime 2020/8/13 16:11
**/
DeviceTypeVO
deviceTypeDetail
(
Long
deviceTypeId
);
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/service/impl/DeviceDataServiceImpl.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
service
.
impl
;
import
com.esv.datacenter.iot.common.component.TimescaleComponent
;
import
com.esv.datacenter.iot.common.constants.CommonConstants
;
import
com.esv.datacenter.iot.module.datamodel.entity.DataModelEntity
;
import
com.esv.datacenter.iot.module.datamodel.service.DataModelPropertyService
;
import
com.esv.datacenter.iot.module.datamodel.service.DataModelService
;
import
com.esv.datacenter.iot.module.datamodel.vo.DataModelPropertyVO
;
import
com.esv.datacenter.iot.module.devicemodel.service.DeviceDataService
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataPropertyVO
;
import
com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO
;
import
com.zaxxer.hikari.HikariDataSource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.service.impl.DeviceDataServiceImpl
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:12
* @version: 1.0
*/
@Slf4j
@Service
(
"deviceDataService"
)
public
class
DeviceDataServiceImpl
implements
DeviceDataService
{
private
DataModelService
dataModelService
;
private
DataModelPropertyService
dataModelPropertyService
;
private
JdbcTemplate
jdbcTemplate
;
@Autowired
public
DeviceDataServiceImpl
(
DataModelService
dataModelService
,
DataModelPropertyService
dataModelPropertyService
,
TimescaleComponent
timescaleComponent
)
{
this
.
dataModelService
=
dataModelService
;
this
.
dataModelPropertyService
=
dataModelPropertyService
;
HikariDataSource
dataSource
=
timescaleComponent
.
getHikariDataSource
();
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
}
@Override
public
DeviceDataVO
currentData
(
Long
deviceId
,
Long
dataModelId
)
{
DataModelEntity
dataModelEntity
=
dataModelService
.
getModelInfo
(
dataModelId
);
if
(
dataModelEntity
==
null
)
{
return
null
;
}
DeviceDataVO
deviceDataVO
=
new
DeviceDataVO
();
BeanUtils
.
copyProperties
(
dataModelEntity
,
deviceDataVO
);
Map
<
String
,
Object
>
dataMap
=
selectCurrentData
(
deviceId
,
dataModelId
);
if
(
dataMap
!=
null
&&
dataMap
.
containsKey
(
"time"
))
{
deviceDataVO
.
setReportTime
((
Date
)
dataMap
.
get
(
"time"
));
}
List
<
DataModelPropertyVO
>
propertyList
=
dataModelPropertyService
.
getModelPropertyList
(
dataModelId
);
if
(
propertyList
!=
null
&&
!
propertyList
.
isEmpty
())
{
List
<
DeviceDataPropertyVO
>
list
=
new
ArrayList
<>(
propertyList
.
size
());
// List<String> columnNames = new ArrayList<>();
// propertyList.forEach(v -> columnNames.add(v.getPropertyCode()));
for
(
DataModelPropertyVO
dataModelPropertyVO
:
propertyList
)
{
DeviceDataPropertyVO
deviceDataPropertyVO
=
new
DeviceDataPropertyVO
();
BeanUtils
.
copyProperties
(
dataModelPropertyVO
,
deviceDataPropertyVO
);
String
propertyCode
=
deviceDataPropertyVO
.
getPropertyCode
();
// 获取最新数据
if
(
dataMap
!=
null
&&
dataMap
.
containsKey
(
propertyCode
))
{
String
propertyValue
=
String
.
valueOf
(
dataMap
.
get
(
propertyCode
));
deviceDataPropertyVO
.
setPropertyValue
(
propertyValue
);
}
// 加入到返回结果集
list
.
add
(
deviceDataPropertyVO
);
}
deviceDataVO
.
setPropertyList
(
list
);
}
return
deviceDataVO
;
}
private
Map
<
String
,
Object
>
selectCurrentData
(
Long
deviceId
,
Long
dataModelId
)
{
String
tableName
=
CommonConstants
.
MODEL_DATA_TABLE_PREFIX
+
dataModelId
;
String
sql
=
"select * from "
+
tableName
+
" where device_id = ?"
+
" order by time desc limit 1"
;
try
{
return
jdbcTemplate
.
queryForMap
(
sql
,
deviceId
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/service/impl/DeviceInstanceServiceImpl.java
View file @
c5806d06
...
...
@@ -191,6 +191,19 @@ public class DeviceInstanceServiceImpl extends ServiceImpl<DeviceInstanceDao, De
baseMapper
.
update
(
entity
,
updateWrapper
);
}
@Override
public
DeviceInstanceVO
deviceInstanceDetail
(
Long
deviceInstanceId
)
{
DeviceInstanceEntity
deviceInstanceEntity
=
baseMapper
.
selectById
(
deviceInstanceId
);
if
(
deviceInstanceEntity
==
null
)
{
return
null
;
}
DeviceInstanceVO
deviceInstanceVO
=
new
DeviceInstanceVO
();
BeanUtils
.
copyProperties
(
deviceInstanceEntity
,
deviceInstanceVO
);
deviceInstanceVO
.
setCreateTime
(
deviceInstanceEntity
.
getCreateTime
().
getTime
());
deviceInstanceVO
.
setUpdateTime
(
deviceInstanceEntity
.
getUpdateTime
().
getTime
());
return
deviceInstanceVO
;
}
@Override
public
void
saveInstanceMqttTopicAuth
(
Long
deviceTypeId
,
Long
deviceInstanceId
,
String
clientId
)
{
// 获取设备对应的数据模型
...
...
src/main/java/com/esv/datacenter/iot/module/devicemodel/service/impl/DeviceTypeServiceImpl.java
View file @
c5806d06
...
...
@@ -9,11 +9,10 @@ import com.esv.datacenter.iot.common.response.ECode;
import
com.esv.datacenter.iot.common.vo.PageResultVO
;
import
com.esv.datacenter.iot.module.datamodel.entity.DataModelEntity
;
import
com.esv.datacenter.iot.module.datamodel.service.DataModelPropertyService
;
import
com.esv.datacenter.iot.module.datamodel.vo.DataModelBriefVO
;
import
com.esv.datacenter.iot.module.datamodel.vo.DataModelDetailVO
;
import
com.esv.datacenter.iot.module.datamodel.vo.DataModelPropertyVO
;
import
com.esv.datacenter.iot.module.devicemodel.dao.DeviceTypeDao
;
import
com.esv.datacenter.iot.module.devicemodel.dto.DeviceInstanceDto
;
import
com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto
;
import
com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity
;
import
com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm
;
import
com.esv.datacenter.iot.module.devicemodel.service.DeviceDataMapService
;
...
...
@@ -201,4 +200,15 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType
return
voList
;
}
@Override
public
DeviceTypeVO
deviceTypeDetail
(
Long
deviceTypeId
)
{
DeviceTypeDto
deviceTypeDto
=
baseMapper
.
deviceTypeDetail
(
deviceTypeId
);
DeviceTypeVO
deviceTypeVO
=
new
DeviceTypeVO
();
BeanUtils
.
copyProperties
(
deviceTypeDto
,
deviceTypeVO
);
deviceTypeVO
.
setCreateTime
(
deviceTypeDto
.
getCreateTime
().
getTime
());
deviceTypeVO
.
setUpdateTime
(
deviceTypeDto
.
getUpdateTime
().
getTime
());
return
deviceTypeVO
;
}
}
\ No newline at end of file
src/main/java/com/esv/datacenter/iot/module/devicemodel/vo/DeviceDataPropertyVO.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
vo
;
import
lombok.Data
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataPropertyVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:07
* @version: 1.0
*/
@Data
public
class
DeviceDataPropertyVO
{
/**
* 主键
*/
private
Long
id
;
/**
* 模型ID
*/
private
Long
modelId
;
/**
* 属性代码
*/
private
String
propertyCode
;
/**
* 属性名称
*/
private
String
propertyName
;
/**
* 属性类型(字典表)
*/
private
Integer
propertyType
;
/**
* 属性默认值
*/
private
String
propertyDefaultValue
;
/**
* 属性单位
*/
private
String
propertyUnit
;
/**
* 排列序号
*/
private
Long
sortNum
;
private
String
propertyValue
;
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/vo/DeviceDataVO.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
vo
;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.List
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:09
* @version: 1.0
*/
@Data
public
class
DeviceDataVO
{
/**
* 主键
*/
private
Long
id
;
/**
* 模型名称
*/
private
String
name
;
/**
* 模型描述
*/
private
String
description
;
private
Date
reportTime
;
private
List
<
DeviceDataPropertyVO
>
propertyList
;
}
src/main/java/com/esv/datacenter/iot/module/devicemodel/vo/DeviceDetailVO.java
0 → 100644
View file @
c5806d06
package
com
.
esv
.
datacenter
.
iot
.
module
.
devicemodel
.
vo
;
import
lombok.Data
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.vo.DeviceDetailVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 15:42
* @version: 1.0
*/
@Data
public
class
DeviceDetailVO
{
/**
* description 设备实例信息
* author chenfm
* createTime 2020/8/13 15:43
**/
private
DeviceInstanceVO
deviceInstance
;
/**
* description 设备类型信息
* author chenfm
* createTime 2020/8/13 15:43
**/
private
DeviceTypeVO
deviceType
;
}
src/main/resources/mapper/devicemodel/DeviceTypeDao.xml
View file @
c5806d06
...
...
@@ -29,4 +29,12 @@
ORDER BY name ASC
</select>
<select
id=
"deviceTypeDetail"
resultType=
"com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto"
>
select type.*, count(instance.id) instance_count
from device_type type
left join device_instance instance on instance.device_type_id = type.id and instance.deleted = 0
where type.id = #{id}
group by type.id
</select>
</mapper>
\ No newline at end of file
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