feat(smoke): support reason tags on smoke logs

This commit is contained in:
nepiedg
2026-04-16 11:06:14 +08:00
parent 411ded8a0c
commit 6e0a06cfcf
8 changed files with 158 additions and 65 deletions
+24 -16
View File
@@ -21,16 +21,17 @@ type SmokeLogService struct {
// smokeLogCreateRow 用于写入 fa_smoke_log,避免 SmokeLog 的 default 标签覆盖 0 值。
type smokeLogCreateRow struct {
ID int `gorm:"column:id;primaryKey;autoIncrement"`
UID int `gorm:"column:uid"`
SmokeTime *time.Time `gorm:"column:smoke_time"`
SmokeAt *time.Time `gorm:"column:smoke_at"`
Remark string `gorm:"column:remark"`
CreateTime *int64 `gorm:"column:createtime"`
UpdateTime *int64 `gorm:"column:updatetime"`
DeleteTime *int64 `gorm:"column:deletetime"`
Level *int64 `gorm:"column:level"`
Num *int `gorm:"column:num"`
ID int `gorm:"column:id;primaryKey;autoIncrement"`
UID int `gorm:"column:uid"`
SmokeTime *time.Time `gorm:"column:smoke_time"`
SmokeAt *time.Time `gorm:"column:smoke_at"`
Remark string `gorm:"column:remark"`
ReasonTags smokemodel.StringSlice `gorm:"column:reason_tags"`
CreateTime *int64 `gorm:"column:createtime"`
UpdateTime *int64 `gorm:"column:updatetime"`
DeleteTime *int64 `gorm:"column:deletetime"`
Level *int64 `gorm:"column:level"`
Num *int `gorm:"column:num"`
}
func (smokeLogCreateRow) TableName() string {
@@ -42,11 +43,12 @@ func NewSmokeLogService(db *gorm.DB) *SmokeLogService {
}
type CreateSmokeLogRequest struct {
SmokeTime *time.Time
SmokeAt *time.Time
Remark string
Level int64
Num int
SmokeTime *time.Time
SmokeAt *time.Time
Remark string
ReasonTags smokemodel.StringSlice
Level int64
Num int
}
func (s *SmokeLogService) Create(ctx context.Context, uid int, req CreateSmokeLogRequest) (*smokemodel.SmokeLog, error) {
@@ -82,6 +84,7 @@ func (s *SmokeLogService) Create(ctx context.Context, uid int, req CreateSmokeLo
SmokeTime: smokeTime,
SmokeAt: smokeAt,
Remark: req.Remark,
ReasonTags: req.ReasonTags,
CreateTime: &createTime,
UpdateTime: &updateTime,
Level: &level,
@@ -98,6 +101,7 @@ func (s *SmokeLogService) Create(ctx context.Context, uid int, req CreateSmokeLo
SmokeTime: insert.SmokeTime,
SmokeAt: insert.SmokeAt,
Remark: insert.Remark,
ReasonTags: insert.ReasonTags,
CreateTime: insert.CreateTime,
UpdateTime: insert.UpdateTime,
DeleteTime: insert.DeleteTime,
@@ -393,7 +397,7 @@ func (s *SmokeLogService) ListLatest(ctx context.Context, uid int, limit int) ([
var items []smokemodel.SmokeLog
if err := s.db.WithContext(ctx).
Model(&smokemodel.SmokeLog{}).
Select("id, uid, smoke_time, smoke_at, remark, level, num, createtime, updatetime, deletetime").
Select("id, uid, smoke_time, smoke_at, remark, reason_tags, level, num, createtime, updatetime, deletetime").
Where("uid = ? AND (deletetime IS NULL OR deletetime = 0)", uid).
Order("COALESCE(smoke_at, FROM_UNIXTIME(createtime), smoke_time) DESC").
Order("id DESC").
@@ -431,6 +435,7 @@ type UpdateSmokeLogRequest struct {
SmokeAtProvided bool
SmokeAt *time.Time
Remark *string
ReasonTags *smokemodel.StringSlice
Level *int64
Num *int
}
@@ -455,6 +460,9 @@ func (s *SmokeLogService) Update(ctx context.Context, uid int, id int, req Updat
if req.Remark != nil {
updates["remark"] = *req.Remark
}
if req.ReasonTags != nil {
updates["reason_tags"] = *req.ReasonTags
}
if req.Level != nil {
if *req.Level < 0 {
updates["level"] = int64(1)