100 lines
4.8 KiB
Go
100 lines
4.8 KiB
Go
|
|
package hr
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"WiiGoLibrary/framework/db/v1/utils/mssql/unique"
|
|||
|
|
"WiiGoLibrary/framework/hub/v1/dblib"
|
|||
|
|
"time"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
const PermissionTable = "hr_u_permission"
|
|||
|
|
const PositionPermissionTable = "hr_r_position_permission"
|
|||
|
|
|
|||
|
|
// 权限类型常量
|
|||
|
|
const (
|
|||
|
|
// 组织管理权限
|
|||
|
|
PermOrganizationView = 1001 // 组织查看权限
|
|||
|
|
PermOrganizationCreate = 1002 // 组织创建权限
|
|||
|
|
PermOrganizationUpdate = 1003 // 组织更新权限
|
|||
|
|
PermOrganizationDelete = 1004 // 组织删除权限
|
|||
|
|
|
|||
|
|
// 岗位管理权限
|
|||
|
|
PermPositionView = 2001 // 岗位查看权限
|
|||
|
|
PermPositionCreate = 2002 // 岗位创建权限
|
|||
|
|
PermPositionUpdate = 2003 // 岗位更新权限
|
|||
|
|
PermPositionDelete = 2004 // 岗位删除权限
|
|||
|
|
|
|||
|
|
// 人员管理权限
|
|||
|
|
PermStaffView = 3001 // 人员查看权限
|
|||
|
|
PermStaffCreate = 3002 // 人员创建权限
|
|||
|
|
PermStaffUpdate = 3003 // 人员更新权限
|
|||
|
|
PermStaffDelete = 3004 // 人员删除权限
|
|||
|
|
|
|||
|
|
// 请假审批权限
|
|||
|
|
PermLeaveApprove = 4001 // 请假审批权限
|
|||
|
|
PermLeaveView = 4002 // 请假查看权限
|
|||
|
|
|
|||
|
|
// 工作流管理权限
|
|||
|
|
PermWorkflowAdmin = 5001 // 工作流管理权限
|
|||
|
|
|
|||
|
|
// 系统管理权限
|
|||
|
|
PermSystemAdmin = 9999 // 系统管理员权限
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// PermissionModel 权限模型
|
|||
|
|
type PermissionModel struct {
|
|||
|
|
RecordGuid unique.UUID `gorm:"column:RecordGuid;type:UNIQUEIDENTIFIER;primaryKey;not null;default:newid();" json:"RecordGuid"`
|
|||
|
|
PermissionID int `gorm:"column:PermissionID;type:INT;not null;uniqueIndex;" json:"PermissionID"` // 权限ID
|
|||
|
|
PermissionName string `gorm:"column:PermissionName;type:NVARCHAR(50);not null;" json:"PermissionName"` // 权限名称
|
|||
|
|
PermissionCode string `gorm:"column:PermissionCode;type:NVARCHAR(50);not null;uniqueIndex;" json:"PermissionCode"` // 权限代码
|
|||
|
|
Description string `gorm:"column:Description;type:NVARCHAR(200);" json:"Description"` // 权限描述
|
|||
|
|
Category int16 `gorm:"column:Category;type:SMALLINT;not null;default:0;" json:"Category"` // 权限分类
|
|||
|
|
RecordType int16 `gorm:"column:RecordType;not null;" json:"RecordType"` // 记录类型
|
|||
|
|
RecordStatus int16 `gorm:"column:RecordStatus;not null;default:0;" json:"RecordStatus"` // 记录状态
|
|||
|
|
CreateTime time.Time `gorm:"column:CreateTime;type:DATETIME;default:CURRENT_TIMESTAMP;<-:create;" json:"CreateTime"`
|
|||
|
|
UpdateTime time.Time `gorm:"column:UpdateTime;type:DATETIME;default:CURRENT_TIMESTAMP;autoUpdateTime;" json:"UpdateTime"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// PositionPermissionModel 岗位权限关系模型
|
|||
|
|
type PositionPermissionModel struct {
|
|||
|
|
RecordGuid unique.UUID `gorm:"column:RecordGuid;type:UNIQUEIDENTIFIER;primaryKey;not null;default:newid();" json:"RecordGuid"`
|
|||
|
|
PositionGuid unique.UUID `gorm:"column:PositionGuid;type:UNIQUEIDENTIFIER;index:idx_position_perm,priority:1;not null;" json:"PositionGuid"` // 岗位GUID
|
|||
|
|
PermissionGuid unique.UUID `gorm:"column:PermissionGuid;type:UNIQUEIDENTIFIER;index:idx_position_perm,priority:2;not null;" json:"PermissionGuid"` // 权限GUID
|
|||
|
|
PositionID int64 `gorm:"column:PositionID;type:BIGINT;not null;" json:"PositionID"` // 岗位ID
|
|||
|
|
PermissionID int `gorm:"column:PermissionID;type:INT;not null;" json:"PermissionID"` // 权限ID
|
|||
|
|
GrantType int16 `gorm:"column:GrantType;type:SMALLINT;not null;default:0;" json:"GrantType"` // 授权类型:0-直接授权,1-继承授权
|
|||
|
|
RecordType int16 `gorm:"column:RecordType;not null;" json:"RecordType"` // 记录类型
|
|||
|
|
RecordStatus int16 `gorm:"column:RecordStatus;not null;default:0;" json:"RecordStatus"` // 记录状态
|
|||
|
|
CreateTime time.Time `gorm:"column:CreateTime;type:DATETIME;default:CURRENT_TIMESTAMP;<-:create;" json:"CreateTime"`
|
|||
|
|
UpdateTime time.Time `gorm:"column:UpdateTime;type:DATETIME;default:CURRENT_TIMESTAMP;autoUpdateTime;" json:"UpdateTime"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func init() {
|
|||
|
|
dblib.DBIns.RegisterAutoMigrateModel(&PermissionModel{})
|
|||
|
|
dblib.DBIns.RegisterAutoMigrateModel(&PositionPermissionModel{})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (p *PermissionModel) TableName() string {
|
|||
|
|
return PermissionTable
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (pp *PositionPermissionModel) TableName() string {
|
|||
|
|
return PositionPermissionTable
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func PermissionInstance() *PermissionModel {
|
|||
|
|
return &PermissionModel{
|
|||
|
|
RecordGuid: unique.NewV4(),
|
|||
|
|
RecordType: 0,
|
|||
|
|
RecordStatus: 0,
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func PositionPermissionInstance() *PositionPermissionModel {
|
|||
|
|
return &PositionPermissionModel{
|
|||
|
|
RecordGuid: unique.NewV4(),
|
|||
|
|
GrantType: 0,
|
|||
|
|
RecordType: 0,
|
|||
|
|
RecordStatus: 0,
|
|||
|
|
}
|
|||
|
|
}
|