From ae6b4aa0d3762f27461877084d323270915aa3db Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 30 Oct 2023 16:02:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=B8=8A=E4=BC=A0logo--debug=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_preprocess_logo_gen.go | 3 +- model/gmodel/fs_user_debug_gen.go | 22 +++++++++ model/gmodel/fs_user_debug_logic.go | 2 + model/gmodel/var_gen.go | 2 + .../internal/logic/uploadlogodebuglogic.go | 46 +++++++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 model/gmodel/fs_user_debug_gen.go create mode 100644 model/gmodel/fs_user_debug_logic.go diff --git a/model/gmodel/fs_preprocess_logo_gen.go b/model/gmodel/fs_preprocess_logo_gen.go index 103e3912..53a6f572 100644 --- a/model/gmodel/fs_preprocess_logo_gen.go +++ b/model/gmodel/fs_preprocess_logo_gen.go @@ -11,6 +11,8 @@ type FsPreprocessLogo struct { LocationCode *string `gorm:"index;default:'';" json:"location_code"` // RestaurantName *string `gorm:"index;default:'';" json:"restaurant_name"` // ResourceUrl *string `gorm:"default:'';" json:"resource_url"` // + ResourceVectorUrl *string `gorm:"default:'';" json:"resource_vector_url"` // + OriginFileName *string `gorm:"default:'';" json:"origin_file_name"` // RestaurantType *string `gorm:"default:'';" json:"restaurant_type"` // Address *string `gorm:"default:'';" json:"address"` // ZipCode *string `gorm:"default:'';" json:"zip_code"` // @@ -21,7 +23,6 @@ type FsPreprocessLogo struct { Source *string `gorm:"index;default:'';" json:"source"` // Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // - ResourceVectorUrl *string `gorm:"default:'';" json:"resource_vector_url"` // } type FsPreprocessLogoModel struct { db *gorm.DB diff --git a/model/gmodel/fs_user_debug_gen.go b/model/gmodel/fs_user_debug_gen.go new file mode 100644 index 00000000..54a33f9b --- /dev/null +++ b/model/gmodel/fs_user_debug_gen.go @@ -0,0 +1,22 @@ +package gmodel + +import ( + "gorm.io/gorm" + "time" +) + +// fs_user_debug 用户debug +type FsUserDebug struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 用户 ID + Metadata *[]byte `gorm:"default:'';" json:"metadata"` // + Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // 时间 + GuestId *int64 `gorm:"default:0;" json:"guest_id"` // +} +type FsUserDebugModel struct { + db *gorm.DB + name string +} + +func NewFsUserDebugModel(db *gorm.DB) *FsUserDebugModel { + return &FsUserDebugModel{db: db, name: "fs_user_debug"} +} diff --git a/model/gmodel/fs_user_debug_logic.go b/model/gmodel/fs_user_debug_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_user_debug_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index fc9bfc38..91fb2139 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -108,6 +108,7 @@ type AllModelsGen struct { FsToolUser *FsToolUserModel // fs_tool_user 3d设计工具用户表 FsTrade *FsTradeModel // fs_trade FsUser *FsUserModel // fs_user 用户表 + FsUserDebug *FsUserDebugModel // fs_user_debug 用户debug FsUserDesign *FsUserDesignModel // fs_user_design 废弃表 FsUserInfo *FsUserInfoModel // fs_user_info 用户信息表 FsUserMaterial *FsUserMaterialModel // fs_user_material 用户素材表 @@ -222,6 +223,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen { FsToolUser: NewFsToolUserModel(gdb), FsTrade: NewFsTradeModel(gdb), FsUser: NewFsUserModel(gdb), + FsUserDebug: NewFsUserDebugModel(gdb), FsUserDesign: NewFsUserDesignModel(gdb), FsUserInfo: NewFsUserInfoModel(gdb), FsUserMaterial: NewFsUserMaterialModel(gdb), diff --git a/server/upload/internal/logic/uploadlogodebuglogic.go b/server/upload/internal/logic/uploadlogodebuglogic.go index a1aacbcd..b5c9d180 100644 --- a/server/upload/internal/logic/uploadlogodebuglogic.go +++ b/server/upload/internal/logic/uploadlogodebuglogic.go @@ -13,12 +13,14 @@ import ( "fusenapi/utils/s3url_to_s3id" "io" "net/http" + "time" "context" "fusenapi/server/upload/internal/svc" "fusenapi/server/upload/internal/types" + "github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" ) @@ -149,6 +151,50 @@ func (l *UploadLogoDebugLogic) UploadLogoDebug(req *types.UploadLogoDebugReq, us return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err)) } resultStr = resLogoStandard.Res + resultStrB := []byte(resultStr) + + var module = "logo" + var nowTime = time.Now().UTC() + // 新增素材记录 + materialInfo := gmodel.FsUserMaterial{ + Module: &module, + UserId: &userId, + GuestId: &guestId, + ResourceId: &uploadRes.ResourceId, + ResourceUrl: &uploadRes.ResourceUrl, + Metadata: &resultStrB, + Ctime: &nowTime, + } + err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { + var userDebug gmodel.FsUserDebug + res01 := tx.Model(&gmodel.FsUserDebug{}).Where("guest_id = ?", guestId).Take(&userDebug) + if res01.Error != nil { + if !errors.Is(res01.Error, gorm.ErrRecordNotFound) { + logc.Errorf(l.ctx, "FsUserDebug Take err:%+v", res01.Error) + return res01.Error + } else { + res02 := tx.Model(&gmodel.FsUserDebug{}).Create(&gmodel.FsUserDebug{ + GuestId: &guestId, + Ctime: &nowTime, + }) + if res02.Error != nil { + logc.Errorf(l.ctx, "FsUserDebug Create err:%+v", res02.Error) + return res02.Error + } + } + } + resCreate := tx.Create(&materialInfo) + err = resCreate.Error + if err != nil { + logc.Errorf(l.ctx, "FsUserMaterial Create err:%+v", err) + return err + } + return nil + }) + + if err != nil { + return resp.SetStatusWithMessage(basic.CodeApiErr, "") + } //解析用户素材元数据 var metaData map[string]interface{}