实现对文件是否重命名的控制,目前设定为管理员上传的文件不会重命名,完善日志输出存储
This commit is contained in:
@@ -4,6 +4,7 @@ import com.fjy.spring.domain.TbFile;
|
||||
import com.fjy.spring.enums.ResultEnum;
|
||||
import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.service.FileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import java.io.File;
|
||||
|
||||
@Controller
|
||||
@Slf4j
|
||||
public class DeleteController {
|
||||
@Autowired
|
||||
private FileService fileService;//文件相关数据库操作
|
||||
@@ -37,7 +39,7 @@ public class DeleteController {
|
||||
TbFile resfile = fileService.findFileById(tbFile);
|
||||
File filepath = new File(resfile.getColfilepath());
|
||||
if (!filepath.exists()) {
|
||||
System.out.println("删除文件失败:" + resfile.getColfilename() + "不存在!");
|
||||
log.error("删除文件失败:" + resfile.getColfilename() + "不存在!");
|
||||
} else {
|
||||
if (filepath.isFile()){
|
||||
deleteFile(resfile.getColfilepath(),resfile.getColfileid());
|
||||
@@ -60,14 +62,14 @@ public class DeleteController {
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (file.delete()) {
|
||||
fileService.deleteFileById(tbFile);
|
||||
System.out.println("删除单个文件" + fileName + "成功!");
|
||||
log.info("删除单个文件" + fileName + "成功!");
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("删除单个文件" + fileName + "失败!");
|
||||
log.info("删除单个文件" + fileName + "失败!");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
System.out.println("删除单个文件失败:" + fileName + "不存在!");
|
||||
log.info("删除单个文件失败:" + fileName + "不存在!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fjy.spring.enums.ResultEnum;
|
||||
import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.FileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -55,7 +56,7 @@ public class DownLoadController {
|
||||
@ResponseBody
|
||||
public List<TbFile> toDownloadOne(){
|
||||
TbUser user = (TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
|
||||
System.out.println(user.toString());
|
||||
//log.info(user.toString());
|
||||
List<TbFile> files = fileService.findByColuserid(user.getColuserid());
|
||||
//此处做空指针判断并抛出错误
|
||||
if (files!=null)
|
||||
@@ -81,12 +82,12 @@ public class DownLoadController {
|
||||
TbFile tbFile = fileService.findFileById(file);
|
||||
//TbFile tbFile = fileService.findFile(file);
|
||||
|
||||
System.out.println(tbFile.getColfilepath());
|
||||
//System.out.println(tbFile.getColfilepath());
|
||||
|
||||
String ctxPath = tbFile.getColfilepath();
|
||||
String downLoadPath = ctxPath;
|
||||
//String downLoadPath = ctxPath + tbFile.getColfilename();
|
||||
System.out.println(downLoadPath);
|
||||
//System.out.println(downLoadPath);
|
||||
try {
|
||||
long fileLength = new File(downLoadPath).length();
|
||||
response.setContentType("application/x-msdownload;");
|
||||
@@ -146,7 +147,7 @@ public class DownLoadController {
|
||||
// 要生成的压缩文件地址和文件名称
|
||||
String zipFileName=courseName+folder+".zip";
|
||||
String desPath = zipPath+"\\"+zipFileName;
|
||||
System.out.println("打包文件存储地址:"+desPath);
|
||||
//System.out.println("打包文件存储地址:"+desPath);
|
||||
|
||||
File zipFile = new File(desPath);
|
||||
ZipOutputStream zipStream = null;
|
||||
@@ -244,13 +245,13 @@ public class DownLoadController {
|
||||
if (f.isFile()) {
|
||||
fileList.add(f);
|
||||
} else if (f.isDirectory()) {
|
||||
System.out.println(f.getAbsolutePath());
|
||||
//log.info(f.getAbsolutePath());
|
||||
path.add(f.getAbsolutePath());
|
||||
getFileString(f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
for (File f1 : fileList) {
|
||||
System.out.println(f1.getName());
|
||||
//System.out.println(f1.getName());
|
||||
path.add(f1.getAbsolutePath());
|
||||
/*name[j]=f1.getName();j++;*/
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.FeedBackService;
|
||||
import com.fjy.spring.untils.RedirectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -19,6 +20,7 @@ import java.util.Date;
|
||||
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class FeedBackController {
|
||||
|
||||
@Autowired
|
||||
@@ -42,7 +44,7 @@ public class FeedBackController {
|
||||
feedBack.setUserid(user.getColuserid());
|
||||
RedirectUtil red = new RedirectUtil();
|
||||
if (feedBackService.addContent(feedBack)){
|
||||
System.out.println("写入数据库成功");
|
||||
log.info("反馈信息写入数据库成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.FileService;
|
||||
import com.fjy.spring.service.LogService;
|
||||
import com.fjy.spring.untils.FormatFileSizeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -25,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@Slf4j
|
||||
public class UpLoadController {
|
||||
|
||||
@Autowired
|
||||
@@ -91,13 +93,15 @@ public class UpLoadController {
|
||||
file.setColip(request.getRemoteAddr());
|
||||
file.setColuserid(user.getColuserid());
|
||||
if (fileService.addFile(file))
|
||||
System.out.println("记录写入数据库成功");
|
||||
log.info("记录写入数据库成功");
|
||||
//System.out.println("记录写入数据库成功");
|
||||
else
|
||||
System.out.println("记录写入数据库失败");
|
||||
log.error("记录写入数据库失败");
|
||||
//System.out.println("记录写入数据库失败");
|
||||
|
||||
System.out.println("文件上传到: " + uploadUrl + filename);
|
||||
System.out.println("文件大小: " + new FormatFileSizeUtil().GetFileSize(imageFile.getSize()));
|
||||
System.out.println("文件名: " + filename);
|
||||
log.info("文件上传到: " + uploadUrl + filename);
|
||||
log.info("文件大小: " + new FormatFileSizeUtil().GetFileSize(imageFile.getSize()));
|
||||
log.info("文件名: " + filename);
|
||||
|
||||
File targetFile = new File(uploadUrl + filename);
|
||||
if (!targetFile.exists()) {
|
||||
@@ -133,7 +137,8 @@ public class UpLoadController {
|
||||
@RequestMapping("/moreUpload")
|
||||
public void moreUpload(HttpServletRequest request,
|
||||
@RequestParam(value = "courseName",required = false) String courseName,
|
||||
@RequestParam(value = "folder",required = false) String folder) {
|
||||
@RequestParam(value = "folder",required = false) String folder,
|
||||
@RequestParam(value = "rename",required = true) boolean rename) {
|
||||
|
||||
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> files = multipartHttpServletRequest.getFileMap();
|
||||
@@ -142,8 +147,14 @@ public class UpLoadController {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateNowStr = sdf.format(date);
|
||||
String uploadUrl;
|
||||
//String uploadUrl = request.getSession().getServletContext().getRealPath("/") + "upload/";
|
||||
String uploadUrl = serverProperties.getFilePath()+ "upload/"+courseName+"/"+folder+"/";
|
||||
if (rename){
|
||||
uploadUrl = serverProperties.getFilePath()+ "upload/"+courseName+"/"+folder+"/";
|
||||
}else {
|
||||
uploadUrl = serverProperties.getFilePath()+ "upload/";
|
||||
}
|
||||
|
||||
|
||||
File dir = new File(uploadUrl);
|
||||
if (!dir.exists()) {
|
||||
@@ -155,35 +166,43 @@ public class UpLoadController {
|
||||
for (MultipartFile file : files.values()) {
|
||||
String filename = file.getOriginalFilename();
|
||||
String suffix = "."+filename.substring(filename.lastIndexOf(".") + 1);//获取文件后缀
|
||||
|
||||
File targetFile = new File(uploadUrl + user.getColstudentno()+user.getColrealname()+suffix);
|
||||
|
||||
System.out.println("文件上传到: " + uploadUrl + filename);
|
||||
System.out.println("文件大小: " + new FormatFileSizeUtil().GetFileSize(file.getSize()));
|
||||
System.out.println("文件名: " + filename);
|
||||
|
||||
TbFile tbFile = new TbFile();
|
||||
String pathname;
|
||||
if (rename){
|
||||
pathname = uploadUrl + user.getColstudentno()+user.getColrealname()+suffix;
|
||||
tbFile.setColfilename(user.getColstudentno()+user.getColrealname()+suffix);
|
||||
}else {
|
||||
pathname = uploadUrl + filename;
|
||||
tbFile.setColfilename(filename);
|
||||
}
|
||||
File targetFile = new File(pathname);
|
||||
|
||||
log.info("文件上传到: " + uploadUrl + filename);
|
||||
log.info("文件大小: " + new FormatFileSizeUtil().GetFileSize(file.getSize()));
|
||||
log.info("文件名: " + filename);
|
||||
|
||||
|
||||
tbFile.setColfilesize(new FormatFileSizeUtil().GetFileSize(file.getSize()));
|
||||
tbFile.setColfilename(user.getColstudentno()+user.getColrealname()+suffix);
|
||||
|
||||
tbFile.setColtime(dateNowStr);
|
||||
tbFile.setColrealname(filename);
|
||||
tbFile.setColfilepath(uploadUrl + user.getColstudentno()+user.getColrealname()+suffix);//文件自动学号+姓名命名
|
||||
tbFile.setColfilepath(pathname);//文件自动学号+姓名命名
|
||||
tbFile.setColip(request.getRemoteAddr());
|
||||
tbFile.setColuserid(user.getColuserid());
|
||||
tbFile.setCourseName(courseName);
|
||||
tbFile.setWorkFolder(folder);
|
||||
|
||||
TbLog log = new TbLog();
|
||||
log.setUserid(user.getColuserid());
|
||||
log.setColtime(dateNowStr);
|
||||
log.setColip(httpServletRequest.getRemoteAddr());
|
||||
log.setColheader(user.getColname()+"上传了"+filename+"文件");
|
||||
logService.addLogRec(log);
|
||||
TbLog logs = new TbLog();
|
||||
logs.setUserid(user.getColuserid());
|
||||
logs.setColtime(dateNowStr);
|
||||
logs.setColip(httpServletRequest.getRemoteAddr());
|
||||
logs.setColheader(user.getColname()+"上传了'"+filename+"'文件");
|
||||
logService.addLogRec(logs);
|
||||
|
||||
if (fileService.addFile(tbFile))
|
||||
System.out.println("记录写入数据库成功");
|
||||
log.info("记录写入数据库成功");
|
||||
else
|
||||
System.out.println("记录写入数据库失败");
|
||||
log.error("记录写入数据库失败");
|
||||
|
||||
if (!targetFile.exists()) {
|
||||
try {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.UserService;
|
||||
import com.fjy.spring.untils.CodingUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
@@ -16,6 +17,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigInteger;
|
||||
|
||||
@Controller
|
||||
@Slf4j
|
||||
public class UpdateController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@@ -36,7 +38,7 @@ public class UpdateController {
|
||||
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
||||
}
|
||||
if (userService.doRegisterService(tbUser)){
|
||||
System.out.println(tbUser.getColname()+" 信息更新成功");
|
||||
log.info(tbUser.getColname()+" 信息更新成功");
|
||||
return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";
|
||||
// return "login";
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<configuration>
|
||||
|
||||
<!--<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<pattern>
|
||||
%d - %msg%n
|
||||
</pattern>
|
||||
</layout>
|
||||
</appender>-->
|
||||
</appender>
|
||||
<!--每天输出一个文件,使用RollingFileAppender滚动输出策略-->
|
||||
<appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!--根据范围仅保留info的日志-->
|
||||
@@ -48,7 +48,7 @@
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<!--<appender-ref ref="consoleLog"/>-->
|
||||
<appender-ref ref="consoleLog"/>
|
||||
<appender-ref ref="fileInfoLog"/>
|
||||
<appender-ref ref="fileErrorLog"/>
|
||||
</root>
|
||||
|
||||
@@ -5,6 +5,7 @@ var Main = {
|
||||
form: {
|
||||
content: '',
|
||||
},
|
||||
fileList: [],
|
||||
feedbackData:[
|
||||
{
|
||||
id: 68,
|
||||
@@ -60,6 +61,18 @@ var Main = {
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
uploadURL(row) {
|
||||
return getRootPath_web()+"/moreUpload?rename=false";
|
||||
},
|
||||
submitUpload() {
|
||||
this.$refs.upload.submit();
|
||||
},
|
||||
handleRemove(file, fileList) {
|
||||
console.log(file, fileList);
|
||||
},
|
||||
handlePreview(file) {
|
||||
console.log(file);
|
||||
},
|
||||
ClickToJump(targe){
|
||||
window.location.href=getRootPath_web()+"/" + targe;
|
||||
},
|
||||
|
||||
@@ -328,7 +328,7 @@ var Main = {
|
||||
});
|
||||
},
|
||||
uploadURL(row) {
|
||||
return getRootPath_web()+"/moreUpload?courseName=" + row.coursename + "&folder=" + row.workfolder;
|
||||
return getRootPath_web()+"/moreUpload?courseName=" + row.coursename + "&folder=" + row.workfolder+"&rename=true";
|
||||
},
|
||||
limitTime(row) {
|
||||
return DateDiff(row.worktime.replace(/([^\s]+)\s.*/, "$1"), cur);
|
||||
|
||||
@@ -18,6 +18,21 @@
|
||||
</el-row>
|
||||
</el-col>
|
||||
<el-col :md="13" :lg="13" :xl="13" :sm="18" :xs="23" :offset="1">
|
||||
<el-row>
|
||||
<span>上传模板文件</span>
|
||||
<el-upload class="upload-demo" ref="upload"
|
||||
:action="uploadURL()"
|
||||
:on-preview="handlePreview"
|
||||
:on-remove="handleRemove" :file-list="fileList" :auto-upload="false"
|
||||
name="imageFile">
|
||||
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
||||
<el-button style="margin-left: 10px;" size="small" type="success"
|
||||
@click="submitUpload">
|
||||
上传到服务器
|
||||
</el-button>
|
||||
<!--<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>-->
|
||||
</el-upload>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<h4>发布公告</h4>
|
||||
<el-form :model="form">
|
||||
|
||||
Reference in New Issue
Block a user