dao

package
v0.0.0-...-1b0a6d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FollowStatus uint8 = iota // 关注
	ShieldStatus              // 屏蔽
	BlockStatus               // 拉黑
)
View Source
const (
	PostIndex = "post_index"
	UserIndex = "user_index"
)

Variables

View Source
var (
	ErrRecordNotFound  = gorm.ErrRecordNotFound
	StatusLiked        = 1
	StatusUnliked      = 0
	StatusCollection   = 1
	StatusUnCollection = 0
)
View Source
var (
	ErrMenuNotFound = errors.New("菜单不存在")
	ErrInvalidMenu  = errors.New("无效的菜单参数")
)
View Source
var (
	ErrPostNotFound  = errors.New("post not found")
	ErrInvalidParams = errors.New("invalid parameters")
)
View Source
var (
	// ErrCodeDuplicateUsernameNumber 表示用户名重复的错误码
	ErrCodeDuplicateUsernameNumber uint16 = 1062
	// ErrDuplicateUsername 表示用户名重复错误
	ErrDuplicateUsername = errors.New("用户名已存在")
	// ErrUserNotFound 表示用户未找到错误
	ErrUserNotFound = errors.New("用户不存在")
)
View Source
var ErrDataNotFound = gorm.ErrRecordNotFound

ErrDataNotFound 定义一个全局的记录未找到错误

Functions

func InitTables

func InitTables(db *gorm.DB) error

InitTables 初始化数据库表

Types

type ActivityDAO

type ActivityDAO interface {
	GetRecentActivity(ctx context.Context) ([]RecentActivity, error)
	SetRecentActivity(ctx context.Context, mr RecentActivity) error
}

func NewActivityDAO

func NewActivityDAO(db *gorm.DB, l *zap.Logger) ActivityDAO

type Api

type Api struct {
	ID          int    `json:"id" gorm:"primaryKey;column:id;comment:主键ID"`
	Name        string `json:"name" gorm:"column:name;type:varchar(50);not null;comment:API名称"`
	Path        string `json:"path" gorm:"column:path;type:varchar(255);not null;comment:API路径"`
	Method      int    `json:"method" gorm:"column:method;type:tinyint(1);not null;comment:HTTP请求方法(1:GET,2:POST,3:PUT,4:DELETE)"`
	Description string `json:"description" gorm:"column:description;type:varchar(500);comment:API描述"`
	Version     string `json:"version" gorm:"column:version;type:varchar(20);default:v1;comment:API版本"`
	Category    int    `json:"category" gorm:"column:category;type:tinyint(1);not null;comment:API分类(1:系统,2:业务)"`
	IsPublic    int    `json:"is_public" gorm:"column:is_public;type:tinyint(1);default:0;comment:是否公开(0:否,1:是)"`
	CreateTime  int64  `json:"create_time" gorm:"column:create_time;autoCreateTime;comment:创建时间"`
	UpdateTime  int64  `json:"update_time" gorm:"column:update_time;autoUpdateTime;comment:更新时间"`
	IsDeleted   int    `json:"is_deleted" gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否删除(0:否,1:是)"`
}

type ApiDAO

type ApiDAO interface {
	CreateApi(ctx context.Context, api *Api) error
	GetApiById(ctx context.Context, id int) (*Api, error)
	UpdateApi(ctx context.Context, api *Api) error
	DeleteApi(ctx context.Context, id int) error
	ListApis(ctx context.Context, page, pageSize int) ([]*Api, int, error)
}

func NewApiDAO

func NewApiDAO(db *gorm.DB, l *zap.Logger) ApiDAO

type Check

