Trash Clean function

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-14 14:50:37 +08:00
parent 81e50b15f8
commit b5a5d48df9
6 changed files with 320 additions and 49 deletions

View File

@ -40,16 +40,16 @@
学生管理 学生管理
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown1"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown1">
<li><a class="dropdown-item" href="student/all">学生信息显示</a></li> <li><a class="dropdown-item" href="/student/all">学生信息显示</a></li>
<li><a class="dropdown-item" href="student/queryinfo">学生信息查询</a></li> <li><a class="dropdown-item" href="/student/queryinfo">学生信息查询</a></li>
<li><a class="dropdown-item" href="student/modstep1">学生信息修改(旧)</a></li> <li><a class="dropdown-item" href="/student/modstep1">学生信息修改(旧)</a></li>
<li><a class="dropdown-item" href="student/infomodv2">学生信息修改</a></li> <li><a class="dropdown-item" href="/student/infomodv2">学生信息修改</a></li>
<li><a class="dropdown-item disabled"><del>自己输入sql语句查</del>(划掉,没做)</a></li> <li><a class="dropdown-item disabled"><del>自己输入sql语句查</del>(划掉,没做)</a></li>
<li> <li>
<hr class="dropdown-divider" /> <hr class="dropdown-divider" />
</li> </li>
<li><a class="dropdown-item" href="score/all">成绩查看</a></li> <li><a class="dropdown-item" href="/score/all">成绩查看</a></li>
<li><a class="dropdown-item" href="score/infomodv2">成绩管理</a></li> <li><a class="dropdown-item" href="/score/infomodv2">成绩管理</a></li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li> <li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li> <li>
<hr class="dropdown-divider" /> <hr class="dropdown-divider" />
@ -73,8 +73,8 @@
课程管理 课程管理
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown3"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown3">
<li><a class="dropdown-item" href="course/all">课程查看</a></li> <li><a class="dropdown-item" href="/course/all">课程查看</a></li>
<li><a class="dropdown-item" href="course/infomodv2">课程管理</a></li> <li><a class="dropdown-item" href="/course/infomodv2">课程管理</a></li>
</ul> </ul>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">
@ -84,7 +84,7 @@
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown4"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown4">
<li><a class="dropdown-item" href="#">个人设定</a></li> <li><a class="dropdown-item" href="#">个人设定</a></li>
<li><a class="dropdown-item" href="#">系统设定</a></li> <li><a class="dropdown-item" href="/system/settings">系统设定</a></li>
<li><a class="dropdown-item" href="#">用户管理</a></li> <li><a class="dropdown-item" href="#">用户管理</a></li>
<li><a class="dropdown-item" href="#">日志管理</a></li> <li><a class="dropdown-item" href="#">日志管理</a></li>
<li><a class="dropdown-item" href="#">版本信息</a></li> <li><a class="dropdown-item" href="#">版本信息</a></li>

View File

@ -138,7 +138,12 @@
<div class="card-body" style="min-width: 175px"> <div class="card-body" style="min-width: 175px">
<div class="row mb-2 mt-4"> <div class="row mb-2 mt-4">
<div class="col-lg-2 text-center"> <div class="col-lg-2 text-center">
<button type="button" class="btn btn-secondary btn-lg">清除缓存文件</button> <p>缓存文件大小:<mark>${trashSize}</mark></p>
</div>
</div>
<div class="row mb-2 mt-4">
<div class="col-lg-2 text-center">
<button type="button" class="btn btn-secondary btn-lg" onclick="cleantrash()" data-mdb-toggle="tooltip" data-mdb-placement="bottom" title="这将会清除工作目录下的垃圾文件">清除缓存文件</button>
</div> </div>
</div> </div>
</div> </div>
@ -155,35 +160,13 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"> <h5 class="modal-title" id="exampleModalLabel">
<i class="fas fa-circle-exclamation me-2"></i>错误 <i class="fas fa-circle-info me-2"></i>提示
</h5> </h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<c:if test="${not empty errorMessage}"> <c:if test="${not empty message}">
${errorMessage} ${message}
</c:if>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-mdb-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModalLabel2"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel2">
<i class="fas fa-circle-check me-2"></i>成功
</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<c:if test="${not empty successMessage}">
${successMessage}
</c:if> </c:if>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -205,14 +188,14 @@
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/mdb.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/mdb.min.js"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
// 判断模型中是否存在错误信息 <c:if test="${not empty message && message ne 'null'}">
<c:if test="${not empty errorMessage && errorMessage ne 'null'}">
$('#exampleModal').modal('show'); $('#exampleModal').modal('show');
</c:if> </c:if>
<c:if test="${not empty successMessage && successMessage ne 'null'}">
$('#exampleModal2').modal('show');
</c:if>
}); });
function cleantrash(){
//click this button to clean (/system/clean)
window.location.href = "/system/clean";
}
</script> </script>
</body> </body>

