finclip-app-manager/infrastructure/db/repo/mysql/red_dot.go

54 lines
1.8 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package mysql
import (
"context"
"finclip-app-manager/domain/entity"
"finclip-app-manager/domain/repository"
"gorm.io/gorm"
"time"
)
var _ repository.IRedDotRepo = new(RedDotByMysqlRepo)
type RedDotByMysqlRepo struct {
}
type RedDotReadRecordMysql struct {
Id uint `bson:"id" gorm:"primary_key;column:id" sql:"auto_increment;primary_key;unique"`
Type string `json:"type" gorm:"column:type;type:varchar(64);comment:红点类型"`
TraceId string `json:"traceId" gorm:"column:trace_id;type:varchar(64);comment:红点唯一标识"`
AccountId string `json:"accountId" gorm:"column:account_id;type:varchar(64);comment:已经阅读的账户Id"`
CreateTime int64 `json:"createTime" gorm:"column:create_time;type:BIGINT(16);comment:创建时间"`
UpdateTime int64 `json:"updateTime" gorm:"column:update_time;type:BIGINT(16);comment:更新时间"`
}
func (RedDotReadRecordMysql) TableName() string {
return "red_dot_read_record"
}
func (r RedDotByMysqlRepo) ReadTrialQr(ctx context.Context, readDotType string, id string, userId string) error {
info := entity.RedDotReadRecord{
Type: readDotType,
TraceId: id,
AccountId: userId,
CreateTime: time.Now().UnixNano() / 1e6,
}
return DB.Model(&RedDotReadRecordMysql{}).Create(convertRedDotReadRecordToRedDotReadRecordMysql(&info)).Error
}
func (r RedDotByMysqlRepo) NotFound(err error) bool {
return err == gorm.ErrRecordNotFound
}
func convertRedDotReadRecordToRedDotReadRecordMysql(redDotReadRecord *entity.RedDotReadRecord) RedDotReadRecordMysql {
result := RedDotReadRecordMysql{}
result.Type = redDotReadRecord.Type
result.TraceId = redDotReadRecord.TraceId
result.AccountId = redDotReadRecord.AccountId
result.CreateTime = redDotReadRecord.CreateTime
result.UpdateTime = redDotReadRecord.UpdateTime
return result
}