type Check struct {
	ID        int64  `gorm:"primaryKey;autoIncrement"`                     // 审核ID
	PostID    uint   `gorm:"not null"`                                     // 帖子ID
	Content   string `gorm:"type:text;not null"`                           // 审核内容
	Title     string `gorm:"size:255;not null"`                            // 审核标签
	Author    int64  `gorm:"column:author_id;index"`                       // 提交审核的用户ID
	Status    uint8  `gorm:"default:0"`                                    // 审核状态
	Remark    string `gorm:"type:text"`                                    // 审核备注
	CreatedAt int64  `gorm:"column:created_at;type:bigint;not null"`       // 创建时间
	UpdatedAt int64  `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间
}

type CheckDAO

type CheckDAO interface {
	Create(ctx context.Context, check Check) (int64, error)                     // 创建审核记录
	UpdateStatus(ctx context.Context, check Check) error                        // 更新审核状态
	FindAll(ctx context.Context, pagination domain.Pagination) ([]Check, error) // 获取审核列表
	FindByID(ctx context.Context, checkId int64) (Check, error)
	FindByPostId(ctx context.Context, postId uint) (Check, error) // 获取审核详情
	GetCheckCount(ctx context.Context) (int64, error)
}

func NewCheckDAO

func NewCheckDAO(db *gorm.DB, l *zap.Logger) CheckDAO

type Comment

type Comment struct {
	Id            int64         `gorm:"autoIncrement;primaryKey"`                                            // 评论ID
	UserId        int64         `gorm:"index:idx_user_id"`                                                   // 发表评论的用户ID
	Biz           string        `gorm:"index:idx_biz_type_id"`                                               // 业务类型
	BizId         int64         `gorm:"index:idx_biz_type_id"`                                               // 业务ID
	Content       string        `gorm:"column:content;type:text"`                                            // 评论内容
	PostId        int64         `gorm:"index:idx_post_id"`                                                   // 帖子ID,用于多级评论
	RootId        sql.NullInt64 `gorm:"column:root_id;index"`                                                // 根评论ID
	PID           sql.NullInt64 `gorm:"column:pid;index"`                                                    // 父评论ID
	ParentComment *Comment      `gorm:"ForeignKey:PID;AssociationForeignKey:ID;constraint:OnDelete:CASCADE"` // 父评论
	CreatedAt     int64         `gorm:"autoCreateTime"`                                                      // 创建时间
	UpdatedAt     int64         `gorm:"autoUpdateTime"`                                                      // 更新时间
}

Comment 评论模型定义

type CommentDAO

type CommentDAO interface {
	CreateComment(ctx context.Context, comment Comment) error
	DeleteCommentById(ctx context.Context, commentId int64) error
	FindCommentsByPostId(ctx context.Context, postId int64, minId, limit int64) ([]Comment, error)
	GetMoreCommentsReply(ctx context.Context, rootId, maxId, limit int64) ([]Comment, error)
	FindRepliesByRid(ctx context.Context, rid int64, id int64, limit int64) ([]Comment, error)
}

CommentDAO 评论数据访问接口定义

func NewCommentDAO

func NewCommentDAO(db *gorm.DB, l *zap.Logger) CommentDAO

NewCommentDAO 创建新的评论服务

type Interactive

type Interactive struct {
	ID           int64  `gorm:"primaryKey;autoIncrement"`                     // 互动记录ID,主键,自增
	BizID        uint   `gorm:"uniqueIndex:biz_type_id"`                      // 业务ID,用于标识互动的业务对象
	BizName      string `gorm:"type:varchar(128);uniqueIndex:biz_type_id"`    // 业务名称
	ReadCount    int64  `gorm:"column:read_count"`                            // 阅读数量
	LikeCount    int64  `gorm:"column:like_count"`                            // 点赞数量
	CollectCount int64  `gorm:"column:collect_count"`                         // 收藏数量
	UpdateTime   int64  `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间,Unix时间戳
	CreateTime   int64  `gorm:"column:created_at;type:bigint"`                // 创建时间,Unix时间戳
}

Interactive 互动信息结构体

type InteractiveDAO

type InteractiveDAO interface {
	IncrReadCnt(ctx context.Context, biz string, postId uint) error
	BatchIncrReadCnt(ctx context.Context, biz []string, postIds []uint) error
	InsertLikeInfo(ctx context.Context, lb UserLikeBiz) error
	DeleteLikeInfo(ctx context.Context, lb UserLikeBiz) error
	InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
	DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
	GetLikeInfo(ctx context.Context, biz string, postId uint, uid int64) (UserLikeBiz, error)
	GetCollectInfo(ctx context.Context, biz string, postId uint, uid int64) (UserCollectionBiz, error)
	Get(ctx context.Context, biz string, postId uint) (Interactive, error)
	GetByIds(ctx context.Context, biz string, postIds []uint) ([]Interactive, error)
}