View File

@ -1,9 +1,95 @@
package cyou.chenx221.controller; package cyou.chenx221.controller;
import cyou.chenx221.helper.UsernameHelper;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.io.File;
import java.text.DecimalFormat;
@Controller @Controller
@RequestMapping("/system") @RequestMapping("/system")
public class SystemController { public class SystemController {
@GetMapping("/settings")
public String getSettings(Model model, @ModelAttribute("message") String message) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
if(message!=null && !message.isEmpty()){
model.addAttribute("message", message);
}
model.addAttribute("trashSize", formatFileSize(getTrashSize()));
return "settings";
}
public long getTrashSize() {
File directory = new File("file");
long size = 0;
if (directory.exists() && directory.isDirectory()) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
size += file.length();
}
}
}
}
return size;
}
public String formatFileSize(long size) {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
double kiloByte = size / 1024.0;
double megaByte = kiloByte / 1024.0;
double gigaByte = megaByte / 1024.0;
double teraByte = gigaByte / 1024.0;
if (teraByte > 1) {
return decimalFormat.format(teraByte) + " TB";
} else if (gigaByte > 1) {
return decimalFormat.format(gigaByte) + " GB";
} else if (megaByte > 1) {
return decimalFormat.format(megaByte) + " MB";
} else if (kiloByte > 1) {
return decimalFormat.format(kiloByte) + " KB";
} else {
return size + " B";
}
}
@GetMapping("/clean")
public String getClean(RedirectAttributes redirectAttributes) {
//todo: clean work path file/*.csv
File directory = new File("file");
// 检查目录是否存在
if (directory.exists() && directory.isDirectory()) {
// 获取目录中的所有文件
File[] files = directory.listFiles();
// 遍历文件并删除以 ".csv" 结尾的文件
if (files != null) {
for (File file : files) {
if (file.isFile()) {
if (file.delete()) {
System.out.println("REPORT: Trash " + file.getName() + " deleted");
} else {
System.out.println("REPORT: Trash " + file.getName() + " delete failed");
}
}
}
} else {
System.out.println("REPORT: no trash file found");
}
}
redirectAttributes.addFlashAttribute("message", "清理完毕");
return "redirect:/system/settings";
}
} }

View File

@ -40,16 +40,16 @@
学生管理 学生管理
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown1"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown1">
<li><a class="dropdown-item" href="student/all">学生信息显示</a></li> <li><a class="dropdown-item" href="/student/all">学生信息显示</a></li>
<li><a class="dropdown-item" href="student/queryinfo">学生信息查询</a></li> <li><a class="dropdown-item" href="/student/queryinfo">学生信息查询</a></li>
<li><a class="dropdown-item" href="student/modstep1">学生信息修改(旧)</a></li> <li><a class="dropdown-item" href="/student/modstep1">学生信息修改(旧)</a></li>
<li><a class="dropdown-item" href="student/infomodv2">学生信息修改</a></li> <li><a class="dropdown-item" href="/student/infomodv2">学生信息修改</a></li>
<li><a class="dropdown-item disabled"><del>自己输入sql语句查</del>(划掉,没做)</a></li> <li><a class="dropdown-item disabled"><del>自己输入sql语句查</del>(划掉,没做)</a></li>
<li> <li>
<hr class="dropdown-divider" /> <hr class="dropdown-divider" />
</li> </li>
<li><a class="dropdown-item" href="score/all">成绩查看</a></li> <li><a class="dropdown-item" href="/score/all">成绩查看</a></li>
<li><a class="dropdown-item" href="score/infomodv2">成绩管理</a></li> <li><a class="dropdown-item" href="/score/infomodv2">成绩管理</a></li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li> <li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li> <li>
<hr class="dropdown-divider" /> <hr class="dropdown-divider" />
@ -73,8 +73,8 @@
课程管理 课程管理
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown3"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown3">
<li><a class="dropdown-item" href="course/all">课程查看</a></li> <li><a class="dropdown-item" href="/course/all">课程查看</a></li>
<li><a class="dropdown-item" href="course/infomodv2">课程管理</a></li> <li><a class="dropdown-item" href="/course/infomodv2">课程管理</a></li>
</ul> </ul>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">
@ -84,7 +84,7 @@
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown4"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown4">
<li><a class="dropdown-item" href="#">个人设定</a></li> <li><a class="dropdown-item" href="#">个人设定</a></li>
<li><a class="dropdown-item" href="#">系统设定</a></li> <li><a class="dropdown-item" href="/system/settings">系统设定</a></li>
<li><a class="dropdown-item" href="#">用户管理</a></li> <li><a class="dropdown-item" href="#">用户管理</a></li>
<li><a class="dropdown-item" href="#">日志管理</a></li> <li><a class="dropdown-item" href="#">日志管理</a></li>
<li><a class="dropdown-item" href="#">版本信息</a></li> <li><a class="dropdown-item" href="#">版本信息</a></li>

