feat: 增加告警导出功能

iec104
huangfeng 1 year ago
parent 29b10fc45e
commit 17b5a12e5d

@ -1,8 +1,10 @@
package com.xydl.cac.controller;
import com.alibaba.excel.EasyExcel;
import com.xydl.cac.entity.Warning;
import com.xydl.cac.model.ConditionModel;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.ReportService;
import com.xydl.cac.service.WarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -12,6 +14,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;
@RestController
@Api(tags = {"告警信息相关接口"})
@ -30,4 +35,21 @@ public class WarningController extends BasicController {
Page<Warning> result = service.list(condition);
return Response.success(result);
}
@GetMapping("export")
@ApiOperation("导出告警数据")
public void export(@Validated ConditionModel condition, HttpServletResponse response) throws Exception {
if (condition.getPageNum() != null || condition.getPageSize() != null) {
condition.setPageNum(this.initPageNum(condition.getPageNum()));
condition.setPageSize(this.initPageSize(condition.getPageSize()));
}
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename="
+ URLEncoder.encode("告警数据.xlsx", "UTF-8"));
List<Warning> result = service.listAll(condition);
EasyExcel.write(response.getOutputStream(), Warning.class)
.sheet("告警数据")
.doWrite(result);
}
}

@ -1,5 +1,8 @@
package com.xydl.cac.entity;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -24,70 +27,96 @@ public class Warning {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@ExcelIgnore
private Integer id;
@ApiModelProperty("装置ID")
@Column(name = "sensor_id")
@ExcelIgnore
private Integer sensorId;
@ApiModelProperty("装置名称")
@Column(name = "sensor_name")
@ColumnWidth(20)
@ExcelProperty(value = "装置名称", order = 3)
private String sensorName;
@ApiModelProperty("主设备名称")
@Column(name = "zsb_name")
@ColumnWidth(20)
@ExcelProperty(value = "主设备名称", order = 2)
private String zsbName;
@ApiModelProperty("规则ID")
@Column(name = "rule_id")
@ExcelIgnore
private Integer ruleId;
@ApiModelProperty("字段名")
@Column(name = "field")
@ExcelIgnore
private String field;
@ApiModelProperty("数据采集时间")
@Column(name = "d_time")
@ColumnWidth(20)
@ExcelProperty(value = "数据采集时间", order = 4)
private Date dTime;
@ApiModelProperty("告警时间")
@Column(name = "warn_time")
@ColumnWidth(20)
@ExcelProperty(value = "告警时间", order = 1)
private Date warnTime;
@ApiModelProperty("告警值")
@ApiModelProperty("当前值")
@Column(name = "warn_value")
@ColumnWidth(10)
@ExcelProperty(value = "当前值", order = 6)
private String warnValue;
@ApiModelProperty("阈值")
@Column(name = "threshold")
@ColumnWidth(10)
@ExcelProperty(value = "阈值", order = 8)
private String threshold;
@ApiModelProperty("告警信息")
@Column(name = "warn_desc")
@ColumnWidth(30)
@ExcelProperty(value = "告警信息", order = 5)
private String warnDesc;
@ApiModelProperty("触发信息")
@Column(name = "trigger_desc")
@ColumnWidth(20)
@ExcelProperty(value = "触发信息", order = 7)
private String triggerDesc;
@ApiModelProperty("告警 0:低 1:中 2:高")
@ApiModelProperty("告警级 0:低 1:中 2:高")
@Column(name = "warn_level")
@ColumnWidth(15)
@ExcelProperty(value = "告警等级", order = 9)
private Integer warnLevel;
@ApiModelProperty("处理状态")
@Column(name = "state")
@ExcelIgnore
private String state;
@ApiModelProperty("处理结果描述")
@Column(name = "process")
@ExcelIgnore
private String process;
@ApiModelProperty("处理人id")
@Column(name = "process_user")
@ExcelIgnore
private String processUser;
@ApiModelProperty("处理时间")
@Column(name = "process_time")
@ExcelIgnore
private Date processTime;
}

@ -4,8 +4,12 @@ import com.xydl.cac.entity.Warning;
import com.xydl.cac.model.ConditionModel;
import org.springframework.data.domain.Page;
import java.util.List;
public interface WarningService {
Page<Warning> list(ConditionModel condition) throws Exception;
List<Warning> listAll(ConditionModel condition) throws Exception;
}

@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.util.List;
@Service
@Slf4j
@ -46,4 +47,26 @@ public class WarningServiceImpl implements WarningService {
Page<Warning> result = repository.findAll(specification, request);
return result;
}
@Override
public List<Warning> listAll(ConditionModel condition) throws Exception {
Specification<Warning> specification = (root, query, builder) -> {
Predicate predicate = builder.conjunction();
if (condition.getId() != null) {
predicate.getExpressions().add(builder.equal(root.get("sensorId"), condition.getId().toString()));
}
if (StringUtils.isNotBlank(condition.getState())) {
predicate.getExpressions().add(builder.equal(root.get("state"), condition.getState()));
}
if (condition.getStartTime() != null) {
predicate.getExpressions().add(builder.greaterThan(root.get("warnTime"), condition.getStartTime()));
}
if (condition.getEndTime() != null) {
predicate.getExpressions().add(builder.lessThanOrEqualTo(root.get("warnTime"), condition.getEndTime()));
}
query.orderBy(builder.desc(root.get("warnTime")));
return predicate;
};
return repository.findAll(specification);
}
}

Loading…
Cancel
Save