Golang Web 前后端分离企业级后台开发项目计划书V2.0模型代码
Golang Web 前后端分离企业级后台开发项目计划书V2.0模型代码rbac.go代码packagemodelimport(timegorm.io/gorm)// User 用户表typeUserstruct{IDintgorm:primarykey;comment:用户IDUsernamestringgorm:type:varchar(50);uniqueIndex;not null;comment:用户名Passwordstringgorm:type:varchar(255);not null;comment:密码(加密存储) json:-Nicknamestringgorm:type:varchar(50);comment:昵称Emailstringgorm:type:varchar(100);uniqueIndex;comment:邮箱Mobilestringgorm:type:varchar(20);index;comment:手机号Statusint8gorm:default:1;comment:状态(1:启用 0:禁用)CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联角色多对多//Roles []Role gorm:many2many:user_role;comment:用户关联的角色Roles*[]Rolegorm:-Permissions*[]Permissiongorm:-Menus*[]Menugorm:-Departments*[]Departmentgorm:-Positions*[]Positiongorm:-}// TableName 指定用户表名func(User)TableName()string{returnsys_user}// Role 角色表typeRolestruct{IDintgorm:primarykey;comment:角色IDNamestringgorm:type:varchar(50);uniqueIndex;not null;comment:角色名称Codestringgorm:type:varchar(50);uniqueIndex;not null;comment:角色标识码Descriptionstringgorm:type:varchar(200);comment:角色描述Sortintgorm:default:0;comment:排序Statusint8gorm:default:1;comment:状态(1:启用 0:禁用)CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联用户多对多//Users []User gorm:many2many:sys_user_role;comment:拥有此角色的用户// 关联权限多对多//Permissions []Permission gorm:many2many:sys_role_permission;comment:角色拥有的权限// 关联菜单多对多//Menus []Menu gorm:many2many:sys_role_menu;comment:角色可见的菜单}// TableName 指定角色表名func(Role)TableName()string{returnsys_role}// Permission 权限表操作权限typePermissionstruct{IDintgorm:primarykey;comment:权限IDNamestringgorm:type:varchar(100);not null;comment:权限名称展示用Keystringgorm:type:varchar(100);uniqueIndex;not null;comment:权限标识如 user:createModulestringgorm:type:varchar(50);index;comment:所属模块用户管理、订单管理等Descriptionstringgorm:type:varchar(200);comment:权限描述CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联角色多对多//Roles []Role gorm:many2many:sys_role_permission;comment:拥有此权限的角色}// TableName 指定权限表名func(Permission)TableName()string{returnsys_permission}// Menu 菜单表前端导航菜单typeMenustruct{IDintgorm:primarykey;comment:菜单IDNamestringgorm:type:varchar(50);not null;comment:菜单名称Pathstringgorm:type:varchar(100);comment:前端路由路径Componentstringgorm:type:varchar(100);comment:前端组件路径ParentIDuintgorm:default:0;comment:父菜单ID0表示根菜单Sortintgorm:default:0;comment:同级排序Iconstringgorm:type:varchar(50);comment:菜单图标IsHiddenboolgorm:default:false;comment:是否隐藏不在侧边栏显示CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联角色多对多//Roles []Role gorm:many2many:sys_role_menu;comment:可见此菜单的角色}// TableName 指定菜单表名func(Menu)TableName()string{returnsys_menu}// 多对多中间表 // UserRole 用户-角色关联表typeUserRolestruct{UserIDintgorm:primaryKey;autoIncrement:false;comment:用户IDRoleIDintgorm:primaryKey;autoIncrement:false;comment:角色ID}// TableName 指定关联表名func(UserRole)TableName()string{returnsys_user_role}// RolePermission 角色-权限关联表typeRolePermissionstruct{RoleIDintgorm:primaryKey;autoIncrement:false;comment:角色IDPermissionIDintgorm:primaryKey;autoIncrement:false;comment:权限ID}// TableName 指定关联表名func(RolePermission)TableName()string{returnsys_role_permission}// RoleMenu 角色-菜单关联表typeRoleMenustruct{RoleIDintgorm:primaryKey;autoIncrement:false;comment:角色IDMenuIDintgorm:primaryKey;autoIncrement:false;comment:菜单ID}// TableName 指定关联表名func(RoleMenu)TableName()string{returnsys_role_menu}system.go代码packagemodelimport(timegorm.io/gorm)// 注册记录表 // Registration 用户注册记录表typeRegistrationstruct{IDint64gorm:primarykey;comment:注册记录IDUsernamestringgorm:type:varchar(50);not null;comment:注册用户名Passwordstringgorm:type:varchar(255);not null;comment:注册密码(加密)Emailstringgorm:type:varchar(100);comment:注册邮箱Mobilestringgorm:type:varchar(20);comment:注册手机号RegisterTypestringgorm:type:varchar(20);not null;default:normal;comment:注册类型(normal:普通用户 admin:管理员用户)Statusint8gorm:default:0;comment:审核状态(0:待审核 1:审核通过 2:审核拒绝)ReviewRemarkstringgorm:type:varchar(200);comment:审核备注ReviewedByuintgorm:default:0;comment:审核人IDReviewedAt*time.Timecomment:审核时间IPstringgorm:type:varchar(50);comment:注册IPUserAgentstringgorm:type:varchar(500);comment:注册设备信息CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间}func(Registration)TableName()string{returnsys_registration}// 部门管理 // Department 部门表typeDepartmentstruct{IDuintgorm:primarykey;comment:部门IDNamestringgorm:type:varchar(50);not null;comment:部门名称Codestringgorm:type:varchar(50);uniqueIndex;comment:部门编码ParentIDuintgorm:default:0;comment:父部门IDLeaderstringgorm:type:varchar(50);comment:负责人Phonestringgorm:type:varchar(20);comment:联系电话Emailstringgorm:type:varchar(100);comment:邮箱Sortintgorm:default:0;comment:排序Statusint8gorm:default:1;comment:状态(1:启用 0:禁用)CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联用户多对多//Users []User gorm:many2many:sys_user_department;comment:部门下的用户}func(Department)TableName()string{returnsys_department}// UserDepartment 用户-部门关联表多对多typeUserDepartmentstruct{UserIDintgorm:primaryKey;autoIncrement:false;comment:用户IDDepartmentIDuintgorm:primaryKey;autoIncrement:false;comment:部门ID}func(UserDepartment)TableName()string{returnsys_user_department}// 岗位管理 // Position 岗位表typePositionstruct{IDuintgorm:primarykey;comment:岗位IDNamestringgorm:type:varchar(50);not null;comment:岗位名称Codestringgorm:type:varchar(50);uniqueIndex;comment:岗位编码Sortintgorm:default:0;comment:排序Statusint8gorm:default:1;comment:状态(1:启用 0:禁用)Remarkstringgorm:type:varchar(200);comment:备注CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联用户多对多//Users []User gorm:many2many:sys_user_position;comment:岗位下的用户}func(Position)TableName()string{returnsys_position}// UserPosition 用户-岗位关联表多对多typeUserPositionstruct{UserIDintgorm:primaryKey;autoIncrement:false;comment:用户IDPositionIDuintgorm:primaryKey;autoIncrement:false;comment:岗位ID}func(UserPosition)TableName()string{returnsys_user_position}// 字典管理 // DictType 字典类型表typeDictTypestruct{IDuintgorm:primarykey;comment:字典类型IDNamestringgorm:type:varchar(50);not null;comment:字典类型名称Typestringgorm:type:varchar(50);uniqueIndex;not null;comment:字典类型标识如 sys_user_statusStatusint8gorm:default:1;comment:状态(1:启用 0:禁用)Remarkstringgorm:type:varchar(200);comment:备注CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联字典数据//DictData []DictData gorm:foreignKey:DictTypeID}func(DictType)TableName()string{returnsys_dict_type}// DictData 字典数据表typeDictDatastruct{IDintgorm:primarykey;comment:字典数据IDDictTypeIDuintgorm:index;not null;comment:字典类型IDLabelstringgorm:type:varchar(50);not null;comment:字典标签展示值Valuestringgorm:type:varchar(50);not null;comment:字典键值存储值Sortintgorm:default:0;comment:排序Statusint8gorm:default:1;comment:状态(1:启用 0:禁用)Remarkstringgorm:type:varchar(200);comment:备注CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联字典类型//DictType DictType gorm:foreignKey:DictTypeID}func(DictData)TableName()string{returnsys_dict_data}// 参数管理 // Config 参数配置表typeConfigstruct{IDintgorm:primarykey;comment:参数IDNamestringgorm:type:varchar(100);not null;comment:参数名称Keystringgorm:type:varchar(100);uniqueIndex;not null;comment:参数键名如 system.log.levelValuestringgorm:type:text;comment:参数键值Typestringgorm:type:varchar(20);default:string;comment:参数类型(string/int/bool/array)IsSystemint8gorm:default:0;comment:是否系统内置(1:是 0:否)Remarkstringgorm:type:varchar(200);comment:备注CreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间}func(Config)TableName()string{returnsys_config}// 通知公告 // Notice 通知公告表typeNoticestruct{IDintgorm:primarykey;comment:公告IDTitlestringgorm:type:varchar(100);not null;comment:公告标题Contentstringgorm:type:text;comment:公告内容Typestringgorm:type:varchar(20);default:notice;comment:类型(notice:通知 announcement:公告)Prioritystringgorm:type:varchar(10);default:normal;comment:优先级(high/normal/low)Statusint8gorm:default:1;comment:状态(1:发布 0:草稿)PublishTime*time.Timecomment:发布时间为空则立即发布ExpireTime*time.Timecomment:过期时间CreatedByuintgorm:comment:创建人IDCreatedAt time.Timecomment:创建时间UpdatedAt time.Timecomment:更新时间DeletedAt gorm.DeletedAtgorm:index;comment:软删除时间// 关联已读记录//ReadRecords []NoticeRead gorm:foreignKey:NoticeID}func(Notice)TableName()string{returnsys_notice}// NoticeRead 公告已读记录表typeNoticeReadstruct{IDint64gorm:primarykey;comment:记录IDNoticeIDintgorm:index;not null;comment:公告IDUserIDintgorm:index;not null;comment:用户IDReadTime time.Timegorm:comment:阅读时间CreatedAt time.Timecomment:创建时间}func(NoticeRead)TableName()string{returnsys_notice_read}// 操作日志 // OperationLog 操作日志记录表typeOperationLogstruct{IDint64gorm:primarykey;comment:日志IDUserIDuintgorm:index;comment:操作用户IDUsernamestringgorm:type:varchar(50);comment:操作用户名Modulestringgorm:type:varchar(50);comment:操作模块Operationstringgorm:type:varchar(50);comment:操作类型如 create/update/delete/exportMethodstringgorm:type:varchar(10);comment:请求方法(GET/POST/PUT/DELETE)URLstringgorm:type:varchar(500);comment:请求URLParamsstringgorm:type:text;comment:请求参数Resultstringgorm:type:text;comment:返回结果Durationint64gorm:comment:执行耗时(毫秒)IPstringgorm:type:varchar(50);comment:操作IPUserAgentstringgorm:type:varchar(500);comment:用户代理Statusint8gorm:default:1;comment:操作状态(1:成功 0:失败)ErrorMsgstringgorm:type:text;comment:错误信息CreatedAt time.Timegorm:index;comment:创建时间}func(OperationLog)TableName()string{returnsys_operation_log}// 登录日志 // LoginLog 登录日志表系统访问记录typeLoginLogstruct{IDint64gorm:primarykey;comment:日志IDUserIDuintgorm:index;comment:登录用户ID可能为0表示未注册或未知Usernamestringgorm:type:varchar(50);comment:登录用户名LoginTypestringgorm:type:varchar(20);default:normal;comment:登录类型(normal:普通登录 sms:短信登录 qr:扫码等)Statusint8gorm:default:1;comment:登录状态(1:成功 0:失败)ErrorMsgstringgorm:type:varchar(200);comment:失败原因IPstringgorm:type:varchar(50);index;comment:登录IPLocationstringgorm:type:varchar(100);comment:登录地点(根据IP解析)UserAgentstringgorm:type:varchar(500);comment:设备信息LoginTime time.Timegorm:index;comment:登录时间LogoutTime*time.Timecomment:登出时间如果记录}func(LoginLog)TableName()string{returnsys_login_log}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2508054.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!