feat:日志管理接口修改
This commit is contained in:
parent
141387c979
commit
9b04069649
|
@ -16,6 +16,12 @@
|
|||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<artifactId>jeecg-boot-base-core</artifactId>
|
||||
</dependency>
|
||||
<!--ftp依赖-->
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package org.jeecg;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class JeecgBootLogManageApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JeecgBootLogManageApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
package org.jeecg.modules.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.FTPUtil;
|
||||
import org.jeecg.modules.entity.FileInfo;
|
||||
import org.jeecg.modules.entity.LogManage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("logManage")
|
||||
@Api(value = "日志管理", tags = "日志管理")
|
||||
public class LogManageController {
|
||||
|
||||
@Autowired
|
||||
private FTPUtil ftpUtil;
|
||||
|
||||
@GetMapping("findFtpFolders")
|
||||
@ApiOperation(value = "查询日志文件夹树形结构", notes = "查询日志文件夹树形结构")
|
||||
public List<LogManage> findFtpFolders(String workPath){
|
||||
List<LogManage> result = new ArrayList<>();
|
||||
workPath = "/"+workPath;
|
||||
FTPClient ftpClient = ftpUtil.LoginFTP(workPath);
|
||||
if(Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException("ftp连接失败!");
|
||||
}
|
||||
try {
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories());
|
||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||
int num =1;
|
||||
for (FTPFile ftpFile:ftpFiles) {
|
||||
LogManage logManage = new LogManage();
|
||||
logManage.setName(ftpFile.getName());
|
||||
logManage.setOrderNum(num);
|
||||
logManage.setParentNum(0);
|
||||
logManage.setPath(workPath+ "/" + ftpFile.getName() + "/");
|
||||
result.add(logManage);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(result)){
|
||||
List<LogManage> list = new LinkedList<>();
|
||||
for (LogManage logManage:result) {
|
||||
list = ftpUtil.findDirectory(ftpClient, list, logManage.getOrderNum(), workPath + "/" + logManage.getName() + "/");
|
||||
}
|
||||
result.addAll(list);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
result = this.LogManageTree(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将当前的文件夹转换成树形结构
|
||||
* @param logManages
|
||||
* @return
|
||||
*/
|
||||
public List<LogManage> LogManageTree(List<LogManage> logManages){
|
||||
if (logManages == null) {
|
||||
return null;
|
||||
}
|
||||
List<LogManage> result = new LinkedList<>();
|
||||
Integer TOP_NODE_ID = 0;
|
||||
logManages.forEach(logManage -> {
|
||||
Integer pid = logManage.getParentNum();
|
||||
if (pid == null || TOP_NODE_ID.equals(pid)) {
|
||||
result.add(logManage);
|
||||
return;
|
||||
}
|
||||
for (LogManage manage : logManages) {
|
||||
Integer id = manage.getOrderNum();
|
||||
if (id != null && id.equals(pid)) {
|
||||
if (manage.getChildren() == null) {
|
||||
manage.initChildren();
|
||||
}
|
||||
logManage.setHashParent(true);
|
||||
manage.getChildren().add(logManage);
|
||||
manage.setHashChild(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询目录下文件内容
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("findFiles")
|
||||
@ApiOperation(value = "查询目录下文件内容", notes = "查询目录下文件内容")
|
||||
public List<FileInfo> findFiles(String path){
|
||||
List<FileInfo> result = new ArrayList<>();
|
||||
if (!path.endsWith("/")){
|
||||
path = path+"/";
|
||||
}
|
||||
FTPClient ftpClient = ftpUtil.LoginFTP(path);
|
||||
if (Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException("ftp连接失败!");
|
||||
}
|
||||
try {
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
|
||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||
for (FTPFile ftpFile:ftpFiles) {
|
||||
if (ftpFile.isFile()){
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setFileName(ftpFile.getName());
|
||||
fileInfo.setFilePath(path+ftpFile.getName()+"/");
|
||||
fileInfo.setFileSize(String.format("%.2f", Double.valueOf(Double.valueOf(ftpFile.getSize())/1024)) + "KB");
|
||||
fileInfo.setFileDate(DateUtils.formatDate(ftpFile.getTimestamp(),"yyyy-MM-dd"));
|
||||
result.add(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("downloadFile")
|
||||
@ApiOperation(value = "ftp文件下载", notes = "ftp文件下载")
|
||||
public void downloadFile(String localPath, String fileName, HttpServletResponse response) throws IOException {
|
||||
if (localPath.contains(fileName)){
|
||||
localPath=localPath.substring(0,localPath.indexOf(fileName));
|
||||
}
|
||||
//重置响应信息
|
||||
response.reset();
|
||||
//设置响应类型
|
||||
response.setContentType("application/download");
|
||||
//解决中文不能生成文件
|
||||
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(fileName,"UTF-8"));
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
//获取文件的输入流
|
||||
InputStream in = ftpUtil.downloadFTPFile(localPath, fileName);
|
||||
//获取输出流
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
//声明一个长度参数
|
||||
int len;
|
||||
//声明字节数组
|
||||
byte[] bytes = new byte[1024];
|
||||
//判断如果输入流的字节长度不等于-1,进行字节数组内容的读取
|
||||
while ((len = in.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, len);
|
||||
}
|
||||
out.flush();
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.jeecg.modules.entity;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class LogManage {
|
||||
|
||||
private String name;
|
||||
|
||||
private String path;
|
||||
|
||||
private Integer orderNum;
|
||||
|
||||
private Integer parentNum;
|
||||
|
||||
private boolean hashParent;
|
||||
|
||||
private boolean hashChild;
|
||||
|
||||
private List<LogManage> children;
|
||||
|
||||
public void initChildren(){
|
||||
children = Lists.newArrayList();
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,11 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- jeecg-system-log-manage依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<artifactId>jeecg-module-log-manage</artifactId>
|
||||
</dependency>
|
||||
<!-- feign 熔断限流、分布式锁、xxljob示例
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -78,6 +78,7 @@
|
|||
<module>jeecg-boot-base-core</module>
|
||||
<module>jeecg-module-demo</module>
|
||||
<module>jeecg-module-system</module>
|
||||
<module>jeecg-module-log-manage</module>
|
||||
</modules>
|
||||
|
||||
<repositories>
|
||||
|
@ -165,7 +166,12 @@
|
|||
<artifactId>jeecg-system-biz</artifactId>
|
||||
<version>${jeecgboot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- log-manage 模块-->
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<artifactId>jeecg-module-log-manage</artifactId>
|
||||
<version>${jeecgboot.version}</version>
|
||||
</dependency>
|
||||
<!-- jeecg tools -->
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
|
|
Loading…
Reference in New Issue
Block a user