Files
slogan/styleagent/dao/plan_effect_image_dao.go
T
adminandClaude Opus 4.7 ef22f7672a feat: slogan-agent MVP 服务端完整实现
- 用户域:注册/登录(JWT)/修改密码/个人资料
- 照片/衣橱/身形/化身:上传存储 + 3D 化身模板匹配
- 穿搭生成:天气(高德+和风+缓存) → 规则预筛 → LLM 规划(1次调用)
  → 规则评分(5维100分制) → 全低分触发 LLM 兜底创作 → 异步任务状态机
- 效果图:选主方案后异步生成 3 视角(mock/wanx 供应商 + 内容 hash 缓存 + 每日限额)
- 商业化:合作门店列表(seed 4 家)
- 冒烟:全链路端到端验证通过(mock LLM/天气),23 个 API 端点

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-31 12:15:11 +08:00

74 lines
2.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dao
import (
"context"
"slogan-agent/styleagent/consts"
"slogan-agent/styleagent/model/entity"
"github.com/gogf/gf/v2/frame/g"
)
var PlanEffectImage = &planEffectImageDao{}
type planEffectImageDao struct{}
func init() {
ctx := context.Background()
_, err := g.DB().Exec(ctx, `CREATE TABLE IF NOT EXISTS `+consts.TableNamePlanEffectImage+` (
id INTEGER PRIMARY KEY AUTOINCREMENT,
plan_id INTEGER NOT NULL,
angle TEXT NOT NULL DEFAULT '',
url TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'pending',
prompt_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 plan_effect_image table failed: %v", err)
}
_, _ = g.DB().Exec(ctx, "CREATE INDEX IF NOT EXISTS idx_slogan_effect_plan ON "+consts.TableNamePlanEffectImage+"(plan_id)")
}
func (d *planEffectImageDao) Insert(ctx context.Context, data *entity.PlanEffectImage) (int64, error) {
r, err := g.DB().Exec(ctx,
"INSERT INTO "+consts.TableNamePlanEffectImage+" (plan_id, angle, url, status, prompt_snapshot, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now','localtime'), datetime('now','localtime'))",
data.PlanId, data.Angle, data.Url, data.Status, data.PromptSnapshot)
if err != nil {
return 0, err
}
return r.LastInsertId()
}
func (d *planEffectImageDao) ListByPlan(ctx context.Context, planId int64) ([]*entity.PlanEffectImage, error) {
var list []*entity.PlanEffectImage
err := g.DB().Model(consts.TableNamePlanEffectImage).Ctx(ctx).
Where("plan_id", planId).OrderAsc("id").Scan(&list)
return list, err
}
// CountByUserToday 统计用户当日已生成的效果图数量(join outfit_plan 拿 user_id
func (d *planEffectImageDao) CountByUserToday(ctx context.Context, userId int64) (int, error) {
n, err := g.DB().Model(consts.TableNamePlanEffectImage+" p").
InnerJoin(consts.TableNameOutfitPlan+" o", "p.plan_id = o.id").
Ctx(ctx).
Where("o.user_id", userId).
Where("date(p.created_at) = date('now','localtime')").
Where("p.status IN (?)", g.Slice{consts.EffectStatusDone, consts.EffectStatusRendering}).
Count()
return n, err
}
func (d *planEffectImageDao) UpdateStatus(ctx context.Context, id int64, status, url string) error {
_, err := g.DB().Model(consts.TableNamePlanEffectImage).Ctx(ctx).Data(g.Map{
"status": status, "url": url, "updated_at": "datetime('now','localtime')",
}).Where("id", id).Update()
return err
}
func (d *planEffectImageDao) DeleteByPlan(ctx context.Context, planId int64) error {
_, err := g.DB().Model(consts.TableNamePlanEffectImage).Ctx(ctx).
Unscoped().Where("plan_id", planId).Delete()
return err
}