From 43c5f20ad7104a315c62d0c33e2b5248cc703975 Mon Sep 17 00:00:00 2001 From: guosl Date: Fri, 5 Jul 2024 19:24:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Erepo=E8=A1=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/repo/organization.go | 41 +++++++++++++++++ internal/repo/organization_role.go | 45 +++++++++++++++++++ internal/repo/organization_role_author.go | 43 ++++++++++++++++++ internal/repo/role.go | 41 +++++++++++++++++ internal/repo/role_menu_permission.go | 43 ++++++++++++++++++ internal/repo/user_organization.go | 43 ++++++++++++++++++ internal/service/organization/interface.go | 0 internal/service/organization/organization.go | 32 +++++++++++++ 8 files changed, 288 insertions(+) create mode 100644 internal/repo/organization.go create mode 100644 internal/repo/organization_role.go create mode 100644 internal/repo/organization_role_author.go create mode 100644 internal/repo/role.go create mode 100644 internal/repo/role_menu_permission.go create mode 100644 internal/repo/user_organization.go create mode 100644 internal/service/organization/interface.go create mode 100644 internal/service/organization/organization.go diff --git a/internal/repo/organization.go b/internal/repo/organization.go new file mode 100644 index 0000000..6f91f48 --- /dev/null +++ b/internal/repo/organization.go @@ -0,0 +1,41 @@ +// Code generated by sql2gorm. DO NOT EDIT. +package repo + +import ( + "time" + + "github.com/samber/do" + "gorm.io/gorm" +) + +// 组织表 +type Organization struct { + ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id + Name string `gorm:"column:name;NOT NULL"` // 组织名 + ParentID uint `gorm:"column:parent_id;default:0"` // 上级组织id + Sort uint `gorm:"column:sort;default:0"` // 层级序号 + Status int `gorm:"column:status;default:1"` // 状态:0-无效,1-有效 + Path string `gorm:"column:path"` // 全路径 + CreatedBy string `gorm:"column:created_by"` // 创建人 + CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 + ModifiedBy string `gorm:"column:modified_by"` // 修改人 + ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 +} + +func (m *Organization) TableName() string { + return "organization" +} + +type OrganizationRepo interface{ + +} + +type orginizationRepo struct{ + db *gorm.DB +} + +func NewOrganization(i *do.Injector)(OrganizationRepo,error){ + return &orginizationRepo{ + db:do.MustInvoke[*gorm.DB](i), + },nil +} \ No newline at end of file diff --git a/internal/repo/organization_role.go b/internal/repo/organization_role.go new file mode 100644 index 0000000..228786a --- /dev/null +++ b/internal/repo/organization_role.go @@ -0,0 +1,45 @@ +// Code generated by sql2gorm. DO NOT EDIT. +package repo + +import ( + "time" + + "github.com/samber/do" + "gorm.io/gorm" +) + + +func init(){ + do.Provide[UserOrganizationRepo](nil,NewUserOrganizationRepo) +} + +// 组织角色表 +type OrganizationRole struct { + ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id + OrgID uint `gorm:"column:org_id;NOT NULL"` // 组织id + RoleID uint `gorm:"column:role_id;NOT NULL"` // 角色id + CreatedBy string `gorm:"column:created_by"` // 创建人 + CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 + ModifiedBy string `gorm:"column:modified_by"` // 修改人 + ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 +} + +func (m *OrganizationRole) TableName() string { + return "organization_role" +} + + +type OrganizationRoleRepo interface{ + +} + +type organizationRoleRepo struct { + db *gorm.DB +} + +func NewOrganizationRoleRepo(i *do.Injector)(OrganizationRoleRepo,error){ + return &organizationRoleRepo{ + db:do.MustInvoke[*gorm.DB](i), + },nil +} + diff --git a/internal/repo/organization_role_author.go b/internal/repo/organization_role_author.go new file mode 100644 index 0000000..25e017a --- /dev/null +++ b/internal/repo/organization_role_author.go @@ -0,0 +1,43 @@ +// Code generated by sql2gorm. DO NOT EDIT. +package repo + +import ( + "time" + + "github.com/samber/do" + "gorm.io/gorm" +) + +func init(){ + do.Provide[OrganizationRoleAuthorRepo](nil,NewOrganizationRoleAuthorRepo) +} + +// 组织角色授权表 +type OrganizationRoleAuthor struct { + ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id + OrgID uint `gorm:"column:org_id;NOT NULL"` // 组织id + RoleID uint `gorm:"column:role_id;NOT NULL"` // 角色id + Option int `gorm:"column:option;default:0;NOT NULL"` // 选择:0-选择组织,1-选择组织含下级 + CreatedBy string `gorm:"column:created_by"` // 创建人 + CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 + ModifiedBy string `gorm:"column:modified_by"` // 修改人 + ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 +} + +func (m *OrganizationRoleAuthor) TableName() string { + return "organization_role_author" +} + +type OrganizationRoleAuthorRepo interface{ + +} + +type organizationRoleAuthorRepo struct{ + db *gorm.DB +} + +func NewOrganizationRoleAuthorRepo(i *do.Injector)(OrganizationRoleAuthorRepo,error){ + return &organizationRoleAuthorRepo{ + db:do.MustInvoke[*gorm.DB](i), + },nil +} \ No newline at end of file diff --git a/internal/repo/role.go b/internal/repo/role.go new file mode 100644 index 0000000..8d4e05a --- /dev/null +++ b/internal/repo/role.go @@ -0,0 +1,41 @@ +// Code generated by sql2gorm. DO NOT EDIT. +package repo + +import ( + "time" + + "github.com/samber/do" + "gorm.io/gorm" +) + +func init(){ + do.Provide[RoleRepo](nil,NewRoleRepo) +} + +// 表 +type Role struct { + ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id + Name string `gorm:"column:name;NOT NULL"` // 名称 + CreatedBy string `gorm:"column:created_by"` // 创建人 + CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 + ModifiedBy string `gorm:"column:modified_by"` // 修改人 + ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 +} + +func (m *Role) TableName() string { + return "role" +} + +type RoleRepo interface{ + +} + +type roleRepo struct{ + db *gorm.DB +} + +func NewRoleRepo(i *do.Injector)(RoleRepo,error){ + return &roleRepo{ + db :do.MustInvoke[*gorm.DB](i), + },nil +} \ No newline at end of file diff --git a/internal/repo/role_menu_permission.go b/internal/repo/role_menu_permission.go new file mode 100644 index 0000000..b488525 --- /dev/null +++ b/internal/repo/role_menu_permission.go @@ -0,0 +1,43 @@ +// Code generated by sql2gorm. DO NOT EDIT. +package repo + +import ( + "time" + + "github.com/samber/do" + "gorm.io/gorm" +) + +func init(){ + do.Provide[RoleMenuPermissionRepo](nil,NewRoleMenuPermissionRepo) +} + + +// 角色菜单权限表 +type RoleMenuPermission struct { + ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id + MenuID uint `gorm:"column:menu_id;NOT NULL"` // 菜单id + RoleID uint `gorm:"column:role_id;NOT NULL"` // 角色id + CreatedBy string `gorm:"column:created_by"` // 创建人 + CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 + ModifiedBy string `gorm:"column:modified_by"` // 修改人 + ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 +} + +func (m *RoleMenuPermission) TableName() string { + return "role_menu_permission" +} + +type RoleMenuPermissionRepo interface{ + +} + +type roleMenuPermissionRepo struct{ + db *gorm.DB +} + +func NewRoleMenuPermissionRepo(i *do.Injector)(RoleMenuPermissionRepo,error){ + return &roleMenuPermissionRepo{ + db:do.MustInvoke[*gorm.DB](i), + },nil +} \ No newline at end of file diff --git a/internal/repo/user_organization.go b/internal/repo/user_organization.go new file mode 100644 index 0000000..2c89b49 --- /dev/null +++ b/internal/repo/user_organization.go @@ -0,0 +1,43 @@ +// Code generated by sql2gorm. DO NOT EDIT. +package repo + +import ( + "time" + + "github.com/samber/do" + "gorm.io/gorm" +) + +func init(){ + do.Provide[UserOrganizationRepo](nil,NewUserOrganizationRepo) +} + +// 用户组织表 +type UserOrganization struct { + ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id + UserID uint `gorm:"column:user_id;NOT NULL"` // 用户id + OrgID uint `gorm:"column:org_id;NOT NULL"` // 组织id + Leader int `gorm:"column:leader;default:0"` // 是否是组织领导:一个组织只能有一个领导人 + CreatedBy string `gorm:"column:created_by"` // 创建人 + CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 + ModifiedBy string `gorm:"column:modified_by"` // 修改人 + ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 +} + +func (m *UserOrganization) TableName() string { + return "user_organization" +} + +type UserOrganizationRepo interface{ + +} + +type userOrganizationRepo struct{ + db *gorm.DB +} + +func NewUserOrganizationRepo(i *do.Injector)(UserOrganizationRepo,error){ + return &userOrganizationRepo{ + db:do.MustInvoke[*gorm.DB](i), + },nil +} \ No newline at end of file diff --git a/internal/service/organization/interface.go b/internal/service/organization/interface.go new file mode 100644 index 0000000..e69de29 diff --git a/internal/service/organization/organization.go b/internal/service/organization/organization.go new file mode 100644 index 0000000..7d95f36 --- /dev/null +++ b/internal/service/organization/organization.go @@ -0,0 +1,32 @@ +package organization + +import ( + "busniess-user-center/config" + "busniess-user-center/internal/repo" + "busniess-user-center/pkg/redis" + + "github.com/samber/do" + "go.uber.org/zap" +) + +func init() { + do.Provide(nil, NewOrganizationService) +} + +type organizationService struct { + logger *zap.SugaredLogger + appRepo repo.OrganizationRepo + menuRepo repo.MenuRepo + redis *redis.Redis + conf *config.AppConfig +} + +func NewOrganizationService(i *do.Injector) (OrganizationService, error) { + return &organizationService{ + logger: do.MustInvoke[*zap.SugaredLogger](i), + appRepo: do.MustInvoke[repo.OrganizationRepo](i), + menuRepo: do.MustInvoke[repo.MenuRepo](i), + redis: do.MustInvoke[*redis.Redis](i), + conf: do.MustInvoke[*config.AppConfig](i), + }, nil +}