1
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -17,29 +17,47 @@ type avatarModelDao struct{}
|
||||
func init() {
|
||||
ctx := context.Background()
|
||||
_, err := g.DB().Exec(ctx, `CREATE TABLE IF NOT EXISTS `+consts.TableNameAvatarModel+` (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL UNIQUE,
|
||||
face_template_id INTEGER NOT NULL DEFAULT 0,
|
||||
body_template_id INTEGER NOT NULL DEFAULT 0,
|
||||
skin_tone_index INTEGER NOT NULL DEFAULT 0,
|
||||
face_texture_url TEXT NOT NULL DEFAULT '',
|
||||
glb_url TEXT NOT NULL DEFAULT '',
|
||||
build_status TEXT NOT NULL DEFAULT 'pending',
|
||||
error TEXT NOT NULL DEFAULT '',
|
||||
params_snapshot TEXT NOT NULL DEFAULT '',
|
||||
created_at DATETIME DEFAULT (datetime('now','localtime')),
|
||||
updated_at DATETIME DEFAULT (datetime('now','localtime'))
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL UNIQUE,
|
||||
glb_url TEXT NOT NULL DEFAULT '',
|
||||
build_status TEXT NOT NULL DEFAULT 'pending',
|
||||
error TEXT NOT NULL DEFAULT '',
|
||||
params_snapshot TEXT NOT NULL DEFAULT '',
|
||||
created_at DATETIME DEFAULT (datetime('now','localtime')),
|
||||
updated_at DATETIME DEFAULT (datetime('now','localtime'))
|
||||
)`)
|
||||
if err != nil {
|
||||
g.Log().Warningf(ctx, "create avatar_model table failed: %v", err)
|
||||
}
|
||||
// 迁移:移除已废弃列(模板/肤色/纹理从未写入,frames_url 已从代码删除)
|
||||
for _, col := range []string{"face_template_id", "body_template_id", "skin_tone_index", "face_texture_url", "frames_url"} {
|
||||
if !avatarColumnExists(ctx, consts.TableNameAvatarModel, col) {
|
||||
continue
|
||||
}
|
||||
if _, err := g.DB().Exec(ctx, "ALTER TABLE "+consts.TableNameAvatarModel+" DROP COLUMN "+col); err != nil {
|
||||
g.Log().Warningf(ctx, "drop avatar_model column %s failed: %v", col, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func avatarColumnExists(ctx context.Context, table, column string) bool {
|
||||
rows, err := g.DB().Ctx(ctx).Query(ctx, "PRAGMA table_info("+table+")")
|
||||
if err != nil {
|
||||
g.Log().Warningf(ctx, "query avatar_model columns failed: %v", err)
|
||||
return false
|
||||
}
|
||||
for _, r := range rows {
|
||||
if r["name"].String() == column {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *avatarModelDao) Insert(ctx context.Context, data *entity.AvatarModel) (int64, error) {
|
||||
r, err := g.DB().Exec(ctx,
|
||||
"INSERT INTO "+consts.TableNameAvatarModel+" (user_id, face_template_id, body_template_id, skin_tone_index, face_texture_url, glb_url, build_status, error, params_snapshot, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now','localtime'), datetime('now','localtime'))",
|
||||
data.UserId, data.FaceTemplateId, data.BodyTemplateId, data.SkinToneIndex,
|
||||
data.FaceTextureUrl, data.GlbUrl, data.BuildStatus, data.Error, data.ParamsSnapshot)
|
||||
"INSERT INTO "+consts.TableNameAvatarModel+" (user_id, glb_url, build_status, error, params_snapshot, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now','localtime'), datetime('now','localtime'))",
|
||||
data.UserId, data.GlbUrl, data.BuildStatus, data.Error, data.ParamsSnapshot)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@ type AvatarGetReq struct {
|
||||
}
|
||||
|
||||
type AvatarGetRes struct {
|
||||
FaceTemplateId int `json:"face_template_id"`
|
||||
BodyTemplateId int `json:"body_template_id"`
|
||||
SkinToneIndex int `json:"skin_tone_index"`
|
||||
GlbUrl string `json:"glb_url"`
|
||||
BuildStatus string `json:"build_status"`
|
||||
Error string `json:"error"`
|
||||
GlbUrl string `json:"glb_url"`
|
||||
BuildStatus string `json:"build_status"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
@@ -5,10 +5,6 @@ import "github.com/gogf/gf/v2/os/gtime"
|
||||
type AvatarModel struct {
|
||||
Id int64 `orm:"id" json:"id"`
|
||||
UserId int64 `orm:"user_id" json:"user_id"`
|
||||
FaceTemplateId int `orm:"face_template_id" json:"face_template_id"`
|
||||
BodyTemplateId int `orm:"body_template_id" json:"body_template_id"`
|
||||
SkinToneIndex int `orm:"skin_tone_index" json:"skin_tone_index"`
|
||||
FaceTextureUrl string `orm:"face_texture_url" json:"face_texture_url"`
|
||||
GlbUrl string `orm:"glb_url" json:"glb_url"`
|
||||
BuildStatus string `orm:"build_status" json:"build_status"`
|
||||
Error string `orm:"error" json:"error"`
|
||||
|
||||
@@ -66,7 +66,6 @@ func (s *avatarService) Build(ctx context.Context, userId int64) (*dto.AvatarBui
|
||||
return avatarBuildOutcome{id: existing.Id}, nil
|
||||
}
|
||||
if err := dao.AvatarModel.Update(ctx, existing.Id, map[string]any{
|
||||
"face_template_id": 0, "body_template_id": 0, "skin_tone_index": 0,
|
||||
"glb_url": "",
|
||||
"build_status": consts.AvatarBuildProcessing, "error": "",
|
||||
"params_snapshot": snapshot,
|
||||
@@ -201,9 +200,7 @@ func (s *avatarService) Get(ctx context.Context, userId int64) (*dto.AvatarGetRe
|
||||
return &dto.AvatarGetRes{}, nil
|
||||
}
|
||||
return &dto.AvatarGetRes{
|
||||
FaceTemplateId: a.FaceTemplateId, BodyTemplateId: a.BodyTemplateId,
|
||||
SkinToneIndex: a.SkinToneIndex, GlbUrl: a.GlbUrl,
|
||||
BuildStatus: a.BuildStatus, Error: a.Error,
|
||||
GlbUrl: a.GlbUrl, BuildStatus: a.BuildStatus, Error: a.Error,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user