InteractiveDAO 互动数据访问对象接口

func NewInteractiveDAO

func NewInteractiveDAO(db *gorm.DB, l *zap.Logger) InteractiveDAO

type Job

type Job struct {
	Id          int64  `gorm:"primaryKey,autoIncrement"`               // 任务ID,主键,自增
	Name        string `gorm:"type:varchar(128);unique"`               // 任务名称,唯一
	Executor    string `gorm:"type:varchar(255)"`                      // 执行者,执行该任务的实体
	Expression  string `gorm:"type:varchar(255)"`                      // 调度表达式,用于描述任务的调度时间
	Cfg         string `gorm:"type:text"`                              // 配置,任务的具体配置信息
	Status      int    `gorm:"type:int"`                               // 任务状态,用于标识任务当前的状态(如启用、禁用等)
	Version     int    `gorm:"type:int"`                               // 版本号,用于乐观锁控制并发更新
	NextTime    int64  `gorm:"index"`                                  // 下次执行时间,Unix时间戳
	CreateTime  int64  `gorm:"column:created_at;type:bigint;not null"` // 创建时间,Unix时间戳
	UpdatedTime int64  `gorm:"column:updated_at;type:bigint;not null"` // 更新时间,Unix时间戳
}

type JobDAO

type JobDAO interface {
	Preempt(ctx context.Context) (Job, error)
	Release(ctx context.Context, jobId int64) error
	UpdateTime(ctx context.Context, id int64) error
	UpdateNextTime(ctx context.Context, id int64, t time.Time) error
}

JobDAO 定义了任务数据访问对象接口

func NewJobDAO

func NewJobDAO(db *gorm.DB) JobDAO

NewJobDAO 创建并初始化 jobDAO 实例

type ListPubPost

type ListPubPost struct {
	ID           uint      `bson:"id"`           // MongoDB的ObjectID
	CreatedAt    time.Time `bson:"createdat"`    // 创建时间
	UpdatedAt    time.Time `bson:"updatedat"`    // 更新时间
	Title        string    `bson:"title"`        // 文章标题
	Content      string    `bson:"content"`      // 文章内容
	Status       uint8     `bson:"status"`       // 文章状态,如草稿、发布等
	AuthorID     int64     `bson:"authorid"`     // 用户uid
	Slug         string    `bson:"slug"`         // 文章的唯一标识,用于生成友好URL
	CategoryID   int64     `bson:"categoryid"`   // 关联分类表的外键
	PlateID      int64     `bson:"plateid"`      // 关联板块表的外键
	Plate        Plate     `bson:"plate"`        // 板块关系
	Tags         string    `bson:"tags"`         // 文章标签,以逗号分隔
	CommentCount int64     `bson:"commentcount"` // 文章的评论数量
}

type LotteryDraw

type LotteryDraw struct {
	ID           int           `gorm:"primaryKey;autoIncrement"`                                                         // 抽奖活动的唯一标识符
	Name         string        `gorm:"column:name;not null"`                                                             // 抽奖活动名称
	Description  string        `gorm:"column:description;type:text"`                                                     // 抽奖活动描述
	StartTime    int64         `gorm:"column:start_time;not null"`                                                       // 活动开始时间(UNIX 时间戳)
	EndTime      int64         `gorm:"column:end_time;not null"`                                                         // 活动结束时间(UNIX 时间戳)
	Status       string        `gorm:"column:status;type:varchar(20)"`                                                   // 活动状态
	CreatedAt    int64         `gorm:"column:created_at;autoCreateTime"`                                                 // 创建时间(UNIX 时间戳)
	UpdatedAt    int64         `gorm:"column:updated_at;autoUpdateTime"`                                                 // 更新时间(UNIX 时间戳)
	Participants []Participant `gorm:"foreignKey:LotteryID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 参与者列表
}

LotteryDraw 数据库中的抽奖活动模型

type LotteryDrawDAO

type LotteryDrawDAO interface {
	CreateLotteryDraw(ctx context.Context, model LotteryDraw) error
	GetLotteryDrawByID(ctx context.Context, id int) (LotteryDraw, error)
	ListLotteryDraws(ctx context.Context, status string, pagination domain.Pagination) ([]LotteryDraw, error)
	ExistsLotteryDrawByName(ctx context.Context, name string) (bool, error)
	HasUserParticipatedInLottery(ctx context.Context, id int, userID int64) (bool, error)

	CreateSecondKillEvent(ctx context.Context, model SecondKillEvent) error
	GetSecondKillEventByID(ctx context.Context, id int) (SecondKillEvent, error)
	ListSecondKillEvents(ctx context.Context, status string, pagination domain.Pagination) ([]SecondKillEvent, error)
	ExistsSecondKillEventByName(ctx context.Context, name string) (bool, error)
	HasUserParticipatedInSecondKill(ctx context.Context, id int, userID int64) (bool, error)

	AddParticipant(ctx context.Context, model Participant) error

	ListPendingLotteryDraws(ctx context.Context, currentTime int64) ([]LotteryDraw, error)
	UpdateLotteryDrawStatus(ctx context.Context, id int, status string) error
	ListPendingSecondKillEvents(ctx context.Context, currentTime int64) ([]SecondKillEvent, error)
	UpdateSecondKillEventStatus(ctx context.Context, id int, status string) error
	ListActiveLotteryDraws(ctx context.Context, currentTime int64) ([]LotteryDraw, error)
	ListActiveSecondKillEvents(ctx context.Context, currentTime int64) ([]SecondKillEvent, error)
}

func NewLotteryDrawDAO

func NewLotteryDrawDAO(db *gorm.DB, l *zap.Logger) LotteryDrawDAO
type Menu struct {
	ID         int     `json:"id" gorm:"primaryKey;column:id;comment:菜单ID"`
	Name       string  `json:"name" gorm:"column:name;type:varchar(50);not null;comment:菜单显示名称"`
	ParentID   int     `json:"parent_id" gorm:"column:parent_id;default:0;comment:上级菜单ID,0表示顶级菜单"`
	Path       string  `json:"path" gorm:"column:path;type:varchar(255);not null;comment:前端路由访问路径"`
	Component  string  `json:"component" gorm:"column:component;type:varchar(255);not null;comment:前端组件文件路径"`
	Icon       string  `json:"icon" gorm:"column:icon;type:varchar(50);default:'';comment:菜单显示图标"`
	SortOrder  int     `json:"sort_order" gorm:"column:sort_order;default:0;comment:菜单显示顺序,数值越小越靠前"`
	RouteName  string  `json:"route_name" gorm:"column:route_name;type:varchar(50);not null;comment:前端路由名称,需唯一"`
	Hidden     int     `json:"hidden" gorm:"column:hidden;type:tinyint(1);default:0;comment:菜单是否隐藏(0:显示 1:隐藏)"`
	CreateTime int64   `json:"create_time" gorm:"column:create_time;autoCreateTime;comment:记录创建时间戳"`
	UpdateTime int64   `json:"update_time" gorm:"column:update_time;autoUpdateTime;comment:记录最后更新时间戳"`
	IsDeleted  int     `json:"is_deleted" gorm:"column:is_deleted;type:tinyint(1);default:0;comment:逻辑删除标记(0:未删除 1:已删除)"`
	Children   []*Menu `json:"children" gorm:"-"` // 子菜单列表,不映射到数据库
}
type MenuDAO interface {
	CreateMenu(ctx context.Context, menu *Menu) error
	GetMenuById(ctx context.Context, id int) (*Menu, error)
	UpdateMenu(ctx context.Context, menu *Menu) error
	DeleteMenu(ctx context.Context, id int) error
	ListMenus(ctx context.Context, page, pageSize int) ([]*Menu, int, error)
	GetMenuTree(ctx context.Context) ([]*Menu, error)
}

func NewMenuDAO

func NewMenuDAO(db *gorm.DB, l *zap.Logger) MenuDAO

type Participant

type Participant struct {
	ID             string `gorm:"primaryKey;column:id;type:char(36)"` // 参与记录的唯一标识符 (UUID)
	LotteryID      *int   `gorm:"column:lottery_id"`                  // 抽奖活动ID,可为null
	SecondKillID   *int   `gorm:"column:second_kill_id"`              // 秒杀活动ID,可为null
	UserID         int64  `gorm:"column:user_id;not null"`            // 参与者的用户ID
	ParticipatedAt int64  `gorm:"column:participated_at;not null"`    // 参与时间(UNIX 时间戳)
}

Participant 数据库中的参与者记录模型

type PermissionDAO

type PermissionDAO interface {
	AssignRole(ctx context.Context, roleId int, menuIds []int, apiIds []int) error
	AssignRoleToUser(ctx context.Context, userId int, roleIds []int, menuIds []int, apiIds []int) error
	AssignRoleToUsers(ctx context.Context, userIds []int, roleIds []int, menuIds []int, apiIds []int) error

	RemoveUserPermissions(ctx context.Context, userId int) error
	RemoveRolePermissions(ctx context.Context, roleId int) error
	RemoveUsersPermissions(ctx context.Context, userIds []int) error
}

func NewPermissionDAO

func NewPermissionDAO(db *gorm.DB, l *zap.Logger, enforcer *casbin.Enforcer, apiDao ApiDAO) PermissionDAO

type Plate

type Plate struct {
	ID          int64  `gorm:"primaryKey;autoIncrement"`      // 板块ID
	Name        string `gorm:"size:255;not null;uniqueIndex"` // 板块名称
	Description string `gorm:"type:text"`                     // 板块描述
	CreateTime  int64  `gorm:"column:created_at;type:bigint"` // 创建时间
	UpdatedTime int64  `gorm:"column:updated_at;type:bigint"` // 更新时间
	DeletedTime int64  `gorm:"column:deleted_at;type:bigint"` // 删除时间
	Deleted     bool   `gorm:"column:deleted;default:false"`  // 是否删除
	Uid         int64  `gorm:"index"`                         // 板主id
	Posts       []Post `gorm:"foreignKey:PlateID"`            // 帖子关系
}

type PlateDAO

type PlateDAO interface {
	CreatePlate(ctx context.Context, plate domain.Plate) error
	ListPlate(ctx context.Context, pagination domain.Pagination) ([]Plate, error)
	UpdatePlate(ctx context.Context, plate domain.Plate) error
	DeletePlate(ctx context.Context, plateId int64, uid int64) error
}

func NewPlateDAO

func NewPlateDAO(l *zap.Logger, db *gorm.DB) PlateDAO

type Post

type Post struct {
	gorm.Model
	Title        string `gorm:"size:255;not null"`            // 文章标题
	Content      string `gorm:"type:text;not null"`           // 文章内容
	Status       uint8  `gorm:"default:0"`                    // 文章状态,如草稿、发布等
	AuthorID     int64  `gorm:"column:author_id;index"`       // 用户uid
	Slug         string `gorm:"size:100;uniqueIndex"`         // 文章的唯一标识,用于生成友好URL
	CategoryID   int64  `gorm:"index"`                        // 关联分类表的外键
	PlateID      int64  `gorm:"index"`                        // 关联板块表的外键
	Plate        Plate  `gorm:"foreignKey:PlateID"`           // 板块关系
	Tags         string `gorm:"type:varchar(255);default:''"` // 文章标签,以逗号分隔
	CommentCount int64  `gorm:"default:0"`                    // 文章的评论数量
}

type PostDAO

type PostDAO interface {
	Insert(ctx context.Context, post Post) (uint, error)                              // 创建一个新的帖子记录
	UpdateById(ctx context.Context, post Post) error                                  // 根据ID更新一个帖子记录
	UpdateStatus(ctx context.Context, post Post) error                                // 更新帖子的状态
	GetById(ctx context.Context, postId uint, uid int64) (Post, error)                // 根据ID获取一个帖子记录
	GetPubById(ctx context.Context, postId uint) (ListPubPost, error)                 // 根据ID获取一个已发布的帖子记录
	ListPub(ctx context.Context, pagination domain.Pagination) ([]ListPubPost, error) // 获取已发布的帖子记录列表
	List(ctx context.Context, pagination domain.Pagination) ([]Post, error)           // 获取个人的帖子记录列表
	DeleteById(ctx context.Context, post Post) error
	ListAllPost(ctx context.Context, pagination domain.Pagination) ([]Post, error)
	GetPost(ctx context.Context, postId uint) (Post, error)
	GetPostCount(ctx context.Context) (int64, error)
}

func NewPostDAO

func NewPostDAO(db *gorm.DB, l *zap.Logger, client *mongo.Client) PostDAO

type PostSearch

type PostSearch struct {
	Id       uint     `json:"id"`
	Title    string   `json:"title"`
	AuthorId int64    `json:"author_id"`
	Status   uint8    `json:"status"`
	Content  string   `json:"content"`
	Tags     []string `json:"tags"`
}

type Profile

type Profile struct {
	ID       int64  `gorm:"primaryKey;autoIncrement"`
	UserID   int64  `gorm:"not null;index"`
	RealName string `gorm:"size:50"`
	Avatar   string `gorm:"type:text"`
	About    string `gorm:"type:text"`
	Birthday string `gorm:"column:birthday;type:varchar(10)"`
}

Profile 用户资料信息模型

type RecentActivity

type RecentActivity struct {
	ID          int64  `gorm:"primaryKey;autoIncrement"`
	UserID      int64  `gorm:"column:user_id;not null" json:"user_id"`
	Description string `gorm:"type:varchar(255);not null"`
	Time        string `gorm:"type:varchar(255);not null"`
}

type Relation

type Relation struct {
	ID         int64 `gorm:"column:id;primaryKey;autoIncrement"`                     // 主键ID
	FollowerID int64 `gorm:"column:follower_id;uniqueIndex:follower_id_followee_id"` // 关注者ID
	FolloweeID int64 `gorm:"column:followee_id;uniqueIndex:follower_id_followee_id"` // 被关注者ID
	Status     uint8 `gorm:"column:status"`                                          // 关系类型
	Deleted    bool  `gorm:"column:deleted"`                                         // 删除标志
	CreatedAt  int64 `gorm:"column:created_at"`                                      // 创建时间
	UpdatedAt  int64 `gorm:"column:updated_at"`                                      // 更新时间
}

Relation 存储用户的关注数据

type RelationCount

type RelationCount struct {
	ID            int64 `gorm:"column:id;primaryKey;autoIncrement"` // 主键ID
	UserID        int64 `gorm:"column:user_id;unique"`              // 用户ID
	FollowerCount int64 `gorm:"column:follower_count"`              // 粉丝数量
	FolloweeCount int64 `gorm:"column:followee_count"`              // 关注数量
	CreatedAt     int64 `gorm:"column:created_at"`                  // 创建时间
	UpdatedAt     int64 `gorm:"column:updated_at"`                  // 更新时间
}

RelationCount 存储用户的粉丝和关注数量

type RelationDAO

type RelationDAO interface {
	ListFollowerRelations(ctx context.Context, followerID int64, pagination domain.Pagination) ([]Relation, error)
	ListFolloweeRelations(ctx context.Context, followeeID int64, pagination domain.Pagination) ([]Relation, error)
	FollowUser(ctx context.Context, followerID, followeeID int64) error
	CancelFollowUser(ctx context.Context, followerID, followeeID int64) error
	UpdateStatus(ctx context.Context, followerID, followeeID int64, status bool) error
	FollowCount(ctx context.Context, userID int64) (RelationCount, error)
}

RelationDAO 定义了与用户关系相关的接口

func NewRelationDAO

func NewRelationDAO(db *gorm.DB, l *zap.Logger) RelationDAO

NewRelationDAO 创建RelationDAO实例

type Role

type Role struct {
	ID          int     `json:"id" gorm:"primaryKey;column:id;comment:主键ID"`
	Name        string  `json:"name" gorm:"column:name;type:varchar(50);not null;unique;comment:角色名称"`
	Description string  `json:"description" gorm:"column:description;type:varchar(255);comment:角色描述"`
	RoleType    int     `json:"role_type" gorm:"column:role_type;type:tinyint(1);not null;comment:角色类型(1:系统角色,2:自定义角色)"`
	IsDefault   int     `json:"is_default" gorm:"column:is_default;type:tinyint(1);default:0;comment:是否为默认角色(0:否,1:是)"`
	CreateTime  int64   `json:"create_time" gorm:"column:create_time;autoCreateTime;comment:创建时间"`
	UpdateTime  int64   `json:"update_time" gorm:"column:update_time;autoUpdateTime;comment:更新时间"`
	IsDeleted   int     `json:"is_deleted" gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否删除(0:否,1:是)"`
	Menus       []*Menu `json:"menus" gorm:"-"`
	Apis        []*Api  `json:"apis" gorm:"-"`
}

type RoleDAO

type RoleDAO interface {
	CreateRole(ctx context.Context, role *Role, menuIds []int, apiIds []int) error
	GetRoleById(ctx context.Context, id int) (*Role, error)
	UpdateRole(ctx context.Context, role *Role) error
	DeleteRole(ctx context.Context, id int) error
	ListRoles(ctx context.Context, page, pageSize int) ([]*Role, int, error)
	GetRole(ctx context.Context, roleId int) (*Role, error)
	GetUserRole(ctx context.Context, userId int) (*Role, error)
}

func NewRoleDAO

func NewRoleDAO(db *gorm.DB, l *zap.Logger, enforcer *casbin.Enforcer, permissionDao PermissionDAO) RoleDAO

type SearchDAO

type SearchDAO interface {
	CreateIndex(ctx context.Context, indexName string, properties ...interface{}) error
	CreatePostIndex(ctx context.Context, properties ...interface{}) error
	CreateUserIndex(ctx context.Context, properties ...interface{}) error
	SearchPosts(ctx context.Context, keywords []string) ([]PostSearch, error)
	SearchUsers(ctx context.Context, keywords []string) ([]UserSearch, error)
	InputUser(ctx context.Context, user UserSearch) error
	InputPost(ctx context.Context, post PostSearch) error
	DeleteUserIndex(ctx context.Context, userId int64) error
	DeletePostIndex(ctx context.Context, postId uint) error
}

