Commit 2054574e authored by chenfm's avatar chenfm

告警查询

修改获取模型数据接口
parent 0ced5eff
......@@ -35,4 +35,6 @@ public class AlarmListForm {
private String deviceName;
private Integer alarmLevel;
}
......@@ -3,6 +3,7 @@ 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.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.web.bind.annotation.PostMapping;
......@@ -11,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* @description:
......@@ -35,8 +35,8 @@ public class DashboardController {
}
@PostMapping("modelData")
public EResponse modelData(@RequestBody DashboardReq dashboardReq) {
List<Map<String, Object>> list = dashboardService.modelData(dashboardReq);
public EResponse<List<ModelDataVO>> modelData(@RequestBody List<DashboardReq> dashboardReqList) {
List<ModelDataVO> list = dashboardService.modelData(dashboardReqList);
return EResponse.ok(list);
}
......
......@@ -16,11 +16,6 @@ import java.util.List;
@Data
public class DashboardReq {
/**
* 模型ID
*/
private Long modelId;
/**
* description 实例id
* param
......@@ -28,7 +23,12 @@ public class DashboardReq {
* author chenfm
* createTime 2020/8/3 20:20
**/
private Long instanceId;
private Long deviceId;
/**
* 模型ID
*/
private Long modelId;
/**
* description 属性列表
......
package com.esv.datacenter.iot.module.dashboard.service;
import com.esv.datacenter.iot.module.dashboard.req.DashboardReq;
import com.esv.datacenter.iot.module.dashboard.vo.ModelDataVO;
import java.util.List;
import java.util.Map;
/**
* @description:
......@@ -16,6 +16,6 @@ import java.util.Map;
*/
public interface DashboardService {
List<Map<String, Object>> modelData(DashboardReq dashboardReq);
List<ModelDataVO> modelData(List<DashboardReq> dashboardReqList);
}
......@@ -3,15 +3,14 @@ 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.esv.datacenter.iot.module.dashboard.vo.ModelDataVO;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
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;
import java.util.*;
/**
* @description:
......@@ -35,16 +34,22 @@ public class DashboardServiceImpl implements DashboardService {
}
@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
+ " where instance_id = ?"
+ " order by time desc limit 100";
log.info("select modelData sql: {}", sql);
return jdbcTemplate.queryForList(sql, dashboardReq.getInstanceId());
public List<ModelDataVO> modelData(List<DashboardReq> dashboardReqList) {
List<ModelDataVO> modelDataVOList = new ArrayList<>();
for (DashboardReq dashboardReq : dashboardReqList) {
Long modelId = dashboardReq.getModelId();
String tableName = "iot_model_" + modelId;
String sql = "select time"
+ getSqlParams(dashboardReq.getPropertyCodeList(), false)
+ " from "
+ tableName
+ " where device_id = ?"
+ " order by time desc limit 100";
log.info("select modelData sql: {}", sql);
List<Map<String, Object>> dataList = jdbcTemplate.queryForList(sql, dashboardReq.getDeviceId());
modelDataVOList.add(new ModelDataVO(modelId, dataList));
}
return modelDataVOList;
}
private String getSqlParams(Collection collection, boolean isString) {
......
package com.esv.datacenter.iot.module.dashboard.vo;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.dashboard.vo.ModelDataVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/10 15:29
* @version: 1.0
*/
@Data
public class ModelDataVO {
/**
* 模型ID
*/
private Long modelId;
/**
* description 数据列表
* author chenfm
* createTime 2020/8/10 15:30
**/
List<Map<String, Object>> dataList;
public ModelDataVO() {
}
public ModelDataVO(Long modelId, List<Map<String, Object>> dataList) {
this.modelId = modelId;
this.dataList = dataList;
}
}
......@@ -24,6 +24,14 @@
left join data_model_alarm_rule rule on alarm.alarm_rule_id = rule.id
left join data_model model on rule.model_id = model.id
left join data_model_property property on rule.property_id = property.id
<where>
<if test="alarmListForm.deviceName != null">
device.name like '%${alarmListForm.deviceName}%'
</if>
<if test="alarmListForm.alarmLevel != null">
and rule.alarm_level = #{alarmListForm.alarmLevel}
</if>
</where>
order by alarm.alarm_time desc
</select>
......
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