增加文件重命名功能
This commit is contained in:
parent
ea3b73a10e
commit
7e6cfecacc
@ -9,6 +9,7 @@ public interface IFileService {
|
|||||||
void insertFile(FileBean fileBean);
|
void insertFile(FileBean fileBean);
|
||||||
void batchInsertFile(List<FileBean> fileBeanList);
|
void batchInsertFile(List<FileBean> fileBeanList);
|
||||||
void updateFile(FileBean fileBean);
|
void updateFile(FileBean fileBean);
|
||||||
|
List<FileBean> selectFileByNameAndPath(FileBean fileBean);
|
||||||
FileBean selectFileById(FileBean fileBean);
|
FileBean selectFileById(FileBean fileBean);
|
||||||
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
||||||
List<FileBean> selectFileList(FileBean fileBean);
|
List<FileBean> selectFileList(FileBean fileBean);
|
||||||
|
@ -27,8 +27,6 @@ public class FileController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
IFileService fileService;
|
IFileService fileService;
|
||||||
@Resource
|
|
||||||
IFiletransferService filetransferService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否开启共享文件模式
|
* 是否开启共享文件模式
|
||||||
@ -37,16 +35,6 @@ public class FileController {
|
|||||||
|
|
||||||
public static long treeid = 0;
|
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()){
|
if (!operationCheck().isSuccess()){
|
||||||
return operationCheck();
|
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();
|
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||||
fileBean.setUserId(sessionUserBean.getUserId());
|
fileBean.setUserId(sessionUserBean.getUserId());
|
||||||
|
|
||||||
@ -70,6 +63,37 @@ public class FileController {
|
|||||||
return restResult;
|
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)
|
@RequestMapping(value = "/getfilelist", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<List<FileBean>> getFileList(FileBean fileBean){
|
public RestResult<List<FileBean>> getFileList(FileBean fileBean){
|
||||||
@ -228,7 +252,7 @@ public class FileController {
|
|||||||
return operationCheck();
|
return operationCheck();
|
||||||
}
|
}
|
||||||
String oldfilePath = fileBean.getOldFilePath();
|
String oldfilePath = fileBean.getOldFilePath();
|
||||||
String newfilePath = fileBean.getNewFilePath();
|
String newfilePath = fileBean.getFilePath();
|
||||||
String fileName = fileBean.getFileName();
|
String fileName = fileBean.getFileName();
|
||||||
String extendName = fileBean.getExtendName();
|
String extendName = fileBean.getExtendName();
|
||||||
|
|
||||||
@ -253,7 +277,7 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String files = fileBean.getFiles();
|
String files = fileBean.getFiles();
|
||||||
String newfilePath = fileBean.getNewFilePath();
|
String newfilePath = fileBean.getFilePath();
|
||||||
|
|
||||||
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
||||||
|
|
||||||
|
@ -71,13 +71,23 @@ public class FileBean {
|
|||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private String oldFilePath;
|
private String oldFilePath;
|
||||||
|
// @Transient
|
||||||
|
// private String newFilePath;
|
||||||
@Transient
|
@Transient
|
||||||
private String newFilePath;
|
private String oldFileName;
|
||||||
@Transient
|
@Transient
|
||||||
private String files;
|
private String files;
|
||||||
@Transient
|
@Transient
|
||||||
private int fileType;
|
private int fileType;
|
||||||
|
|
||||||
|
public String getOldFileName() {
|
||||||
|
return oldFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldFileName(String oldFileName) {
|
||||||
|
this.oldFileName = oldFileName;
|
||||||
|
}
|
||||||
|
|
||||||
public long getFileId() {
|
public long getFileId() {
|
||||||
return fileId;
|
return fileId;
|
||||||
}
|
}
|
||||||
@ -174,13 +184,13 @@ public class FileBean {
|
|||||||
this.oldFilePath = oldFilePath;
|
this.oldFilePath = oldFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNewFilePath() {
|
// public String getNewFilePath() {
|
||||||
return newFilePath;
|
// return newFilePath;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setNewFilePath(String newFilePath) {
|
// public void setNewFilePath(String newFilePath) {
|
||||||
this.newFilePath = newFilePath;
|
// this.newFilePath = newFilePath;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public String getFiles() {
|
public String getFiles() {
|
||||||
return files;
|
return files;
|
||||||
|
@ -11,6 +11,7 @@ public interface FileMapper {
|
|||||||
void insertFile(FileBean fileBean);
|
void insertFile(FileBean fileBean);
|
||||||
void batchInsertFile(List<FileBean> fileBeanList);
|
void batchInsertFile(List<FileBean> fileBeanList);
|
||||||
void updateFile(FileBean fileBean);
|
void updateFile(FileBean fileBean);
|
||||||
|
List<FileBean> selectFileByNameAndPath(FileBean fileBean);
|
||||||
FileBean selectFileById(FileBean fileBean);
|
FileBean selectFileById(FileBean fileBean);
|
||||||
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
||||||
List<FileBean> selectFileList(FileBean fileBean);
|
List<FileBean> selectFileList(FileBean fileBean);
|
||||||
|
@ -53,6 +53,11 @@ public class FileService implements IFileService {
|
|||||||
fileMapper.updateFile(fileBean);
|
fileMapper.updateFile(fileBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FileBean> selectFileByNameAndPath(FileBean fileBean) {
|
||||||
|
return fileMapper.selectFileByNameAndPath(fileBean);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileBean selectFileById(FileBean fileBean) {
|
public FileBean selectFileById(FileBean fileBean) {
|
||||||
return fileMapper.selectFileById(fileBean);
|
return fileMapper.selectFileById(fileBean);
|
||||||
|
@ -4,23 +4,19 @@ eureka.client.fetchRegistry=false
|
|||||||
eureka.client.server.waitTimeInMsWhenSyncEmpty=0
|
eureka.client.server.waitTimeInMsWhenSyncEmpty=0
|
||||||
#eureka.instance.hostname=localhost
|
#eureka.instance.hostname=localhost
|
||||||
#eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:8761/eureka/
|
#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
|
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配置
|
||||||
mybatis.type-aliases-package=com.qiwenshare.file.domain
|
mybatis.type-aliases-package=com.qiwenshare.file.domain
|
||||||
mybatis.config-locations=classpath:mybatis/mybatis-config.xml
|
mybatis.config-locations=classpath:mybatis/mybatis-config.xml
|
||||||
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
|
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
|
||||||
|
#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
#jdbc连接
|
#jdbc连接
|
||||||
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
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.username=root
|
||||||
spring.datasource.password=ma123456
|
spring.datasource.password=ma123456
|
||||||
|
|
||||||
|
@ -26,9 +26,19 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateFile" parameterType="com.qiwenshare.file.domain.FileBean">
|
<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
|
update file
|
||||||
SET fileName = #{fileName}, uploadTime = #{uploadTime}
|
SET fileName = #{fileName}, uploadTime = #{uploadTime}
|
||||||
where fileId = #{fileId}
|
where fileId = #{fileId}
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
@ -96,6 +106,14 @@
|
|||||||
WHERE isDir = 1 and userId=#{userId}
|
WHERE isDir = 1 and userId=#{userId}
|
||||||
</select>
|
</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 id="selectFileByExtendName" resultType="FileBean" parameterType="java.lang.String">-->
|
||||||
<!-- select * from file-->
|
<!-- select * from file-->
|
||||||
<!-- where extendName in-->
|
<!-- where extendName in-->
|
||||||
|
Loading…
Reference in New Issue
Block a user