func NewSearchDAO

func NewSearchDAO(db *gorm.DB, client *elasticsearch.TypedClient, l *zap.Logger) SearchDAO

NewSearchDAO 创建并返回一个新的 SearchDAO 实例

type SecondKillEvent

type SecondKillEvent struct {
	ID           int           `gorm:"primaryKey;autoIncrement"`                                                            // 秒杀活动的唯一标识符
	Name         string        `gorm:"column:name;not null"`                                                                // 秒杀活动名称
	Description  string        `gorm:"column:description;type:text"`                                                        // 秒杀活动描述
	StartTime    int64         `gorm:"column:start_time;not null"`                                                          // 活动开始时间(UNIX 时间戳)
	EndTime      int64         `gorm:"column:end_time;not null"`                                                            // 活动结束时间(UNIX 时间戳)
	Status       string        `gorm:"column:status;type:varchar(20)"`                                                      // 活动状态
	CreatedAt    int64         `gorm:"column:created_at;autoCreateTime"`                                                    // 创建时间(UNIX 时间戳)
	UpdatedAt    int64         `gorm:"column:updated_at;autoUpdateTime"`                                                    // 更新时间(UNIX 时间戳)
	Participants []Participant `gorm:"foreignKey:SecondKillID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 参与者列表
}

SecondKillEvent 数据库中的秒杀活动模型

type SmsDAO

type SmsDAO interface {
	Insert(ctx context.Context, log VCodeSmsLog) error
	FindFailedLogs(ctx context.Context) ([]VCodeSmsLog, error) //查找当前时刻以前,发送失败的logs,后续需要重新发送
	Update(ctx context.Context, log VCodeSmsLog) error
}

func NewSmsDAO

func NewSmsDAO(db *gorm.DB, l *zap.Logger) SmsDAO

type User

type User struct {
	ID           int64   `gorm:"primarykey"`
	CreateTime   int64   `gorm:"column:created_at;type:bigint;not null"`
	UpdatedTime  int64   `gorm:"column:updated_at;type:bigint;not null"`
	DeletedTime  int64   `gorm:"column:deleted_at;type:bigint;index"`
	Username     string  `gorm:"column:username;type:varchar(100);uniqueIndex;not null"`
	PasswordHash string  `gorm:"not null"`
	Deleted      bool    `gorm:"column:deleted;default:false;not null"`
	Email        string  `gorm:"type:varchar(100)"`
	Phone        *string `gorm:"type:varchar(15);uniqueIndex"`
	Profile      Profile `gorm:"foreignKey:UserID;references:ID"`
	Roles        string  `gorm:"column:roles;type:json;comment:用户角色ID列表"`
}

User 用户模型

type UserCollectionBiz

type UserCollectionBiz struct {
	ID           int64  `gorm:"primaryKey;autoIncrement"`                     // 收藏记录ID,主键,自增
	Uid          int64  `gorm:"index"`                                        // 用户ID,用于标识哪个用户收藏
	BizID        uint   `gorm:"index"`                                        // 业务ID,用于标识收藏的业务对象
	BizName      string `gorm:"type:varchar(255)"`                            // 业务名称
	Status       int    `gorm:"column:status"`                                // 状态,用于表示收藏的状态(如有效、无效等)
	CollectionId int64  `gorm:"index"`                                        // 收藏ID,用于标识具体的收藏对象
	UpdateTime   int64  `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间,Unix时间戳
	CreateTime   int64  `gorm:"column:created_at;type:bigint"`                // 创建时间,Unix时间戳
	Deleted      bool   `gorm:"column:deleted;default:false"`                 // 删除标志,表示该记录是否被删除
}

