Commit 56727ab3 authored by chenfm's avatar chenfm

模型数据查询最新100条记录

parent c54b9127
package com.esv.datacenter.iot.module.dashboard.controller; 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.DashboardReq;
import com.esv.datacenter.iot.module.dashboard.service.DashboardService; import com.esv.datacenter.iot.module.dashboard.service.DashboardService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -34,8 +35,9 @@ public class DashboardController { ...@@ -34,8 +35,9 @@ public class DashboardController {
} }
@PostMapping("modelData") @PostMapping("modelData")
public List<Map<String, Object>> modelData(@RequestBody DashboardReq dashboardReq) { public EResponse modelData(@RequestBody DashboardReq dashboardReq) {
return dashboardService.modelData(dashboardReq); List<Map<String, Object>> list = dashboardService.modelData(dashboardReq);
return EResponse.ok(list);
} }
} }
...@@ -4,6 +4,7 @@ import com.esv.datacenter.iot.common.component.TimescaleComponent; ...@@ -4,6 +4,7 @@ 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.DashboardReq;
import com.esv.datacenter.iot.module.dashboard.service.DashboardService; import com.esv.datacenter.iot.module.dashboard.service.DashboardService;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -21,11 +22,14 @@ import java.util.Map; ...@@ -21,11 +22,14 @@ import java.util.Map;
* @createTime: 2020/8/3 20:24 * @createTime: 2020/8/3 20:24
* @version: 1.0 * @version: 1.0
*/ */
@Slf4j
@Service("dashboardService") @Service("dashboardService")
public class DashboardServiceImpl implements DashboardService { public class DashboardServiceImpl implements DashboardService {
private TimescaleComponent timescaleComponent; private TimescaleComponent timescaleComponent;
private JdbcTemplate jdbcTemplate = null;
@Autowired @Autowired
public DashboardServiceImpl(TimescaleComponent timescaleComponent) { public DashboardServiceImpl(TimescaleComponent timescaleComponent) {
this.timescaleComponent = timescaleComponent; this.timescaleComponent = timescaleComponent;
...@@ -37,10 +41,15 @@ public class DashboardServiceImpl implements DashboardService { ...@@ -37,10 +41,15 @@ public class DashboardServiceImpl implements DashboardService {
String sql = "select time" String sql = "select time"
+ getSqlParams(dashboardReq.getPropertyCodeList(), false) + getSqlParams(dashboardReq.getPropertyCodeList(), false)
+ " from " + " from "
+ tableName; + tableName
HikariDataSource dataSource = timescaleComponent.getHikariDataSource(); + " where instance_id = ?"
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + " order by time desc limit 100";
return jdbcTemplate.queryForList(sql); log.info("select modelData sql: {}", sql);
if (jdbcTemplate == null) {
HikariDataSource dataSource = timescaleComponent.getHikariDataSource();
jdbcTemplate = new JdbcTemplate(dataSource);
}
return jdbcTemplate.queryForList(sql, dashboardReq.getInstanceId());
} }
private String getSqlParams(Collection collection, boolean isString) { private String getSqlParams(Collection collection, boolean isString) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment