mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 03:33:53 +08:00
模块化上传驱动,使用泛型优化工具库降低冗余
This commit is contained in:
@@ -5,15 +5,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao/internal"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/format"
|
||||
)
|
||||
|
||||
// internalSysAttachmentDao is internal type for wrapping internal DAO implements.
|
||||
@@ -31,34 +23,3 @@ var (
|
||||
internal.NewSysAttachmentDao(),
|
||||
}
|
||||
)
|
||||
|
||||
func (dao *sysAttachmentDao) GetMd5File(ctx context.Context, md5 string) (data *sysin.AttachmentListModel, err error) {
|
||||
if err = dao.Ctx(ctx).
|
||||
Where("md5", md5).
|
||||
Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
conf, err := service.SysConfig().GetUpload(ctx)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
data.SizeFormat = format.FileSize(data.Size)
|
||||
data.FileUrl = service.CommonUpload().LastUrl(ctx, conf, data.FileUrl, data.Drive)
|
||||
|
||||
// 只有在上传时才会检查md5值,如果文件存在则更新最后上传时间,保证上传列表更新显示在最前面
|
||||
if data.Id > 0 {
|
||||
_, _ = dao.Ctx(ctx).Where("id", data.Id).Data(g.Map{
|
||||
"status": consts.StatusEnabled,
|
||||
"updated_at": gtime.Now(),
|
||||
}).Update()
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user