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
857dff0a
Commit
857dff0a
authored
Aug 11, 2020
by
chenfm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加模型历史数据查询
parent
2f3b3f4c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
9 deletions
+72
-9
DashboardController.java
.../iot/module/dashboard/controller/DashboardController.java
+8
-0
HistoryDashboardReq.java
...acenter/iot/module/dashboard/req/HistoryDashboardReq.java
+28
-0
DashboardService.java
...center/iot/module/dashboard/service/DashboardService.java
+3
-0
DashboardServiceImpl.java
...t/module/dashboard/service/impl/DashboardServiceImpl.java
+33
-9
No files found.
src/main/java/com/esv/datacenter/iot/module/dashboard/controller/DashboardController.java
View file @
857dff0a
...
...
@@ -2,10 +2,12 @@ package com.esv.datacenter.iot.module.dashboard.controller;
import
com.esv.datacenter.iot.common.response.EResponse
;
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
;
import
com.esv.datacenter.iot.module.dashboard.vo.ModelDataVO
;
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
;
...
...
@@ -40,4 +42,10 @@ public class DashboardController {
return
EResponse
.
ok
(
list
);
}
@PostMapping
(
"modelHistory"
)
public
EResponse
<
List
<
ModelDataVO
>>
modelHistory
(
@RequestBody
@Validated
HistoryDashboardReq
historyDashboardReq
)
{
List
<
ModelDataVO
>
list
=
dashboardService
.
modelHistory
(
historyDashboardReq
);
return
EResponse
.
ok
(
list
);
}
}
src/main/java/com/esv/datacenter/iot/module/dashboard/req/HistoryDashboardReq.java
0 → 100644
View file @
857dff0a
package
com
.
esv
.
datacenter
.
iot
.
module
.
dashboard
.
req
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
java.util.List
;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.dashboard.req.HistoryDashboardReq
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/11 10:08
* @version: 1.0
*/
@Data
public
class
HistoryDashboardReq
{
@NotNull
private
Long
beginTime
;
@NotNull
private
Long
endTime
;
List
<
DashboardReq
>
dashboardReqList
;
}
src/main/java/com/esv/datacenter/iot/module/dashboard/service/DashboardService.java
View file @
857dff0a
package
com
.
esv
.
datacenter
.
iot
.
module
.
dashboard
.
service
;
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.vo.ModelDataVO
;
import
java.util.List
;
...
...
@@ -18,4 +19,6 @@ public interface DashboardService {
List
<
ModelDataVO
>
modelData
(
List
<
DashboardReq
>
dashboardReqList
);
List
<
ModelDataVO
>
modelHistory
(
HistoryDashboardReq
historyDashboardReq
);
}
src/main/java/com/esv/datacenter/iot/module/dashboard/service/impl/DashboardServiceImpl.java
View file @
857dff0a
...
...
@@ -2,6 +2,7 @@ package com.esv.datacenter.iot.module.dashboard.service.impl;
import
com.esv.datacenter.iot.common.component.TimescaleComponent
;
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
;
import
com.esv.datacenter.iot.module.dashboard.vo.ModelDataVO
;
import
com.zaxxer.hikari.HikariDataSource
;
...
...
@@ -10,7 +11,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* @description:
...
...
@@ -40,7 +44,7 @@ public class DashboardServiceImpl implements DashboardService {
Long
modelId
=
dashboardReq
.
getModelId
();
String
tableName
=
"iot_data_model_"
+
modelId
;
String
sql
=
"select time"
+
getSqlParams
(
dashboardReq
.
getPropertyCodeList
()
,
false
)
+
getSqlParams
(
dashboardReq
.
getPropertyCodeList
())
+
" from "
+
tableName
+
" where device_id = ?"
...
...
@@ -52,17 +56,37 @@ public class DashboardServiceImpl implements DashboardService {
return
modelDataVOList
;
}
private
String
getSqlParams
(
Collection
collection
,
boolean
isString
)
{
@Override
public
List
<
ModelDataVO
>
modelHistory
(
HistoryDashboardReq
historyDashboardReq
)
{
Timestamp
beginTime
=
new
Timestamp
(
historyDashboardReq
.
getBeginTime
());
Timestamp
endTime
=
new
Timestamp
(
historyDashboardReq
.
getEndTime
());
List
<
DashboardReq
>
dashboardReqList
=
historyDashboardReq
.
getDashboardReqList
();
List
<
ModelDataVO
>
modelDataVOList
=
new
ArrayList
<>();
for
(
DashboardReq
dashboardReq
:
dashboardReqList
)
{
Long
modelId
=
dashboardReq
.
getModelId
();
String
tableName
=
"iot_data_model_"
+
modelId
;
String
sql
=
"select time"
+
getSqlParams
(
dashboardReq
.
getPropertyCodeList
())
+
" from "
+
tableName
+
" where device_id = ?"
+
" and (time > ?)"
+
" order by time"
;
log
.
info
(
"select modelData sql: {}"
,
sql
);
List
<
Map
<
String
,
Object
>>
dataList
=
jdbcTemplate
.
queryForList
(
sql
,
dashboardReq
.
getDeviceId
(),
beginTime
);
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
(
","
);
if
(
isString
)
{
builder
.
append
(
"'"
);
}
builder
.
append
(
key
.
toString
());
if
(
isString
)
{
builder
.
append
(
"'"
);
}
}
return
builder
.
toString
();
}
...
...
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