增加文件重命名功能
This commit is contained in:
parent
ea3b73a10e
commit
7e6cfecacc
@ -9,6 +9,7 @@ public interface IFileService {
|
||||
void insertFile(FileBean fileBean);
|
||||
void batchInsertFile(List<FileBean> fileBeanList);
|
||||
void updateFile(FileBean fileBean);
|
||||
List<FileBean> selectFileByNameAndPath(FileBean fileBean);
|
||||
FileBean selectFileById(FileBean fileBean);
|
||||
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
||||
List<FileBean> selectFileList(FileBean fileBean);
|
||||
|
@ -27,8 +27,6 @@ public class FileController {
|
||||
|
||||
@Resource
|
||||
IFileService fileService;
|
||||
@Resource
|
||||
IFiletransferService filetransferService;
|
||||
|
||||
/**
|
||||
* 是否开启共享文件模式
|
||||
@ -37,16 +35,6 @@ public class FileController {
|
||||
|
||||
public static long treeid = 0;
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/fileindex")
|
||||
@ResponseBody
|
||||
public ModelAndView essayIndex() {
|
||||
ModelAndView mv = new ModelAndView("/file/fileIndex.html");
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
@ -59,7 +47,12 @@ public class FileController {
|
||||
if (!operationCheck().isSuccess()){
|
||||
return operationCheck();
|
||||
}
|
||||
|
||||
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(fileBean);
|
||||
if (fileBeans != null && !fileBeans.isEmpty()) {
|
||||
restResult.setErrorMessage("同名文件已存在");
|
||||
restResult.setSuccess(false);
|
||||
return restResult;
|
||||
}
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
fileBean.setUserId(sessionUserBean.getUserId());
|
||||
|
||||
@ -70,6 +63,37 @@ public class FileController {
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件重命名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/renamefile", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public RestResult<String> renameFile(@RequestBody FileBean fileBean) {
|
||||
RestResult<String> restResult = new RestResult<>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return operationCheck();
|
||||
}
|
||||
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
fileBean.setUserId(sessionUserBean.getUserId());
|
||||
fileBean.setUploadTime(DateUtil.getCurrentTime());
|
||||
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(fileBean);
|
||||
if (fileBeans != null && !fileBeans.isEmpty()) {
|
||||
restResult.setErrorMessage("同名文件已存在");
|
||||
restResult.setSuccess(false);
|
||||
return restResult;
|
||||
}
|
||||
if (1 == fileBean.getIsDir()) {
|
||||
fileBean.setOldFilePath(fileBean.getFilePath() + fileBean.getOldFileName() + "/");
|
||||
fileBean.setFilePath(fileBean.getFilePath() + fileBean.getFileName() + "/");
|
||||
}
|
||||
fileService.updateFile(fileBean);
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getfilelist", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RestResult<List<FileBean>> getFileList(FileBean fileBean){
|
||||
@ -228,7 +252,7 @@ public class FileController {
|
||||
return operationCheck();
|
||||
}
|
||||
String oldfilePath = fileBean.getOldFilePath();
|
||||
String newfilePath = fileBean.getNewFilePath();
|
||||
String newfilePath = fileBean.getFilePath();
|
||||
String fileName = fileBean.getFileName();
|
||||
String extendName = fileBean.getExtendName();
|
||||
|
||||
@ -253,7 +277,7 @@ public class FileController {
|
||||
}
|
||||
|
||||
String files = fileBean.getFiles();
|
||||
String newfilePath = fileBean.getNewFilePath();
|
||||
String newfilePath = fileBean.getFilePath();
|
||||
|
||||
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
||||
|
||||
|
@ -71,13 +71,23 @@ public class FileBean {
|
||||
|
||||
@Transient
|
||||
private String oldFilePath;
|
||||
// @Transient
|
||||
// private String newFilePath;
|
||||
@Transient
|
||||
private String newFilePath;
|
||||
private String oldFileName;
|
||||
@Transient
|
||||
private String files;
|
||||
@Transient
|
||||
private int fileType;
|
||||
|
||||
public String getOldFileName() {
|
||||
return oldFileName;
|
||||
}
|
||||
|
||||
public void setOldFileName(String oldFileName) {
|
||||
this.oldFileName = oldFileName;
|
||||
}
|
||||
|
||||
public long getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
@ -174,13 +184,13 @@ public class FileBean {
|
||||
this.oldFilePath = oldFilePath;
|
||||
}
|
||||
|
||||
public String getNewFilePath() {
|
||||
return newFilePath;
|
||||
}
|
||||
|
||||
public void setNewFilePath(String newFilePath) {
|
||||
this.newFilePath = newFilePath;
|
||||
}
|
||||
// public String getNewFilePath() {
|
||||
// return newFilePath;
|
||||
// }
|
||||
//
|
||||
// public void setNewFilePath(String newFilePath) {
|
||||
// this.newFilePath = newFilePath;
|
||||
// }
|
||||
|
||||
public String getFiles() {
|
||||
return files;
|
||||
|
@ -11,6 +11,7 @@ public interface FileMapper {
|
||||
void insertFile(FileBean fileBean);
|
||||
void batchInsertFile(List<FileBean> fileBeanList);
|
||||
void updateFile(FileBean fileBean);
|
||||
List<FileBean> selectFileByNameAndPath(FileBean fileBean);
|
||||
FileBean selectFileById(FileBean fileBean);
|
||||
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
||||
List<FileBean> selectFileList(FileBean fileBean);
|
||||
|
@ -53,6 +53,11 @@ public class FileService implements IFileService {
|
||||
fileMapper.updateFile(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBean> selectFileByNameAndPath(FileBean fileBean) {
|
||||
return fileMapper.selectFileByNameAndPath(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileBean selectFileById(FileBean fileBean) {
|
||||
return fileMapper.selectFileById(fileBean);
|
||||
|
@ -4,23 +4,19 @@ eureka.client.fetchRegistry=false
|
||||
eureka.client.server.waitTimeInMsWhenSyncEmpty=0
|
||||
#eureka.instance.hostname=localhost
|
||||
#eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:8761/eureka/
|
||||
spring.application.name=web
|
||||
spring.application.name=qiwen-file
|
||||
#日志配置
|
||||
logging.file=/qiwen/log/web.log
|
||||
logging.file=/qiwenshare/qiwen-file/log/web.log
|
||||
logging.level.root=info
|
||||
# 控制台日志输出格式
|
||||
# -5表示从左显示5个字符宽度
|
||||
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %boldYellow(%thread) | %boldGreen(%logger) | %msg%n
|
||||
# 文件中输出的格式
|
||||
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} = [%thread] = %-5level = %logger{50} - %msg%n
|
||||
|
||||
#mybatis配置
|
||||
mybatis.type-aliases-package=com.qiwenshare.file.domain
|
||||
mybatis.config-locations=classpath:mybatis/mybatis-config.xml
|
||||
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
|
||||
#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
#jdbc连接
|
||||
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.url = jdbc:mysql://localhost:3306/file?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8
|
||||
spring.datasource.url = jdbc:mysql://localhost:3306/file?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=ma123456
|
||||
|
||||
|
@ -26,9 +26,19 @@
|
||||
</insert>
|
||||
|
||||
<update id="updateFile" parameterType="com.qiwenshare.file.domain.FileBean">
|
||||
<choose>
|
||||
<when test="isDir == 1">
|
||||
UPDATE file SET filename=#{fileName}, uploadTime = #{uploadTime}
|
||||
where fileId = #{fileId};
|
||||
UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';
|
||||
</when>
|
||||
<otherwise>
|
||||
update file
|
||||
SET fileName = #{fileName}, uploadTime = #{uploadTime}
|
||||
where fileId = #{fileId}
|
||||
</otherwise>
|
||||
</choose>
|
||||
|
||||
</update>
|
||||
|
||||
|
||||
@ -96,6 +106,14 @@
|
||||
WHERE isDir = 1 and userId=#{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectFileByNameAndPath" parameterType="com.qiwenshare.file.domain.FileBean"
|
||||
resultType="com.qiwenshare.file.domain.FileBean">
|
||||
SELECT * FROM file
|
||||
WHERE filename = #{fileName} AND filepath = #{filePath}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<!-- <select id="selectFileByExtendName" resultType="FileBean" parameterType="java.lang.String">-->
|
||||
<!-- select * from file-->
|
||||
<!-- where extendName in-->
|
||||
|
Loading…
Reference in New Issue
Block a user