From b8de590d99cefd5e6ddf7a236d5a18e3cbe4a107 Mon Sep 17 00:00:00 2001 From: yxh Date: Wed, 25 Jun 2025 22:30:39 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app/common/logic/upload/upload.go | 39 ++++++++++++++-------- internal/app/common/model/common.go | 6 ++-- 2 files changed, 28 insertions(+), 17 deletions(-) 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))*$#排序参数不合法"` // 排序方式 }