View File

@ -0,0 +1,202 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<title>成绩信息修改v2</title>
<script src="${pageContext.request.contextPath}/resources/js/jquery-3.7.0.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/mdb.min.css"/>
<style>
.tab-pane {
min-height: 500px;
}
</style>
</head>
<body style="font-family: 'Noto Sans SC Regular',serif">
<!--Main Navigation-->
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light" style="z-index: 1;min-height: 58.59px">
<div class="container">
<button class="navbar-toggler" type="button" data-mdb-toggle="collapse"
data-mdb-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<a class="navbar-brand mt-2 mt-lg-0" href="#">
<i class="fas fa-chalkboard-user me-2"></i>
教务管理系统
</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">首页</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
学生管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown1">
<li><a class="dropdown-item" href="#">学生信息查询</a></li>
<li><a class="dropdown-item" href="#">学生信息管理</a></li>
<li><a class="dropdown-item" href="#">学生信息管理</a></li>
<li>
<hr class="dropdown-divider"/>
</li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li><a class="dropdown-item" href="#">学生成绩管理</a></li>
<li>
<hr class="dropdown-divider"/>
</li>
<li><a class="dropdown-item" href="#">学生选课管理</a></li>
<li><a class="dropdown-item" href="#">学生选课管理</a></li>
<li><a class="dropdown-item" href="#">学生选课管理</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown2" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
教师管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown2">
<li><a class="dropdown-item" href="#">教师信息管理</a></li>
<li><a class="dropdown-item" href="#">教师课程管理</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown3" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
课程管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown3">
<li><a class="dropdown-item" href="#">课程信息管理</a></li>
<li><a class="dropdown-item" href="#">课程安排管理</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown4" role="button"
data-mdb-toggle="dropdown" aria-expanded="false">
系统管理
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown4">
<li><a class="dropdown-item" href="#">个人设定</a></li>
<li><a class="dropdown-item" href="#">用户管理</a></li>
<li><a class="dropdown-item" href="#">日志管理</a></li>
<li><a class="dropdown-item" href="#">版本信息</a></li>
</ul>
</li>
</ul>
</div>
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>
<a class="dropdown-item" href="${pageContext.request.contextPath}/logout">登出</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!--Main Navigation-->
<!--Main layout-->
<main>
<div class="bg-image shadow-2-strong vh-100"
style="background-image: url('${pageContext.request.contextPath}/resources/img/jason-blackeye-nyL-rzwP-Mk-unsplash.jpg'); margin-top: -58.59px;">
<div class="mask d-flex align-items-center h-100" style="background-color: hsla(0, 0%, 100%, 0.5);">
<div class="container d-flex justify-content-center">
<button type="button" class="btn btn-primary" onclick="location.href='../dashboard'">返回</button>
<div class="container">
<div class="card rounded-4 shadow-3-strong" style="min-width: 244px">
<ul class="nav nav-tabs" id="ex1" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active fs-6" id="ex1-tab-1" data-mdb-toggle="tab" href="#ex1-tabs-1"
role="tab" aria-controls="ex1-tabs-1" aria-selected="true">高级设置</a>
</li>
</ul>
<hr class="hr" style="margin: 1px"/>
<div class="tab-content" id="ex1-content">
<div class="tab-pane fade show active" id="ex1-tabs-1" role="tabpanel"
aria-labelledby="ex1-tab-1">
<div class="card-body" style="min-width: 175px">
<div class="row">
<div class="col-lg-2 text-center">
<p>缓存文件大小:<mark>${trashSize}</mark></p>
</div>
</div>
<div class="row">
<div class="col-lg-2 text-center">
<button type="button" class="btn btn-secondary btn-lg" onclick="cleantrash()" data-mdb-toggle="tooltip" data-mdb-placement="bottom" title="这将会清除工作目录下的垃圾文件">清除缓存文件</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
<i class="fas fa-circle-info me-2"></i>提示
</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<c:if test="${not empty message}">
${message}
</c:if>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-mdb-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
</main>
<!--Main layout-->
<!-- Footer -->
<footer class="bg-link text-center text-lg-start ">
</footer>
<!-- Footer -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/mdb.min.js"></script>
<script>
$(document).ready(function () {
<c:if test="${not empty message && message ne 'null'}">
$('#exampleModal').modal('show');
</c:if>
});
function cleantrash(){
//click this button to clean (/system/clean)
window.location.href = "/system/clean";
}
</script>
</body>
</html>