Finish some move things.
This commit is contained in:
parent
5936f917b3
commit
7f7fba0425
@ -101,10 +101,16 @@ func (this *DashboardService) maintain() {
|
||||
totalMatterNum := this.matterDao.CountBetweenTime(longTimeAgo, endTime)
|
||||
this.logger.Info("历史文件总数:%d", totalMatterNum)
|
||||
|
||||
matterSize := this.matterDao.SizeBetweenTime(startTime, endTime)
|
||||
var matterSize int64
|
||||
if matterNum != 0 {
|
||||
matterSize = this.matterDao.SizeBetweenTime(startTime, endTime)
|
||||
}
|
||||
this.logger.Info("文件大小:%d", matterSize)
|
||||
|
||||
totalMatterSize := this.matterDao.SizeBetweenTime(longTimeAgo, endTime)
|
||||
var totalMatterSize int64
|
||||
if totalMatterNum != 0 {
|
||||
totalMatterSize = this.matterDao.SizeBetweenTime(longTimeAgo, endTime)
|
||||
}
|
||||
this.logger.Info("历史文件总大小:%d", totalMatterSize)
|
||||
|
||||
cacheSize := this.imageCacheDao.SizeBetweenTime(startTime, endTime)
|
||||
|
@ -16,6 +16,7 @@ type ImageCacheService struct {
|
||||
Bean
|
||||
imageCacheDao *ImageCacheDao
|
||||
userDao *UserDao
|
||||
matterDao *MatterDao
|
||||
}
|
||||
|
||||
//初始化方法
|
||||
@ -33,6 +34,11 @@ func (this *ImageCacheService) Init() {
|
||||
this.userDao = b
|
||||
}
|
||||
|
||||
b = CONTEXT.GetBean(this.matterDao)
|
||||
if b, ok := b.(*MatterDao); ok {
|
||||
this.matterDao = b
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//获取某个文件的详情,会把父级依次倒着装进去。如果中途出错,直接抛出异常。
|
||||
@ -234,3 +240,21 @@ func (this *ImageCacheService) cacheImage(writer http.ResponseWriter, request *h
|
||||
|
||||
return imageCache
|
||||
}
|
||||
|
||||
//删除一个Matter的所有缓存文件。如果matter是文件夹,那么就删除该文件夹下的所有文件的缓存文件。
|
||||
func (this *ImageCacheService) Delete(matter *Matter) {
|
||||
|
||||
//目录的话递归删除。
|
||||
if matter.Dir {
|
||||
matters := this.matterDao.List(matter.Uuid, matter.UserUuid, nil)
|
||||
|
||||
for _, f := range matters {
|
||||
this.Delete(f)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
this.imageCacheDao.DeleteByMatterUuid(matter.Uuid)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,11 @@ import (
|
||||
|
||||
type MatterController struct {
|
||||
BaseController
|
||||
matterDao *MatterDao
|
||||
matterService *MatterService
|
||||
downloadTokenDao *DownloadTokenDao
|
||||
imageCacheDao *ImageCacheDao
|
||||
matterDao *MatterDao
|
||||
matterService *MatterService
|
||||
downloadTokenDao *DownloadTokenDao
|
||||
imageCacheDao *ImageCacheDao
|
||||
imageCacheService *ImageCacheService
|
||||
}
|
||||
|
||||
//初始化方法 start to develop v3.
|
||||
@ -40,6 +41,10 @@ func (this *MatterController) Init() {
|
||||
if b, ok := b.(*ImageCacheDao); ok {
|
||||
this.imageCacheDao = b
|
||||
}
|
||||
b = CONTEXT.GetBean(this.imageCacheService)
|
||||
if b, ok := b.(*ImageCacheService); ok {
|
||||
this.imageCacheService = b
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -470,6 +475,7 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
|
||||
|
||||
srcUuidsStr := request.FormValue("srcUuids")
|
||||
destUuid := request.FormValue("destUuid")
|
||||
userUuid := request.FormValue("userUuid")
|
||||
|
||||
var srcUuids []string
|
||||
//验证参数。
|
||||
@ -479,7 +485,6 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
|
||||
srcUuids = strings.Split(srcUuidsStr, ",")
|
||||
}
|
||||
|
||||
userUuid := request.FormValue("userUuid")
|
||||
user := this.checkUser(writer, request)
|
||||
if user.Role != USER_ROLE_ADMINISTRATOR {
|
||||
userUuid = user.Uuid
|
||||
@ -495,9 +500,13 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
|
||||
if destUuid == "" {
|
||||
this.PanicBadRequest("destUuid参数必填")
|
||||
} else {
|
||||
if destUuid != MATTER_ROOT {
|
||||
if destUuid == MATTER_ROOT {
|
||||
destMatter = NewRootMatter(user)
|
||||
} else {
|
||||
destMatter = this.matterService.Detail(destUuid)
|
||||
|
||||
if !destMatter.Dir {
|
||||
this.PanicBadRequest("目标不是文件夹")
|
||||
}
|
||||
if user.Role != USER_ROLE_ADMINISTRATOR && destMatter.UserUuid != user.Uuid {
|
||||
this.PanicUnauthorized("没有权限")
|
||||
}
|
||||
@ -514,40 +523,39 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
|
||||
this.PanicUnauthorized("没有权限")
|
||||
}
|
||||
|
||||
if srcMatter.Puuid == destUuid {
|
||||
if srcMatter.Puuid == destMatter.Uuid {
|
||||
this.PanicBadRequest("没有进行移动,操作无效!")
|
||||
}
|
||||
|
||||
//判断同级文件夹中是否有同名的文件
|
||||
count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, destUuid, srcMatter.Dir, srcMatter.Name)
|
||||
count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, destMatter.Uuid, srcMatter.Dir, srcMatter.Name)
|
||||
|
||||
if count > 0 {
|
||||
this.PanicBadRequest("【" + srcMatter.Name + "】在目标文件夹已经存在了,操作失败。")
|
||||
}
|
||||
|
||||
//判断和目标文件夹是否是同一个主人。
|
||||
if destUuid != MATTER_ROOT {
|
||||
if srcMatter.UserUuid != destMatter.UserUuid {
|
||||
panic("文件和目标文件夹的拥有者不是同一人")
|
||||
}
|
||||
if srcMatter.UserUuid != destMatter.UserUuid {
|
||||
panic("文件和目标文件夹的拥有者不是同一人")
|
||||
}
|
||||
|
||||
//文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。
|
||||
tmpMatter := destMatter
|
||||
for tmpMatter != nil {
|
||||
if uuid == tmpMatter.Uuid {
|
||||
panic("文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。")
|
||||
}
|
||||
tmpMatter = tmpMatter.Parent
|
||||
//文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。
|
||||
tmpMatter := destMatter
|
||||
for tmpMatter != nil {
|
||||
if uuid == tmpMatter.Uuid {
|
||||
panic("文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。")
|
||||
}
|
||||
|
||||
tmpMatter = tmpMatter.Parent
|
||||
}
|
||||
|
||||
srcMatters = append(srcMatters, srcMatter)
|
||||
}
|
||||
|
||||
for _, srcMatter := range srcMatters {
|
||||
srcMatter.Puuid = destUuid
|
||||
srcMatter = this.matterDao.Save(srcMatter)
|
||||
|
||||
//TODO:移动物理目录并且加锁。
|
||||
this.matterService.Move(srcMatter, destMatter)
|
||||
|
||||
}
|
||||
|
||||
return this.Success(nil)
|
||||
|
@ -33,3 +33,15 @@ func (Matter) TableName() string {
|
||||
func (this *Matter) AbsolutePath() string {
|
||||
return GetUserFileRootDir(this.Username) + this.Path
|
||||
}
|
||||
|
||||
//创建一个 ROOT 的matter,主要用于统一化处理移动复制等内容。
|
||||
func NewRootMatter(user *User) *Matter {
|
||||
matter := &Matter{}
|
||||
matter.Uuid = MATTER_ROOT
|
||||
matter.UserUuid = user.Uuid
|
||||
matter.Username = user.Username
|
||||
matter.Dir = true
|
||||
matter.Path = ""
|
||||
|
||||
return matter
|
||||
}
|
||||
|
@ -18,8 +18,9 @@ import (
|
||||
//@Service
|
||||
type MatterService struct {
|
||||
Bean
|
||||
matterDao *MatterDao
|
||||
userDao *UserDao
|
||||
matterDao *MatterDao
|
||||
userDao *UserDao
|
||||
imageCacheService *ImageCacheService
|
||||
}
|
||||
|
||||
//初始化方法
|
||||
@ -37,6 +38,11 @@ func (this *MatterService) Init() {
|
||||
this.userDao = b
|
||||
}
|
||||
|
||||
b = CONTEXT.GetBean(this.imageCacheService)
|
||||
if b, ok := b.(*ImageCacheService); ok {
|
||||
this.imageCacheService = b
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//根据一个文件夹路径,找到最后一个文件夹的uuid,如果中途出错,返回err.
|
||||
@ -625,3 +631,80 @@ func (this *MatterService) DownloadFile(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//调整一个Matter的path值
|
||||
func (this *MatterService) adjustPath(matter *Matter, parentMatter *Matter) {
|
||||
|
||||
if matter.Dir {
|
||||
//如果源是文件夹
|
||||
|
||||
//首先调整好自己
|
||||
matter.Path = parentMatter.Path + "/" + matter.Name
|
||||
matter = this.matterDao.Save(matter)
|
||||
|
||||
//调整该文件夹下文件的Path.
|
||||
matters := this.matterDao.List(matter.Uuid, matter.UserUuid, nil)
|
||||
|
||||
for _, m := range matters {
|
||||
this.adjustPath(m, matter)
|
||||
}
|
||||
|
||||
} else {
|
||||
//如果源是普通文件
|
||||
|
||||
matter.Path = parentMatter.Path + "/" + matter.Name
|
||||
matter = this.matterDao.Save(matter)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//将一个srcMatter放置到另一个destMatter(必须为文件夹)下
|
||||
func (this *MatterService) Move(srcMatter *Matter, destMatter *Matter) {
|
||||
|
||||
if !destMatter.Dir {
|
||||
this.PanicBadRequest("目标必须为文件夹")
|
||||
}
|
||||
|
||||
if srcMatter.Dir {
|
||||
//如果源是文件夹
|
||||
destAbsolutePath := destMatter.AbsolutePath() + "/" + srcMatter.Name
|
||||
srcAbsolutePath := srcMatter.AbsolutePath()
|
||||
|
||||
err := os.Rename(srcAbsolutePath, destAbsolutePath)
|
||||
this.PanicError(err)
|
||||
|
||||
//修改数据库中信息
|
||||
srcMatter.Puuid = destMatter.Uuid
|
||||
srcMatter.Path = destMatter.Path + "/" + srcMatter.Name
|
||||
srcMatter = this.matterDao.Save(srcMatter)
|
||||
|
||||
//调整该文件夹下文件的Path.
|
||||
matters := this.matterDao.List(srcMatter.Uuid, srcMatter.UserUuid, nil)
|
||||
|
||||
//调整该文件夹下面所有文件的Path值
|
||||
for _, m := range matters {
|
||||
this.adjustPath(m, srcMatter)
|
||||
}
|
||||
|
||||
} else {
|
||||
//如果源是普通文件
|
||||
|
||||
destAbsolutePath := destMatter.AbsolutePath() + "/" + srcMatter.Name
|
||||
srcAbsolutePath := srcMatter.AbsolutePath()
|
||||
|
||||
err := os.Rename(srcAbsolutePath, destAbsolutePath)
|
||||
this.PanicError(err)
|
||||
|
||||
//删除对应的缓存。
|
||||
this.imageCacheService.Delete(srcMatter)
|
||||
|
||||
//修改数据库中信息
|
||||
srcMatter.Puuid = destMatter.Uuid
|
||||
srcMatter.Path = destMatter.Path + "/" + srcMatter.Name
|
||||
srcMatter = this.matterDao.Save(srcMatter)
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user