Commit 2054574e authored by chenfm's avatar chenfm

告警查询

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