第一版完成
This commit is contained in:
571
internal/dao/dao.go
Normal file
571
internal/dao/dao.go
Normal file
@@ -0,0 +1,571 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// 数据访问对象实例
|
||||
var (
|
||||
User = NewUserDao()
|
||||
Role = NewRoleDao()
|
||||
Article = NewArticleDao()
|
||||
News = NewNewsDao()
|
||||
Attachment = NewAttachmentDao()
|
||||
Partner = NewPartnerDao()
|
||||
Contact = NewContactDao()
|
||||
Config = NewConfigDao()
|
||||
)
|
||||
|
||||
// UserDao 用户数据访问对象
|
||||
type UserDao struct {
|
||||
table string
|
||||
group string
|
||||
columns UserColumns
|
||||
}
|
||||
|
||||
type UserColumns struct {
|
||||
Id string
|
||||
Account string
|
||||
NickName string
|
||||
Avatar string
|
||||
Email string
|
||||
Password string
|
||||
Balance string
|
||||
QrCode string
|
||||
RoleId string
|
||||
IsSysNotifications string
|
||||
IsCollectionNotifications string
|
||||
IsMarketingNotifications string
|
||||
Ip string
|
||||
IpTable string
|
||||
Status string
|
||||
LastResetPasswordAt string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
func NewUserDao() *UserDao {
|
||||
return &UserDao{
|
||||
group: "default",
|
||||
table: "users",
|
||||
columns: UserColumns{
|
||||
Id: "id",
|
||||
Account: "account",
|
||||
NickName: "nick_name",
|
||||
Avatar: "avatar",
|
||||
Email: "email",
|
||||
Password: "password",
|
||||
Balance: "balance",
|
||||
QrCode: "qr_code",
|
||||
RoleId: "role_id",
|
||||
IsSysNotifications: "is_sys_notifications",
|
||||
IsCollectionNotifications: "is_collection_notifications",
|
||||
IsMarketingNotifications: "is_marketing_notifications",
|
||||
Ip: "ip",
|
||||
IpTable: "ip_table",
|
||||
Status: "status",
|
||||
LastResetPasswordAt: "last_reset_password_at",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *UserDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *UserDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *UserDao) Columns() UserColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *UserDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *UserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// RoleDao 角色数据访问对象
|
||||
type RoleDao struct {
|
||||
table string
|
||||
group string
|
||||
columns RoleColumns
|
||||
}
|
||||
|
||||
type RoleColumns struct {
|
||||
Id string
|
||||
Name string
|
||||
Description string
|
||||
Permissions string
|
||||
Status string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
func NewRoleDao() *RoleDao {
|
||||
return &RoleDao{
|
||||
group: "default",
|
||||
table: "roles",
|
||||
columns: RoleColumns{
|
||||
Id: "id",
|
||||
Name: "name",
|
||||
Description: "description",
|
||||
Permissions: "permissions",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *RoleDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *RoleDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *RoleDao) Columns() RoleColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *RoleDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *RoleDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// ArticleDao 文章数据访问对象
|
||||
type ArticleDao struct {
|
||||
table string
|
||||
group string
|
||||
columns ArticleColumns
|
||||
}
|
||||
|
||||
type ArticleColumns struct {
|
||||
Id string
|
||||
Title string
|
||||
Slug string
|
||||
Summary string
|
||||
Content string
|
||||
HtmlContent string
|
||||
CoverImage string
|
||||
CategoryId string
|
||||
Tags string
|
||||
AuthorId string
|
||||
ViewCount string
|
||||
LikeCount string
|
||||
CommentCount string
|
||||
IsPublished string
|
||||
IsFeatured string
|
||||
IsTop string
|
||||
SeoTitle string
|
||||
SeoDescription string
|
||||
SeoKeywords string
|
||||
PublishedAt string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
func NewArticleDao() *ArticleDao {
|
||||
return &ArticleDao{
|
||||
group: "default",
|
||||
table: "articles",
|
||||
columns: ArticleColumns{
|
||||
Id: "id",
|
||||
Title: "title",
|
||||
Slug: "slug",
|
||||
Summary: "summary",
|
||||
Content: "content",
|
||||
HtmlContent: "html_content",
|
||||
CoverImage: "cover_image",
|
||||
CategoryId: "category_id",
|
||||
Tags: "tags",
|
||||
AuthorId: "author_id",
|
||||
ViewCount: "view_count",
|
||||
LikeCount: "like_count",
|
||||
CommentCount: "comment_count",
|
||||
IsPublished: "is_published",
|
||||
IsFeatured: "is_featured",
|
||||
IsTop: "is_top",
|
||||
SeoTitle: "seo_title",
|
||||
SeoDescription: "seo_description",
|
||||
SeoKeywords: "seo_keywords",
|
||||
PublishedAt: "published_at",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *ArticleDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *ArticleDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *ArticleDao) Columns() ArticleColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *ArticleDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *ArticleDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// NewsDao 新闻数据访问对象
|
||||
type NewsDao struct {
|
||||
table string
|
||||
group string
|
||||
columns NewsColumns
|
||||
}
|
||||
|
||||
type NewsColumns struct {
|
||||
Id string
|
||||
Title string
|
||||
Slug string
|
||||
Summary string
|
||||
Content string
|
||||
CoverImage string
|
||||
Category string
|
||||
Source string
|
||||
Author string
|
||||
ViewCount string
|
||||
IsPublished string
|
||||
IsFeatured string
|
||||
IsTop string
|
||||
PublishedAt string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
func NewNewsDao() *NewsDao {
|
||||
return &NewsDao{
|
||||
group: "default",
|
||||
table: "news",
|
||||
columns: NewsColumns{
|
||||
Id: "id",
|
||||
Title: "title",
|
||||
Slug: "slug",
|
||||
Summary: "summary",
|
||||
Content: "content",
|
||||
CoverImage: "cover_image",
|
||||
Category: "category",
|
||||
Source: "source",
|
||||
Author: "author",
|
||||
ViewCount: "view_count",
|
||||
IsPublished: "is_published",
|
||||
IsFeatured: "is_featured",
|
||||
IsTop: "is_top",
|
||||
PublishedAt: "published_at",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *NewsDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *NewsDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *NewsDao) Columns() NewsColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *NewsDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *NewsDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// AttachmentDao 附件数据访问对象
|
||||
type AttachmentDao struct {
|
||||
table string
|
||||
group string
|
||||
columns AttachmentColumns
|
||||
}
|
||||
|
||||
type AttachmentColumns struct {
|
||||
Id string
|
||||
OriginalName string
|
||||
FileName string
|
||||
FilePath string
|
||||
FileUrl string
|
||||
FileSize string
|
||||
FileType string
|
||||
MimeType string
|
||||
FileExt string
|
||||
StorageType string
|
||||
UploadIp string
|
||||
UploadedBy string
|
||||
UsageCount string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
func NewAttachmentDao() *AttachmentDao {
|
||||
return &AttachmentDao{
|
||||
group: "default",
|
||||
table: "attachments",
|
||||
columns: AttachmentColumns{
|
||||
Id: "id",
|
||||
OriginalName: "original_name",
|
||||
FileName: "file_name",
|
||||
FilePath: "file_path",
|
||||
FileUrl: "file_url",
|
||||
FileSize: "file_size",
|
||||
FileType: "file_type",
|
||||
MimeType: "mime_type",
|
||||
FileExt: "file_ext",
|
||||
StorageType: "storage_type",
|
||||
UploadIp: "upload_ip",
|
||||
UploadedBy: "uploaded_by",
|
||||
UsageCount: "usage_count",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *AttachmentDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *AttachmentDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *AttachmentDao) Columns() AttachmentColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *AttachmentDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *AttachmentDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// PartnerDao 合作伙伴数据访问对象
|
||||
type PartnerDao struct {
|
||||
table string
|
||||
group string
|
||||
columns PartnerColumns
|
||||
}
|
||||
|
||||
type PartnerColumns struct {
|
||||
Id string
|
||||
Name string
|
||||
Logo string
|
||||
Website string
|
||||
Description string
|
||||
Category string
|
||||
SortOrder string
|
||||
IsFeatured string
|
||||
Status string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
func NewPartnerDao() *PartnerDao {
|
||||
return &PartnerDao{
|
||||
group: "default",
|
||||
table: "partners",
|
||||
columns: PartnerColumns{
|
||||
Id: "id",
|
||||
Name: "name",
|
||||
Logo: "logo",
|
||||
Website: "website",
|
||||
Description: "description",
|
||||
Category: "category",
|
||||
SortOrder: "sort_order",
|
||||
IsFeatured: "is_featured",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *PartnerDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *PartnerDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *PartnerDao) Columns() PartnerColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *PartnerDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *PartnerDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// ContactDao 联系我们数据访问对象
|
||||
type ContactDao struct {
|
||||
table string
|
||||
group string
|
||||
columns ContactColumns
|
||||
}
|
||||
|
||||
type ContactColumns struct {
|
||||
Id string
|
||||
Name string
|
||||
Email string
|
||||
Phone string
|
||||
Company string
|
||||
Subject string
|
||||
Message string
|
||||
Ip string
|
||||
UserAgent string
|
||||
Status string
|
||||
Reply string
|
||||
RepliedAt string
|
||||
RepliedBy string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
func NewContactDao() *ContactDao {
|
||||
return &ContactDao{
|
||||
group: "default",
|
||||
table: "contacts",
|
||||
columns: ContactColumns{
|
||||
Id: "id",
|
||||
Name: "name",
|
||||
Email: "email",
|
||||
Phone: "phone",
|
||||
Company: "company",
|
||||
Subject: "subject",
|
||||
Message: "message",
|
||||
Ip: "ip",
|
||||
UserAgent: "user_agent",
|
||||
Status: "status",
|
||||
Reply: "reply",
|
||||
RepliedAt: "replied_at",
|
||||
RepliedBy: "replied_by",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *ContactDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *ContactDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *ContactDao) Columns() ContactColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *ContactDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *ContactDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// ConfigDao 配置数据访问对象
|
||||
type ConfigDao struct {
|
||||
table string
|
||||
group string
|
||||
columns ConfigColumns
|
||||
}
|
||||
|
||||
type ConfigColumns struct {
|
||||
Id string
|
||||
ConfigKey string
|
||||
ConfigValue string
|
||||
ConfigType string
|
||||
GroupName string
|
||||
Description string
|
||||
SortOrder string
|
||||
IsSystem string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
func NewConfigDao() *ConfigDao {
|
||||
return &ConfigDao{
|
||||
group: "default",
|
||||
table: "site_configs",
|
||||
columns: ConfigColumns{
|
||||
Id: "id",
|
||||
ConfigKey: "config_key",
|
||||
ConfigValue: "config_value",
|
||||
ConfigType: "config_type",
|
||||
GroupName: "group_name",
|
||||
Description: "description",
|
||||
SortOrder: "sort_order",
|
||||
IsSystem: "is_system",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *ConfigDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
func (dao *ConfigDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
func (dao *ConfigDao) Columns() ConfigColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
func (dao *ConfigDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
func (dao *ConfigDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user