重构一下数据库

This commit is contained in:
2026-01-18 20:35:21 +08:00
parent 485307e7de
commit ff4e069a7e
20 changed files with 477 additions and 131 deletions

View File

@@ -0,0 +1,22 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"TrangleAgent/internal/dao/internal"
)
// forumBoardsDao is the data access object for the table forum_boards.
// You can define custom methods on it to extend its functionality as needed.
type forumBoardsDao struct {
*internal.ForumBoardsDao
}
var (
// ForumBoards is a globally accessible object for table forum_boards operations.
ForumBoards = forumBoardsDao{internal.NewForumBoardsDao()}
)
// Add your custom methods and functionality below.

View File

@@ -0,0 +1,22 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"TrangleAgent/internal/dao/internal"
)
// forumSectionsDao is the data access object for the table forum_sections.
// You can define custom methods on it to extend its functionality as needed.
type forumSectionsDao struct {
*internal.ForumSectionsDao
}
var (
// ForumSections is a globally accessible object for table forum_sections operations.
ForumSections = forumSectionsDao{internal.NewForumSectionsDao()}
)
// Add your custom methods and functionality below.

View File

@@ -0,0 +1,103 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// ForumBoardsDao is the data access object for the table forum_boards.
type ForumBoardsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns ForumBoardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// ForumBoardsColumns defines and stores column names for the table forum_boards.
type ForumBoardsColumns struct {
Id string // 版块ID主键
SectionId string // 所属频道ID关联 forum_sections.id无外键可为空=不分区)
Name string // 版块名称
Description string // 版块简介
CoverImage string // 版块封面图URL
Status string // 状态normal=正常 hidden=隐藏 deleted=删除
DisplayOrder string // 排序值(越大越靠前)
PostCount string // 帖子总数(冗余)
TodayPostCount string // 今日发帖数(冗余,可选)
LastPostId string // 最后一篇帖子ID冗余可选
LastPostAt string // 最后发帖时间(冗余,可选)
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
}
// forumBoardsColumns holds the columns for the table forum_boards.
var forumBoardsColumns = ForumBoardsColumns{
Id: "id",
SectionId: "section_id",
Name: "name",
Description: "description",
CoverImage: "cover_image",
Status: "status",
DisplayOrder: "display_order",
PostCount: "post_count",
TodayPostCount: "today_post_count",
LastPostId: "last_post_id",
LastPostAt: "last_post_at",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewForumBoardsDao creates and returns a new DAO object for table data access.
func NewForumBoardsDao(handlers ...gdb.ModelHandler) *ForumBoardsDao {
return &ForumBoardsDao{
group: "default",
table: "forum_boards",
columns: forumBoardsColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *ForumBoardsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *ForumBoardsDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *ForumBoardsDao) Columns() ForumBoardsColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *ForumBoardsDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *ForumBoardsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *ForumBoardsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -21,32 +21,32 @@ type ForumCommentsDao struct {
// ForumCommentsColumns defines and stores column names for the table forum_comments.
type ForumCommentsColumns struct {
Id string // 评论ID主键
UserId string // 评论发布者ID关联users.id无外键
PostId string // 所属帖子ID关联forum_posts.id无外键
ParentId string // 父评论IDNULL=评论非NULL=回复某条评论
Content string // 评论内容支持emoji
Status string // 评论状态normal=正常 deleted=软删除 audit=审核中 reject=审核驳回
LikeCount string // 点赞数
ReplyCount string // 回复数(冗余字段
CreatedAt string // 评论创建时间
UpdatedAt string // 评论更新时间
DeletedAt string // 软删除时间
Id string // 评论ID主键
PostId string // 所属帖子ID关联 forum_posts.id无外键
UserId string // 评论发布者ID关联 users.id无外键
ParentId string // 父评论IDNULL=一级评论非NULL=二级评论指向一级评论ID无外键
ReplyToUserId string // 回复的用户ID可选用于展示“回复@xxx”无外键
Content string // 评论内容支持emoji
Status string // 状态normal=正常 deleted=软删 audit=审核中 reject=驳回
LikeCount string // 点赞数(冗余)
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
}
// forumCommentsColumns holds the columns for the table forum_comments.
var forumCommentsColumns = ForumCommentsColumns{
Id: "id",
UserId: "user_id",
PostId: "post_id",
ParentId: "parent_id",
Content: "content",
Status: "status",
LikeCount: "like_count",
ReplyCount: "reply_count",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
Id: "id",
PostId: "post_id",
UserId: "user_id",
ParentId: "parent_id",
ReplyToUserId: "reply_to_user_id",
Content: "content",
Status: "status",
LikeCount: "like_count",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewForumCommentsDao creates and returns a new DAO object for table data access.

View File

@@ -21,34 +21,46 @@ type ForumPostsDao struct {
// ForumPostsColumns defines and stores column names for the table forum_posts.
type ForumPostsColumns struct {
Id string // 帖子ID主键
UserId string // 发帖用户ID关联users.id无外键
Title string // 帖子标题
Content string // 帖子正文(支持富文本/emoji
CoverImage string // 帖子封面图URL
Status string // 帖子状态normal=正常 deleted=软删除 audit=审核中 reject=审核驳回
ViewCount string // 浏览量(冗余字段)
LikeCount string // 点赞数(冗余字段)
CommentCount string // 评论数(冗余字段)
CreatedAt string // 发帖时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
Id string // 帖子ID主键
BoardId string // 所属版块ID关联 forum_boards.id无外键
UserId string // 发帖用户ID关联 users.id无外键
Title string // 帖子标题
Content string // 帖子正文(支持富文本/emoji
CoverImage string // 帖子封面图URL
Status string // 状态normal=正常 deleted=软删 audit=审核中 reject=驳回
IsPinned string // 是否置顶0否 1是
IsEssence string // 是否精华0否 1是
ViewCount string // 浏览量(冗余)
LikeCount string // 点赞数(冗余)
CommentCount string // 评论数(冗余)
CollectCount string // 收藏数(冗余,可选)
LastCommentId string // 最后一条评论ID冗余可选
LastCommentAt string // 最后评论时间(冗余,可选)
CreatedAt string // 发帖时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
}
// forumPostsColumns holds the columns for the table forum_posts.
var forumPostsColumns = ForumPostsColumns{
Id: "id",
UserId: "user_id",
Title: "title",
Content: "content",
CoverImage: "cover_image",
Status: "status",
ViewCount: "view_count",
LikeCount: "like_count",
CommentCount: "comment_count",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
Id: "id",
BoardId: "board_id",
UserId: "user_id",
Title: "title",
Content: "content",
CoverImage: "cover_image",
Status: "status",
IsPinned: "is_pinned",
IsEssence: "is_essence",
ViewCount: "view_count",
LikeCount: "like_count",
CommentCount: "comment_count",
CollectCount: "collect_count",
LastCommentId: "last_comment_id",
LastCommentAt: "last_comment_at",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewForumPostsDao creates and returns a new DAO object for table data access.

View File

@@ -0,0 +1,93 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// ForumSectionsDao is the data access object for the table forum_sections.
type ForumSectionsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns ForumSectionsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// ForumSectionsColumns defines and stores column names for the table forum_sections.
type ForumSectionsColumns struct {
Id string // 频道/分区ID主键
Name string // 频道名称
Description string // 频道简介
Icon string // 频道图标URL
Status string // 状态normal=正常 hidden=隐藏 deleted=删除
DisplayOrder string // 排序值(越大越靠前)
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
}
// forumSectionsColumns holds the columns for the table forum_sections.
var forumSectionsColumns = ForumSectionsColumns{
Id: "id",
Name: "name",
Description: "description",
Icon: "icon",
Status: "status",
DisplayOrder: "display_order",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewForumSectionsDao creates and returns a new DAO object for table data access.
func NewForumSectionsDao(handlers ...gdb.ModelHandler) *ForumSectionsDao {
return &ForumSectionsDao{
group: "default",
table: "forum_sections",
columns: forumSectionsColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *ForumSectionsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *ForumSectionsDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *ForumSectionsDao) Columns() ForumSectionsColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *ForumSectionsDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *ForumSectionsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *ForumSectionsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -27,16 +27,12 @@ type UsersColumns struct {
Nickname string // 昵称
Gender string // 性别0未知 1男 2女
BirthDate string // 生日
UserType string // 用户类型:normal普通用户vip为VIP用户
VipStartAt string // VIP开始时间
VipEndAt string // VIP结束时间
UserType string // 用户类型:1 user 2 admin
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
RealityRole string // 现实身份/角色
AbnormalRole string // 异常身份/角色
JobTitle string // 职位
Commendation string //
Admonition string //
Email string //
RedTrace string // 红轨
YellowTrace string // 黄轨
@@ -52,15 +48,11 @@ var usersColumns = UsersColumns{
Gender: "gender",
BirthDate: "birth_date",
UserType: "user_type",
VipStartAt: "vip_start_at",
VipEndAt: "vip_end_at",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
RealityRole: "reality_role",
AbnormalRole: "abnormal_role",
JobTitle: "job_title",
Commendation: "Commendation",
Admonition: "Admonition",
Email: "email",
RedTrace: "red_trace",
YellowTrace: "yellow_trace",