diff --git a/internal/app/common/logic/upload/upload.go b/internal/app/common/logic/upload/upload.go index a310044..8397226 100644 --- a/internal/app/common/logic/upload/upload.go +++ b/internal/app/common/logic/upload/upload.go @@ -16,6 +16,7 @@ import ( "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/text/gregex" "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" @@ -73,14 +74,19 @@ func (s *sUpload) UploadFile(ctx context.Context, existsFile, err = service.SysAttachment().GetByMd5(ctx, md5) liberr.ErrIsNil(ctx, err, "获取文件信息失败") if existsFile != nil { - result = &model.UploadResponse{ - Size: existsFile.Size, - Path: existsFile.Path, - FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path, - Name: existsFile.Name, - Type: existsFile.MimeType, + if !gfile.Exists(g.Cfg().MustGet(ctx, "server.serverRoot").String() + "/" + existsFile.Path) { + //文件不存在,删除sysAttachment表中不存在的条目 + _ = service.SysAttachment().Delete(ctx, []int64{existsFile.Id}) + } else { + result = &model.UploadResponse{ + Size: existsFile.Size, + Path: existsFile.Path, + FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path, + Name: existsFile.Name, + Type: existsFile.MimeType, + } + return } - return } uploader := upload.GetUploader(upload.UploaderType(source)) if uploader == nil { @@ -266,14 +272,19 @@ func (s *sUpload) CheckMultipart(ctx context.Context, req *model.CheckMultipartR liberr.ErrIsNil(ctx, err, "获取文件信息失败") res = new(model.CheckMultipartRes) if existsFile != nil { - res.Attachment = &model.UploadResponse{ - Size: existsFile.Size, - Path: existsFile.Path, - FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path, - Name: existsFile.Name, - Type: existsFile.MimeType, + if !gfile.Exists(g.Cfg().MustGet(ctx, "server.serverRoot").String() + "/" + existsFile.Path) { + // 文件不存在,删除sysAttachment表中不存在的条目 + _ = service.SysAttachment().Delete(ctx, []int64{existsFile.Id}) + } else { + res.Attachment = &model.UploadResponse{ + Size: existsFile.Size, + Path: existsFile.Path, + FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path, + Name: existsFile.Name, + Type: existsFile.MimeType, + } + return } - return } uploader := upload.GetUploader(upload.UploaderType(req.DriverType)) diff --git a/internal/app/common/model/common.go b/internal/app/common/model/common.go index 611bcc1..b1f5982 100644 --- a/internal/app/common/model/common.go +++ b/internal/app/common/model/common.go @@ -9,9 +9,9 @@ package model // PageReq 公共请求参数 type PageReq struct { - DateRange []string `p:"dateRange"` //日期范围 - PageNum int `p:"pageNum"` //当前页码 - PageSize int `p:"pageSize"` //每页数 + DateRange []string `p:"dateRange"` //日期范围 + PageNum int `p:"pageNum"` //当前页码 + PageSize int `p:"pageSize"` //每页数 OrderBy string `p:"orderBy" v:"regex:^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?\\s+(asc|desc|ASC|DESC)(?:\\s*,\\s*[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?\\s+(asc|desc|ASC|DESC))*$#排序参数不合法"` // 排序方式 }