Skip to content

Commit

Permalink
Merge pull request #9714 from dataease/pr@dev-v2@feat_report_lark
Browse files Browse the repository at this point in the history
feat(X-Pack): 定时报告-飞书报告
  • Loading branch information
fit2cloud-chenyw committed May 17, 2024
2 parents 4fe6ea7 + 7b4417d commit de6c3d4
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 28 deletions.
5 changes: 5 additions & 0 deletions core/core-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
<version>${itextpdf.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>${flexmark.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion de-xpack
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<angus-mail.version>2.0.3</angus-mail.version>
<mysql-connector-j.version>8.2.0</mysql-connector-j.version>
<itextpdf.version>8.0.4</itextpdf.version>
<flexmark.version>0.62.2</flexmark.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import io.dataease.api.communicate.dto.MessageDTO;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

Expand All @@ -10,4 +14,7 @@ public interface CommunicateApi {

@PostMapping("/send")
void send(@RequestBody MessageDTO dto);

@GetMapping("/down/{fileId}/{fileName}/{suffix}")
ResponseEntity<ByteArrayResource> down(@PathVariable("fileId") String fileId, @PathVariable("fileName") String fileName, @PathVariable("suffix") String suffix) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.api.lark.dto.LarkEnableEditor;
import io.dataease.api.lark.dto.LarkTokenRequest;
import io.dataease.api.lark.vo.LarkGroupVO;
import io.dataease.api.lark.vo.LarkInfoVO;
import io.dataease.api.lark.dto.LarkSettingCreator;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -38,4 +39,8 @@ public interface LarkApi {
@Operation(summary = "飞书绑定", hidden = true)
@PostMapping("/bind")
void bind(@RequestBody LarkTokenRequest request);

@Operation(summary = "获取飞书群组", hidden = true)
@GetMapping("/getGroup")
LarkGroupVO getGroup();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.dataease.api.lark.dto;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
public class LarkGroupItem implements Serializable {
@Serial
private static final long serialVersionUID = -3458959523154279946L;

private String chat_id;
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.dataease.api.lark.vo;

import io.dataease.api.lark.dto.LarkGroupItem;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

@Data
public class LarkGroupVO implements Serializable {
@Serial
private static final long serialVersionUID = 39710350567348130L;

private boolean valid;
private List<LarkGroupItem> groupList;
}
5 changes: 5 additions & 0 deletions sdk/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpclient.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class StaticResourceConstants {
public static String MAP_DIR = ensureSuffix(USER_HOME, FILE_SEPARATOR) + "map";
public static String CUSTOM_MAP_DIR = ensureSuffix(USER_HOME, FILE_SEPARATOR) + "geo";
public static String APPEARANCE_DIR = ensureSuffix(USER_HOME, FILE_SEPARATOR) + "appearance";
public static String REPORT_DIR = ensureSuffix(USER_HOME, FILE_SEPARATOR) + "report";

public static String MAP_URL = "/map";
public static String GEO_URL = "/geo";
Expand Down
126 changes: 106 additions & 20 deletions sdk/common/src/main/java/io/dataease/utils/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.dataease.utils;

import io.dataease.exception.DEException;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -9,6 +10,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class FileUtils {

Expand Down Expand Up @@ -51,9 +54,10 @@ public static String getExtensionName(String filename) {

public static void validateExist(String path) {
File dir = new File(path);
if (dir.exists()) return ;
if (dir.exists()) return;
dir.mkdirs();
}

/**
* 将文件名解析成文件的上传路径
*/
Expand All @@ -62,7 +66,7 @@ public static File upload(MultipartFile file, String filePath) {
String suffix = getExtensionName(file.getOriginalFilename());
try {
validateExist(filePath);
String fileName = name + "." + suffix;
String fileName = name + "." + suffix;
String path = filePath + fileName;
// getCanonicalFile 可解析正确各种路径
File dest = new File(path).getCanonicalFile();
Expand All @@ -78,45 +82,46 @@ public static File upload(MultipartFile file, String filePath) {
}
return null;
}
public static void copyFolder(String sourcePath,String targetPath) throws Exception{

public static void copyFolder(String sourcePath, String targetPath) throws Exception {
//源文件夹路径
File sourceFile = new File(sourcePath);
//目标文件夹路径
File targetFile = new File(targetPath);

if(!sourceFile.exists()){
if (!sourceFile.exists()) {
throw new Exception("文件夹不存在");
}
if(!sourceFile.isDirectory()){
if (!sourceFile.isDirectory()) {
throw new Exception("源文件夹不是目录");
}
if(!targetFile.exists()){
if (!targetFile.exists()) {
targetFile.mkdirs();
}
if(!targetFile.isDirectory()){
if (!targetFile.isDirectory()) {
throw new Exception("目标文件夹不是目录");
}

File[] files = sourceFile.listFiles();
if(files == null || files.length == 0){
if (files == null || files.length == 0) {
return;
}

for(File file : files){
for (File file : files) {
//文件要移动的路径
String movePath = targetFile+File.separator+file.getName();
if(file.isDirectory()){
String movePath = targetFile + File.separator + file.getName();
if (file.isDirectory()) {
//如果是目录则递归调用
copyFolder(file.getAbsolutePath(),movePath);
}else {
copyFolder(file.getAbsolutePath(), movePath);
} else {
//如果是文件则复制文件
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(movePath));

byte[] b = new byte[1024];
int temp = 0;
while((temp = in.read(b)) != -1){
out.write(b,0,temp);
while ((temp = in.read(b)) != -1) {
out.write(b, 0, temp);
}
out.close();
in.close();
Expand All @@ -125,12 +130,12 @@ public static void copyFolder(String sourcePath,String targetPath) throws Except
}


public static String copy(File source, String targetDir) throws IOException{
public static String copy(File source, String targetDir) throws IOException {
String name = source.getName();
String destPath = null;
if (targetDir.endsWith("/") || targetDir.endsWith("\\")){
if (targetDir.endsWith("/") || targetDir.endsWith("\\")) {
destPath = targetDir + name;
}else{
} else {
destPath = targetDir + "/" + name;
}
File DestFile = new File(destPath);
Expand Down Expand Up @@ -159,7 +164,7 @@ public static String readJson(File file) {
try {
FileReader fileReader = new FileReader(file);
Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");
int ch=0;
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
Expand All @@ -176,11 +181,92 @@ public static String readJson(File file) {

public static void deleteFile(String path) {
File file = new File(path);
if (file.exists()){
if (file.exists()) {
if (file.isDirectory()) {
Arrays.stream(file.listFiles()).forEach(item -> deleteFile(item.getAbsolutePath()));
}
file.delete();
}
}

public static boolean exist(String path) {
File file = new File(path);
return file.exists();
}

public static List<String> listFileNames(String path) {
File file = new File(path);
if (!file.exists()) {
return null;
} else {
File[] files = file.listFiles();

assert files != null;

return Arrays.stream(files).map(File::getName).collect(Collectors.toList());
}
}

public static String getSuffix(String fileName) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
}

public static String getPrefix(String fileName) {
return fileName.substring(0, fileName.lastIndexOf("."));
}

public static byte[] readBytes(String path) {
File file = new File(path);
if (!file.exists() || !file.isFile()) {
DEException.throwException("文件不存在");
}

byte[] bytes = null;

try {
FileInputStream fis = new FileInputStream(file);

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();

try {
byte[] buffer = new byte[4096];

while (true) {
int bytesRead;
if ((bytesRead = fis.read(buffer)) == -1) {
bytes = bos.toByteArray();
break;
}

bos.write(buffer, 0, bytesRead);
}
} catch (Throwable var9) {
try {
bos.close();
} catch (Throwable var8) {
var9.addSuppressed(var8);
}

throw var9;
}

bos.close();
} catch (Throwable var10) {
try {
fis.close();
} catch (Throwable var7) {
var10.addSuppressed(var7);
}

throw var10;
}

fis.close();
} catch (Exception var11) {
var11.printStackTrace();
}

return bytes;
}
}

0 comments on commit de6c3d4

Please sign in to comment.