Skip to content

Commit

Permalink
[manager] import and export by excel (#891)
Browse files Browse the repository at this point in the history
  [manager]export by excel via `ExcelImExportServiceImpl.java`

  [manager]import by excel via `ExcelImExportServiceImpl.java`

  [manager]fix log level and static method.

  Update pom.xml

Signed-off-by: zqr10159 <[email protected]>

---------

Signed-off-by: zqr10159 <[email protected]>
  • Loading branch information
zqr10159 authored Apr 18, 2023
1 parent 0f42edc commit 1d15df9
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 4 deletions.
12 changes: 12 additions & 0 deletions collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
<groupId>org.dromara.hertzbeat</groupId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>

<artifactId>hertzbeat-collector</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<maven.install.skip>true</maven.install.skip>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<mysql.version>8.0.28</mysql.version>
<nekohtml.version>1.9.22</nekohtml.version>
<spring-boot-starter-sureness.version>1.0.8</spring-boot-starter-sureness.version>
<warehouse.version>1.0</warehouse.version>
<easy-poi.version>4.3.0</easy-poi.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -123,6 +128,11 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>${easy-poi.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

package org.dromara.hertzbeat.manager.service.impl;

import cn.afterturn.easypoi.excel.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hertzbeat.common.entity.manager.Monitor;
import org.dromara.hertzbeat.common.entity.manager.Param;
import org.dromara.hertzbeat.common.entity.manager.Tag;
Expand All @@ -41,6 +43,7 @@
* @author <a href="mailto:[email protected]">gcdd1993</a>
* Created by gcdd1993 on 2023/3/31
*/
@Slf4j
abstract class AbstractImExportServiceImpl implements ImExportService {

@Resource
Expand Down Expand Up @@ -118,6 +121,7 @@ private MonitorDto convert(ExportMonitorDTO exportMonitor) {
var monitorDto = new MonitorDto();
monitorDto.setDetected(true);
var monitor = new Monitor();
log.debug("exportMonitor.monitor{}", exportMonitor.monitor);
BeanUtils.copyProperties(exportMonitor.monitor, monitor);
monitor.setTags(tagService.listTag(new HashSet<>(exportMonitor.monitor.tags)));
monitorDto.setMonitor(monitor);
Expand All @@ -132,39 +136,59 @@ private MonitorDto convert(ExportMonitorDTO exportMonitor) {
return monitorDto;
}

protected String fileNamePrefix() {
protected String
fileNamePrefix() {
return "hertzbeat_monitor_" + LocalDate.now();
}

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@ExcelTarget(value = "ExportMonitorDTO")
protected static class ExportMonitorDTO {
@ExcelEntity(name = "Monitor")
private MonitorDTO monitor;
@ExcelCollection(name = "Params")
private List<ParamDTO> params;
@ExcelCollection(name = "Metrics")
private List<String> metrics;
}


@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@ExcelTarget(value = "MonitorDTO")
protected static class MonitorDTO {
@Excel(name = "Name")
private String name;
@Excel(name = "App")
private String app;
@Excel(name = "Host")
private String host;
@Excel(name = "Intervals")
private Integer intervals;
@Excel(name = "Status")
private Byte status;
@Excel(name = "Description")
private String description;
@Excel(name = "Tags")
private List<Long> tags;
}


@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@ExcelTarget(value = "ParamDTO")
protected static class ParamDTO {
@Excel(name = "Field")
private String field;
@Excel(name = "Value")
private String value;
@Excel(name = "Type")
private Byte type;
}


}
Loading

0 comments on commit 1d15df9

Please sign in to comment.