mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-03 12:29:14 +08:00
optimal del log tip
This commit is contained in:
parent
5696d9e3d2
commit
5f90d08612
@ -33,6 +33,7 @@ import io.jpom.common.BaseAgentController;
|
||||
import io.jpom.system.WebAopLog;
|
||||
import io.jpom.util.LayuiTreeUtil;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@ -67,9 +68,7 @@ public class LogManageController extends BaseAgentController {
|
||||
File file = FileUtil.file(webAopLog.getPropertyValue(), path);
|
||||
// 判断修改时间
|
||||
long modified = file.lastModified();
|
||||
if (System.currentTimeMillis() - modified < TimeUnit.DAYS.toMillis(1)) {
|
||||
return JsonMessage.getString(405, "不能删除当天的日志");
|
||||
}
|
||||
Assert.state(System.currentTimeMillis() - modified > TimeUnit.DAYS.toMillis(1), "不能删除近一天相关的日志(文件修改时间)");
|
||||
if (FileUtil.del(file)) {
|
||||
return JsonMessage.getString(200, "删除成功");
|
||||
}
|
||||
|
@ -33,14 +33,15 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.forward.NodeForward;
|
||||
import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.permission.SystemPermission;
|
||||
import io.jpom.permission.ClassFeature;
|
||||
import io.jpom.permission.Feature;
|
||||
import io.jpom.permission.MethodFeature;
|
||||
import io.jpom.permission.SystemPermission;
|
||||
import io.jpom.socket.ServiceFileTailWatcher;
|
||||
import io.jpom.system.WebAopLog;
|
||||
import io.jpom.util.LayuiTreeUtil;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -61,59 +62,58 @@ import java.util.concurrent.TimeUnit;
|
||||
public class LogManageController extends BaseServerController {
|
||||
|
||||
|
||||
@RequestMapping(value = "log_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.LIST)
|
||||
public String logData(String nodeId) {
|
||||
if (StrUtil.isNotEmpty(nodeId)) {
|
||||
return NodeForward.request(getNode(), getRequest(), NodeUrl.SystemLog).toString();
|
||||
}
|
||||
WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
|
||||
JSONArray data = LayuiTreeUtil.getTreeData(webAopLog.getPropertyValue());
|
||||
return JsonMessage.getString(200, "", data);
|
||||
}
|
||||
@RequestMapping(value = "log_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.LIST)
|
||||
public String logData(String nodeId) {
|
||||
if (StrUtil.isNotEmpty(nodeId)) {
|
||||
return NodeForward.request(getNode(), getRequest(), NodeUrl.SystemLog).toString();
|
||||
}
|
||||
WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
|
||||
JSONArray data = LayuiTreeUtil.getTreeData(webAopLog.getPropertyValue());
|
||||
return JsonMessage.getString(200, "", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 需要验证是否最后修改时间
|
||||
*
|
||||
* @param nodeId 节点
|
||||
* @param path 路径
|
||||
* @return json
|
||||
*/
|
||||
@RequestMapping(value = "log_del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.DEL)
|
||||
public String logData(String nodeId,
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
|
||||
if (StrUtil.isNotEmpty(nodeId)) {
|
||||
return NodeForward.request(getNode(), getRequest(), NodeUrl.DelSystemLog).toString();
|
||||
}
|
||||
WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
|
||||
File file = FileUtil.file(webAopLog.getPropertyValue(), path);
|
||||
// 判断修改时间
|
||||
long modified = file.lastModified();
|
||||
if (System.currentTimeMillis() - modified < TimeUnit.DAYS.toMillis(1)) {
|
||||
return JsonMessage.getString(405, "不能删除当天的日志");
|
||||
}
|
||||
if (FileUtil.del(file)) {
|
||||
// 离线上一个日志
|
||||
ServiceFileTailWatcher.offlineFile(file);
|
||||
return JsonMessage.getString(200, "删除成功");
|
||||
}
|
||||
return JsonMessage.getString(500, "删除失败");
|
||||
}
|
||||
/**
|
||||
* 删除 需要验证是否最后修改时间
|
||||
*
|
||||
* @param nodeId 节点
|
||||
* @param path 路径
|
||||
* @return json
|
||||
*/
|
||||
@RequestMapping(value = "log_del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.DEL)
|
||||
public String logData(String nodeId,
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
|
||||
if (StrUtil.isNotEmpty(nodeId)) {
|
||||
return NodeForward.request(getNode(), getRequest(), NodeUrl.DelSystemLog).toString();
|
||||
}
|
||||
WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
|
||||
File file = FileUtil.file(webAopLog.getPropertyValue(), path);
|
||||
// 判断修改时间
|
||||
long modified = file.lastModified();
|
||||
Assert.state(System.currentTimeMillis() - modified > TimeUnit.DAYS.toMillis(1), "不能删除近一天相关的日志(文件修改时间)");
|
||||
|
||||
if (FileUtil.del(file)) {
|
||||
// 离线上一个日志
|
||||
ServiceFileTailWatcher.offlineFile(file);
|
||||
return JsonMessage.getString(200, "删除成功");
|
||||
}
|
||||
return JsonMessage.getString(500, "删除失败");
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "log_download", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.DOWNLOAD)
|
||||
public void logDownload(String nodeId,
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
|
||||
if (StrUtil.isNotEmpty(nodeId)) {
|
||||
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.DownloadSystemLog);
|
||||
return;
|
||||
}
|
||||
WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
|
||||
File file = FileUtil.file(webAopLog.getPropertyValue(), path);
|
||||
if (file.isFile()) {
|
||||
ServletUtil.write(getResponse(), file);
|
||||
}
|
||||
}
|
||||
@RequestMapping(value = "log_download", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.DOWNLOAD)
|
||||
public void logDownload(String nodeId,
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
|
||||
if (StrUtil.isNotEmpty(nodeId)) {
|
||||
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.DownloadSystemLog);
|
||||
return;
|
||||
}
|
||||
WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
|
||||
File file = FileUtil.file(webAopLog.getPropertyValue(), path);
|
||||
if (file.isFile()) {
|
||||
ServletUtil.write(getResponse(), file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user