UserCollectionBiz 用户收藏业务结构体

type UserDAO

type UserDAO interface {
	CreateUser(ctx context.Context, u User) error
	FindByID(ctx context.Context, id int64) (User, error)
	FindByUsername(ctx context.Context, username string) (User, error)
	FindByPhone(ctx context.Context, phone string) (User, error)
	UpdatePasswordByUsername(ctx context.Context, username string, newPassword string) error
	DeleteUser(ctx context.Context, username string, uid int64) error
	UpdateProfile(ctx context.Context, profile domain.Profile) error
	GetProfileByUserID(ctx context.Context, userId int64) (domain.Profile, error)
	ListUser(ctx context.Context, pagination domain.Pagination) ([]domain.UserWithProfile, error)
}

func NewUserDAO

func NewUserDAO(db *gorm.DB, node *sf.Node, l *zap.Logger, ce *casbin.Enforcer) UserDAO

type UserLikeBiz

type UserLikeBiz struct {
	ID         int64  `gorm:"primaryKey;autoIncrement"`                     // 点赞记录ID,主键,自增
	Uid        int64  `gorm:"index"`                                        // 用户ID,用于标识哪个用户点赞
	BizID      uint   `gorm:"index"`                                        // 业务ID,用于标识点赞的业务对象
	BizName    string `gorm:"type:varchar(255)"`                            // 业务名称
	Status     int    `gorm:"type:int"`                                     // 状态,用于表示点赞的状态(如有效、无效等)
	UpdateTime int64  `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间,Unix时间戳
	CreateTime int64  `gorm:"column:created_at;type:bigint"`                // 创建时间,Unix时间戳
	Deleted    bool   `gorm:"column:deleted;default:false"`                 // 删除标志,表示该记录是否被删除
}

UserLikeBiz 用户点赞业务结构体

type UserSearch

type UserSearch struct {
	Id       int64  `json:"id"`
	Username string `json:"username"`
	RealName string `json:"real_name"`
	Phone    string `json:"phone"`
}

type VCodeSmsLog

type VCodeSmsLog struct {
	Id          int64  `gorm:"column:id;primaryKey;autoIncrement"`           // 自增ID
	SmsId       int64  `gorm:"column:sms_id"`                                // 短信类型ID
	SmsType     string `gorm:"column:sms_type"`                              // 短信类型
	Mobile      string `gorm:"column:mobile"`                                // 手机号
	VCode       string `gorm:"column:v_code"`                                // 验证码
	Driver      string `gorm:"column:driver"`                                // 服务商类型
	Status      int64  `gorm:"column:status"`                                // 发送状态,1为成功,0为失败
	StatusCode  string `gorm:"column:status_code"`                           // 状态码
	CreateTime  int64  `gorm:"column:created_at;type:bigint;not null"`       // 创建时间
	UpdatedTime int64  `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间
	DeletedTime int64  `gorm:"column:deleted_at;type:bigint;index"`          // 删除时间
}

VCodeSmsLog 表示用户认证操作的日志记录

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL