Commit b35e36bd authored by huangcb's avatar huangcb

Merge branch 'master' into huangchb

parents 20beff75 86266298
......@@ -243,7 +243,7 @@ public class TimescaleComponent {
return sb.toString();
}
private HikariDataSource getHikariDataSource() {
public HikariDataSource getHikariDataSource() {
HikariDataSource dataSource = this.dynamicDataSource.getDynamicDataSource(initDataSourceConfig());
return dataSource;
}
......
package com.esv.datacenter.iot.module.dashboard.controller;
import com.esv.datacenter.iot.module.dashboard.req.DashboardReq;
import com.esv.datacenter.iot.module.dashboard.service.DashboardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.List;
import java.util.Map;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.dashboard.controller.DashboardController
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/7/31 17:53
* @version: 1.0
*/
@Slf4j
@RestController
@RequestMapping("dashboard")
public class DashboardController {
private DashboardService dashboardService;
@Autowired
public DashboardController(DashboardService dashboardService) {
this.dashboardService = dashboardService;
}
@PostMapping("modelData")
public List<Map<String, Object>> modelData(@RequestBody DashboardReq dashboardReq) {
return dashboardService.modelData(dashboardReq);
}
}
package com.esv.datacenter.iot.module.dashboard.req;
import lombok.Data;
import java.util.List;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.dashboard.req.DashboardReq
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/3 20:16
* @version: 1.0
*/
@Data
public class DashboardReq {
/**
* 模型ID
*/
private Long modelId;
/**
* description 实例id
* param
* return
* author chenfm
* createTime 2020/8/3 20:20
**/
private Long instanceId;
/**
* description 属性列表
* param
* return
* author chenfm
* createTime 2020/8/3 20:20
**/
private List<String> propertyCodeList;
}
package com.esv.datacenter.iot.module.dashboard.service;
import com.esv.datacenter.iot.module.dashboard.req.DashboardReq;
import java.util.List;
import java.util.Map;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.dashboard.service.DashboardService
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/3 20:23
* @version: 1.0
*/
public interface DashboardService {
List<Map<String, Object>> modelData(DashboardReq dashboardReq);
}
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.service.DashboardService;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.dashboard.service.impl.DashboardServiceImpl
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/3 20:24
* @version: 1.0
*/
@Service("dashboardService")
public class DashboardServiceImpl implements DashboardService {
private TimescaleComponent timescaleComponent;
@Autowired
public DashboardServiceImpl(TimescaleComponent timescaleComponent) {
this.timescaleComponent = timescaleComponent;
}
@Override
public List<Map<String, Object>> modelData(DashboardReq dashboardReq) {
String tableName = "iot_model_" + dashboardReq.getModelId();
String sql = "select time"
+ getSqlParams(dashboardReq.getPropertyCodeList(), false)
+ " from "
+ tableName;
HikariDataSource dataSource = timescaleComponent.getHikariDataSource();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
return jdbcTemplate.queryForList(sql);
}
private String getSqlParams(Collection collection, boolean isString) {
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();
}
}
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