first commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package mysqldao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/global"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/mysqlmodel"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// HoroscopeDao 运势数据访问
|
||||
type HoroscopeDao struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewHoroscopeDao 创建运势 DAO
|
||||
func NewHoroscopeDao() *HoroscopeDao {
|
||||
return &HoroscopeDao{db: global.MysqlEngine}
|
||||
}
|
||||
|
||||
// HoroscopeCreate 创建运势记录
|
||||
func (d *HoroscopeDao) HoroscopeCreate(ctx context.Context, horoscope *mysqlmodel.Horoscope) error {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.HoroscopeCreate")
|
||||
defer span.End()
|
||||
|
||||
if err := d.db.WithContext(ctx).Create(horoscope).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// HoroscopeGetByZodiacAndDate 按星座和日期查询运势(幂等)
|
||||
func (d *HoroscopeDao) HoroscopeGetByZodiacAndDate(ctx context.Context, zodiac string, statDate int64) (*mysqlmodel.Horoscope, error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.HoroscopeGetByZodiacAndDate")
|
||||
defer span.End()
|
||||
|
||||
var horoscope mysqlmodel.Horoscope
|
||||
if err := d.db.WithContext(ctx).Where("zodiac = ? AND stat_date = ?", zodiac, statDate).First(&horoscope).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return nil, err
|
||||
}
|
||||
return &horoscope, nil
|
||||
}
|
||||
|
||||
// HoroscopeGetByDate 按日期查询当日全部星座运势。
|
||||
func (d *HoroscopeDao) HoroscopeGetByDate(ctx context.Context, statDate int64) ([]mysqlmodel.Horoscope, error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.HoroscopeGetByDate")
|
||||
defer span.End()
|
||||
|
||||
var list []mysqlmodel.Horoscope
|
||||
if err := d.db.WithContext(ctx).Where("stat_date = ?", statDate).Find(&list).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// AIHoroscopeFlowLogDao 星座运势 AI 流水数据访问
|
||||
type AIHoroscopeFlowLogDao struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewAIHoroscopeFlowLogDao 创建星座运势 AI 流水 DAO
|
||||
func NewAIHoroscopeFlowLogDao() *AIHoroscopeFlowLogDao {
|
||||
return &AIHoroscopeFlowLogDao{db: global.MysqlEngine}
|
||||
}
|
||||
|
||||
// AIHoroscopeFlowLogCreate 创建星座运势 AI 流水
|
||||
func (d *AIHoroscopeFlowLogDao) AIHoroscopeFlowLogCreate(ctx context.Context, log *mysqlmodel.AIHoroscopeFlowLog) error {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.AIHoroscopeFlowLogCreate")
|
||||
defer span.End()
|
||||
|
||||
if err := d.db.WithContext(ctx).Create(log).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AIHoroscopeFlowLogGetByRequestID 按请求ID查询流水(幂等)
|
||||
func (d *AIHoroscopeFlowLogDao) AIHoroscopeFlowLogGetByRequestID(ctx context.Context, requestID string) (*mysqlmodel.AIHoroscopeFlowLog, error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.AIHoroscopeFlowLogGetByRequestID")
|
||||
defer span.End()
|
||||
|
||||
var log mysqlmodel.AIHoroscopeFlowLog
|
||||
if err := d.db.WithContext(ctx).Where("request_id = ?", requestID).First(&log).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return nil, err
|
||||
}
|
||||
return &log, nil
|
||||
}
|
||||
|
||||
// AIRecommendFlowLogDao AI 推荐流水数据访问
|
||||
type AIRecommendFlowLogDao struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewAIRecommendFlowLogDao 创建 AI 推荐流水 DAO
|
||||
func NewAIRecommendFlowLogDao() *AIRecommendFlowLogDao {
|
||||
return &AIRecommendFlowLogDao{db: global.MysqlEngine}
|
||||
}
|
||||
|
||||
// AIRecommendFlowLogCreate 创建 AI 推荐流水
|
||||
func (d *AIRecommendFlowLogDao) AIRecommendFlowLogCreate(ctx context.Context, log *mysqlmodel.AIRecommendFlowLog) error {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.AIRecommendFlowLogCreate")
|
||||
defer span.End()
|
||||
|
||||
if err := d.db.WithContext(ctx).Create(log).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AIRecommendFlowLogGetByRequestID 按请求ID查询流水(幂等)
|
||||
func (d *AIRecommendFlowLogDao) AIRecommendFlowLogGetByRequestID(ctx context.Context, requestID string) (*mysqlmodel.AIRecommendFlowLog, error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.AIRecommendFlowLogGetByRequestID")
|
||||
defer span.End()
|
||||
|
||||
var log mysqlmodel.AIRecommendFlowLog
|
||||
if err := d.db.WithContext(ctx).Where("request_id = ?", requestID).First(&log).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return nil, err
|
||||
}
|
||||
return &log, nil
|
||||
}
|
||||
Reference in New Issue
Block a user