fix(文件复制): 完善文件复制功能

This commit is contained in:
MAC 2021-12-02 23:08:06 +08:00
parent 5b8eb58984
commit 70dbd8a7b5
7 changed files with 61 additions and 7 deletions

View File

@ -305,11 +305,11 @@ public class FileController {
if (userFile.getIsDir() == 1) {
String testFilePath = oldfilePath + fileName + "/";
if (newfilePath.startsWith(testFilePath)) {
return RestResult.fail().message("原路径与目标路径冲突,不能移动");
return RestResult.fail().message("原路径与目标路径冲突,不能复制");
}
}
userFileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId());
userFileService.userFileCopy(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId());
return RestResult.success();
}

View File

@ -39,4 +39,16 @@ public class FileBean {
@Column(columnDefinition="varchar(32)")
private String identifier;
@Column(columnDefinition="varchar(25)")
private String createTime;
@Column(columnDefinition="bigint(20)")
private Long createUserId;
@Column(columnDefinition="varchar(25)")
private String modifyTime;
@Column(columnDefinition="bigint(20)")
private Long modifyUserId;
}

View File

@ -11,10 +11,14 @@ public interface FileMapper extends BaseMapper<FileBean> {
void batchInsertFile(List<FileBean> fileBeanList);
// void updateFile(FileBean fileBean);
void incPointCountByPathAndName(@Param("oldFilePath") String oldFilePath,
@Param("fileName") String fileName,
@Param("extendName") String extendName,
@Param("userId") long userId);
void incPointCountByByFilepath(@Param("oldFilePath") String oldFilePath,
@Param("userId") long userId);

View File

@ -92,6 +92,8 @@ public class FiletransferService implements IFiletransferService {
fileBean.setFileSize(uploadFileResult.getFileSize());
fileBean.setStorageType(uploadFileResult.getStorageType().getCode());
fileBean.setPointCount(1);
fileBean.setCreateTime(DateUtil.getCurrentTime());
fileBean.setCreateUserId(userId);
fileMapper.insert(fileBean);
UserFile userFile = new UserFile();

View File

@ -116,8 +116,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
}
userFileMapper.batchInsertByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId);
//移动根目录
// userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId);
fileMapper.incPointCountByPathAndName(newfilePath, fileName, extendName, userId);
//移动子目录
oldfilePath = oldfilePath + fileName + "/";
@ -130,6 +129,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
if (extendName == null) { //为null说明是目录则需要移动子目录
userFileMapper.batchInsertByFilepath(oldfilePath, newfilePath, userId);
fileMapper.incPointCountByByFilepath(oldfilePath, userId);
}
}

View File

@ -43,7 +43,7 @@ spring.servlet.multipart.enabled=true
spring.main.allow-bean-definition-overriding=true
mybatis-plus.type-aliases-package=com.qiwenshare.web.domain
mybatis-plus.type-aliases-package=com.qiwenshare.file.domain
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis-plus.configuration.map-underscore-to-camel-case=false
mybatis-plus.global-config.banner=false

View File

@ -16,5 +16,41 @@
#{file.fileSize}, #{file.isDir})
</foreach>
</insert>
<update id="incPointCountByPathAndName">
update file
set pointCount = pointCount + 1
where fileId in (
select fileId from userfile
<where>
<if test="userId != 0">
and userId = #{userId}
</if>
<if test="fileName != null">
and fileName = #{fileName}
</if>
<if test="oldFilePath != null">
and filePath = #{oldFilePath}
</if>
<if test="extendName != null">
and extendName = #{extendName}
</if>
and isDir = 0
</where>
)
</update>
<update id="incPointCountByByFilepath">
update file
set pointCount = pointCount + 1
where fileId in (
select fileId from userfile
where
filePath like N'${oldFilePath}%'
and userId = #{userId}
and isDir = 0
)
</update>
</mapper>