告警信息查询 确认接口新增
This commit is contained in:
parent
851c332df8
commit
efd0f66ad9
@ -6,10 +6,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeviceEventInfo {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long eventTime;
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long eventId;
|
||||
|
||||
private Integer eventType;
|
||||
|
@ -2,6 +2,7 @@ package com.das.modules.data.service;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.modules.data.domain.DeviceEventInfo;
|
||||
import com.das.modules.data.service.impl.DataServiceImpl;
|
||||
import com.das.modules.equipment.domain.vo.IotModelFieldVo;
|
||||
@ -609,9 +610,10 @@ public class TDEngineService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<DeviceEventInfo> queryEvent(Integer eventLevel, Long startTime, Long endTime, List<String> deviceCodeList) {
|
||||
public PageDataInfo<DeviceEventInfo> queryEvent(Integer eventLevel, Long startTime, Long endTime, List<String> deviceCodeList, Integer limit, Integer offset) {
|
||||
List<DeviceEventInfo> result = new ArrayList<>();
|
||||
StringBuffer sb = new StringBuffer(2048);
|
||||
Integer total = 0;
|
||||
sb.append("select t.* from event_info t where ");
|
||||
sb.append(String.format(" t.event_time >= %d and t.event_time < %d", startTime, endTime));
|
||||
if (eventLevel != null) {
|
||||
@ -628,7 +630,13 @@ public class TDEngineService {
|
||||
}
|
||||
}
|
||||
sb.append(" order by t.event_time");
|
||||
if (limit != null){
|
||||
sb.append(" limit ").append(offset).append(",").append(limit);
|
||||
total = getEventCount(eventLevel,startTime,endTime,deviceCodeList);
|
||||
}
|
||||
|
||||
log.debug(sb.toString());
|
||||
|
||||
try (Connection conn = hikariDataSource.getConnection();
|
||||
Statement smt = conn.createStatement();
|
||||
ResultSet rs = smt.executeQuery(sb.toString())) {
|
||||
@ -648,9 +656,42 @@ public class TDEngineService {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取数据异常", e);
|
||||
return result;
|
||||
return PageDataInfo.build(result, total);
|
||||
}
|
||||
return result;
|
||||
return PageDataInfo.build(result, total);
|
||||
}
|
||||
|
||||
private Integer getEventCount(Integer eventLevel, Long startTime, Long endTime, List<String> deviceCodeList){
|
||||
List<DeviceEventInfo> result = new ArrayList<>();
|
||||
StringBuffer sb = new StringBuffer(2048);
|
||||
sb.append("select count(t.*) as total from event_info t where ");
|
||||
sb.append(String.format(" t.event_time >= %d and t.event_time < %d", startTime, endTime));
|
||||
if (eventLevel != null) {
|
||||
sb.append(String.format(" and t.event_level = %d", eventLevel));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(deviceCodeList)) {
|
||||
sb.append(" and t.device_code in (");
|
||||
for (int i = 0; i < deviceCodeList.size(); i++) {
|
||||
if (i == deviceCodeList.size() - 1) {
|
||||
sb.append("'").append(deviceCodeList.get(i)).append("')");
|
||||
} else {
|
||||
sb.append("'").append(deviceCodeList.get(i)).append("',");
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug(sb.toString());
|
||||
Integer total = null;
|
||||
try (Connection conn = hikariDataSource.getConnection();
|
||||
Statement smt = conn.createStatement();
|
||||
ResultSet rs = smt.executeQuery(sb.toString())) {
|
||||
|
||||
while (rs.next()) {
|
||||
total = rs.getInt("total");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取数据异常", e);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public void confirmEvent(DeviceEventInfo deviceEventInfo) {
|
||||
|
@ -2,6 +2,7 @@ package com.das.modules.event.controller;
|
||||
|
||||
import com.das.common.result.R;
|
||||
import com.das.common.utils.JsonUtils;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.modules.data.domain.DeviceEventInfo;
|
||||
import com.das.modules.event.domain.EventQueryParam;
|
||||
import com.das.modules.event.service.EventService;
|
||||
@ -33,12 +34,12 @@ public class EventController {
|
||||
* @return TD数据库数据
|
||||
*/
|
||||
@PostMapping("/query")
|
||||
public R<List<DeviceEventInfo>> queryEvent(@RequestBody @Valid EventQueryParam param) {
|
||||
public PageDataInfo<DeviceEventInfo> queryEvent(@RequestBody @Valid EventQueryParam param) {
|
||||
if (log.isDebugEnabled()){
|
||||
log.debug("/api/event/query is calling");
|
||||
log.debug(JsonUtils.toJsonString(param));
|
||||
}
|
||||
return R.success(eventService.queryEvent(param));
|
||||
return eventService.queryEvent(param);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,12 +14,12 @@ public class EventQueryParam
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private String startTime;
|
||||
private Long startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
private Long endTime;
|
||||
|
||||
/**
|
||||
* 事件等级
|
||||
@ -30,4 +30,14 @@ public class EventQueryParam
|
||||
* 设备编码列表
|
||||
*/
|
||||
private List<String> deviceCode;
|
||||
|
||||
/**
|
||||
* pageNum;
|
||||
*/
|
||||
private Integer pageNum;
|
||||
|
||||
/**
|
||||
* pageSize
|
||||
*/
|
||||
private Integer pageSize;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.das.modules.event.service;
|
||||
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.modules.data.domain.DeviceEventInfo;
|
||||
import com.das.modules.event.domain.EventQueryParam;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -7,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import java.util.List;
|
||||
|
||||
public interface EventService {
|
||||
List<DeviceEventInfo> queryEvent(EventQueryParam param);
|
||||
PageDataInfo<DeviceEventInfo> queryEvent(EventQueryParam param);
|
||||
|
||||
void confirmEvent(List<DeviceEventInfo> deviceEventInfoList);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.das.modules.event.service.impl;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.das.common.config.SessionUtil;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||
import com.das.modules.data.domain.DeviceEventInfo;
|
||||
import com.das.modules.data.service.TDEngineService;
|
||||
@ -22,11 +23,15 @@ public class EventServiceImpl implements EventService {
|
||||
private TDEngineService tdEngineService;
|
||||
|
||||
@Override
|
||||
public List<DeviceEventInfo> queryEvent(EventQueryParam param) {
|
||||
if (param.getStartTime() == null || param.getEndTime() ==null){
|
||||
public PageDataInfo<DeviceEventInfo> queryEvent(EventQueryParam param) {
|
||||
if (param.getStartTime() == null || param.getEndTime() == null) {
|
||||
throw new ServiceException("查询时间不能为空");
|
||||
}
|
||||
List<DeviceEventInfo> deviceEventInfos = tdEngineService.queryEvent(param.getEventLevel(), Long.valueOf(param.getStartTime()), Long.valueOf(param.getEndTime()), param.getDeviceCode());
|
||||
Integer offset = null;
|
||||
if (param.getPageNum() != null) {
|
||||
offset = (param.getPageNum() - 1) * param.getPageSize();
|
||||
}
|
||||
PageDataInfo<DeviceEventInfo> deviceEventInfos = tdEngineService.queryEvent(param.getEventLevel(), param.getStartTime(), param.getEndTime(), param.getDeviceCode(), param.getPageSize(), offset);
|
||||
return deviceEventInfos;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user